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/)
-   -   error in conditional UDF code (https://www.cfd-online.com/Forums/fluent-udf/124401-error-conditional-udf-code.html)

Bollonga October 4, 2013 07:44

error in conditional UDF code
 
Hi guys,

I'm working on a dynamic mesh UDF, it is quite simple but when I try to compile my c code for the DEFINE_CG_MOTION I encounter an error in a line:

error c2100 illegal indirection

I post the code here:

DEFINE_CG_MOTION(wall, dt, cg_vel, cg_omega, time, dtime)
{

real vel, w, omega, T;

#define AMP 0.4;
#define FREQ 1

w = 2.0*M_PI*FREQ;
T=1/FREQ;

vel = AMP*sin(w*time);
omega = 0.5*M_PI*M_PI*sin(w*time);

if (mod(time,T) > T/4 && mod(time,T) < 3*T/4)
{
omega=-omega;
}

cg_vel[0] = vel; /* x-velocity*/
cg_vel[1] = 0.0;
cg_vel[2] = 0.0;

cg_omega[0]=0.0;
cg_omega[1]=0.0;
cg_omega[2]=omega;

}

The error is in the if line. (14 line)

I have tried several ways to write this conditional but I haven't found the way.

Does anybody know what's wrong there?

Thanks a lot!

kornetka October 6, 2013 03:39

Hi
I think all #defines should be placed outside DEFINE_CG_MOTION. Try putting them at the beginning of your udf, right after #includes.
Pzdr,
kornetkta

Bollonga October 7, 2013 04:36

Hi Kornetka,

Yes, I modified that and changed a little bit the code. Now the error is in the use of the function mod():

error LNK2019: unresolved external symbol mod referenced in function sheld

I post the new code:
Code:

DEFINE_CG_MOTION(wall, dt, cg_vel, cg_omega, time, dtime)
{

    real amp, freq, vel, w, omega, T, b;
 
    amp = 0.4;
    freq = 1;

    w = 2.0*M_PI*freq;
    T=1/freq;

    vel = amp*sin(w*time);
    omega = 0.5*M_PI*M_PI*sin(w*time);

    b=mod(time,T);

    if(b>T/4 && b<3*T/4)
      {
        omega=-omega;
      }

    cg_vel[0] = vel; /* x-velocity*/
    cg_vel[1] = 0.0;
    cg_vel[2] = 0.0;

    cg_omega[0]=0.0;
    cg_omega[1]=0.0;
    cg_omega[2]=omega;

}

Any ideas?

Thanks a lot!

kornetka October 7, 2013 12:01

Though it's tempting to use, I think the actual function is fmod(), not mod() - http://en.cppreference.com/w/c/numeric/math/fmod.


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