August 31, 2023 at 12:25 am
Subscriber
Hi,
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 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 with C_U_M2(c,t) (or any other _M2 macros) it encounters the segmentation error.