CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   FLUENT (http://www.cfd-online.com/Forums/fluent/)
-   -   UDF compile error (http://www.cfd-online.com/Forums/fluent/79922-udf-compile-error.html)

feupes September 8, 2010 10:39

UDF compile error
 
Hi

When ever I try to compile the UDF file this message appears:
error C2109: subscript requires array or pointer type

What it should do is make a water tank vibrate with the action of a discrete acceleration in time.
Can anyone tell me where's the error and if there is a simpler way of writing this function?

Thanks in advance!

Here is the function:

#include"udf.h"
DEFINE_CG_MOTION(wave, dt, vel, omega, time, dtime)
{
/* these are the accelerations in each time step with deltat=0,02s*/
real a = 0.0580711302903;
real b = 0.0145322051660;
real c = -0.0404236449378;
real d = 0.264406521306;
real e = 0.118997934085;
real f = -0.118836401038;
real g = -0.0401178859565;
real h = -0.106652194087;
real i = -0.364683929085;
real j = -0.323308392979;
real k = -0.0480849265815;
real l = -0.0303855198926;
real m = 0.7425039562890;
real n = 1.83807300038;
real o = 1.40528558499;
real p = -0.171611555011;
real q = -1.24726011302;
real r = -0.934601363045;
real s = -0.760612964632;
real t = -1.35824485418;
real u = -1.68408008553;
real v = -1.19671180747;
real w = 0.188111001925;
real x = -0.450769504904;
real y = -1.40067612412;

real tempo;
tempo = time;

/* change of velocity with each time step */
/* v(i+1) = v(i) + accel*delta t */
if
(tempo <= 0.02)
{v[0] = v[0] + a*dtime;}
if (tempo <= 0.04)
{v[0] = v[0] + b*dtime;}
if (tempo <= 0.06)
{v[0] = v[0] + c*dtime;}
if (tempo <= 0.08)
{v[0] = v[0] + d*dtime;}
if (tempo <= 0.10)
{v[0] = v[0] + e*dtime;}
if (tempo <= 0.12)
{v[0] = v[0] + f*dtime;}
if (tempo <= 0.14)
{v[0] = v[0] + g*dtime;}
if (tempo <= 0.16)
{v[0] = v[0] + h*dtime;}
if (tempo <= 0.18)
{v[0] = v[0] + i*dtime;}
if (tempo <= 0.20)
{v[0] = v[0] + j*dtime;}
if (tempo <= 0.22)
{v[0] = v[0] + k*dtime;}
if (tempo <= 0.24)
{v[0] = v[0] + l*dtime;}
if (tempo <= 0.26)
{v[0] = v[0] + m*dtime;}
if (tempo <= 0.28)
{v[0] = v[0] + n*dtime;}
if (tempo <= 0.30)
{v[0] = v[0] + o*dtime;}
if (tempo <= 0.32)
{v[0] = v[0] + p*dtime;}
if (tempo <= 0.34)
{v[0] = v[0] + q*dtime;}
if (tempo <= 0.36)
{v[0] = v[0] + r*dtime;}
if (tempo <= 0.38)
{v[0] = v[0] + s*dtime;}
if (tempo <= 0.40)
{v[0] = v[0] + t*dtime;}
if (tempo <= 0.42)
{v[0] = v[0] + u*dtime;}
if (tempo <= 0.44)
{v[0] = v[0] + v*dtime;}
if (tempo <= 0.46)
{v[0] = v[0] + w*dtime;}
if (tempo <= 0.48)
{v[0] = v[0] + x*dtime;}
if (tempo <= 0.50)
{v[0] = v[0] + y*dtime;}
}

Micael September 8, 2010 17:09

If I understand what you try to do, you wrote v[0], but it should be vel[0].

Also, it looks to me that your "if" structure does not do what you expect it to do. As an example, if the statement (tempo <= 0.02) is true, then every statement of other "if" is also true. Hence, they will be all executed sequentially. In such case you get:
v[0] = v[0] + a*dtime + b*dtime + c*dtime + ... + y*dtime

feupes September 9, 2010 06:42

Re
 
Thanks a lot!
It works fine now

Regards feupes

feupes September 13, 2010 10:52

Re
 
The function works fine now but it only executes once every 0,02 seconds!
Does anyone know how to make it execute every fluent time step?

Thanks
feupes

Micael September 13, 2010 20:04

How does look like the function now?

feupes September 14, 2010 05:26

Re
 
This is the one I used:

#include"udf.h"
DEFINE_CG_MOTION(wave, dt, vel, omega, time, dtime)
{

real a = 0.0580711302903;
real b = 0.0145322051660;
real c = -0.0404236449378;
real d = 0.264406521306;
real e = 0.118997934085;
real f = -0.118836401038;
real g = -0.0401178859565;
real h = -0.106652194087;
real i = -0.364683929085;
real j = -0.323308392979;
real k = -0.0480849265815;
real l = -0.0303855198926;
real m = 0.7425039562890;
real n = 1.83807300038;
real o = 1.40528558499;
real p = -0.171611555011;
real q = -1.24726011302;
real r = -0.934601363045;
real s = -0.760612964632;
real t = -1.35824485418;
real u = -1.68408008553;
real v = -1.19671180747;
real w = 0.188111001925;
real x = -0.450769504904;
real y = -1.40067612412;

real tempo;
tempo = time;


if (tempo <= 0.02)
{vel[0] = vel[0] + a*dtime;}
if (0,02 < tempo <= 0.04)
{vel[0] = vel[0] + b*dtime;}
if (0,04 < tempo <= 0.06)
{vel[0] = vel[0] + c*dtime;}
if (0,06 < tempo <= 0.08)
{vel[0] = vel[0] + d*dtime;}
if (0,08 < tempo <= 0.10)
{vel[0] = vel[0] + e*dtime;}
if (0,10 < tempo <= 0.12)
{vel[0] = vel[0] + f*dtime;}
if (0,12 < tempo <= 0.14)
{vel[0] = vel[0] + g*dtime;}
if (0,14 < tempo <= 0.16)
{vel[0] = vel[0] + h*dtime;}
if (0,16 < tempo <= 0.18)
{vel[0] = vel[0] + i*dtime;}
if (0,18 < tempo <= 0.20)
{vel[0] = vel[0] + j*dtime;}
if (0,20 < tempo <= 0.22)
{vel[0] = vel[0] + k*dtime;}
if (0,22 < tempo <= 0.24)
{vel[0] = vel[0] + l*dtime;}
if (0,24 < tempo <= 0.26)
{vel[0] = vel[0] + m*dtime;}
if (0,26 < tempo <= 0.28)
{vel[0] = vel[0] + n*dtime;}
if (0,28 < tempo <= 0.30)
{vel[0] = vel[0] + o*dtime;}
if (0,30 < tempo <= 0.32)
{vel[0] = vel[0] + p*dtime;}
if (0,32 < tempo <= 0.34)
{vel[0] = vel[0] + q*dtime;}
if (0,34 < tempo <= 0.36)
{vel[0] = vel[0] + r*dtime;}
if (0,36 < tempo <= 0.38)
{vel[0] = vel[0] + s*dtime;}
if (0,38 < tempo <= 0.40)
{vel[0] = vel[0] + t*dtime;}
if (0,40 < tempo <= 0.42)
{vel[0] = vel[0] + u*dtime;}
if (0,42 < tempo <= 0.44)
{vel[0] = vel[0] + v*dtime;}
if (0,44 < tempo <= 0.46)
{vel[0] = vel[0] + w*dtime;}
if (0,46 < tempo <= 0.48)
{vel[0] = vel[0] + x*dtime;}
if (0,48 < tempo <= 0.50)
{vel[0] = vel[0] + y*dtime;}
}


I also came up with this one for the first 12 accelerations but it doesn't work at all..

#include "udf.h"

DEFINE_CG_MOTION(wave, dt, vel, omega, time, dtime)

{
int i;

real a [12] = { 0.145322051660, -0.404236449378, 2.64406521306, 1.18997934085, -1.18836401038, -0.401178859565, -1.06652194087, -3.64683929085, -3.23308392979, -0.480849265815, -0.303855198926, 7.425039562890 };


for (i = 1 ; i <= 12 ; i++)
{vel[0]= vel[0] + dtime*a[i-1];
if (time <= 0,02*i)
{i=i-1;}
}

}

Thanks for your help!

Micael September 14, 2010 10:36

First of all, there is some confusion in your code with decimal point and decimal comma. Only use decimal point.

Well, if I understand what you try to do, I would do this:

#include "udf.h"
DEFINE_CG_MOTION(wave, dt, vel, omega, time, dtime)
{
real a[25] = {0.0580711302903, 0.0145322051660, -0.0404236449378, 0.264406521306, 0.118997934085, -0.118836401038, -0.0401178859565, -0.106652194087, -0.364683929085, -0.323308392979, -0.0480849265815, -0.0303855198926, 0.7425039562890, 1.83807300038, 1.40528558499, -0.171611555011, -1.24726011302, -0.934601363045, -0.760612964632, -1.35824485418, -1.68408008553, -1.19671180747, 0.188111001925, -0.450769504904, -1.40067612412};

int i;
i = floor(time/0.02);
vel[0] += a[i]*dtime;
}

krishnaprasad September 15, 2010 01:17

udf problem
 
i have a program to generate stock's second order waves. but after loading in fluent the file name is not showing in the DYNAMIC ZONE WINDOW...and an error is showing that no moving zone selected!!...

what is Error: Divergence detected in AMG solver: x-momentum?

can u please help me.. i am including the udf.
thank u in adv

#include "udf.h"
#define PI 3.14159265
#define GRAV 9.81
#define H 1.5
#define D 10.0
#define T 6
#define L 20

DEFINE_PROFILE(x_velocity, thread, position)
{
real x[ND_ND];
real y;
real AA,BB,CC,DD,EE,FF,GG,LL,ZZ,K;
face_t f;
begin_f_loop(f, thread)
{
real t = RP_Get_Real("flow-time");
F_CENTROID(x,f,thread);
y = x[1];
ZZ= y - D;
K = 2*PI/L;
AA= cosh (K*(ZZ + D));
BB= cosh (K* D);
CC = sinh (K*D);
DD= cos (PI/2.0 -2.0 *PI*(t/T));
EE= cos (2.0*(PI/2.0 -2.0 *PI*(t/T)));
FF= cosh (2.0*K*D);
GG= cosh (2.0*(K*(ZZ + D)));
LL= D+(H*DD/2.0)+(PI*H*H/(8.0*L))*(BB/pow (CC,3.0))*(2.0+FF)*EE;

if (y <= D)
F_PROFILE(f,thread,position)=H/2.0*(GRAV*T/L)*AA*DD/BB+0.75*PI*PI*H*H/(L*T)*GG*EE/pow(CC,4.0);
else if (y <= LL)
F_PROFILE(f,thread,position)=H/2.0*(GRAV*T/L)*BB*DD/BB+0.75*PI*PI*H*H/(L*T)*FF*EE/pow(CC,4.0);
else
F_PROFILE(f, thread, position) = 0;
}
end_f_loop(f, thread)
}
DEFINE_PROFILE(y_velocity, thread, position)
{
real x[ND_ND];
real y;
real K,MM,NN,OO,PP,QQ,RR,SS,TT,UU,VV,WW,ZZZ;
face_t f;
begin_f_loop(f, thread)
{
real t = RP_Get_Real("flow-time");
F_CENTROID(x,f,thread);
y = x[1];
ZZZ= y - D;
K = 2*PI/L;
MM= sinh (K*(ZZZ + D));
NN= cosh (K* D);
OO= cos (PI/2.0 - (2.0 *PI* t/T));
WW= cos (2.0*(PI/2.0 -2.0 *PI*(t/T)));
VV= sin (PI/2.0 - (2.0 *PI* t/T));
QQ= sin (2.0*(PI/2.0 -2.0 *PI*(t/T)));
RR= sinh (K*D);
SS= cosh (2.0*K*D);
TT= sinh (2.0*(K*(ZZZ + D)));
UU= sinh (2.0*K*D);
PP= D+(H*OO/2.0)+(PI*H*H/(8.0*L))*(NN/pow (RR,3.0))*(2.0+SS)*WW;
if (y <= D)
F_PROFILE(f,thread,position)=H/2.0*(GRAV*T/L)*MM*VV/NN+0.75*PI*PI*H*H/(L*T)*TT*QQ/pow(RR,4.0);
else if (y <= PP)
F_PROFILE(f,thread,position)=H/2.0*(GRAV*T/L)*RR*VV/NN+0.75*PI*PI*H*H/(L*T)*UU*QQ/pow(RR,4.0);
else
F_PROFILE(f, thread, position) = 0;
}
end_f_loop(f, thread)
}


All times are GMT -4. The time now is 09:47.