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/)
-   -   Problems with UDF in parallel mode (https://www.cfd-online.com/Forums/fluent-udf/160123-problems-udf-parallel-mode.html)

rikfr986 October 2, 2015 09:48

Problems with UDF in parallel mode
 
Hi!
I have written a UDF to calculate the average value of a passive scalar at the outlet boundary to use it as a prescribed value at the inlet. The code works fine when in serial mode but not in parallel. seems like only one of the cores got the right value!? or how to express it.

Would be very pleased if someone knows what's wrong or could guide me in right direction!

see code below

#include "udf.h"
#include "mem.h"

real concavg, concavg1;
real conc;

DEFINE_EXECUTE_AT_END(out_ave)
{

Domain *d;
real area,
real area_tot;

real A[ND_ND];
Thread *t;
face_t f;

d=Get_Domain(1);
t=Lookup_Thread(d,5);

area=0;
area_tot=0;
conc=0;
concavg=0;
concavg1=0;


begin_f_loop(f,t)
{

F_AREA(A,f,t);
area=NV_MAG(A);
area_tot+=area;

conc=F_UDSI(f, t, 0);
concavg += conc*area;

concavg1=concavg/area_tot;

printf("\n area_tot = %f\n",area_tot); /*print once for every cell face on outlet, counts to the right area, OK!*/
printf("\n concavg = %f\n",concavg1); /*print once for every cell face on outlet, right value, OK!*/


}
end_f_loop(f,t)

printf("\n area_tot2 = %f\n",area_tot);/* Print once for every core, first one OK the other three =0??!*/
printf("\n concavg2 = %f\n",concavg1);


}

DEFINE_PROFILE ( inl_uds, t, i)
{

face_t face;
face_t f;
real flow_time, inlvalue;

flow_time=RP_Get_Real("flow-time");

if(flow_time<0.5)
{
begin_f_loop(face, t)
{
F_PROFILE(face, t, i)=1;
}
end_f_loop(face, t)
}
else
{
begin_f_loop(face, t)
{
inlvalue=concavg1;/*F_UDMI(f,t,0);*/

F_PROFILE(face, t, i)=inlvalue;

}
end_f_loop(face, t)
}
}

brunoc October 6, 2015 12:17

The documentation has a section about parallelizing UDFs. You can't just use the version you use in serial, since part of the information can't be accessed by all compute nodes.

For instance, the averaging procedure you're doing won't work since some of the compute nodes might not have any cells on the zone you're looking for. That is why you're getting a null area on some partitions.

Search for Global Reduction Macros in the doc and make the appropriate corrections (but read the entire parallel section to know other things you'll need to change).

Cheers.


All times are GMT -4. The time now is 07:36.