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/)
-   -   Parallel UDF Problem (https://www.cfd-online.com/Forums/fluent-udf/45115-parallel-udf-problem.html)

Dimitris June 20, 2007 21:56

Parallel UDF Problem
 
Hi everybody

I made a udf to calculate on a specific face the average value of scalar quantity, and it runs fine in serial mode. I tried to use it in parallel mode in a dual core machine but I failed. I used some complier's directives in order to overcome it but I didn't manage it. The serial listing is attached.

/************************************************** **********************/

DEFINE_EXECUTE_AT_END(Scalar_average)

{

int curr_ts = N_TIME;

real tfa = 0.0;

real tfi = 0.0;

real mfi = 0.0;

real time = CURRENT_TIME;

int id = 10;

real A[ND_ND];

FILE *fp = fopen("usds_story.txt","a+");

face_t f;

Domain *d = Get_Domain(1);

Thread *t=Lookup_Thread(d,id);

{

begin_f_loop(f, t)

{

F_AREA(A,f,t);

tfa += NV_MAG(A);

tfi += F_UDSI(f,t,0)*NV_MAG(A);

}

end_f_loop(f, t)

}

mfi = tfi / tfa;

Message ("Time Step:%5d Time:%7.4e Average Value:%12.4e\n", curr_ts, time, mfi);

fprintf(fp,"%5d %7.4e %12.4e\n", curr_ts, time, mfi);

fclose(fp);

}

Thanks in advance


Bogdan June 21, 2007 02:45

Re: Parallel UDF Problem
 
To write files in parallel is not as easy as in serial. in parallel only host can write to file, so you need to send the values from nodes to node 0, and node 0 send the values to host. you need to use the macros PRF_CSEND_REAL, PRF_CRECV_REAL, etc. It's an example in the UDF manual, have a look.

Bogdan June 21, 2007 04:13

Re: Parallel UDF Problem
 
try like this:

#include "udf.h"

DEFINE_EXECUTE_AT_END(Scalar_average)

{

#if !RP_HOST

int curr_ts = N_TIME;

real tfa = 0.0;

real tfi = 0.0;

real time = CURRENT_TIME;

int id = 10;

real A[ND_ND];

face_t f;

Domain *d = Get_Domain(1);

Thread *t=Lookup_Thread(d,id);

#endif

real mfi = 0.0;

#if !RP_NODE

FILE *fp = fopen("usds_story.txt","a+");

#endif

#if RP_HOST

int curr_ts,time;

#endif

#if !RP_HOST

begin_f_loop(f, t)

{

F_AREA(A,f,t);

tfa += NV_MAG(A);

tfi += F_UDSI(f,t,0)*NV_MAG(A);

}

end_f_loop(f, t)

tfi=PRF_GRSUM1(tfi);

tfa=PRF_GRSUM1(tfa);

mfi = tfi / tfa;

#endif

node_to_host_real_1(mfi);

node_to_host_int_2(curr_ts,time);

#if !RP_HOST

Message0("Time Step:%5d Time:%7.4e Average Value:%12.4e\n", curr_ts, time, mfi);

#endif

#if !RP_NODE

fprintf(fp,"%5d %7.4e %12.4e\n", curr_ts, time, mfi);

fclose(fp);

#endif

}


Dimitris June 21, 2007 06:37

Re: Parallel UDF Problem
 
Thank you Bogdan

Your solution works perfectly

Bogdan June 21, 2007 07:03

Re: Parallel UDF Problem
 
I'm glad, but just I found a small error, time is not an int but a real, so modify as follows:

instead of

#if RP_HOST

int curr_ts,time;

#endif

modify

#if RP_HOST

int curr_ts;

real time;

#endif

and instead of

node_to_host_real_1(mfi);

node_to_host_int_2(curr_ts,time);

modify

node_to_host_real_2(mfi,time);

node_to_host_int_1(curr_ts);

regards

Dimitris June 21, 2007 07:10

Re: Parallel UDF Problem
 
I have already done all these. It was obvious to be corrected all these points. But the general concept was absolutely right.

Thanks once more

sham83 May 29, 2011 23:48

Hi guys,

Can someone help me to modify my UDF below to parallel UDF. I am simulating oscillating cylinder and need to compile my UDF in Linux parallel.

#include "udf.h"

#define AA 0.03
#define TT 4.1667
#define OM (2.0*M_PI/TT)

DEFINE_CG_MOTION(updown,dt,vel,omega,time,dtime)
{
vel[1] = AA*OM*cos(OM*time);
}


thanks.

masoodsaqi September 20, 2013 02:51

parallel programming
 
i am the new user of the fluent, i have made program for the direct contact condensation model. it works on serial. but i want to made the parallel one kindly help me out in this,,,,,
#include "udf.h"
#define PI 3.141592654
#define PR_NUMBER(cp,mu,k) ((cp)*(mu)/(k))
#define IP_HEAT_COEFF(k,nu,d) ((k)*(Nu)/(d))
DEFINE_MASS_TRANSFER(liq_gas_source,cell,thread,fr om_index,from_species_index, to_index, to_species_index)
{ double alfa_g,alfa_f,Hig,Hif, q_val,m_lg,t_sub,t_sup,Tsat,Hsat,Hsat_f,NV_VEC(v), v_fg,v_f,afg;
Thread *gas = THREAD_SUB_THREAD(thread, from_index);Thread *liq = THREAD_SUB_THREAD(thread, to_index);
double kf = C_K_L(cell,liq),p_op,press,d ; //= C_PHASE_DIAMETER(cell,gas)
double ro_f=C_R(cell,liq),cp_f=C_CP(cell,liq),hfg,mu_f=C_ MU_L(cell,liq);
double F1,F2,F3,F4,F5,F6,F7,Re,Pr,Nu;
double sat_hf (double Tsat1);double sat_hg (double Tsat1);double sat_t (double press);double bub_dia (double teta);
//------------------------------------------------
alfa_f=C_VOF(cell,liq); //liquid volume fraction.
alfa_g=1.0-C_VOF(cell,liq); //vapor volume fraction.
// -------------------------------------------------
NV_DD(v,=,C_U(cell,gas),C_V(cell,gas),C_W(cell,gas ),-,C_U(cell,liq),C_V(cell,liq),C_W(cell,liq)); //relative velocity vector
v_fg = NV_MAG(v); //relative velocity magnitude.
if(alfa_g<0.00001)
v_fg=v_fg*alfa_g*100000.0;
v_f=sqrt(C_U(cell,liq)*C_U(cell,liq)+C_V(cell,liq) *C_V(cell,liq)+C_W(cell,liq)*C_W(cell,liq)); //liquid velocity magnitude.
//--------------------------------------------------
p_op = RP_Get_Real ("operating-pressure"); // operating pressure.
press = C_P(cell,thread) + p_op; // absolute pressure = gauge pressure + operating pressure.
// -------------------------------------------
Tsat=sat_t(press); //Saturation Temperature at sysytem Pressure.
//--------------------------------------------------------//
Hsat=sat_hg(Tsat); //Saturation vapor enthalpy at saturation Temperature.
// _________________________________________________
Hsat_f=sat_hf(Tsat); //Saturation liquid enthalpy at saturation Temperature.
// -------------------------------------------------
t_sub=Tsat-C_T(cell, liq); //Liquid Subcooling.
t_sup=Tsat-C_T(cell, gas); //vapor Superheat.
hfg=Hsat-Hsat_f;
d=bub_dia(t_sub); //mean bubble diameter.
afg=6.0*alfa_g/d; //interfacial area per unit volume.
//-----------------------------------------------
Hig=0.0; Hif=0.0;
Re = RE_NUMBER(ro_f,v_fg,d,mu_f);
Pr = PR_NUMBER (cp_f,mu_f,kf);
if (Re <776.06)
Nu = 2. + 0.6*sqrt(Re)*pow(Pr,1./3.);
if (Re >=776.06)
Nu = 2. + 0.27*pow(Re,0.62)*pow(Pr,1./3.);
Hif = IP_HEAT_COEFF(kf,Nu,d);
C_UDMI(cell,thread,0)=Hif;
Hif=Hif*afg;
Hig=10000.0*alfa_f;
C_UDMI(cell,thread,1)=Hig;
Hig=10000.0*alfa_f*afg;
Hif=(Hif>0.0)? Hif:0.0;
Hig=(Hig>0.0)? Hig:0.0;
//-----------------------------------------------
F1=(alfa_g-1.0e-10)/(0.1-1.0e-10);
F2=(F1<1.0)? F1:1.0;
F3=(F2>0.0)? F2:0.0;
F4=472.4*alfa_g*alfa_f;
F5=(F4>4.724)? F4:4.7240;
F6=F3*17539.0*F5;
Hif=(F6<Hif)? F6:Hif;
if (afg>0.0)
C_UDMI(cell,thread,2)=Hif/afg;
// -----------------------------------------------
q_val=Hig*t_sup+Hif*t_sub;
// -------------- Condensation ------------------
F3=0.0;
if (q_val>0.0)
{
F3=q_val/hfg;
F3= (F3>20000.0)? 20000.0:F3;
}
// ---------------Evaporation ------------------
F4=0.0;
if(q_val<0.0)
F4=q_val/hfg;
// ---------------------------------------------
m_lg=0.0;
m_lg=F3;
C_UDMI(cell,thread,3)=afg;
return (m_lg);
}
//---------------------------------------------------------------------------------------------------------------------------------
double sat_hf (double Tsat1)
{ double c1,c2,c3,c4,c5,Hsat_f;
if (Tsat1 < 273.16)
{ c1=3.678415406; c2=94.566331838;c3=-633700.4102444666;
Hsat_f=c1*pow(Tsat1,2.0)+c2*Tsat1+c3; }
else if ((Tsat1>=273.16) & (Tsat1<=458.15))
{ c1=0.00000097;c2=0.002933502;c3=-3.38991465;c4=5320.465596609;c5=-1265549.5606907;
Hsat_f=c1*pow(Tsat1,4.0)+c2*pow(Tsat1,3.0)+c3*pow( Tsat1,2.0)+c4*Tsat1+c5; }
else if ((Tsat1>458.15) & (Tsat1<588.150))
{ c1=0.028052788; c2=-38.680020889;c3= 22284.565666958;c4=-4003454.94420909;
Hsat_f=c1*pow(Tsat1,3.0)+c2*pow(Tsat1,2.)+c3*Tsat1 +c4; }
else if ((Tsat1>=588.150) & (Tsat1<633.150))
{ c1=0.610403253; c2=-1079.52580492;c3=642594.322849692; c4=-127269493.290113;
Hsat_f=c1*pow(Tsat1,3.0)+c2*pow(Tsat1,2.0)+c3*Tsat 1+c4; }
else
{ c1=2649.754012668; c2=- 3368892.04636868; c3= 1072543945.66977;
Hsat_f=c1*pow(Tsat1,2.0)+c2*Tsat1+c3; }
return Hsat_f;
}
//---------------------------------------------------
double sat_hg (double Tsat1)
{ double c1,c2,c3,c4,c5,Hsat;
if (Tsat1<=269.15)
{ c1=-0.012899897;c2=1861.128740978;c3=1994029.58484808;
Hsat=c1*pow(Tsat1,2.)+c2*Tsat1+c3; }
else if ((Tsat1>269.150) & (Tsat1<=358.15))
{ c1=-0.00798344; c2=6.377237731; c3=146.657325997; c4=2148141.56510444;
Hsat=c1*pow(Tsat1,3.)+c2*pow(Tsat1,2.)+c3*Tsat1+c4 ; }
else if ((Tsat1>358.15) & (Tsat1<458.15))
{ c1=-0.014401837;c2=13.590523939;c3=-2555.16588222;c4=2485409.51767315;
Hsat=c1*pow(Tsat1,3.)+c2*pow(Tsat1,2.)+c3*Tsat1+c4 ; }
else if ((Tsat1>=458.15) & (Tsat1<=558.15))
{ c1=-0.000124769;c2=0.22202041;c3=-155.344116048;c4=51361.267113676; c5=-3995548.42675866;
Hsat=c1*pow(Tsat1,4.)+c2*pow(Tsat1,3.)+c3*pow(Tsat 1,2.)+c4*Tsat1+c5; }
else if ((Tsat1>558.15) & (Tsat1<588.15))
{ c1=-0.177777778;c2=283.203809529;c3=-151359.20946363;c4=29939791.2629894;
Hsat=c1*pow(Tsat1,3.0)+c2*pow(Tsat1,2.0)+c3*Tsat1+ c4; }
else if ((Tsat1>=588.15) & (Tsat1<=623.150))
{ c1=-0.012; c2=28.391200001;c3=-25225.882420901;c4=9972990.42478661;c5=-1477098302.26595;
Hsat=c1*pow(Tsat1,4.)+c2*pow(Tsat1,3.)+c3*pow(Tsat 1,2.)+c4*Tsat1+c5; }
else
{ c1=-107.446320491; c2=203758.913457164;c3=-128801861.923354;c4=27142374107.2608;
Hsat=c1*pow(Tsat1,3.0)+c2*pow(Tsat1,2.0)+c3*Tsat1+ c4; }
return Hsat;
}
//---------------------------------------------------
double sat_t (double press)
{ double c1,c2,c3,n1,Tsat;
if (press<=85.35)
{ c1=210.739597573;n1=0.039362021;
Tsat=c1*pow(press,n1); }
else if ((press>85.35) & (press<=437.6))
{ c1=207.962053686;n1=0.042353185;
Tsat=c1*pow(press,n1); }
else if ((press>437.6) & (press<=1227.6))
{ c1=-0.000008432;c2=0.031700943; c3=-16.214491439+273.15;
Tsat=c1*pow(press,2.)+c2*press+c3; }
else if ((press>1227.6) & (press<7383.7))
{ c1=16.71336998; c2=-109.349132911+273.15;
Tsat=c1*log(press)+c2; }
else if ((press>=7383.7) & (press<25033.0))
{ c1=20.470120624;c2=-142.617297081+273.15;
Tsat=c1*log(press)+c2; }
else if ((press>=25033.0) & (press<=57834.0))
{ c1=24.25874557; c2=-180.96039468+273.15;
Tsat=c1*log(press)+c2; }
else if ((press>57834.0) & (press<=143280.0))
{ c1=27.960189855;c2=-221.972248234+273.15;
Tsat=c1*log(press)+c2; }
else if ((press>143280.0) & (press<=313000.0))
{ c1=4.989420793; n1=0.260632601; c2=273.15;
Tsat=c1*pow(press,n1)+c2; }
else if ((press>313000.0) & (press<=617800.0))
{ c1=5.779367813; n1=0.249057459; c2=273.15;
Tsat=c1*pow(press,n1)+c2; }
else if ((press>617800.0) & (press<1723000.0))
{ c1=6.41872514; n1=0.241236812; c2=273.15;
Tsat=c1*pow(press,n1)+c2; }
else if ((press>=1723000.0) & (press<5941800.0))
{ c1=6.784406757; n1=0.237370672; c2=273.15;
Tsat=c1*pow(press,n1)+c2; }
else if ((press>=5941800.0) & (press<=12845000.0))
{ c1=6.870220827; n1=0.236551273; c2=273.15;
Tsat=c1*pow(press,n1)+c2; }
else if ((press>12845000.0) & (press<=18651000.0))
{ c1=7.241741603; n1=0.233334685; c2=273.15;
Tsat=c1*pow(press,n1)+c2; }
else
{ c1=7.742231269; n1=0.229326725; c2=273.15;
Tsat=c1*pow(press,n1)+c2; }
return Tsat;
}
//----------------------------------------------
double bub_dia (double teta)
{ double d0=1.5e-4;
double teta0=13.5;
double d1=1.5e-3;
double teta1=0.0;
double d;
if (teta>13.5)
d=d0;
else if (teta<0.0)
d=d1;
else
d=(d1*(teta-teta0)+d0*(teta1-teta))/(teta1-teta0);
return d;
}


All times are GMT -4. The time now is 17:13.