CFD Online Discussion Forums

CFD Online Discussion Forums (
-   FLUENT (
-   -   Problem to parallelize a UDF (

pilou March 9, 2011 07:32

Problem to parallelize a UDF

I'm now facing a big issue trying to make a serial UDF parallel.
This UDF is divided into 2 parts. An execute_on_demand at the begining to read and send to nodes some scheme variables and the second one that is used to simulate some reaction rates at wall.

The UDF works perfectly in serial but I need now to adapt it for parallel computation.
The main problem seems to be the fact that I have to call a face on a different thread.

#include <udf.h>

#define n 0.6
#define F 96485300 /*Constante de Faraday*/

real sig; /*perméabilité oxygene*/
real pinh; /*pression interne hydrogène*/
real permh; /*perméabilité hydrogène*/
real absp; /*absorption poreux*/
int valeur1; /*ID milieu poreux*/
real Pout; /*Pression partielle*/
real U; /*tension electrique equivalente*/
real dh; /*epaisseur membrane hydrogène*/
real dox; /*epaisseur membrane oxygène*/
real tau; /*toruosité*/
real por; /*porosite*/
real con; /*constricitivite*/
int absoid;
int rejetoid;
int abshid;
int rejethid;
int nspecies;
real p_op;
int type_diff;
int therm_diff;
real uref; /*vitesse reference*/
real alpha; /*viscous resistance*/
real C1;
int ido;
int idh;
real Mm[12];
int n_species;

#if !RP_NODE
printf("OK_demand_1 \n");
sig=RP_Get_Real("udf/permo"); /*sigma*/
permh=RP_Get_Real("udf/permh"); /*perméabilité hydrogène*/
absp=RP_Get_Real("udf/absp"); /*absorption poreux*/
dh=RP_Get_Real("udf/epmemh"); /*epaisseur de la membrane hydrogène*/
dox=RP_Get_Real("udf/epmemo"); /*epaisseur de la membrane oxygène*/
tau=RP_Get_Real("udf/tau"); /*tortuosite*/
con=RP_Get_Real("udf/con"); /*constrictivite*/
por=RP_Get_Real("udf/por"); /*porosite*/
absoid=RP_Get_Integer("udf/absoid"); /*ID absorption Ox*/
abshid=RP_Get_Integer("udf/abshid"); /*ID absorption Hy*/
rejetoid=RP_Get_Integer("udf/rejetoid"); /*ID rejet Ox*/
rejethid=RP_Get_Integer("udf/rejethid"); /*ID rejet Hy*/
alpha=RP_Get_Real("udf/alpha"); /*Inertial resistance*/
C1=RP_Get_Real("udf/c1"); /*Viscous resistance*/
uref=RP_Get_Real("udf/uref"); /*Vitesse de reference*/

host_to_node_real_7(dh,dox,tau,con,por,uref,alpha) ;
host_to_node_int_4(absoid,rejetoid,abshid,rejethid );

Domain *d=Get_Domain(1);

Material *mix = mixture_material(d); /* Get mixture material */
Material *sp;
int i;
real mw[MAX_SPE_EQNS];
char *sp_name;
n_species = 0; /* Reset species counter */
/* Loop over species in mixture */
mixture_species_loop(mix, sp, i) {
/* Get name of species i */
sp_name = MIXTURE_SPECIE_NAME(mix, i);
/* Get species molecular weight */
mw[i] = MATERIAL_PROP(sp, PROP_mwi);
/* Display species data */
Message("%d\t%s\t%f\n", i, sp_name, mw[i]);
if (mw[i] < 32. && mw[i] > 31.8 )
else if (mw[i] < 2.1 && mw[i] > 2.)
printf("ido : %i, identh : %i\n",ido,idh);
printf(" n_species : %i\n",n_species);

printf(" n_species apres endif: %i\n",n_species);
printf("OK_demand_2 \n");

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

DEFINE_SR_RATE(my_rate_ox, f, t, r, mw, yi, rr)

/*Lecture des variables scheme*/

Domain *domain=Get_Domain(1);
/*Controle d'entree dans la fonction*/
/*printf("OK_demand_1 \n");*/

/*Déclaration des variables locales*/
real Pin;

real pos[ND_ND];
real xro[ND_ND];
real xra[ND_ND];

real epsilon = 0.000001;

Thread *ta=Lookup_Thread(domain,absoid);
Thread *tr=Lookup_Thread(domain,rejetoid);
Thread *text;
cell_t cext;
Thread *tin;
cell_t cin;
face_t fin;
face_t fr;
face_t fext;
face_t fa;

/*printf("absoid : %i\t rejetoid : %i\n",THREAD_ID(ta),THREAD_ID(tr)); */

/*Définition des faces et thread temporaires pour les calculs*/

if (THREAD_ID(t)==absoid)
/*printf("premier if\n");

printf("por : %f\t absoid : %i\n",por,absoid);
printf("declaration face ok\n");*/
{ F_CENTROID(xro,fr,tr);
/*printf("xro : %f\t pos : %f\n",xro[1],pos[1]);*/
if (pos[1]>xro[1]-epsilon&&pos[1]<xro[1]+epsilon)
{fin = fr;
/*printf("correspondance trouvee, P : %f\n", F_P(fr,tr));*/

text=THREAD_T0(t); /*Affecte a text le thread adjacent à K->t1*/
cext=F_C0(f,t); /*Renvoie cext cellule adjacente à fext,K->t1*/
tin=THREAD_T0(tr); /*Affecte a tin le thread adjacent à K->t2*/
cin=F_C0(fin,tr); /*Renvoie cin cellule adjacente à fx,K->t2*/

/*printf("thread tin : %i, pression : %f\n", THREAD_ID(tr),C_P(cin,tin));*/

else if (THREAD_ID(t)==rejetoid)

{ F_CENTROID(xra,fa,ta);
if (pos[1]>xra[1]-epsilon&&pos[1]<xra[1]+epsilon)
{fext = fa; }

text=THREAD_T0(ta); /*Affecte a text le thread adjacent à K->t1*/
cext=F_C0(fext,ta); /*Renvoie cext cellule adjacente à fext,K->t1*/
tin=THREAD_T0(t); /*Affecte a tin le thread adjacent à K->t2*/
cin=F_C0(f,t); /*Renvoie cin cellule adjacente à fx,K->t2*/

/*Calcul et affichage de la pression partielle interne*/

Pin = C_YI(cin,tin,ido)*C_R(cin,tin)*UNIVERSAL_GAS_CONST ANT*C_T(cin,tin)/(mw[ido]);

/*printf("Pin : %f\n",Pin);*/

/*Calcul de la pression partielle, tension equivalente et production*/

Pout = C_YI(cext,text,ido)*C_R(cext,text)*UNIVERSAL_GAS_C ONSTANT*C_T(cext,text)/(mw[ido]);
U = log(Pout/Pin)*UNIVERSAL_GAS_CONSTANT*C_T(cext,text)/(4*F);
/*printf("Pout : %f\n",Pout);*/

/*Condition sur le thread pour absorption ou rejet*/

if (THREAD_ID(t)==absoid)


*rr = sig/dox*U/F ;

/*Stockage dans les UDMI*/


else if (THREAD_ID(t)==rejetoid)

*rr = -sig/dox*U/F ;

/*Stockage dans les UDMI*/



If you have any idea to resolve it.
Thanks in advance

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