首页 > 解决方案 > 如何在 OpenFOAM 中读取 0/U 文件中的字典变量

问题描述

我想在 0/U 的入口边界读取“transportProperties”字典的粘度变量“nu”,如下所示:

boundaryField
{
    inlet
    {
        type    codedFixedValue;
        value   uniform (0.006 0 0);
        name    parabolicInlet;
        code
        #{
               // ... some lines of code ...
               scalar nu = readScalar(this->db().lookupObject<IOdictionary>("transportProperties").lookup("nu"));
              // ... some lines of code ...
        #};
    }
}

我得到了这个错误的令牌类型错误:

--> FOAM FATAL IO ERROR:
wrong token type - expected Scalar, found on line 22 the punctuation token '['

file: /home/behzadb/research/Simulations/ConfinedCylinder2D/TestCase-01/constant/transportProperties/nu at line 22.

    From function Foam::Istream& Foam::operator>>(Foam::Istream&, Foam::doubleScalar&)
    in file lnInclude/Scalar.C at line 101.

FOAM exiting

我会很高兴知道我应该如何调用字典并从中读取尺寸标量变量“nu”以用于某些计算(如雷诺数)?

非常感谢,BB

标签: openfoam

解决方案


尝试以下操作:

boundaryField
{
    inlet
    {
        type    codedFixedValue;
        value   uniform (0.006 0 0);
        name    parabolicInlet;
        code
        #{
            // ... some lines of code ...

            dimensionedScalar nu
            (
               "nu",
               dimViscosity,
               this->db().lookupObject<IOdictionary>("transportProperties").lookup("nu")
            );

            // ... some lines of code ...
        #};
    }
}

您收到该错误是因为您试图将运动粘度读取为scalar. 相反,使用dimensionedScalar.

如果您想使用 的标量值nu,可以通过以下方式访问它:

scalar nu_value = nu.value();

推荐阅读