CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   a udf of rotating by DEFINE_ZONE_MOTION & Compute_Force_And_Moment:access violation (https://www.cfd-online.com/Forums/fluent/152679-udf-rotating-define_zone_motion-compute_force_and_moment-access-violation.html)

ender-x May 6, 2015 08:55

a udf of rotating by DEFINE_ZONE_MOTION & Compute_Force_And_Moment:access violation
 
1 Attachment(s)
Hi everyone,

I want to simulate a turbine's rotation in free stream and write the udf as below:

#include "udf.h"
#include "f_wall.h"
static real theta=0.0;
static real omega_calc=0.0;
int flag=0;

DEFINE_ZONE_MOTION(turbinemotion,omega,axis,origin ,velocity,time,dtime)
{
const real inertia =1.38;
Domain *small=Get_Domain(3);
Thread *face_rotor=Lookup_Thread(small,9);
real force_rotor[ND_ND],moment_rotor[ND_ND];
real point_rotor[ND_ND];
real axis_rotor[3]={0.0, 0.0, 1.0}; /* shaft axis directional vector */
real torque_rotor;
real torque,domega,omega_prev,omega_dot,omega_out,power ;
FILE *fd;
int i;
for(i=0;i<=ND_ND;i++)
{
force_rotor[i]=0;
moment_rotor[i]=0;
point_rotor[i]=0;
}
Message ("\npoint2 %f\n ", theta) ;
/* Problem occurs on the line below */
Compute_Force_And_Moment(small,face_rotor,point_ro tor,force_rotor,moment_rotor,1);
Message ("\npoint3 %f\n ", theta) ;
torque_rotor=NV_DOT(moment_rotor,axis_rotor);
torque=torque_rotor;
domega=dtime*torque/inertia;
omega_dot=torque/inertia;
omega_prev=omega_calc;
omega_calc=omega_calc + domega;
omega_out=omega_calc;
theta=theta+0.5*dtime*(omega_prev+omega_calc);
power=torque*omega_out;
Message ("\npoint4 %f\n ", theta) ;
N3V_D (velocity,=,0.0,0.0,0.0);
N3V_D(axis,=,0.0,0.0,1.0);

if ( flag !=N_TIME)
{
fd=fopen("data.txt","a+");
if(flag==0)
{
fprintf(fd,"time torque omega theta power\n");
}
flag=N_TIME;
fprintf(fd," %g %g %g %g %g\n",CURRENT_TIME,torque,omega_out,theta,power);
fclose(fd);
}
Message ("\nomega: %f\n ", omega_out) ;
Message ("\n---------------------------------------\n");

*omega=omega_out;
}

This udf can be compiled by fluent. When I run the simulation an 'access violation' error occured as shown in attached. Now I can confirm that the problem is on the function Compute_Force_And_Moment (see udf /* Problem occurs on the line below */ ), but I don't know how to correct it. Can anybody give me some suggestions?

Thanks in advance.


All times are GMT -4. The time now is 01:55.