CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   FLUENT (http://www.cfd-online.com/Forums/fluent/)
-   -   how can I correct the udf? (http://www.cfd-online.com/Forums/fluent/81209-how-can-i-correct-udf.html)

happyrabbit October 19, 2010 23:14

how can I correct the udf?
 
Hi,everyone. My udf has several errors as blow:
..\..\src\adjust.c(3) : error C2061: syntax error : identifier 'DEFINE'
..\..\src\adjust.c(3) : error C2059: syntax error : ';'
..\..\src\adjust.c(3) : error C2143: syntax error : missing '{' before '-'
..\..\src\adjust.c(3) : error C2059: syntax error : '-'
..\..\src\adjust.c(54) : error C2065: 'thread' : undeclared identifier
..\..\src\adjust.c(54) : error C2223: left of '->storage' must point to struct/union
..\..\src\adjust.c(56) : error C2223: left of '->storage' must point to struct/union
..\..\src\adjust.c(80) : error C2065: 'thread' : undeclared identifier
..\..\src\adjust.c(80) : error C2223: left of '->storage' must point to struct/union
..\..\src\adjust.c(82) : error C2223: left of '->storage' must point to struct/union
and the udf itself as below:
#include "udf.h"
DEFINE_ADJUST(print_f_centroids, domain)
real F-UDMI(f,thread,0)
{ Thread *thread;
face_t f;
real force1=0.,force2=0.;
int ID = 13;
Thread *t= Lookup_Thread(domain, ID);
{
begin_f_loop(f, thread)
{
F_AREA(A,f,thread);
force1+=F_P(f, thread)*NV_MAG(A);
return force1;
}
end_f_loop(f, thread)
}
int ID=16;
Thread *thread = Lookup_Thread(domain, ID);
{
begin_f_loop(f, thread)
{
F_AREA(A,f,thread);
force2+=F_P(f, thread)*NV_MAG(A);
return force2;
}
end_f_loop(f, thread)
}

F_UDMI(f,thread,0)=force1-force2;
printf("F_UDMI(f,thread,0) = %f ", F_UDMI(f,thread,0));
}
DEFINE_CG_MOTION(moveface,dt,vel,omega,time,dtime)
{ Thread *t;
face_t f;
real NV_VEC (A);
real dv;
static real v_prev=0.0;
/* reset velocities */
NV_S(vel,=,0.0);
NV_S(omega,=,0.0);
if(!Data_Valid_P())
return;
/* get the thread pointer for which this motion is defined */
t=DT_THREAD (dt);

/* compute change in velocity, i.e., dv = F * dt / mass
velocity update using explicit Euler formula */
dv=dtime*F_UDMI(f,t,0)/0.05;
v_prev+=dv;
Message("time=%f,x_vel=%f,F_UDMI(f,t,0)=%f\n",time ,v_prev,F_UDMI(f,t,0));
/* set x-component of velocity */
vel[0]=v_prev;
}
DEFINE_CG_MOTION(moveface1,dt,vel,omega,time,dtime )
{ Thread *t;
face_t f;
real NV_VEC (A);
real dv;
static real v_prev=0.0;
/* reset velocities */
NV_S(vel,=,0.0);
NV_S(omega,=,0.0);
if(!Data_Valid_P())
return;
/* get the thread pointer for which this motion is defined */
t=DT_THREAD (dt);
/* compute change in velocity, i.e., dv = F * dt / mass
velocity update using explicit Euler formula */
dv=dtime*F_UDMI(f,t,0)/0.05;
v_prev+=dv;
Message("time=%f,x_vel=%f,F_UDMI(f,t,0)=%f\n",time ,v_prev,F_UDMI(f,t,0));
/* set x-component of velocity */
vel[0]=v_prev;
}
could anyone give me some suggestion ? thanks a lot.

Laurence Wallian October 20, 2010 02:32

the function F-UDMI(f,thread,0) is already defined !
 
I'm not sure, but try to remove the line real F-UDMI(f,thread,0).

P.S. however, I think a ";" is missing in such line : F-UDMI(f,thread,0)

happyrabbit October 20, 2010 02:44

Thanks for your reply.
I use "real F_UDMI(f,thread,0)" to make a sub-function .
can not it work?
just now,I compiled it again ,the error becomes
..\..\src\adjust.c(3) : error C2059: syntax error : 'type'
..\..\src\adjust.c(34) : fatal error C1903: unable to recover from previous error(s); stopping compilation.
can not it work?

happyrabbit October 20, 2010 02:56

what confused me is that for the ID function , the purpose of accessing the force of the wall , is this format write ?
In my model, there are 3 faces need to calculate the force , should I write all of the 3 sub-fuctions in one bracket like the udf I uploaded ?
can you give me some example of the same type?
I will appreciate you very much!

Laurence Wallian October 20, 2010 03:33

sorry but I have never used F_UDMI.

I've juste use DEFINE_ADJUST to sum some variables during unsteady run

but what can I say is that I think you make a confusion between "," and ";"

real force1=0.,force2=0.; => real force1=0.; force2=0.;

In C, all instructions must be closed by a ";"

good luck

happyrabbit October 20, 2010 03:51

Thanks a lot!
I have delete the real F_UDMI,and now it indicates other errors.
I think it is allowable to define multi-paremeters in a parellel line with ,and a ; at the end of the line.
also, the console indicate that the DEFINE_ADJUST could not be used to ruturn a parameter,so I cancle the macro also , instead, put the conmmand to the macro of DEFINE_CG_MOTION.

Laurence Wallian October 20, 2010 04:32

1 Attachment(s)
you can define a variable in your C program.

I don't know if it can help you but in the file joined here, I defined the mean of U,V et P every 10 irerations (it was an unsteady run) :
- I defined a variable CMPT and 3 UDM : U, V and P
- these variables can then be visibles in case-data

happyrabbit October 20, 2010 08:39

Thanks ,I get it that use C_UDMI can get the data translating from the DEFINE_ADJUST.but I still feel that the configuration is in babelism,would you give me some suggestion?

Laurence Wallian October 20, 2010 10:28

sorry but I don't understand your request: if you want to measure forces on faces, you will need F_UDMI instead of C_UDMI ?!

calvin January 28, 2011 10:50

did u find ur way to avoid the " left of storage must point to struct/union" ...i am facing similar errors


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