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

How to convert my UDF to parallel?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 12, 2011, 06:37
Default How to convert my UDF to parallel?
  #1
New Member
 
Thomas
Join Date: Aug 2009
Location: France
Posts: 12
Rep Power: 17
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.

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

Old   September 13, 2011, 09:23
Default
  #2
New Member
 
Thomas
Join Date: Aug 2009
Location: France
Posts: 12
Rep Power: 17
lapin_tout_fou is on a distinguished road
Can anyone help me???
lapin_tout_fou is offline   Reply With Quote

Old   September 22, 2011, 04:51
Default
  #3
Member
 
john
Join Date: Nov 2010
Posts: 50
Rep Power: 16
johnwinter is on a distinguished road
Hi Thomas you have to add #if !RP_HOST and #endif at appropriate places. Dealing with print statement bit tricky. For example i modified your code below.
DEFINE_SOURCE(tube_1_source, cell, thread, dS, eqn)
{
#if !RP_HOST
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;
#endif
#if RP_HOST
return 0.0;
#endif
Follow something similar for the rest

Good luck

John
johnwinter is offline   Reply With Quote

Reply


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
Parallel UDF problem Lindsay FLUENT 4 June 20, 2016 10:37
UDF parallel Lucy Fluent UDF and Scheme Programming 3 May 28, 2013 14:14
Help with Define on Demand UDF in Parallel Mahesh FLUENT 2 August 7, 2007 06:34
Help: how to realize UDF on parallel cluster? Haoyin FLUENT 1 August 6, 2007 14:53
UDF in parallel version. yobee FLUENT 0 August 17, 2004 05:12


All times are GMT -4. The time now is 11:25.