0
点赞
收藏
分享

微信扫一扫

OpenFOAM读取数据字典

我阿霆哥 2022-03-18 阅读 96

读取数据字典

在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;
举报

相关推荐

0 条评论