CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   second previous time step Segmentation error (https://www.cfd-online.com/Forums/fluent/251622-second-previous-time-step-segmentation-error.html)

silversea12 August 29, 2023 15:26

second previous time step Segmentation error
 
Hi,

I tried to get previous time step values in a UDF, but every time I call a 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 get Segmentation fault error.


================================================== ============================

Node 0: Process 11500: Received signal SIGSEGV.

================================================== ============================
The fl process could not be started.


It doesn't happen for the first ones (previous time step, _M1 macros). The _M1 macros work good.

Should I do something in Fluent before using the second previous time step macros (_M2)?
Does Fluent store these second previous time step values by default?
Any suggestion?

LuckyTran August 29, 2023 20:39

Make sure you've actually stepped forward before trying to call M2. There is no M2 field in the first time-step.

silversea12 August 29, 2023 23:17

I don't think that is the problem. I tested it with the if condition and N_TIME (number of time steps) and also by first getting some time steps run and then activating the macro. But every time it runs the _M2 macros, it encounters the segmentation fault. As I mentioned before, there isn't any problem with _M1 macros, even at the beginning time step.

I use Ansys V2022; maybe this is a change in newer versions of Ansys. Or, something should be activated first in order for Fluent to store these second previous time steps.

Have you tested to get results from the _M2 macros?
I am wondering if it is just me or if it has happened to other people too. I searched, but I couldn't find anything about this.

LuckyTran August 29, 2023 23:28

If you truly did multiple time-steps and M1 works but not M2, then the error is in your UDF and not the M2 macro

More specifically, C_T_M1 is the most restrictive of the allowed macros. If C_T_M1 works then there rest should work unless you call a disallowed one like C_uranus_M1. So you are confirming that C_T_M1 works but not C_T_M2?

The macros have not changed in a decade. It's not your Fluent version.

silversea12 August 30, 2023 20:34

Thanks for the reply.

This is the code I tested:
================================================== ====================
/*
Calculate the average velocity at the 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 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);
}
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 it encounters the segmentation error with C_U_M2(c,t) (or any other _M2 macros).

Update: I tested this UDF with older versions of Ansys, such as V19 and V18. It leads to the same outcome.

silversea12 September 1, 2023 14:27

Update:

I used THREAD_STORAGE(t, SV_...))) in the UDF 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.


Am I the only one that gets this problem with _M2 macros?
Would somebody please confirm that any _M2 macros work for them?


All times are GMT -4. The time now is 16:07.