找对象的正确姿势

foundObject,返回是否找到该对象的 Bool 值
lookupObject,返回对象,只能使用const成员函数,
lookupObjectRef,返回的对象可以使用非const成员函数

最简单的场量:

this->mesh().objectRegistry::lookupObject<volScalarField>("rho")
this->mesh().objectRegistry::lookupObject<volVectorField>("U")
this->mesh().objectRegistry::lookupObject<PtrList<scalarField>>("this->thermo().composition().Y()")

模型

湍流模型

const compressible::turbulenceModel& turbModel =
this->db().objectRegistry::lookupObject<compressible::turbulenceModel>
("turbulence");

const compressible::turbulenceModel& turbModel =
lookupObject<compressible::turbulenceModel>
(
turbulenceModel::propertiesName
);

const compressible::turbulenceModel& turbModel =
this->db().lookupObject<compressible::turbulenceModel>
(
turbulenceModel::propertiesName
);

const compressible::turbulenceModel& turbModel =
db().lookupObject<compressible::turbulenceModel>
(
IOobject::groupName
(
compressible::turbulenceModel::propertiesName,
internalField().group()
)
);

const compressible::LESModel& lesModel =
YO2.db().lookupObject<compressible::LESModel>
(
turbulenceModel::propertiesName
);

喷雾模型

if (this->mesh().objectRegistry::foundObject<sprayCloud>(Foam::sprayCloud::typeName))
const basicSprayCloud& spray_ = dynamic_cast<const basicSprayCloud&>(this->mesh().objectRegistry::lookupObject<sprayCloud>(Foam::sprayCloud::typeName));
basicSprayCloud& spray_ = dynamic_cast<basicSprayCloud&>(this->mesh().objectRegistry::lookupObjectRef<sprayCloud>(Foam::sprayCloud::typeName));

探索

输出所有注册在网格上的量:

wordList allFields = this->mesh().sortedNames();
Info<<"allFields ="<<allFields<<endl;

输出的量都是可以通过找对象的方式获取的,但是类型要靠我们自己得到。

文章作者: Yan Zhang
文章链接: https://openfoam.top/lookupObject/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 OpenFOAM 成长之路
您的肯定会给我更大动力~