August 31, 2023 at 12:25 am
Thanks for the reply.
This is the code I tested:
Calculate the average velocity at outlet and print it.
Thread *t, *t_f;
real V, sum = 0., sum_V = 0.;
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);
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.