c语言 - 臭氧 CFD 建模 UDF ansys 流利 NMAKE:致命错误 U1077:返回代码 '0x2'



我正在使用CFD模型来研究臭氧-水相互作用

将臭氧在水中的传质和溶解臭氧分解过程处理为两个用户定义函数(UDF(,并用C语言编程,然后将这两个UDF加载到Ansys Fluent求解器中。关于代码的编译,我遇到了错误使用的UDF代码:

#include "udf.h"
#define vr 0.0025
#define dg 0.003
#define kl 0.0005
#define cn 6.0
DEFINE_VR_RATE(vol_reac_rate, c, t, r, mw, yi, rr, rr_t)
{
real *rr
real yi[0] = C_YI(cell,thread,0)
*rr = vr*C_VOF(c,t)*C_R(c,t)*yi[0]/mw[0];

return *rr;
} 
/*define ozone decay volume reaction rate */

DEFINE_MASS_TRANSFER (liq_gas_transfer, cell, thread, from_index,from_species_index, to_index, to_species_index)
{
real m_lg;
Thread *gas, *liq;
gas = THREAD_SUB_THREAD(thread, from_species_index);
liq = THREAD_SUB_THREAD(thread, to_species_index);
m_lg = kl*cn/dg *C_VOF(cell,gas); /*unit:[s^-1] */

return (m_lg);
} /*define ozone mass transfer rate */

我得到的错误:

mass_transfer_udf.c
....srcmass_transfer_udf.c(10): error C2082: redefinition of formal parameter 'rr'
....srcmass_transfer_udf.c(10): error C2146: syntax error: missing ';' before identifier 'real'
....srcmass_transfer_udf.c(10): error C2275: 'real': illegal use of this type as an expression
C:PROGRA~1ANSYSI~1ANSYSS~1v221fluentfluent22.1.0srcmainglobal.h(198): note: see declaration of 'real'
....srcmass_transfer_udf.c(10): error C2146: syntax error: missing ';' before identifier 'yi'
....srcmass_transfer_udf.c(10): error C2065: 'thread': undeclared identifier
....srcmass_transfer_udf.c(10): error C2223: left of '->storageArray' must point to struct/union
....srcmass_transfer_udf.c(10): error C2065: 'cell': undeclared identifier
....srcmass_transfer_udf.c(14): warning C4098: 'vol_reac_rate': 'void' function returning a value
NMAKE : fatal error U1077: '"C:Program FilesMicrosoft Visual Studio2022CommunityVCToolsMSVC14.30.30705binHostX86x64cl.EXE"' : return code '0x2'
Stop.Error Object: #f

如何解决这些错误。我对C语言真的很陌生。

错误/警告列表相当简单。如果你阅读了每一个描述,它会告诉你它正在标记的问题,通常,在你的代码中,问题被标记的确切位置。

因此例如关于";形式参数的重新定义在大多数C编译器中,未显式类型化的参数默认为int。因此,在以下方面:

DEFINE_VR_RATE(vol_reac_rate, c, t, r, mw, yi, rr, rr_t)...  

所有参数都默认为int。错误:redefinition of formal parameter 'rr'告诉您,rr在参数列表中定义为int,而real *rr正试图将其重新定义为real

要消除错误,请在每个参数前面加一个C类型,如intfloatdoublecharreal(如果在您的环境中定义(。例如:

typedef  float real; //(your system may already have this type)
DEFINE_VR_RATE(real vol_reac_rate, int c, int t, int r, real mw, real yi[r], real rr, real rr_t)  

注意:我猜测上面需要的实际类型,根据需要进行更改。此外,由于代码中使用了yi[0],因此必须将参数类型化为数组或指针。这里我选择了数组,并随机使用r作为参数来调整yi:yi[r]

关于";语法错误:缺少";">:这只是标记一个丢失的;语句终止符。编辑此:

real *rr
real yi[0] = C_YI(cell,thread,0)

对此:

//real *rr;  //will already be defined in your parameter list
yi[0] = C_YI(cell,thread,0); //ditto

关于_&quotreal":非法使用此类型作为表达式">
real在您的环境中被视为一种类型,因此应该仅用于键入变量,但您在像变量一样的表达式中使用它。这个错误很可能是前面提到的一个错误造成的,一旦键入了函数参数并放置了;,这个错误就会消失。

关于_&quot线程':未声明的标识符">(也称为"cell"(CCD_ 20没有在函数CCD_ 21中使用的范围内的任何地方声明。它可能在头文件中,也可能在另一个.C文件中,但不在此编译器单元中。

关于-";'->左侧;storageArray"必须指向结构/联合">
structunion类型必须占据语句->storageArray的左侧。在你的代码中,它显然不是。

关于&quotvol_reac_rate":"void"函数返回一个值">
函数vol_reac_rate(...)的类型显然是void,但在函数的主体中有一个return x语句。

相关内容

最新更新