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 DPM Udf problem (https://www.cfd-online.com/Forums/fluent-udf/88645-parallel-dpm-udf-problem.html)

dust_2 May 23, 2011 05:44

Parallel DPM Udf problem
 
Hi, all! I wrote a DPM UDF for fluent 6.3.26. But I don't know how to edit it to parallel UDF(1CPU 8cores ). Can anyone help me, plz?:(

By the way, could this udf run on Liunx system?


#include "udf.h"
#include "dpm.h"
#include "math.h"
#include "time.h"
#include "stdio.h"
static int n=0;


double integral(double s) // to generate a parabolic particle distribution
{
double a=0.0,b=5.0,mid=2.5,y=-0.004*mid*mid*mid+0.3*mid;
for(;fabs(s-y)>1e-6; )
{
if(s>y)
{
a=mid;
mid=(mid+b)/2.0;
}
else
{
b=mid;
mid=(a+mid)/2.0;
}
y=-0.004*mid*mid*mid+0.3*mid;
}

return mid;
}

DEFINE_DPM_INJECTION_INIT(init_particles,I)
{

Particle *p;
FILE *fp;
real xm[ND_ND];
double R=0.0, x=0.0, y=0.0, an=0.0,k=0.0;
if(n==0)srand((unsigned)time( NULL ));
k=rand()/(double)(RAND_MAX);
R=integral(k);
an=rand()/(double)(RAND_MAX)*2*3.1415926;
x=R*sin(an)/200.0;
y=R*cos(an)/200.0;
Message ("\n n=%d, k=%f\n",n, k);
n++;
p=I->p_init;
P_POS(p)[0]=x;
P_POS(p)[1]=y;
P_POS(p)[2]=0.0;
Message ("particle position x=%f, y=%f\n", P_POS(p)[0],P_POS(p)[1]);
xm[0]=P_POS(p)[0];
xm[1]=P_POS(p)[1];
xm[2]=P_POS(p)[2];
P_DIAM(p)=5e-6;
P_RHO(p)=1000;
P_MASS(p)=P_RHO(p)*M_PI*pow(P_DIAM(p),3.0)/6.0;
P_FLOW_RATE(p)=P_MASS(p)/0.06;
fp=fopen("e:\\test\\pa.txt","at");
fprintf(fp,"%f %f %f\n",R,xm[0],xm[1]);
fclose(fp);

}

johnwinter June 10, 2011 05:12

for parallel code you should keep
#if !RP_HOST
#endif
and
#if ! RP_NODE
#endif

has to be kept at appropriate places in the code. See UDF manual for more details

dust_2 June 10, 2011 09:26

Quote:

Originally Posted by johnwinter (Post 311412)
for parallel code you should keep
#if !RP_HOST
#endif
and
#if ! RP_NODE
#endif

has to be kept at appropriate places in the code. See UDF manual for more details

Thanks for your reply. But I just don't know where to put them. The manual only has one page mentioned about the paralleliztion of DPM model. And it mainly talks about message output.

johnwinter June 11, 2011 01:43

HI i am not an expert, based on my knowledge i have corrected your code below

#include "udf.h"
#include "dpm.h"
#include "math.h"
#include "time.h"
#include "stdio.h"
static int n=0;


double integral(double s) // to generate a parabolic particle distribution
{
#if !RP_HOST

double a=0.0,b=5.0,mid=2.5,y=-0.004*mid*mid*mid+0.3*mid;
for(;fabs(s-y)>1e-6; )
{
if(s>y)
{
a=mid;
mid=(mid+b)/2.0;
}
else
{
b=mid;
mid=(a+mid)/2.0;
}
y=-0.004*mid*mid*mid+0.3*mid;
}

return mid;
#end if
}

DEFINE_DPM_INJECTION_INIT(init_particles,I)
{
#if !RP_HOST

Particle *p;
FILE *fp;
real xm[ND_ND];
double R=0.0, x=0.0, y=0.0, an=0.0,k=0.0;
if(n==0)srand((unsigned)time( NULL ));
k=rand()/(double)(RAND_MAX);
R=integral(k);
an=rand()/(double)(RAND_MAX)*2*3.1415926;
x=R*sin(an)/200.0;
y=R*cos(an)/200.0;
// Message ("\n n=%d, k=%f\n",n, k);
n++;
p=I->p_init;
P_POS(p)[0]=x;
P_POS(p)[1]=y;
P_POS(p)[2]=0.0;
//Message ("particle position x=%f, y=%f\n", P_POS(p)[0],P_POS(p)[1]);
xm[0]=P_POS(p)[0];
xm[1]=P_POS(p)[1];
xm[2]=P_POS(p)[2];
P_DIAM(p)=5e-6;
P_RHO(p)=1000;
P_MASS(p)=P_RHO(p)*M_PI*pow(P_DIAM(p),3.0)/6.0;
P_FLOW_RATE(p)=P_MASS(p)/0.06;
#endif
node_to_host_real_3(R, xm[0],xm[1]);
#if !RP_NODE

fp=fopen("e:\\test\\pa.txt","at");
fprintf(fp,"%f %f %f\n",R,xm[0],xm[1]);
fclose(fp);
#endif
}

you may need to change some more look at carefully and change. all the best

dust_2 June 11, 2011 11:03

Quote:

Originally Posted by johnwinter (Post 311551)
HI i am not an expert, based on my knowledge i have corrected your code below

#include "udf.h"
#include "dpm.h"
#include "math.h"
#include "time.h"
#include "stdio.h"
static int n=0;


double integral(double s) // to generate a parabolic particle distribution
{
#if !RP_HOST

double a=0.0,b=5.0,mid=2.5,y=-0.004*mid*mid*mid+0.3*mid;
for(;fabs(s-y)>1e-6; )
{
if(s>y)
{
a=mid;
mid=(mid+b)/2.0;
}
else
{
b=mid;
mid=(a+mid)/2.0;
}
y=-0.004*mid*mid*mid+0.3*mid;
}

return mid;
#end if
}

DEFINE_DPM_INJECTION_INIT(init_particles,I)
{
#if !RP_HOST

Particle *p;
FILE *fp;
real xm[ND_ND];
double R=0.0, x=0.0, y=0.0, an=0.0,k=0.0;
if(n==0)srand((unsigned)time( NULL ));
k=rand()/(double)(RAND_MAX);
R=integral(k);
an=rand()/(double)(RAND_MAX)*2*3.1415926;
x=R*sin(an)/200.0;
y=R*cos(an)/200.0;
// Message ("\n n=%d, k=%f\n",n, k);
n++;
p=I->p_init;
P_POS(p)[0]=x;
P_POS(p)[1]=y;
P_POS(p)[2]=0.0;
//Message ("particle position x=%f, y=%f\n", P_POS(p)[0],P_POS(p)[1]);
xm[0]=P_POS(p)[0];
xm[1]=P_POS(p)[1];
xm[2]=P_POS(p)[2];
P_DIAM(p)=5e-6;
P_RHO(p)=1000;
P_MASS(p)=P_RHO(p)*M_PI*pow(P_DIAM(p),3.0)/6.0;
P_FLOW_RATE(p)=P_MASS(p)/0.06;
#endif
node_to_host_real_3(R, xm[0],xm[1]);
#if !RP_NODE

fp=fopen("e:\\test\\pa.txt","at");
fprintf(fp,"%f %f %f\n",R,xm[0],xm[1]);
fclose(fp);
#endif
}

you may need to change some more look at carefully and change. all the best

WOW! Thanks a lot! I'll try it.


All times are GMT -4. The time now is 21:02.