CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

Parallel UDF Problem

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 20, 2007, 21:56
Default Parallel UDF Problem
  #1
Dimitris
Guest
 
Posts: n/a
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

  Reply With Quote

Old   June 21, 2007, 02:45
Default Re: Parallel UDF Problem
  #2
Bogdan
Guest
 
Posts: n/a
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.
  Reply With Quote

Old   June 21, 2007, 04:13
Default Re: Parallel UDF Problem
  #3
Bogdan
Guest
 
Posts: n/a
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

}

  Reply With Quote

Old   June 21, 2007, 06:37
Default Re: Parallel UDF Problem
  #4
Dimitris
Guest
 
Posts: n/a
Thank you Bogdan

Your solution works perfectly
  Reply With Quote

Old   June 21, 2007, 07:03
Default Re: Parallel UDF Problem
  #5
Bogdan
Guest
 
Posts: n/a
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
  Reply With Quote

Old   June 21, 2007, 07:10
Default Re: Parallel UDF Problem
  #6
Dimitris
Guest
 
Posts: n/a
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
  Reply With Quote

Old   May 29, 2011, 23:48
Default
  #7
New Member
 
hisham
Join Date: May 2011
Posts: 6
Rep Power: 15
sham83 is on a distinguished road
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.
sham83 is offline   Reply With Quote

Old   September 20, 2013, 02:51
Default parallel programming
  #8
New Member
 
MASOOD UR REHMAN
Join Date: Sep 2013
Posts: 1
Rep Power: 0
masoodsaqi is on a distinguished road
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;
}
masoodsaqi is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem loading UDF library in parallel cluster Veera Gutti FLUENT 8 July 26, 2016 08:24
Parallel UDF problem Lindsay FLUENT 4 June 20, 2016 10:37
UDF parallel Lucy Fluent UDF and Scheme Programming 3 May 28, 2013 14:14
UDF in parallel version. yobee FLUENT 0 August 17, 2004 05:12
parallel mode - small problem? co2 FLUENT 2 June 2, 2004 00:47


All times are GMT -4. The time now is 16:34.