|
楼主 |
发表于 2012-8-21 14:36:58
|
显示全部楼层
#include "udf.h"
#include <mem.h>
static real omega_calc = 0.0;
static real theta=0.697777777;
/*extern real omega_out=0.0; */
DEFINE_CG_MOTION(move_flapper,dt,vel,omega,time,dtime)
{
NV_S(omega, =, 0.0);
real torque, torque_w, torque_p,domega, omega_prev, omega_dot, omega_out;
const real inertia = 0.1875;
/* Compute the torque due to pressure P and weight W */
/*-----------------------------------------------------------------------*/
torque_w= -10.06506 * sin(theta); /* -g*L*W*sin(theta) */
torque_p= 81.61488* cos(theta);
torque= torque_p + torque_w;
domega = dtime * torque / inertia;
omega_dot= torque / inertia;
/* Calculate the angular velocity */
/*-----------------------------------------------------------------------*/
omega_prev = omega_calc;
omega_calc = omega_calc + domega;
omega_out = omega_calc;
/* Calculate the angle theta (Taylor expansion) */
/*-----------------------------------------------------------------------*/
theta=theta + 0.5*dtime*(omega_prev+omega_calc);
#if !RP_NODE
Message ("\ntorque_p = %f, torque_W = %f, torque = %f, domega = %f, omega_calc=%f\n", torque_p, torque_W, torque, domega, omega_calc);
Message ("\n---------------------------------------");
Message ("\ntheta: %f\n", theta);
#endif
/* Resitrictions, make it stop at the end points*/
/*-----------------------------------------------------------------------*/
if (theta < 0.0872664626*1.1) /* Corresponds to 5.5 degrees */
{
omega_out=0;
omega_calc=0;
domega=0;
theta=0.0872664626*1.1;
Message("\nSTOP - Almost closed!");
}
if (theta >0.697777777)
{
omega_out=0;
omega_calc=0;
domega=0;
theta=0.697777777;
Message("\nSTOP - Fully open!");
}
#if !RP_NODE
/* Saving the values*/
/*-----------------------------------------------------------------------*/
FILE *fd_time;
FILE *fd_torque;
FILE *fd_omega;
FILE *fd_theta;
fd_time = fopen("data_time.txt","a");
fd_torque = fopen("data_torque.txt","a");
fd_omega = fopen("data_omega.txt","a");
fd_theta = fopen("data_theta.txt","a");
fprintf(fd_time, "%f \n", time);
fprintf(fd_torque, "%f \n", torque);
fprintf(fd_omega, "%f \n", omega_out);
fprintf(fd_theta, "%f \n", theta);
fclose(fd_time);
fclose(fd_torque);
fclose(fd_omega);
fclose(fd_theta);
Message ("\nomega: %f\n ", omega_out) ;
Message ("\n---------------------------------------\n");
#endif
omega[1]=omega_out;
} |
|