|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
本人见了一篇6dof资料,但对里面的last_call代表什么意思不能理解,还有在编译时出错是怎么回事?好像不认识boolean这个..\..\src\6dof.c(195) : error C2146: syntax 运算符 ,我算的是单刚体,是否可以把last_call去掉
下面是compiled时出现的错误
error : missing ';' before identifier 'last_call'
..\..\src\6dof.c(195) : error C2065: 'last_call' : undeclared identifier
望大虾不吝赐教
程序如下:- #include "udf.h"
- #define ZONE_ID1 8 /* face ID of the moving object */
- /* properties of moving object: */
- #define MASS 907.185 /* mass of object, kg */
- #define IXX 27.116 /* moment of intertia, Nms^2 */
- #define IYY 488.094 /* moment of intertia, Nms^2*/
- #define IZZ 488.094 /* moment of intertia, Nms^2 */
- #define IXZ 0.0 /* moment of intertia, Nms^2 */
- #define IXY 0.0 /* moment of intertia, Nms^2 */
- #define IYZ 0.0 /* moment of intertia, Nms^2 */
- #define NUM_CALLS 2 /* number of times routine called
- (number of moving zones) */
- #define R2D 180./M_PI
- /*******************************************************
- * Read/write velocites file
- *******************************************************/
- #if !RP_NODE
- static void
- write_velocities (real *v_old, real *om_old, real *euler)
- {
- FILE *file_velo;
- register int i;
- if ((file_velo = fopen ("velocities_3d", "w")) == NULL)
- Message ("\nCannot open velocities_3d file");
- for (i = 0; i < ND_ND; i++)
- fprintf (file_velo, "%e ", v_old);
- for (i = 0; i < 3; i++)
- fprintf (file_velo, "%e ", om_old);
- for (i = 0; i < 3; i++)
- fprintf (file_velo, "%e ", euler);
- fclose(file_velo);
- }
- #endif
- static void
- read_velocities (real *v_old, real *om_old, real *euler)
- {
- float read_v_old[3], read_om_old[3], read_euler[3];
- register int i;
- #if !RP_NODE
- FILE *file_velo;
- if ((file_velo = fopen ("velocities_3d", "r")) == NULL)
- {
- Message ("\nCannot open velocities_3d file...creating one!");
- if ((file_velo = fopen ("velocities_3d", "w")) == NULL)
- Message ("\nCannot create velocities_3d file...dying!");
- else
- {
- for (i = 0; i < 9; i++)
- fprintf (file_velo, "%e ", 0.0);
- fclose (file_velo);
- file_velo = fopen ("velocities_3d", "r");
- }
- }
- for (i = 0; i < ND_ND; i++)
- fscanf(file_velo, "%e", &read_v_old);
- # if RP_2D
- read_v_old[2] = 0.0;
- # endif
- for (i = 0; i < 3; i++)
- fscanf(file_velo, "%e", &read_om_old);
- for (i = 0; i < 3; i++)
- fscanf(file_velo, "%e", &read_euler);
- fclose(file_velo);
- #endif
- #if PARALLEL
- {
- real exchange[9];
- # if RP_HOST
- for (i = 0; i < 3; i++)
- {
- exchange = (real)read_v_old;
- exchange[i + 3] = (real)read_om_old;
- exchange[i + 6] = (real)read_euler;
- }
- # endif
- host_to_node_real (exchange, 9);
- # if RP_NODE
- for (i = 0; i < 3; i++)
- {
- read_v_old = (float)exchange;
- read_om_old = (float)exchange[i + 3];
- read_euler = (float)exchange[i + 6];
- }
- # endif
- }
- #endif /* PARALLEL */
- for (i = 0; i < 3; i++)
- {
- v_old = (real)read_v_old;
- om_old = (real)read_om_old;
- euler = (real)read_euler;
- }
- }
- /*******************************************************
- * Main 6DOF UDF
- *******************************************************/
- DEFINE_CG_MOTION(six_dof, dt, cg_vel, cg_omega, time, dtime)
- /* six_dof = name shown in Fluent GUI
- dt = thread
- cg_vel = old/updated cg velocity (global)
- cg_omega = old/updated angular velocity (global)
- time = current time
- dtime = time step
- */
- {
- real f_glob[3]; /* Total forces (global) */
- real af_glob[3]; /* Aerodynamic forces (global) */
- real af_body[3]; /* Aerodynamic forces (body) */
- real m_glob[3]; /* Moment (global) */
- real m_body[3]; /* Moment (body) */
- real v_old_glob[3]; /* Velocity at previous time (global) */
- real om_old_body[3]; /* Angular velocity at previous time, rad/sec (body) */
- real om_body[3]; /* Updated angular velocity, rad/sec (body) */
- real al_body[3]; /* angular acceleration, rad/sec/sec (body) */
- real x_cg[3]; /* CG location */
- real euler_angle[3]; /* Euler angles:
- [0] = phi = roll = about x
- [1] = theta = pitch = about y
- [2] = psi = yaw = about z (radians)*/
- real euler_angle_old[3];
- real euler_rate[3]; /* time derivative of euler_angle */
- real grav_acc[3]; /* gravitational acceleration (global) */
- real cf, ct, cs; /* cosines of Euler angles */
- real sf, st, ss; /* sines of Euler angles */
- real RC[3][3]; /* coordinate rotation matrix (body -> global) */
- real RD[3][3]; /* derivative rotation matrix (body -> global) */
- real wx, wy, wz;
- real r1, r2, r3;
- real s1, s2, s3;
- real D;
- real a11, a21, a31, a12, a22, a32, a13, a23, a33;
- register int i;
- Domain *domain = Get_Domain (1);
- Thread *tf1 = Lookup_Thread (domain, ZONE_ID1);
- static int calls = 0;
- static boolean last_call = FALSE;
- /*
- * Initialize gravity acceleration */
- grav_acc[0] = 0.0;
- grav_acc[1] = 0.0;
- grav_acc[2] = 9.81;
- /*
- * Read data previous time step
- */
- read_velocities (v_old_glob, om_old_body, euler_angle);
- /*
- * Get CG position
- */
- for (i = 0; i < ND_ND; i++)
- x_cg = DT_CG(dt);
- /*
- * Count number of calls done
- */
- if ((++calls) == NUM_CALLS)
- last_call = TRUE;
- /*
- * Get aerodynamic forces and moments
- */
- Compute_Force_And_Moment (domain, tf1, x_cg, f_glob, m_glob, TRUE);
- for (i = 0; i < ND_ND; i++)
- af_glob = f_glob;
- /*
- * Add gravity force
- */
- for (i = 0; i < ND_ND; i++)
- f_glob += grav_acc*MASS;
- add_injector_forces (x_cg, euler_angle, f_glob, m_glob);
- /*
- * Calculate the velocity of the CG in the global system
- */
- for (i = 0; i < ND_ND; i++)
- cg_vel = f_glob * dtime / MASS + v_old_glob;
- /*
- * Calculate the new CG position
- */
- for (i = 0; i < ND_ND; i++)
- x_cg = x_cg + cg_vel * dtime;
- /*
- * Calculate the angular velocity in global csys
- */
- /* create transformation matrices (body -> global) for coords and derivs */
- cf = cos(euler_angle[0]); /* cosine(phi) */
- ct = cos(euler_angle[1]); /* cosine(theta) */
- cs = cos(euler_angle[2]); /* cosine(psi) */
- sf = sin(euler_angle[0]); /* sine(phi) */
- st = sin(euler_angle[1]); /* sine(theta) */
- ss = sin(euler_angle[2]); /* sine(psi) */
- RC[0][0] = ct*cs;
- RC[0][1] = sf*st*cs-cf*ss;
- RC[0][2] = cf*st*cs+sf*ss;
- RC[1][0] = ct*ss;
- RC[1][1] = sf*st*ss+cf*cs;
- RC[1][2] = cf*st*ss-sf*cs;
- RC[2][0] = -st;
- RC[2][1] = sf*ct;
- RC[2][2] = cf*ct;
- RD[0][0] = 1.0;
- RD[0][1] = sf*st/ct;
- RD[0][2] = cf*st/ct;
- RD[1][0] = 0.0;
- RD[1][1] = cf;
- RD[1][2] = -sf;
- RD[2][0] = 0.0;
- RD[2][1] = sf/ct;
- RD[2][2] = cf/ct;
- /* transform m_glob to body csys (multiply with transpose of RC)*/
- NV_ROTN_V (m_body, = , m_glob, RC);
- NV_ROTN_V (af_body, = , af_glob, RC);
- /* calculate angular accelarations in body csys */
- wx = om_old_body[0];
- wy = om_old_body[1];
- wz = om_old_body[2];
- r1 = IXX * wx - IXY * wy - IXZ * wz;
- r2 = -IXY * wx + IYY * wy - IYZ * wz;
- r3 = -IXZ * wx - IYZ * wy + IZZ * wz;
- s1 = m_body[0] - (wy*r3-wz*r2);
- s2 = m_body[1] - (wz*r1-wx*r3);
- s3 = m_body[2] - (wx*r2-wy*r1);
- D = IXX * IYY * IZZ - IXX * IYZ * IYZ -
- IYY * IXZ * IXZ - IZZ * IXY * IXY -
- 2.* IXY * IXZ * IYZ;
- a11 = IYY * IZZ - IYZ * IYZ;
- a12 = IXY * IZZ + IYZ * IXZ;
- a13 = IXY * IYZ + IXZ * IYY;
- a21 = IXY * IZZ + IYZ * IXZ;
- a22 = IXX * IZZ - IXZ * IXZ;
- a23 = IXX * IYZ + IXZ * IXY;
- a31 = IXY * IYZ + IXZ * IYY;
- a32 = IXX * IYZ + IXZ * IXY;
- a33 = IXX * IYY - IXY * IXY;
-
- al_body[0] = (a11 * s1 + a12 * s2 + a13 * s3) / D;
- al_body[1] = (a21 * s1 + a22 * s2 + a23 * s3) / D;
- al_body[2] = (a31 * s1 + a32 * s2 + a33 * s3) / D;
-
- /* calculate the new angular velocity in body csys */
- for (i = 0; i < 3; i++)
- om_body = om_old_body + al_body * dtime;
-
- /* transform angular velocity from body to global for return to Fluent */
- NV_ROTP_V (cg_omega, = ,om_body, RC);
-
- /*
- * calculate the new Euler angles
- */
- for (i = 0; i < 3; i++)
- euler_angle_old = euler_angle;
- NV_ROTP_V (euler_rate, =, om_body, RD);
- N3V_S (euler_rate, *=, dtime);
- N3V_V (euler_angle, +=, euler_rate);
-
- #if !RP_NODE
- /*
- * Write protocol files: velocities, omegas, and Euler angles
- */
- if (last_call)
- {
- FILE *file_diag;
-
- if ((file_diag = fopen ("diagnostics_3d", "a")) == NULL)
- Message ("\nCannot open output file");
- fprintf (file_diag, "%f\t" , time);
- fprintf (file_diag, "%f\t%f\t%f\t", x_cg[0], x_cg[1], x_cg[2]);
- fprintf (file_diag, "%f\t%f\t%f\t", cg_vel[0], cg_vel[1], cg_vel[2]);
- fprintf (file_diag, "%f\t%f\t%f\t", om_body[0], om_body[1], om_body[2]);
- fprintf (file_diag, "%f\t%f\t%f\t",
- euler_angle[0], euler_angle[1], euler_angle[2]);
- fprintf (file_diag, "%f\t%f\t%f\t", af_body[0], af_body[1], af_body[2]);
- fprintf (file_diag, "%f\t%f\t%f\n", m_body[0], m_body[1], m_body[2]);
- fclose(file_diag);
-
- write_velocities (cg_vel, om_body, euler_angle);
-
- calls = 0;
- last_call = FALSE;
- }
- #endif
- }
复制代码 |
|