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/)
-   -   Linux vs PC Compiling (https://www.cfd-online.com/Forums/fluent-udf/100439-linux-vs-pc-compiling.html)

Rhyno466 April 25, 2012 11:38

Linux vs PC Compiling
 
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.

Sixkillers April 25, 2012 15:46

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?

Rhyno466 May 5, 2012 20:59

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;

}


Sixkillers May 6, 2012 16:18

Work like a charm on GCC 4.6.3.

Rhyno466 May 6, 2012 18:39

Quote:

Originally Posted by Sixkillers (Post 359588)
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?

Sixkillers May 7, 2012 03:58

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.

Rhyno466 May 9, 2012 13:31

Can you try parallel? Also, is there someplace you can direct me about compiling manually? Thanks

Sixkillers May 9, 2012 16:18

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).

Rhyno466 May 10, 2012 14:19

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?

Sixkillers May 10, 2012 14:49

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 :)

Rhyno466 May 11, 2012 17:01

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!


All times are GMT -4. The time now is 10:48.