-
-
August 29, 2023 at 7:54 pm
Silversea
SubscriberHi,
I wrote a simple UDF to get the previous time step values in a transient model in Ansys Fluent V2022. It worked fine when I used current time macros, e.g., C_R(c,t) or previous time step macros, e.g., C_R_M1(c,t). However, when I tried to get the second previous time step macros, no matter which one, e.g., C_R_M2(c,t), C_U_M2(c,t), or C_T_M2(c,t), I always get Segmentation fault error.
Does fluent store the second previous time step values by default?
Should I do something in fluent before accessing the second previous time step (_M2) macros?
Â
-
August 30, 2023 at 12:56 pm
Atharva Nagarkar
Ansys EmployeeHello,
A segementation error is usually related to incorrect allocation of memory or errors in writing the UDF.
Can you please share your UDF?
Thanks!
-
August 31, 2023 at 12:25 am
Silversea
SubscriberHi,Â
Thanks for the reply.
This is the code I tested:
======================================================================
/*Calculate the average velocity at outlet and print it.*/Â#include "udf.h"ÂDEFINE_EXECUTE_AT_END(pre_time){Domain *d;Thread *t, *t_f;cell_t c;face_t f;real V, sum = 0., sum_V = 0.;real ave;int zone_ID = 7; // outlet IDÂd = Get_Domain(1);Ât_f = Lookup_Thread(d,zone_ID);begin_f_loop(f,t_f){t = THREAD_T0(t_f); // get cell threadc = F_C0(f,t_f); // get corresponding cellV = C_VOLUME(c,t);sum_V += V;sum += V*C_U_M2(c,t);}end_f_loop(f,t_f)ÂÂave = PRF_GRSUM1(sum/sum_V);Âif I_AM_NODE_ZERO_P{Message("ave = %g\n",ave);}}======================================================================ÂIt is a simple code that calculates and prints the average velocity at a boundary. I used it on both 2D and 3D models (very simple models such as 2D laminar flow in a pipe).First, I run the model for a few time steps, e.g. time steps =10. Then I apply the UDF, and continue the simulation.ÂWhen I change the line "sum += V*C_U_M2(c,t);" to  "sum += V*C_U_M1(c,t);" or "sum += V*C_U(c,t);" it perfectly works without error and prints the average velocity. But with C_U_M2(c,t) (or any other _M2 macros) it encounters the segmentation error. -
September 1, 2023 at 6:25 pm
Silversea
SubscriberUpdate:
I tried it on older versions of Ansys, such as 18 and 19, with the same outcome.
Â
I also used THREAD_STORAGE(t, SV_...))) to test whether the memory has already been allocated as follows:
if (THREAD_STORAGE(t,SV_U_M2) == NULL)
{
  Error("error THREAD_STORAGE SV_U_M2");
}and it produced the error. So, it means that memory is not allocated for this macro.
Â
A question, Am I the only one that gets this problem? Would somebody please confirm that any _M2 macros work?
Â
-
September 14, 2023 at 6:42 pm
Selawe97
SubscriberÂ
Hello
I am getting the same problem also, But i read in the documentaion that data from C_T_M1 is available only if user-defined scalars are defined. and i did not understand what that mea!
Â
-
September 15, 2023 at 9:33 am
Rob
Forum ModeratorIt means you'll need some scalars (look in User Defined tab in the solver). They're extra scalar fields we can use to solve "stuff" as required.Â
-
- The topic ‘second previous time step error’ is closed to new replies.
-
3492
-
1057
-
1051
-
965
-
942
© 2025 Copyright ANSYS, Inc. All rights reserved.