fluent UDF parallel problem
Posted January 12, 2017 at 04:13 by tanpeilai
Quote:
Here's a UDF I think should work, though haven't tried it. Either way, give it a shot, or compare it with yours, and see if it works. If not, or yours doesn't, let me know.
Code:
#include "udf.h" #define P_outlet_ID 2 real flow; /* defined outside because will be used in multiple DEFINE macros */ DEFINE_ADJUST(adjust, domain) { /* "Parallelized" Sections */ #if !RP_HOST /* Compile this section for computing processes only (serial and node) since these variables are not available on the host */ Thread *thread; face_t f; thread = Lookup_Thread(domain, P_outlet_ID); flow = 0.0; begin_f_loop(f, thread) /* loop over all faces in thread "thread" */ { /* If this is the node to which face "officially" belongs,*/ if (PRINCIPAL_FACE_P(f,thread)) /* Always TRUE in serial version */ { flow +=F_FLUX(f,thread); } } end_f_loop(f, thread) #if RP_NODE /* Perform node synchronized actions here. Does nothing in Serial */ flow = PRF_GRSUM1(flow); #endif /* RP_NODE */ #endif /* !RP_HOST */ } DEFINE_PROFILE(mass_pri, thread, position) { /* "Parallelized" Sections */ #if !RP_HOST /* Compile this section for computing processes only (serial and node) since these variables are not available on the host */ face_t f; begin_f_loop(f, thread) { F_PROFILE(f, thread, position) = flow; } end_f_loop(f, thread) #endif /* !RP_HOST */ }
Thank you again, it works very well. when I change adjust to EXECUTE_AT_END, it works great too.
But there some different, when use adjust, the mass flow in is from previous iteration, so the two monitors( pressure out and mass flow in) aren't same. when I use EXECUTE_AT_END, they are not same too, but it same to previous timestep. It doesn't change throughout the time step, I think maybe it is better to conservation of mass. thank you.
step flow-time surf-mon-1 surf-mon-2
239 8.6180e+01 -4.8995e-02 0.0000e+00
step flow-time surf-mon-1 surf-mon-2
240 8.6280e+01 -4.8406e-02 4.8995e-02
step flow-time surf-mon-1 surf-mon-2
241 8.6380e+01 -4.7777e-02 4.8406e-02
#include "udf.h"
#define P_outlet_ID 2
real flow; /* defined outside because will be used in multiple DEFINE macros */
DEFINE_EXECUTE_AT_END(measure_mass_flow)
{
/* "Parallelized" Sections */
#if !RP_HOST /* Compile this section for computing processes only (serial
and node) since these variables are not available on the host */
Domain *domain;
Thread *thread;
face_t f;
domain = Get_Domain(1);
thread = Lookup_Thread(domain, P_outlet_ID);
flow = 0.0;
begin_f_loop(f, thread) /* loop over all faces in thread "thread" */
{
/* If this is the node to which face "officially" belongs,*/
if (PRINCIPAL_FACE_P(f,thread)) /* Always TRUE in serial version */
{
flow +=F_FLUX(f,thread);
}
}
end_f_loop(f, thread)
#if RP_NODE
/* Perform node synchronized actions here. Does nothing in Serial */
flow = PRF_GRSUM1(flow);
#endif /* RP_NODE */
#endif /* !RP_HOST */
}
DEFINE_PROFILE(mass_pri, thread, position)
{
/* "Parallelized" Sections */
#if !RP_HOST /* Compile this section for computing processes only (serial
and node) since these variables are not available on the host */
face_t f;
begin_f_loop(f, thread)
{
F_PROFILE(f, thread, position) = flow;
}
end_f_loop(f, thread)
#endif /* !RP_HOST */
}
It's almost same to yours. Thank you very much.
Total Comments 0