What's wrong with my UDF?
Hi all,
This is my code and I'm trying to calculate the value of w by UDF. The value of w is related to the angle at which the fluid impacts the wall. So I loop through the cells first, then loop the faces inside the cells. Finally, I hope that I can save the value of w to the data so that I can see the distribution of w from the contour. But my UDF doesn't work, I don't know what' wrong with it. Thanks very much if you can give me some suggestions. #include "udf.h" #include "math.h" #include "metric.h" #include "mem.h" DEFINE_ON_DEMAND(on_demand_w) { real w; int n; real densic=3200; real c; real alpha; real A[ND_ND]; real vel[3]; real velm; real Am; real cos; real velx; real vely; real velz; real qm; Domain *d; Thread *t; cell_t c0; face_t f; d=Get_Domain(1); c=sqrt(3*480*1000000/densic); thread_loop_c(t,d) { c0=F_C0(f,t); begin_c_loop(c0,t) { real denmix=C_R(c0,t); c_face_loop(c0,t,n) { velx=F_U(f,t); vely=F_V(f,t); velz=F_W(f,t); vel[1]=velx; vel[2]=vely; vel[3]=velz; qm=velx*denmix*3.1416*0.0045*0.0045; F_AREA(A,f,t); velm=NV_MAG(vel); Am=NV_MAG(A); cos=NV_DOT(vel,A)/velm/Am; alpha=asin(cos)*180/3.1416; w=7/3.1416*qm/denmix*pow((velm/c),2.5)*sin(2*alpha)*sin(alpha); C_UDMI(c0,t,0)=w; fprintf("out_w:%g\n",w); } } end_c_loop(c0,t) } } 
Code:
#include "udf.h" I cannot really figure out what you are trying to do, but probably you forgot to loop over all faces or something like that. Your compiler should have complained that something is wrong in this line. Always check compiler errors, especially if you have a problem with compiling! 
And some suggestions to improve your code:
Quote:
Quote:
Code:
vel[1]=F_U(f,t); Quote:
Code:
alpha=asin(cos); 
Quote:

All times are GMT 4. The time now is 12:30. 