读取数据字典
在openFOAM项目文件夹constant中自建一个数据字典,名为myDict,内容包含一个标量数据
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 9
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
format ascii;
class dictionary;
location "constant";
object myDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
myValue 0.05;
// ************************************************************************* //
在main函数中使用IOdictionary
方式读取该数据,代码如下
IOdictionary myDict(
IOobject(
"myDict",
mesh.time().constant(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
);
scalar myValue(readScalar(myDict.lookup("myValue")));
Info<< nl << "数据字典的myValue为" << myValue << nl << endl;