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/)
-   -   Please check out my UDF code (https://www.cfd-online.com/Forums/fluent-udf/89289-please-check-out-my-udf-code.html)

aleisia June 8, 2011 20:25

Please check out my UDF code
 
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("flow-time");
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


johnwinter June 9, 2011 02:10

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".

aleisia June 9, 2011 13:34

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:

Originally Posted by johnwinter (Post 311183)
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".


johnwinter June 10, 2011 04:02

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.


All times are GMT -4. The time now is 17:35.