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

aleisia June 9, 2011 16:57

Please check out my parallelized udf
 
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.

Parallelized udf



#include "udf.h"
DEFINE_SOURCE(cell_SO2mass_source,cell,thread,dS,e qn)
{

#if !RP_HOST
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
d = Get_Domain(1);
t= Lookup_Thread(d, 12); /* defining the inlet surface thread by specifying the Zone_ID*/
#endif /* !RP_HOST */

/* Send the ID value to all the nodes */
host_to_node_int_1(12); /* Does nothing in serial */
host_to_node_real_3(t, cell, thread); /* Does nothing in serial, t is the thread of inlet surface, thread is the thread of the filter volume */

#if !RP_HOST


begin_f_loop(f,t)
if PRINCIPAL_FACE_P(f,t) /* tests if the face is the principle face FOR COMPILED UDFs ONLY */


{
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)

# if RP_NODE /* Perform node synchronized actions here, Does nothing in Serial */
massflowrate = PRF_GRSUM1(massflowrate);
# endif /* RP_NODE */

begin_c_loop(cell,thread)
{
volume = C_VOLUME(cell,thread); /* get cell volume */
vol_tot += volume;
}
end_c_loop(cell,thread)
# if RP_NODE /* Perform node synchronized actions here,Does nothing in Serial */
vol_tot = PRF_GRSUM1(vol_tot);
# endif /* RP_NODE */
#endif /* !RP_HOST */

/* Pass the node's SO2 mass flow rate and volume to the Host for calculating source */
node_to_host_real_2(massflowrate, vol_tot); /* Does nothing in SERIAL */

#if !RP_NODE /* SERIAL or HOST */
source=-0.999989* massflowrate/vol_tot;
dS[eqn]=0.0;

return source;
Message("Sink Rate in Filter %d is %f (kg/m^3/s)\n", filter_zone _id,( =-0.999989* massflowrate/vol_tot));
#endif /* !RP_NODE */

}

My questions:
1. Is there any command like "
if PRINCIPAL_FACE_P(f,t) " for the cells, because I need to calculate the total volume, too. If so, I will add it right after "begin_c_loop(cell,thread)" but outside of the loop "{}".
2. the "filter_zone_id" is the filter volume that I'm interested in, should I use "d" here? or should I go to the "zone" panel, and find out the zone_ID of this filter volume? then put this integer substituting "filter_zone-id"? Let's assume the zone_ID=5, and the zone_ID=12 for the inlet surface, as I already wrote above, to get "
t= Lookup_Thread(d, 12);"
3. Do I have to write another "host_to_node_int_1(5); " to pass the "5" from the host to the node? or "host_to_node_real_3(t, cell, thread);" is actually sufficient enough? After all, cell and thread is already called in DEFINE_SOURCE and they are for the "domain d" of the filter volume.
4. Did I put the "source" right? I mean, I should define the "source" in the host instead of in the nodes, right? i.e., define the source on the basis of the total volume in the host instead of in the partitioned domain in the nodes, am I getting this right?

Thanks!


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