关于用lookupObject引用变量报错,求大佬们指点。
-
错误如下:
lnInclude/linearViscousStress.C: In constructor ‘Foam::linearViscousStress<BasicTurbulenceModel>::linearViscousStress(const Foam::word&, const alphaField&, const rhoField&, const volVectorField&, const surfaceScalarField&, const surfaceScalarField&, const transportModel&, const Foam::word&)’: lnInclude/linearViscousStress.C:81:75: error: expected primary-expression before ‘>’ token 81 | const volScalarField& omega_ = this->mesh_.lookupObject<volScalarField>("omega_"); | ^ make: *** [/home/dyfluid/OpenFOAM/OpenFOAM-7/wmake/rules/General/transform:26: /home/dyfluid/OpenFOAM/OpenFOAM-7/platforms/linux64GccDPInt32Opt/src/TurbulenceModels/turbulenceModels/derivedFvPatchFields/wallFunctions/fWallFunctions/fWallFunction/fWallFunctionFvPatchScalarField.o] Error 1
代码如下:
#include "linearViscousStress.H" #include "fvc.H" #include "fvm.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template<class BasicTurbulenceModel> Foam::linearViscousStress<BasicTurbulenceModel>::linearViscousStress ( const word& modelName, const alphaField& alpha, const rhoField& rho, const volVectorField& U, const surfaceScalarField& alphaRhoPhi, const surfaceScalarField& phi, const transportModel& transport, const word& propertiesName ) : BasicTurbulenceModel ( modelName, alpha, rho, U, alphaRhoPhi, phi, transport, propertiesName ), nonlinearStress_ ( IOobject ( IOobject::groupName("nonlinearStress", alphaRhoPhi.group()), this->runTime_.timeName(), this->mesh_ ), this->mesh_, dimensionedSymmTensor ( "nonlinearStress", sqr(dimVelocity), Zero ) ) { tensor I(1,0,0,0,1,0,0,0,1); volSymmTensorField S(twoSymm(fvc::grad(this->U_))); volTensorField W(twoSkew(fvc::grad(this->U_))); const volScalarField& omega_ = this->mesh_.lookupObject<volScalarField>("omega_"); nonlinearStress_ = 1.0/omega_ *( S&S - (1.0/3.0)*magSqr(W)*I + twoSymm(S&W) + (2.5)*(W&W - (1.0/3.0)*magSqr(W)*I)); } // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template<class BasicTurbulenceModel> bool Foam::linearViscousStress<BasicTurbulenceModel>::read() { return BasicTurbulenceModel::read(); } template<class BasicTurbulenceModel> Foam::tmp<Foam::volSymmTensorField> Foam::linearViscousStress<BasicTurbulenceModel>::devRhoReff() const { return volSymmTensorField::New ( IOobject::groupName("devRhoReff", this->alphaRhoPhi_.group()), (-(this->alpha_*this->rho_*this->nuEff())) *dev(twoSymm(fvc::grad(this->U_))) ); } template<class BasicTurbulenceModel> Foam::tmp<Foam::fvVectorMatrix> Foam::linearViscousStress<BasicTurbulenceModel>::divDevRhoReff ( volVectorField& U ) const { return ( - fvc::div((this->alpha_*this->rho_*this->nuEff())*dev2(T(fvc::grad(U)))) - fvc::div((this->alpha_*this->rho_*this->nuEff())*nonlinearStress_ ) - fvm::laplacian(this->alpha_*this->rho_*this->nuEff(), U) ); } template<class BasicTurbulenceModel> Foam::tmp<Foam::fvVectorMatrix> Foam::linearViscousStress<BasicTurbulenceModel>::divDevRhoReff // ( const volScalarField& rho, volVectorField& U ) const { return ( - fvc::div((this->alpha_*rho*this->nuEff())*dev2(T(fvc::grad(U)))) - fvc::div((this->alpha_*rho*this->nuEff())*nonlinearStress_ ) - fvm::laplacian(this->alpha_*rho*this->nuEff(), U) ); } template<class BasicTurbulenceModel> void Foam::linearViscousStress<BasicTurbulenceModel>::correct() { BasicTurbulenceModel::correct(); } // ************************************************************************* //
在线性项里加入一个非线性部分,引用omega_出问题(omega_未在linearViscousStress文件中定义),这个引用方式是按照论坛其他帖子写的,需要怎么改正~
-
-
@bestucan @李东岳
虽然上面编译通过了,可兴致勃勃开始运行算例提示错误如下--> FOAM FATAL ERROR: request for volScalarField omega_ from objectRegistry region0 failed available objects of type volScalarField are 15 ( sigmaMag alphas nu.pos muMag_0 rho nu.molten p_rgh nu alpha.molten nu.neg muMag rho_0 alpha.neg alpha.pos sigmaMag_0 ) From function const Type& Foam::objectRegistry::lookupObject(const Foam::word&) const [with Type = Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>] in file /home/dyfluid/OpenFOAM/OpenFOAM-7/src/OpenFOAM/lnInclude/objectRegistryTemplates.C at line 193.
还是关于omega_的引用问题,我在想是不是因为linearVicousStress.C是父类,而omega是在SSTbase.C中定义的(类似于子类),所以找不到?难道我要在linearVicousStress.C中重新IObject?
还是说这个引用方式有问题...但我用const volScalarField& omega_ = this->mesh_.lookupObject<volScalarField>("omega_");
会编译不通过......不知道老师们有没有想法,十分需要帮助,再次感谢老师们
-
@chen_hao 在 关于用lookupObject引用变量报错,求大佬们指点。 中说:
@bestucan @李东岳
虽然上面编译通过了,可兴致勃勃开始运行算例提示错误如下--> FOAM FATAL ERROR: request for volScalarField omega_ from objectRegistry region0 failed available objects of type volScalarField are 15 ( sigmaMag alphas nu.pos muMag_0 rho nu.molten p_rgh nu alpha.molten nu.neg muMag rho_0 alpha.neg alpha.pos sigmaMag_0 ) From function const Type& Foam::objectRegistry::lookupObject(const Foam::word&) const [with Type = Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>] in file /home/dyfluid/OpenFOAM/OpenFOAM-7/src/OpenFOAM/lnInclude/objectRegistryTemplates.C at line 193.
还是关于omega_的引用问题,我在想是不是因为linearVicousStress.C是父类,而omega是在SSTbase.C中定义的(类似于子类),所以找不到?难道我要在linearVicousStress.C中重新IObject?
还是说这个引用方式有问题...但我用const volScalarField& omega_ = this->mesh_.lookupObject<volScalarField>("omega_");
会编译不通过......不知道老师们有没有想法,十分需要帮助,再次感谢老师们
我的分析原因是:执行求解器的时候linearStress.C先执行,所以此时omega还没注册进表里,显示找不到它,我现在在linearStress.C中加入一个omega的IOobject可不可行,毕竟在SST.C中还会IOobject一次,一个变量可以注册多次吗,会不会影响计算结果?
-
@李东岳
针对 ncompressible::turbulenceModel 模板特化后的 ShihQuadraticKE 模型 ,仔细研究了一下其怎么实现非线性项的实现,发现其是在 NonlinearEddyViscosity.H 中定义 nonlinearStress_ 项,然后用 ShihQuadraticKE 作为子类继承父类 NonlinearEddyViscosity 以便在 ShihQuadraticKE.C 中直接引用omega_。但由于我修改的是SSTkomegabase.H( 继承于TurbulenceModel类 )与 linearViscousStrss.H ( 继承于BasicturbulenceModel原则类 ) 没有特例化,不能简单类似上面的ShihQuadraticKE 模型。需要从新仿造框架,是一项大工程!
我的策略是:在现有的文件上直接硬植入,简单很多,毕竟涉及到湍流模型的类错综复杂,针对找不到omega,按照我的分析应该是对的,运行求解器时linearViscousStrss.C先运行此时并未运行SSTkomegabase.C 所以没有omega场注册,找不到他,所以我在creatfield.H中IOobject一下omega场,目前可以算了,结果还未检查,不知道我的理解有没有问题。