这个问题是关于openFoam(泡沫扩展v4)C++的,但是我相信我遇到的问题是一个基本的C++编程问题。
我正在尝试使用autoCreateOmega
函数,其原型(prototype)可以在foam-extend-4.0/src/turbulenceModels/incompressible/RAS/lnInclude/backwardsCompatibilityWallFunctions.H
,定义在相应的backwardsCompatibilityWallFunctions.C
中。
在我的solver.C文件中,顶部具有以下内容:
#include "fvCFD.H"
#include "simpleControl.H"
#include "wallDist.H"
#include "backwardsCompatibilityWallFunctions.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
{
# include "setRootCase.H"
# include "createTime.H"
# include "createMesh.H"
simpleControl simple(mesh);
# include "createFields.H"
我的createFields.H
的一部分看起来像这样: Info<< "Reading field omega\n" << endl;
volScalarField omega
(
IOobject
(
"omega",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
//mesh
autoCreateOmega("omega", mesh, U.db())
);
当我尝试编译此求解器时,出现以下错误:In file included from solver.C:48:0:
createFields.H: In function ‘int main(int, char**)’:
createFields.H:50:46: error: ‘autoCreateOmega’ was not declared in this scope
autoCreateOmega("omega", mesh, U.db())
^
createFields.H:50:46: note: suggested alternative:
In file included from solver.C:37:0:
/home/foam/foam-extend-4.0/src/turbulenceModels/incompressible/RAS/lnInclude/backwardsCompatibilityWallFunctions.H:98:25: note: ‘Foam::incompressible::autoCreateOmega’
tmp<volScalarField> autoCreateOmega
^
solver.dep:714: recipe for target 'Make/linux64GccDPOpt/solver.o' failed
make: *** [Make/linux64GccDPOpt/solver.o] Error 1
为什么不包括"backwardsCompatibilityWallFunctions.H"
允许我在程序中使用autoCreateOmega?任何帮助深表感谢。如果需要更多信息,请告诉我。
编辑
在
"backwardsCompatibilityWallFunctions.H"
中:#ifndef backwardsCompatibilityWallFunctions_H
#define backwardsCompatibilityWallFunctions_H
#include "fvMesh.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace incompressible
{
//- omega
tmp<volScalarField> autoCreateOmega
(
const word& fieldName,
const fvMesh& mesh,
const objectRegistry& obj
);
tmp<volScalarField> autoCreateOmega
(
const word& fieldName,
const fvMesh& mesh
);
并在"backwardsCompatibilityWallFunctions.C"
中tmp<volScalarField> autoCreateOmega
(
const word& fieldName,
const fvMesh& mesh,
const objectRegistry& obj
)
{
return
autoCreateWallFunctionField
<
scalar,
RASModels::omegaWallFunctionFvPatchScalarField
>
(
fieldName,
mesh,
obj
);
}
tmp<volScalarField> autoCreateOmega
(
const word& fieldName,
const fvMesh& mesh
)
{
return
autoCreateWallFunctionField
<
scalar,
RASModels::omegaWallFunctionFvPatchScalarField
>
(
fieldName,
mesh,
mesh
);
}
如建议:如果我添加using Foam::incompressible::autoCreateOmega;
Make/linux64GccDPOpt/solver.o: In function `main':
solver.C:(.text.startup+0x7dd): undefined reference to `Foam::incompressible::autoCreateOmega(Foam::word const&, Foam::fvMesh const&, Foam::objectRegistry const&)'
collect2: error: ld returned 1 exit status
/home/foam/foam-extend-4.0/wmake/Makefile:159: recipe for target '/home/foam/applications/bin/linux64GccDPOpt/solver' failed
make: *** [/home/foam/applications/bin/linux64GccDPOpt/solver] Error 1
最佳答案
由于编译器通知了未声明的函数,而不通知了模棱两可的调用,因此最可能的原因是函数名放在了某些命名空间中。我研究了扩展的OpenSOAP源,建议您在using Foam::incompressible::autoCreateOmega;
之前插入main
。
关于c++ - 包含来自另一个文件的功能会导致范围错误(openFoam),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51814940/