CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   FLUENT (http://www.cfd-online.com/Forums/fluent/)
-   -   parallelization of a UDF (http://www.cfd-online.com/Forums/fluent/92363-parallelization-udf.html)

lapin_tout_fou September 12, 2011 11:54

parallelization of a UDF
 
Hi,

I wrote a UDF but don't know exatly how to parallelize it.
I should use some PRF_GRSUM1 or PRF_GRSUM2 but I don't know how exactly.
Thanks

Here is my serial UDF:

#include "udf.h"

#define tension 40

#define rtotal 1000000

FILE *fout;


real intensity;
real r1,r2;
real p1,p2;
real s1,s2;
real t1,t2;
real z1,z2;
real volume1;
real vol_tot1;
real tempo1;
real tavg1;
real rtot;
real val1,val2;
real vol1,vol2;
real moyenne(int id,Domain *domain);

/* global resistance */
real resistance(real a1,real a2)
{
real resist = 0;
resist = (a1+a2);
return resist;
}

/* initialization */
DEFINE_ON_DEMAND(reprise)
{
intensity = 5.5;
r1 = 0.;
r2 = 10.;
}

/* power sources */
DEFINE_SOURCE(tube_1_source, cell, thread, dS, eqn)
{
t1 = val1;
rtot = resistance(r1,r2);
intensity = tension/(rtot);
r1 = (vol1*rtotal)*((1+0.0045*(t1-293)));
z1 = (r1*intensity*intensity);
p1 = z1 /vol1;
return p1;
}
DEFINE_SOURCE(tube_2_source, cell, thread, dS, eqn)
{
t2 = val2;
rtot = resistance(r1,r2);
intensity = tension/(rtot);
r2 = (vol2*rtotal)*((1+0.0045*(t2-293)));
z2 = (r2*intensity*intensity);
p2 = z2 /vol2;
return p2;
}


/* mean temperature function */

real mean(int id,Domain *domain)

{
cell_t c;
Thread *t;
t = Lookup_Thread(domain,id);
tavg1 = 0.;
vol_tot1 = 0;
begin_c_loop(c,t)
{
volume1 = C_VOLUME(c,t);
tempo1 = C_T(c,t);
vol_tot1 += volume1;
tavg1 += tempo1*volume1;
}
end_c_loop(c,t)
tavg1 /= vol_tot1;
return tavg1;
}

/* volume function */

real volume(int id,Domain *domain)

{
cell_t c;
Thread *t;
t = Lookup_Thread(domain,id);
vol_tot1 = 0;
begin_c_loop(c,t)
{
volume1 = C_VOLUME(c,t);
vol_tot1 += volume1;
}
end_c_loop(c,t)
return vol_tot1;

}

/* display */
DEFINE_ADJUST(puissance,domain)
{
val1 = mean(10095,domain);
val2 = mean(10094,domain);
vol1 = volume(10095,domain);
vol2 = volume(10094,domain);

printf(" temperature1 :%g\n" , val1);
printf(" temperature2 :%g\n" , val2);
printf("power 1 :%g\n" , z1);
printf("power 2 :%g\n" , z2);
printf("tube1 resistance:%g\n" , r1);
printf("tube2 resistance:%g\n" , r2);

fout = fopen("case.txt","a+");
fprintf(fout,"%g %g \n", intensity, rtot);
fclose(fout);

printf("intensity : %g\n" , intensity);
}


All times are GMT -4. The time now is 12:33.