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

Linux vs PC Compiling

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 25, 2012, 12:38
Default Linux vs PC Compiling
  #1
Member
 
Ryne
Join Date: Jan 2010
Posts: 32
Rep Power: 16
Rhyno466 is on a distinguished road
I am rather new to programming of any sort, so I don't know if this is going to be a dumb question or not. I have a UDF that compiles and functions perfectly on Windows. I now have access to a cluster and would like to run my simulations on there. The problems is that while compiling the code, I get many errors about unused variables, none of which I get while compiling on windows. Linux also was not fond of my comments so I had to delete them to get the code to compile. They do load (even with the unused variables errors) but they do not work as I get negative volume errors after a couple time steps.

What code considerations do I need to make for Linux vs. PC?

Will the same math functions used for PC compile and function correctly on Linux?

Any and all help or insight would be vastly appreciated.
Rhyno466 is offline   Reply With Quote

Old   April 25, 2012, 16:46
Default
  #2
Member
 
Join Date: Nov 2011
Location: Czech Republic
Posts: 97
Rep Power: 14
Sixkillers is on a distinguished road
Are you sure that is caused by UDF? I didn't have any problems with compiling UDF on Linux boxes (GCC compiler). Frankly I had only issues with MS compiler, because source files have to be written according to C89 standard. Usually presence of unused variables just emit warnings (UDF is created) and not errors. What compilers flags do you use on Linux?
Sixkillers is offline   Reply With Quote

Old   May 5, 2012, 21:59
Default
  #3
Member
 
Ryne
Join Date: Jan 2010
Posts: 32
Rep Power: 16
Rhyno466 is on a distinguished road
I cannot figure out for the life of me what is wrong with the UDF's with respect to linux. Again, they work absolutely fine on windows but fail on linux. I think the error is due to the calculation of B (beta angle). I get a bunch of unused variable warnings including fp1, P1, T1, I1, r1, Rt1, Rl1, TFY1, TFX1, LFY1, and LFX1.

Here is the UDF. If anyone has any insight into what might be causing these problems that I'm having, I am open to try anything to get this working!!

Code:
#include "udf.h"

double B1 = 0;         
double Bdeg1 = 0;    
double w1 = 0;        
double LVX1 = 0;        
double LVY1 = 0;        
double LX1 = -0.7366;    
double LY1 = 0;            
double V1 = 0;        
double alpha1 = -0.087266;    
double adeg1 = -5;        
double s1 = 0;        
double st1 = 0;        
double lim1 = 0.252;    
double aa1 = 0.087266;    
double da1 = 1.74533;    

DEFINE_CG_MOTION(leading,dt,vel,omega,time,dtime)
{

double flx1 = 0;        
double flvx1 = 0;    
double flvy1 = 0;    
double fly1 = 0;        
double ftx1 = 0;        
double fty1 = 0;        
double ftvx1 = 0;    
double ftvy1 = 0;    
double LFX1 = 0;        
double LFY1 = 0;        
double TFX1 = 0;        
double TFY1 = 0;        
double Rl1 = 0;        
double Rt1 = 0;        
double r1 = .7366;    
double I1 = 1;        
double T1 = 0;        
double ad1 = 0;        
double P1 = 0;        
FILE *fp1;            

#if !RP_HOST        
Domain *d = Get_Domain(1);    
Thread *t1 = Lookup_Thread(d,5);        
Thread *t2 = Lookup_Thread(d,6);        
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);                
flx1 += F_P(f,t1) * A[0];      
fly1 += F_P(f,t1) * A[1];    
flvx1 += -F_STORAGE_R_N3V(f,t1,SV_WALL_SHEAR)[0];     
flvy1 += -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);        
ftx1 += F_P(f,t2) * A[0];    
fty1 += F_P(f,t2) * A[1];    
ftvx1 += -F_STORAGE_R_N3V(f,t2,SV_WALL_SHEAR)[0];    
ftvy1 += -F_STORAGE_R_N3V(f,t2,SV_WALL_SHEAR)[1];    
}
}
end_f_loop(f,t2)        

# if RP_NODE    
flx1 = PRF_GRSUM1(flx1);        
fly1 = PRF_GRSUM1(fly1);        
flvx1 = PRF_GRSUM1(flvx1);    
flvy1 = PRF_GRSUM1(flvy1);    

ftx1 = PRF_GRSUM1(ftx1);        
fty1 = PRF_GRSUM1(fty1);        
ftvx1 = PRF_GRSUM1(ftvx1);    
ftvy1 = PRF_GRSUM1(ftvy1);     

# endif 
# endif 

node_to_host_double_4(ftx1,fty1,ftvx1,ftvy1);    
node_to_host_double_4(flx1,fly1,flvx1,flvy1);    

#if !RP_NODE        
LFX1 = flx1+flvx1;        
LFY1 = fly1+flvy1;        
TFX1 = ftx1+ftvx1;        
TFY1 = fty1+ftvy1;        
Rl1 = LFY1*cos(B1) + LFX1*sin(B1);        
Rt1 = TFY1*cos(B1) + TFX1*sin(B1);        
st1 = s1 * B1;        
T1 = (Rl1*r1) + (Rt1*-r1) - st1;    
w1 += dtime * T1 / I1;        
P1 = T1 * w1;            
V1 = w1*r1;            
LVX1 = V1 * sin(B1);    
LVY1 = V1 * cos(B1);    
LX1 += LVX1 * dtime;    
LY1 += LVY1 * dtime;    
B1 = asin(LY1/r1) * (3.141592654/180);        
Bdeg1 = B1 * (180 / 3.141592654);    

if (LY1 <= -lim1 && alpha1 <= aa1)        
{
ad1 = -da1;        
}

if (LY1 >= lim1 && alpha1 >= -aa1)     
{
ad1 = da1;        
}

alpha1 += -ad1 * dtime;        
adeg1 = alpha1 * (180 / 3.141592654);    

if (time < 2*dtime)        
    {
    fp1 = fopen("data.txt","a");
    fprintf(fp1,"%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\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","Alpha1","AD1","RAD1","Torque","Power","Spring T");
    fclose(fp1);
    }
    
fp1 = fopen("data.txt","a");        
fprintf(fp1,"%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%f\t%f\t%f\t%f\t%f\t%f\n",time,flx1,fly1,flvx1,flvy1,ftx1,fty1,ftvx1,ftvy1,LFX1,LFY1,TFX1,TFY1,Bdeg1,w1,LVX1,LVY1,LX1,LY1,adeg1,ad1,alpha1,T1,P1,st1);
fclose(fp1);

# endif

host_to_node_double_3(LVX1,LVY1,ad1);    

vel[0] = LVX1;     
vel[1] = LVY1;    
omega[2] = ad1;

}
Rhyno466 is offline   Reply With Quote

Old   May 6, 2012, 17:18
Default
  #4
Member
 
Join Date: Nov 2011
Location: Czech Republic
Posts: 97
Rep Power: 14
Sixkillers is on a distinguished road
Work like a charm on GCC 4.6.3.
Sixkillers is offline   Reply With Quote

Old   May 6, 2012, 19:39
Default
  #5
Member
 
Ryne
Join Date: Jan 2010
Posts: 32
Rep Power: 16
Rhyno466 is on a distinguished road
Quote:
Originally Posted by Sixkillers View Post
Work like a charm on GCC 4.6.3.
As in it did not give you unused variable errors?

Did you compile through fluent or manually?

Did you compile while running in parallel?
Rhyno466 is offline   Reply With Quote

Old   May 7, 2012, 04:58
Default
  #6
Member
 
Join Date: Nov 2011
Location: Czech Republic
Posts: 97
Rep Power: 14
Sixkillers is on a distinguished road
Quote:
As in it did not give you unused variable errors?
yes, no errors and no warnings


Quote:
Did you compile through fluent or manually?
manually

Quote:
Did you compile while running in parallel?
I compiled for serial, I could try it for parallel too if you want.
Sixkillers is offline   Reply With Quote

Old   May 9, 2012, 14:31
Default
  #7
Member
 
Ryne
Join Date: Jan 2010
Posts: 32
Rep Power: 16
Rhyno466 is on a distinguished road
Can you try parallel? Also, is there someplace you can direct me about compiling manually? Thanks
Rhyno466 is offline   Reply With Quote

Old   May 9, 2012, 17:18
Default
  #8
Member
 
Join Date: Nov 2011
Location: Czech Republic
Posts: 97
Rep Power: 14
Sixkillers is on a distinguished road
When I compile it on parallel I see warnings about unused variables, but UDF library is created. The UDF manual explains well how to compile your custom UDF on Unices (I am using 64bit Linux).
Sixkillers is offline   Reply With Quote

Old   May 10, 2012, 15:19
Default
  #9
Member
 
Ryne
Join Date: Jan 2010
Posts: 32
Rep Power: 16
Rhyno466 is on a distinguished road
Ok, that is what I get too and the simulations runs but eventually fails. I believe this is due to how variables in the UDF are being calculated (or not being properly calculated). Do you have any insight or suggestions for my UDF?
Rhyno466 is offline   Reply With Quote

Old   May 10, 2012, 15:49
Default
  #10
Member
 
Join Date: Nov 2011
Location: Czech Republic
Posts: 97
Rep Power: 14
Sixkillers is on a distinguished road
It is good practice to check (at least in the stage of debugging), if you returning valid data to Fluent. For example they are finite and have physical meaning. For that purpose you can use isfinite(x) macro (in GCC) or _finite(x) when you are using MS compiler. Here is my set of macros, which I use for both compilers.

Code:
#ifdef _MSC_VER /*for MS compiler*/
#include <float.h>
#define isfinite(x) _finite(x)
#define isnan(x) _isnan(x)
#endif

#define CHECK_COEF(result) \
    if(!isfinite(result)) { \
       fprintf(stderr, "\nDetected: %e in %s:%i\n", result, __FUNCTION__, __LINE__); \
       abort(); } \
       (void)0
#endif
Then you just call CHECK_COEF(yourVariable); before each function return. It isn't really magical, but it helped me to troubleshoot my UDFs several times

Last edited by Sixkillers; May 11, 2012 at 17:13.
Sixkillers is offline   Reply With Quote

Old   May 11, 2012, 18:01
Default
  #11
Member
 
Ryne
Join Date: Jan 2010
Posts: 32
Rep Power: 16
Rhyno466 is on a distinguished road
Thanks for your help. Apparently I have been using the wrong parallel interconnect settings. Once I used the correct ones, everything was fine. I never really thought about that because I used simpler UDF's without a problem before!
Rhyno466 is offline   Reply With Quote

Reply

Tags
compiling, linux

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
Compiling Error Red Hat Linux 5 LWhitson2 OpenFOAM Installation 1 October 16, 2011 05:42
Dual Boot Windows and Linux and Go Open Source andyj Main CFD Forum 2 October 21, 2010 17:49
Problem Compiling OF 15 On linux 64 skidootom OpenFOAM Bugs 1 October 9, 2008 17:10
Compiling OF on Linux mips64 mou_mi OpenFOAM Installation 0 June 25, 2008 18:20
Compiling UDF's Under Linux OS Yasser Nabavi FLUENT 2 April 24, 2006 20:59


All times are GMT -4. The time now is 04:40.