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

Parallelize UDF help

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 13, 2012, 17:00
Default Parallelize UDF help
  #1
Member
 
Ryne
Join Date: Jan 2010
Posts: 32
Rep Power: 16
Rhyno466 is on a distinguished road
I have written a UDF for a dynamic mesh movement. I think I have parallelized it correctly, but my output file ends up having two entries for each timestep. The worst part is that i copied a previous (simpler test) code that works and just added to it. I do not know what I am doing wrong and am hoping someone can spot the error in my code.

Code:

Code:
#include "udf.h"

DEFINE_CG_MOTION(thesis_1,dt,vel,omega,time,dtime)
{
/* Initialize the variables */
double flx = 0;
double flvx = 0;
double flvy = 0;
double fly = 0;
double ftx = 0;
double fty = 0;
double ftvx = 0;
double ftvy = 0;
double LFX = 0;
double LFY = 0;
double TFX = 0;
double TFY = 0;
double B = 0.087266463;
double Bdeg = 5;
double Rl = 0;
double Rt = 0;
double r = .7366;
double I = 50;
double t = 0;
double w = 0;
double LVX = 0;
double LVY = 0;
double LX = -0.733797015;
double LY = 0.06419892;
double V = 0;
FILE *fp;


#if !RP_HOST
Domain *d = Get_Domain(1);
Thread *t1 = Lookup_Thread(d,18);
Thread *t2 = Lookup_Thread(d,19);
face_t f;
real NV_VEC(A);
#endif

#if !RP_HOST
begin_f_loop(f,t1)
{
if PRINCIPAL_FACE_P(f,t1)
{
F_AREA(A,f,t1);
flx += F_P(f,t1) * A[0];
fly += F_P(f,t1) * A[1];
flvx += -F_STORAGE_R_N3V(f,t1,SV_WALL_SHEAR)[0];
flvy += -F_STORAGE_R_N3V(f,t1,SV_WALL_SHEAR)[1];
}
}
end_f_loop(f,t1)

begin_f_loop(f,t2)
{
if PRINCIPAL_FACE_P(f,t2)
{
F_AREA(A,f,t2);
ftx += F_P(f,t2) * A[0];
fty += F_P(f,t2) * A[1];
ftvx += -F_STORAGE_R_N3V(f,t2,SV_WALL_SHEAR)[0];
ftvy += -F_STORAGE_R_N3V(f,t2,SV_WALL_SHEAR)[1];
}
}
end_f_loop(f,t2)

# if RP_NODE
flx = PRF_GRSUM1(flx);
fly = PRF_GRSUM1(fly);
flvx = PRF_GRSUM1(flvx);
flvy = PRF_GRSUM1(flvy);

ftx = PRF_GRSUM1(ftx);
fty = PRF_GRSUM1(fty);
ftvx = PRF_GRSUM1(ftvx);
ftvy = PRF_GRSUM1(ftvy); 

# endif 
# endif 

node_to_host_real_4(ftx,fty,ftvx,ftvy);
node_to_host_real_4(flx,fly,flvx,flvy);

#if !RP_NODE
LFX = flx+flvx;
LFY = fly+flvy;
TFX = ftx+ftvx;
TFY = fty+ftvy;
Rl = LFY*cos(B) + LFX*sin(B);
Rt = TFY*cos(B) + TFX*sin(B);
t = (Rl*r) + (Rt*-r);
w += dtime * t / I;
V = w*r;
LVX = V * sin(B);
LVY = V * cos(B);
LX += LVX * dtime;
LY += LVY * dtime;
B = asin(LY/r);
Bdeg = B * (180 / 3.141592654);

if (time < 2*dtime)
    {
    fp = fopen("data.txt","a");
    fprintf(fp,"%s\t\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t\t%s\t\t%s\t\t%s\t\t%s\t\t%s\t\t%s\t\t%s\t\t%s\t\t%s\n","Time","Lead X P","Lead Y P","Lead X V","Lead Y V","Trail X P","Trail Y P","Trail X V","Trail Y V","Lead X","Lead Y","Trail X","Trail Y","Beta","Omega","LVX","LVY","LX","LY");
    fclose(fp);
    }
    
fp = fopen("data.txt","a");
fprintf(fp,"%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t\n",time,flx,fly,flvx,flvy,ftx,fty,ftvx,ftvy,LFX,LFY,TFX,TFY,Bdeg,w,LVX,LVY,LX,LY);
fclose(fp);

Message ("\nL x Vel = %f L y Vel = %f\n", LVX,LVY);

vel[0] = LVX;     
vel[1] = LVY;
# endif


}
Output file example (columns have been excluded):

Code:
Time        Lead X P    Lead Y P    Lead X V    Lead Y V
0.001000    0.000000    0.000000    0.000000    0.000000
Time        Lead X P    Lead Y P    Lead X V    Lead Y V
0.001000    0.000000    0.000000    0.000000    0.000000
0.002000    10.623311    36.454840    0.872069    -0.048243
0.002000    10.623311    36.454840    0.872069    -0.048243
0.003000    0.466253    6.171916    0.494376    -0.022958
0.003000    0.466253    6.171916    0.494376    -0.022958
0.004000    0.472719    6.516934    0.409909    -0.016084
0.004000    0.472719    6.516934    0.409909    -0.016084
0.005000    0.483602    6.807011    0.358680    -0.011679
0.005000    0.483602    6.807011    0.358680    -0.011679
Rhyno466 is offline   Reply With Quote

Old   February 14, 2012, 15:49
Default Update
  #2
Member
 
Ryne
Join Date: Jan 2010
Posts: 32
Rep Power: 16
Rhyno466 is on a distinguished road
It seems that this double printing entry occurs whether or not I am in serial or parallel mode. What would cause Fluent to look at those output lines of code twice per time step? Also, where should the vel[x] code be for this calculation?
Rhyno466 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 parallel error: chip-exec: function not found????? shankara.2 Fluent UDF and Scheme Programming 1 January 16, 2012 23:14
Problem to parallelize a UDF pilou FLUENT 0 March 9, 2011 07:32
Can any one suggest How to Parallelize Serial UDF sri31049 Fluent UDF and Scheme Programming 0 September 9, 2010 08:10
Parallelize a udf coolengineer Fluent UDF and Scheme Programming 0 May 4, 2009 13:35
UDF Help Parallelize Awais Jaffery FLUENT 3 April 30, 2008 02:39


All times are GMT -4. The time now is 22:39.