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/)
-   -   the udf has been hooked to the fluent successfully,but it does not work! (https://www.cfd-online.com/Forums/fluent-udf/89065-udf-has-been-hooked-fluent-successfully-but-does-not-work.html)

hugeforest June 3, 2011 03:57

the udf has been hooked to the fluent successfully,but it does not work!
 
I want to use udf (DEFINE_CG_MOTION) to determine the motion of a rectangular body (2D) according to the pressure on the top and bottom faces. The udf has been successfully hooked to the FLUENT, and the zone has also been successfully defined. But the rectangular body's motion was not affected by the udf and it did not move at all. I'm sure that there is a big difference of the pressure on both faces. There were no error information at all. Additionally, I try to use the command "message" to output the value of some parameters, but no information was shown up in the TUI windows.
I really appreciate your help. Thank you.
Here is my udf:

#include "udf.h"
#include "dynamesh_tools.h"

/* velocities */
static real v_invalve1 = 0.0;
static real v_exvalve1 = 0.0;

/* displacement */
static real s_invalve1 = 0.0;
static real s_exvalve1 = 0.0;

static real lift = -0.0015;

DEFINE_CG_MOTION(invalve1,dt,vel,omega,time,dtime)
{
Thread *t1, *t2;
face_t f;
real NV_VEC(A);
real force, dv, a, ds;
Domain * domain;

int zone_id1=81;
int zone_id2=91;

/* 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 */
domain=THREAD_DOMAIN(DT_THREAD(dt));
t1=Lookup_Thread(domain,zone_id1);
t2=Lookup_Thread(domain,zone_id2);

/* compute pressure force on body by looping through all faces */
force = 0.0;
begin_f_loop(f,t1)
{
F_AREA(A,f,t1);
force += F_P(f,t1) * A[1];
}
end_f_loop(f,t1)

begin_f_loop(f,t2)
{
F_AREA(A,f,t2);
force += F_P(f,t2) * A[1];
}
end_f_loop(f,t2)

/* compute change in velocity, i.e., dv = F * dt / mass
velocity update using explicit Euler formula */
a=force/0.1089;
ds=0.5*a*dtime*dtime;
if(s_invalve1+ds<=lift)
{
v_invalve1=(lift-s_invalve1)/dtime;
s_invalve1=lift;
}
else if(s_invalve1+ds>=0)
{
v_invalve1=(0-s_invalve1)/dtime;
s_invalve1=0;
}
else
{
dv = dtime * a;
v_invalve1 += dv;
s_invalve1 += ds;
}
Message ("time = %f, y_vel = %f, force = %f\n", time, v_invalve1, force);

/* set y-component of velocity */
vel[1] = v_invalve1;
}

sri31049 July 8, 2011 04:31

Hi,

First calculate the pressure force and velocity using DEFINE_EXECUTE_AT_END .

Second use that velocity in DEFINE_CG_MOTION

I hope it will work :)


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