DEFINE_ADJUST UDF for the parallel solver

Additional code is sometimes required to make a UDF work in parallel. One example is a DEFINE_ADJUST macro for calculating a mass weighted average or area weighted average of one or more flow quantities on a boundary thread. The use of the global sum operator, described in Section 3.12 of the Fluent 6 UDF guide is required, but more modifications are needed. Consider the following DEFINE ADJUST function to calculate the area average pressure on a face:

DEFINE_ADJUST(face_av,domain)
{
int surface_thread_id= 7 ;

real total_area=0.0;
real total_pres_a=0.0;

Thread* thread;
face_t face;
real area[ND_ND];

thread = Lookup_Thread(domain,surface_thread_id);

begin_f_loop(face,thread)
{
F_AREA(area,face,thread);
total_area += NV_MAG(area);
total_pres_a += NV_MAG(area)*F_P(face,thread);
}
end_f_loop(face,thread)

Message("Average pressure on Surface %d is %f Pan",surface_thread_id,(total_pres_a/total_area));
}

An example of how to make this function work in parallel is shown in the Resolution field.
A cleaner, more recent version of this example can be found in the FLUENT 6.3 UDF Manual

http://www.fluentusers.com/fluent6326/doc/ori/html/udf/node218.htmDEFINE_ADJUST(face_av,domain)http://www.fluentusers.com/fluent6326/doc/ori/html/udf/node218.htmDEFINE_ADJUST(face_av,domain)
{
int surface_thread_id= 7 ;

real total_area=0.0;
real total_pres_a=0.0;

#if !RP_HOST
Thread* thread; /* these variables are only defined on "calculating" processes (Nodes & serial)
face_t face;
real area[ND_ND];
#endif /* !RP_HOST */

host_to_node_int_1(surface_thread_id); /* Does nothing in SERIAL */

#if RP_NODE
Message("nNode %d is calculating on thread # %dn",myid,surface_thread_id);
#endif /* RP_NODE */

#if !RP_HOST /* SERIAL or NODE */
thread = Lookup_Thread(domain,surface_thread_id);

begin_f_loop(face,thread)
# if RP_NODE
if (I_AM_NODE_SAME_P(F_PART(f,thread))) /* Check to see if face is allocated to this partition (Actually C0 of face) */
# endif
{
F_AREA(area,face,thread);
total_area += NV_MAG(area);
total_pres_a += NV_MAG(area)*F_P(face,thread);
}
end_f_loop(face,thread)

# if RP_NODE
Message("Total Area Before Summing %fn",total_area);
Message("Total Normal Force Before Summing %fn",total_pres_a);

total_area = PRF_GRSUM1(total_area);
total_pres_a = PRF_GRSUM1(total_pres_a);
# endif /* RP_NODE */

#endif /* !RP_HOST */

node_to_host_real_2(total_area,total_pres_a); /* Does nothing in SERIAL */

Message("Total Area After Summing: %fn",total_area);
Message("Total Normal Force After Summing %fn",total_pres_a);
Message("Average pressure on Surface %d is %f Pan",surface_thread_id,(total_pres_a/total_area));

}





Show Form
No comments yet. Be the first to add a comment!