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

problem to make a UDF parallel

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 9, 2011, 06:35
Default problem to make a UDF parallel
  #1
New Member
 
Pierre-Louis Schmitt
Join Date: Jan 2011
Posts: 10
Rep Power: 15
pilou is on a distinguished road
I already sent this on the Fluent forum, don't know if it's the right section, so I resend it here...

Hi,

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;

DEFINE_ON_DEMAND(parallel_scheme)
{
#if !RP_NODE
printf("OK_demand_1 \n");
p_op=RP_Get_Real("operating-pressure");
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*/
type_diff=RP_Get_Boolean("species/multicomponent-diffusion?");
therm_diff=RP_Get_Boolean("species/thermal-diffusion?");
#endif

host_to_node_real_5(sig,permh,absp,C1,p_op);
host_to_node_real_7(dh,dox,tau,con,por,uref,alpha) ;
host_to_node_int_4(absoid,rejetoid,abshid,rejethid );
host_to_node_int_2(type_diff,therm_diff);



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;
Message("\nIndex\tName\tMW\n");
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);
Mm[i]=mw[i];
/* Display species data */
Message("%d\t%s\t%f\n", i, sp_name, mw[i]);
if (mw[i] < 32. && mw[i] > 31.8 )
{ido=i;}
else if (mw[i] < 2.1 && mw[i] > 2.)
{idh=i;}
n_species++;
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");
/*host_to_node_int_1(n_species);*/
}


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


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(pos,f,t);
begin_f_loop(fr,tr)
{ 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));*/
}
}
end_f_loop(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(pos,f,t);
begin_f_loop(fa,ta)
{ F_CENTROID(xra,fa,ta);
if (pos[1]>xra[1]-epsilon&&pos[1]<xra[1]+epsilon)
{fext = fa; }
}
end_f_loop(fa,ta)




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*/

C_UDMI(cext,text,0)=*rr;
C_UDMI(cext,text,1)=U;
C_UDMI(cext,text,2)=Pout;
}

else if (THREAD_ID(t)==rejetoid)

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


/*Stockage dans les UDMI*/

C_UDMI(cin,tin,0)=*rr;
C_UDMI(cin,tin,1)=U;
C_UDMI(cin,tin,2)=Pin;
}


}




If you have any idea to resolve it.
Thanks in advance
Pilou
pilou is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
UDF compiling problem Wouter Fluent UDF and Scheme Programming 6 June 6, 2012 04:43
A UDF Problem in Parallel Mode Jun FLUENT 1 October 26, 2011 12:49
Problem to parallelize a UDF pilou FLUENT 0 March 9, 2011 06:32
OpenFOAM 1.7.1 installation problem on OpenSUSE 11.3 flakid OpenFOAM Installation 16 December 28, 2010 08:48
OpenFOAM with IBM AIX matthias OpenFOAM Installation 20 March 25, 2008 02:36


All times are GMT -4. The time now is 01:52.