CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   UDF Output zero? (https://www.cfd-online.com/Forums/fluent-udf/99003-udf-output-zero.html)

wanghaojie March 23, 2012 10:00

UDF Output zero?
 
Hi all,

I try to save the flow rate on a plane and velocity at another plane here is the udf I used. But the flow rate on the plane output is zero and i further check the velocity on the plane is also zero
Can you guys help me check what the problem is?
I think the thread id is correct.
Can it be the numerical type problem?

#include "udf.h"
#define ID1 10036 /*Window ID*/
#define ID2 10028 /*Horizontal Plane ID*/
DEFINE_EXECUTE_AT_END(SaveData)
{
Domain *d;
FILE *fp;
face_t f;
real A[2];
real x[ND_ND],z;
Thread *t,*t0,*t1;
real incid;
real u=0,v=0,v_door=0,VentRate=0,time=0;
cell_t c0, c1;
/*Ventilation Rate*/
fp = fopen("VentRate.csv","a+");
d = Get_Domain(1);
t = Lookup_Thread (d, ID1);
begin_f_loop(f, t)
{
F_AREA(A,f,t);
c0 = F_C0(f,t);
t0 = THREAD_T0(t);
c1 = F_C1(f,t); /* Get cell on other side of face */
t1 = THREAD_T1(t);
v_door= 0.5*(C_V(c0,t0)+C_V(c1,t1));/*Average the velocity before and after the door)*/
VentRate=0.5*fabs(A[1]*v_door)+VentRate;
printf ("%f\n",time, v_door);
fprintf (fp, "%f\n",time, v_door);
}
end_f_loop(f, t)
time=CURRENT_TIME;
fprintf (fp, "%f,%f\n",time, VentRate);
fclose(fp);
/*Horizontal Velocity*/
fp = fopen("H.csv","a+");
time=CURRENT_TIME;
fprintf (fp, "%f\n",time);
d = Get_Domain(1);
t = Lookup_Thread (d, ID2);
begin_f_loop(f, t)
{
F_CENTROID(x,f,t);
c0 = F_C0(f,t);
t0 = THREAD_T0(t);
c1 = F_C1(f,t); /* Get cell on other side of face */
t1 = THREAD_T1(t);
u= 0.5*(C_U(c0,t0)+C_U(c1,t1));
v= 0.5*(C_V(c0,t0)+C_V(c1,t1));
t0 = THREAD_T0(t);
c1 = F_C1(f,t); /* Get cell on other side of face */
t1 = THREAD_T1(t);
fprintf (fp, "%f,%f,%f,%f,%f\n",x[0],x[1],x[2],u,v);
}
end_f_loop(f, t)
}

wanghaojie March 23, 2012 10:03

Also, I think the fprintf in the loop function wont work at all. I cannot get anything in the output file, but fprintf outside the loop function can give an output...

wanghaojie March 23, 2012 10:27

So now after i changed %f to %g, i am able to use printf and get real results in the fluent, but still cant use fprintf to save the data


All times are GMT -4. The time now is 21:53.