Topics relate to Fluent, CFX, Turbogrid and more

second previous time step error

    • Silversea


      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?


    • Atharva Nagarkar


      A segementation error is usually related to incorrect allocation of memory or errors in writing the UDF.

      Can you please share your UDF?


    • Silversea


      Thanks for the reply.

      This is the code I tested:


      Calculate the average velocity at outlet and print it.
      #include "udf.h"
      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);
      t = THREAD_T0(t_f); // get cell thread
      c = F_C0(f,t_f); // get corresponding cell
      V = C_VOLUME(c,t);
      sum_V += V;
      sum += V*C_U_M2(c,t);
      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. 
    • Silversea


      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?


    • Selawe97



      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!


    • Rob
      Ansys Employee

      It 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. 

Viewing 5 reply threads
  • You must be logged in to reply to this topic.