|
|
The macro PRINCIPAL_FACE_P can be used only in compiled UDFs.
PRF_GRSUM1 and similar global reduction macros (Section 7.5.4 cannot be used in DEFINE_SOURCE UDFs in parallel ANSYS FLUENT. As a workaround, you can write a DEFINE_ADJUST UDF that calculates a global sum value in the adjust function, and then save the variable in user-defined memory. You can subsequently retrieve the stored variable from user-defined memory and use it inside a DEFINE_SOURCE UDF. This is demonstrated below.
In the following example, the spark volume is calculated in the DEFINE_ADJUST function and the value is stored in user-defined memory using C_UDMI. The volume is then retrieved from user-defined memory and used in the DEFINE_SOURCE UDF.
#include "udf.h"
static real spark_center[ND_ND]={20e-3, 1e-3};
static int fluid_chamber_ID = 2;
DEFINE_ADJUST(adjust, domain)
{
real vol, xc[ND_ND], dis[ND_ND], radius;
cell_t c;
Thread * tc;
tc = Lookup_Thread(domain, fluid_chamber_ID);
radius = RP_Get_Real("spark/radius");
vol = 0;
begin_c_loop_int (c, tc)
{
C_CENTROID(xc, c, tc);
NV_VV(dis, =, xc, -, spark_center);
if (NV_MAG(dis) < radius)
{
vol += C_VOLUME(c, tc);
}
}
end_c_loop_int (c, tc)
vol = PRF_GRSUM1(vol);
begin_c_loop_int (c, tc)
{
C_UDMI(c, tc, 1) = vol;
}
end_c_loop_int (c, tc)
}
DEFINE_SOURCE(energy_source, c, t, dS, eqn)
{
#if !RP_HOST
real xc[ND_ND], dis[ND_ND];
real source, radius, vol, CA, rpm, start_CA;
rpm = RP_Get_Real("dynamesh/in-cyn/crank-rpm");
start_CA = RP_Get_Real("spark/start-ca");
CA = rpm*CURRENT_TIME*6+RP_Get_Real("dynamesh/in-cyn/crank-start-angle");
if(CA>=start_CA&&CA<(start_CA+RP_Get_Real("spark/duration")*rpm*6))
{
radius = RP_Get_Real("spark/radius");
vol = C_UDMI(c, t, 1);
C_CENTROID(xc, c, t);
NV_VV(dis, =, xc, -, spark_center);
if (NV_MAG(dis) < radius)
{
source =
RP_Get_Real("spark/energy")/RP_Get_Real("spark/duration")/vol;
return source;
}
else
{
return 0;
}
}
else
{
return 0;
}
#endif
}
|
|
|
Interpreted UDFs cannot be used while running in parallel with an Infiniband interconnect. The compiled UDF approach should be used in this case.
|