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

how to write a parallel UDF?

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

Reply
 
LinkBack Thread Tools Display Modes
Old   September 16, 2011, 11:44
Default how to write a parallel UDF?
  #1
New Member
 
Thomas
Join Date: Aug 2009
Location: France
Posts: 12
Rep Power: 7
lapin_tout_fou is on a distinguished road
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);
}
lapin_tout_fou is offline   Reply With Quote

Reply

Thread Tools
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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Parallel INIT UDF trouble mil3st3g Fluent UDF and Scheme Programming 2 January 6, 2011 15:07
mesh file for flow over a circular cylinder Ardalan Main CFD Forum 6 April 17, 2010 23:40
UDF problem with Parallel Solver manu FLUENT 0 January 24, 2008 15:31
parallel UDF problem kerem FLUENT 2 June 20, 2006 06:56
UDF to write interp files Karl FLUENT 6 February 7, 2002 13:10


All times are GMT -4. The time now is 07:46.