sxliuxiaojun 发表于 2008-10-5 20:32

6dof'中last_call含义及编译问题

本人见了一篇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"
#defineZONE_ID1   8            /* face ID of the moving object */
                                 /* properties of moving object: */
#defineMASS       907.185      /* mass of object, kg */
#defineIXX      27.116       /* moment of intertia, Nms^2 */
#defineIYY      488.094      /* moment of intertia, Nms^2*/
#defineIZZ      488.094      /* moment of intertia, Nms^2 */
#defineIXZ      0.0          /* moment of intertia, Nms^2 */
#defineIXY      0.0          /* moment of intertia, Nms^2 */
#defineIYZ      0.0          /* moment of intertia, Nms^2 */
#defineNUM_CALLS2            /* number of times routine called
                                    (number of moving zones) */
#defineR2D      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, read_om_old, read_euler;
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 = 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;
# if RP_HOST
    for (i = 0; i < 3; i++)
      {
      exchange = (real)read_v_old;
      exchange = (real)read_om_old;
      exchange = (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;
      read_euler = (float)exchange;
      }
# 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;      /* Total forces (global) */
real      af_glob;   /* Aerodynamic forces (global) */
real      af_body;   /* Aerodynamic forces (body) */
real      m_glob;      /* Moment (global) */
real      m_body;      /* Moment (body) */
real      v_old_glob;/* Velocity at previous time (global) */
real      om_old_body; /* Angular velocity at previous time, rad/sec (body) */
real      om_body;   /* Updated angular velocity, rad/sec (body) */
real      al_body;   /* angular acceleration, rad/sec/sec (body) */
real      x_cg;      /* CG location */
real      euler_angle; /* Euler angles:
                                  = phi   = roll= about x
                                  = theta = pitch = about y
                                  = psi   = yaw   = about z (radians)*/
real      euler_angle_old;
real      euler_rate;/* time derivative of euler_angle */
real      grav_acc;    /* gravitational acceleration (global) */
real      cf, ct, cs;   /* cosines of Euler angles */
real      sf, st, ss;   /* sines of Euler angles   */
real      RC;       /* coordinate rotation matrix (body -> global) */
real      RD;       /* 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;
grav_acc = 0.0;
grav_acc = 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);/* cosine(phi)   */
ct = cos(euler_angle);/* cosine(theta) */
cs = cos(euler_angle);/* cosine(psi)   */
sf = sin(euler_angle);/* sine(phi)   */
st = sin(euler_angle);/* sine(theta)   */
ss = sin(euler_angle);/* sine(psi)   */
RC = ct*cs;
RC = sf*st*cs-cf*ss;
RC = cf*st*cs+sf*ss;
RC = ct*ss;
RC = sf*st*ss+cf*cs;
RC = cf*st*ss-sf*cs;
RC = -st;
RC = sf*ct;
RC = cf*ct;
RD = 1.0;
RD = sf*st/ct;
RD = cf*st/ct;
RD = 0.0;
RD = cf;
RD = -sf;
RD = 0.0;
RD = sf/ct;
RD = 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;
wy = om_old_body;
wz = om_old_body;
r1 =IXX * wx - IXY * wy - IXZ * wz;
r2 = -IXY * wx + IYY * wy - IYZ * wz;
r3 = -IXZ * wx - IYZ * wy + IZZ * wz;
s1 = m_body - (wy*r3-wz*r2);
s2 = m_body - (wz*r1-wx*r3);
s3 = m_body - (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 = (a11 * s1 + a12 * s2 + a13 * s3) / D;
al_body = (a21 * s1 + a22 * s2 + a23 * s3) / D;
al_body = (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, x_cg, x_cg);
      fprintf (file_diag, "%f\t%f\t%f\t", cg_vel, cg_vel, cg_vel);
      fprintf (file_diag, "%f\t%f\t%f\t", om_body, om_body, om_body);
      fprintf (file_diag, "%f\t%f\t%f\t",
               euler_angle, euler_angle, euler_angle);
      fprintf (file_diag, "%f\t%f\t%f\t", af_body, af_body, af_body);
      fprintf (file_diag, "%f\t%f\t%f\n", m_body, m_body, m_body);
      fclose(file_diag);

      write_velocities (cg_vel, om_body, euler_angle);

      calls = 0;
      last_call = FALSE;
}
#endif
}

sxliuxiaojun 发表于 2008-10-6 11:36

把last_call定义为整型变量,false用0代替,true用1代替,程序却是通过了 但是又出来新的错误
已复制   1个文件
(system "copy D:\software\°&sup2;×°&Egrave;í&frac14;&thorn;\fluent\fluent\Fluent.Inc\fluent6.2.16\src\makefile_nt.udf libudf\ntx86\2d\makefile")
0
(chdir "libudf")()
(chdir "ntx86\2d")()
6dof.c
..\..\src\6dof.c(264) : warning C4700: local variable 'm_body' used without having been initialized
..\..\src\6dof.c(297) : warning C4700: local variable 'euler_rate' used without having been initialized
..\..\src\6dof.c(316) : warning C4700: local variable 'af_body' used without having been initialized
# Generating udf_names.c because of makefile 6dof.obj
udf_names.c
# Linking libudf.dll because of makefile user_nt.udf udf_names.obj 6dof.obj
Microsoft (R) Incremental Linker Version 6.00.8168
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
   Creating library libudf.lib and object libudf.exp
6dof.obj : error LNK2001: unresolved external symbol _add_injector_forces
libudf.dll : fatal error LNK1120: 1 unresolved externals
我该怎么办呢?

cora 发表于 2008-10-8 01:20

这个例子好像是fluent官方给出的例子

你把'last_call'的声名移到前面看看
页: [1]
查看完整版本: 6dof'中last_call含义及编译问题