
[Sponsors] 
September 8, 2019, 22:39 
What's wrong with my UDF?

#1 
New Member
刘宵
Join Date: Aug 2019
Posts: 4
Rep Power: 3 
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) } } 

September 9, 2019, 15:41 

#2 
Senior Member
Join Date: Nov 2013
Posts: 1,781
Rep Power: 22 
Code:
#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); .. (rest of code removed because the first problem is here) 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! 

September 9, 2019, 15:47 

#3  
Senior Member
Join Date: Nov 2013
Posts: 1,781
Rep Power: 22 
And some suggestions to improve your code:
You should have declared this variable higher up, at least in the default dialect of c that Fluent uses. Quote:
Code:
vel[1]=F_U(f,t); vel[2]=F_V(f,t); vel[3]=F_W(f,t); Quote:
Code:
alpha=asin(cos); w=7/3.1416*qm/denmix*pow((velm/c),2.5)*sin(2*alpha)*sin(alpha); 

September 9, 2019, 21:09 

#4  
New Member
刘宵
Join Date: Aug 2019
Posts: 4
Rep Power: 3 
Quote:


Tags 
udf code 
Thread Tools  Search this Thread 
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
can anyone help me about the udf of dynamic contact angle in FLUENT?  Albert Lee  FLUENT  0  July 1, 2018 08:21 
Dynamic Mesh UDF  Qureshi  FLUENT  7  March 23, 2017 07:37 
whats wrong with this udf ?  h.mortezaee  Fluent UDF and Scheme Programming  3  September 14, 2015 07:32 
something wrong when compiling udf, however the code is correct when interpreting  richard ben  Fluent UDF and Scheme Programming  7  May 11, 2013 07:36 
what's wrong with the UDF  major  FLUENT  6  March 3, 2005 06:39 