
[Sponsors] 
June 8, 2011, 20:25 
Please check out my UDF code

#1 
Member
Join Date: Mar 2011
Posts: 38
Rep Power: 8 
Hi! I want to model a filter (but not modeling it as a porous media), in a room I have SO2 and air mixture. First I want to get the SO2 mass flow rate at the inlet surface of the filter, then multiply it by 0.999989, and set the sink rate of the filter volume as 0.999989*(SO2 mass flow rate at the inlet surface)/(Volume of filter). For the outlet of the filter, I set it as "interior", and my simulation is always transient.
Below is my code, please advise. #include "udf.h" DEFINE_SOURCE(cell_SO2mass_source,cell,thread,dS,e qn) { real x[ND_ND]; real source, t, massflowrate, volume, vol_tot; real ti = RP_Get_Real("flowtime"); real NV_VEC(flux), NV_VEC(A); /* declaring vectors flux and A */ face_t face, f Cell_t cell Thread *thread C_CENTROID(x,cell,thread); x=x[0]; /*****给出每个单元的x坐标*******/ y=x[1]; /*****给出每个单元的y坐标*******/ z=x[2]; /*****给出每个单元的z坐标*******/ d = Get_Domain(1); t= Lookup_Thread(d, 12); /* defining the inlet surface thread by specifying the Zone_ID*/ begin_f_loop(f,t) { NV_D(flux, =, F_U(f,t), F_V(f,t), F_W(f,t)); /* defining flux in terms of velocity field */ NV_S(flux, *=, F_R(f,t)) /* multiplying density to get flux vector */ F_AREA(A,f,t) /* face normal vector returned from F_AREA */ massflowrate+= F_YI(f,t,i)*NV_DOT(flux,A); /* dot product of the inlet surface flux and area vector*/ /* multiplied by the mass fraction of species i */ } end_f_loop(f,t) massflowrate= PRF_GRSUM1(massflowrate); begin_c_loop(cell,thread) { volume = C_VOLUME(cell,thread); /* get cell volume */ vol_tot += volume; } end_c_loop(cell,thread) vol_tot = PRF_GRSUM1(vol_tot); source=0.999989* massflowrate/vol_tot; dS[eqn]=0.0; return source; } I actually have 2 question: 1. is "f" the inlet surface corresponding to the "t" that I set? "t" is the thread corresponding to inlet surface. 2. is C_CENTROID necessary in this case? 3. someone says "cell_t cell" is wrong, only "cell_t c" is correct, but why? Thanks Last edited by aleisia; June 9, 2011 at 00:18. 

June 9, 2011, 02:10 

#2 
Member
john
Join Date: Nov 2010
Posts: 50
Rep Power: 9 
Hi,
I may not fully answer you. From your udf i understood that you don't need x[ND_ND], you didn't use it anywhere in the code. So don't define it. i fell C_CENTROID not necessary. cell_t cell is there you can use it but DEFINE_SOURCE already calling all cells. So, don't define cell_t at all. Yes, you are calling inlet face "f". 

June 9, 2011, 13:34 

#3  
Member
Join Date: Mar 2011
Posts: 38
Rep Power: 8 
Hi! Thanks for the reply and I agree with you.
How about Thread *thread? I guess I don't need to define thread either, because I already called it in the DEFINE_SOURCE How about the way that I defined the mass flow rate, using dot product? Is that OK? or I can use F_FLUX*F_AREA*F_YI? Quote:


June 10, 2011, 04:02 

#4 
Member
john
Join Date: Nov 2010
Posts: 50
Rep Power: 9 
Yes, you don't need to define thread also.
It seems to me that massflowrate+= F_YI(f,t,i)*NV_DOT(flux,A); is ok. 

Thread Tools  
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
Convergence check in UDF  mittal  Fluent UDF and Scheme Programming  0  January 22, 2011 23:21 
Request for UDF code for forced vibrations  jagadeesh putta  FLUENT  0  November 21, 2007 22:43 
Check UDF  stephen e  FLUENT  1  April 15, 2004 09:51 
Design Integration with CFD?  John C. Chien  Main CFD Forum  19  May 17, 2001 15:56 
UDF Scalar Code: HT 1  Greg Perkins  FLUENT  8  October 20, 2000 12:40 