层流RTS调用机制简析(以simpleFoam为例)



  • 注意到simpleFoam源码的createField.H中含有一行代码:

    singlePhaseTransportModel laminarTransport(U, phi);
    

    将类singlePhaseTransportModel实例化为laminarTransport,并且传给构造函数两个参数U和phi。
    在simpleFoam.C中找到了#include "singlePhaseTransportModel.H"。类singlePhaseTransportModel很有可能在里面定义,因此进入singlePhaseTransportModel.H。
    其路径为$FOAM_SRC/transportModels/incompressible/singlePhaseTransportModel/singlePhaseTransportModel.H,发现类singlePhaseTransportModel,及其构造函数的声明。因此进入singlePhaseTransportModel.C中查看其定义。

    Foam::singlePhaseTransportModel::singlePhaseTransportModel
    (
        const volVectorField& U,
        const surfaceScalarField& phi
    )
    :
        IOdictionary
        (
            IOobject
            (
                "transportProperties",
                U.time().constant(),
                U.db(),
                IOobject::MUST_READ_IF_MODIFIED,
                IOobject::NO_WRITE
            )
        ),
        viscosityModelPtr_(viscosityModel::New("nu", *this, U, phi))
    {}
    

    在类singlePhaseTransportModel构造前,先建立了读取constant/transportProperties的字典,并用
    viscosityModel::New返回了一个叫viscosityModelPtr_的指针。
    因此需要查看viscosityModel::New的定义。路径为$FOAM_SRC/transportModels/incompressible/viscosityModels/viscosityModel/viscosityModelNew.C。相关代码如下:

    Foam::autoPtr<Foam::viscosityModel> Foam::viscosityModel::New
    (
        const word& name,
        const dictionary& viscosityProperties,
        const volVectorField& U,
        const surfaceScalarField& phi
    )
    {
        const word modelType(viscosityProperties.lookup("transportModel"));
    
        Info<< "Selecting incompressible transport model " << modelType << endl;
    
        auto cstrIter = dictionaryConstructorTablePtr_->cfind(modelType);
    
        if (!cstrIter.found())
        {
            FatalErrorInFunction
                << "Unknown viscosityModel type "
                << modelType << nl << nl
                << "Valid viscosityModels :" << endl
                << dictionaryConstructorTablePtr_->sortedToc()
                << exit(FatalError);
        }
    
        return autoPtr<viscosityModel>
            (cstrIter()(name, viscosityProperties, U, phi));
    }
    

    此函数本质是在contant/transportProperties文件中查询关键字transportModel对应的值(以Newtonian为例),并在哈希表中查看是否存在这个Newtonian。返回Newtonian在哈希表中对应的值。以我目前的学习经验来看,这个对应值应该是类Newtonian的一个临时对象,并用cstrIter()(name, viscosityProperties, U, phi)括号里的参数进行了初始化。因此需要找到类Newtonian的构造函数。路径为:$FOAM_SRC/transportModels/incompressible/viscosityModels/Newtonian/Newtonian.C

    Foam::viscosityModels::Newtonian::Newtonian
    (
        const word& name,
        const dictionary& viscosityProperties,
        const volVectorField& U,
        const surfaceScalarField& phi
    )
    :
        viscosityModel(name, viscosityProperties, U, phi),
        nu0_("nu", dimViscosity, viscosityProperties_),
        nu_
        (
            IOobject
            (
                name,
                U_.time().timeName(),
                U_.db(),
                IOobject::NO_READ,
                IOobject::NO_WRITE
            ),
            U_.mesh(),
            nu0_
        )
    {}
    

    在构造类Newtonian时先构造了类viscosityModel。注意到类viscosityModel是类Newtonian的一个父类。因此需要找到类viscosityModel的构造函数。路径为:$FOAM_SRC/transportModels/incompressible/viscosityModels/viscosityModel/viscosityModel.C

    Foam::viscosityModel::viscosityModel
    (
        const word& name,
        const dictionary& viscosityProperties,
        const volVectorField& U,
        const surfaceScalarField& phi
    )
    :
        name_(name),
        viscosityProperties_(viscosityProperties),
        U_(U),
        phi_(phi)
    {}
    

    类viscosityModel的构造函数实际是将形参用于name_,viscosityProperties_,U_和phi_初始化了。这里的viscosityProperties_由于被类Newtonian继承,在类Newtonian的构造函数中可以看见nu0_使用了viscosityProperties_进行初始化。而viscosityProperties_的本质实际就是

     IOdictionary
        (
            IOobject
            (
                "transportProperties",
                U.time().constant(),
                U.db(),
                IOobject::MUST_READ_IF_MODIFIED,
                IOobject::NO_WRITE
            )
        ),
    

    返回看nu0_的初始化:

    nu0_("nu", dimViscosity, viscosityProperties_)
    

    实际是读取constant/transportProperties文件里的nu关键字对应的dimensionedScalar。
    而nu_

        nu_
        (
            IOobject
            (
                name,
                U_.time().timeName(),
                U_.db(),
                IOobject::NO_READ,
                IOobject::NO_WRITE
            ),
            U_.mesh(),
            nu0_
        )
    

    nu_则是以nu0_这个dimensionedScalar构建了一个volScalarField。



  • 赞~~


Log in to reply
 

CFD中文网 2016 - 2020 | 京ICP备15017992号-2