OpenFOAM 可压缩湍流库深度解析

分析可压缩湍流部分的继承关系

OF-7

继承关系:

solver 中:

Info << "Creating turbulence model.\n" << nl;
autoPtr<compressible::turbulenceModel> turbulence
(
compressible::turbulenceModel::New
(
rho,
U,
phi,
thermo
)
);

其中 Foam::compressible::turbulenceModelFoam::compressible::ThermalDiffusivity<CompressibleTurbulenceModel<fluidThermo>>typedef

所以这里首先调用的是 ThermalDiffusivity 中的 New

template<class BasicTurbulenceModel>
Foam::autoPtr<Foam::ThermalDiffusivity<BasicTurbulenceModel>>
Foam::ThermalDiffusivity<BasicTurbulenceModel>::New
(
const volScalarField& rho,
const volVectorField& U,
const surfaceScalarField& phi,
const transportModel& transport,
const word& propertiesName
)
{
return autoPtr<ThermalDiffusivity>
(
static_cast<ThermalDiffusivity*>(
BasicTurbulenceModel::New
(
rho,
U,
phi,
transport,
propertiesName
).ptr())
);
}

CompressibleTurbulenceModel<class TransportModel>BasicTurbulenceModel 的实例化,
因此接下来来到了 CompressibleTurbulenceModel
声明:

template<class TransportModel>
class CompressibleTurbulenceModel
:
public TurbulenceModel
<
geometricOneField,
volScalarField,
compressibleTurbulenceModel,
TransportModel
>

New 函数:

template<class TransportModel>
Foam::autoPtr<Foam::CompressibleTurbulenceModel<TransportModel>>
Foam::CompressibleTurbulenceModel<TransportModel>::New
(
const volScalarField& rho,
const volVectorField& U,
const surfaceScalarField& phi,
const transportModel& transport,
const word& propertiesName
)
{
return autoPtr<CompressibleTurbulenceModel>
(
static_cast<CompressibleTurbulenceModel*>(
TurbulenceModel
<
geometricOneField,
volScalarField,
compressibleTurbulenceModel,
transportModel
>::New
(
geometricOneField(),
rho,
U,
phi,
phi,
transport,
propertiesName
).ptr())
);
}

接着来到 TurbulenceModel 这里用到了 RTS
New 函数:

static autoPtr<TurbulenceModel> New
(
const alphaField& alpha,
const rhoField& rho,
const volVectorField& U,
const surfaceScalarField& alphaRhoPhi,
const surfaceScalarField& phi,
const transportModel& transport,
const word& propertiesName = turbulenceModel::propertiesName
);

构造函数:

Foam::TurbulenceModel<Alpha, Rho, BasicTurbulenceModel, TransportModel>::
TurbulenceModel
(
const alphaField& alpha,
const rhoField& rho,
const volVectorField& U,
const surfaceScalarField& alphaRhoPhi,
const surfaceScalarField& phi,
const transportModel& transport,
const word& propertiesName
)
:
BasicTurbulenceModel
(
rho,
U,
alphaRhoPhi,
phi,
propertiesName
),
alpha_(alpha),
transport_(transport)
{}

它的模板基类 BasicTurbulenceModel 的实例化是 compressibleTurbulenceModel

Foam::compressibleTurbulenceModel::compressibleTurbulenceModel
(
const volScalarField& rho,
const volVectorField& U,
const surfaceScalarField& alphaRhoPhi,
const surfaceScalarField& phi,
const word& propertiesName
)
:
turbulenceModel
(
U,
alphaRhoPhi,
phi,
propertiesName
),
rho_(rho)
{}

最后来到了:turbulenceModel

Foam::turbulenceModel::turbulenceModel
(
const volVectorField& U,
const surfaceScalarField& alphaRhoPhi,
const surfaceScalarField& phi,
const word& propertiesName
)

初始化列表中:alphaRhoPhi_(alphaRhoPhi)
另有函数:

inline const surfaceScalarField& alphaRhoPhi() const
{
return alphaRhoPhi_;
}

combustionModel.H 中:

inline Foam::tmp<Foam::surfaceScalarField> Foam::combustionModel::phi() const
{
return turbulence().alphaRhoPhi();
}

就是说,solver#include "compressibleCreatePhi.H" 创建的 phi 逐级传到了湍流模型中,我可以使用 Foam::combustionModel::phi() 来调用它。

相同的,燃烧模型和湍流模型中的 phi() 也都是返回 solver 中的 phi。

OF-8

继承关系:

湍流模型构建

solver 中:

Info << "Creating turbulence model.\n" << nl;
autoPtr<compressible::momentumTransportModel> turbulence
(
compressible::momentumTransportModel::New
(
rho,
U,
phi,
thermo
)
);

其中 compressible::momentumTransportModelCompressibleMomentumTransportModel<fluidThermo>typedef

所以这里首先调用的是 CompressibleMomentumTransportModel::New

template<class TransportModel>
Foam::autoPtr<Foam::CompressibleMomentumTransportModel<TransportModel>>
Foam::CompressibleMomentumTransportModel<TransportModel>::New
(
const volScalarField& rho,
const volVectorField& U,
const surfaceScalarField& phi,
const transportModel& transport
)
{
return autoPtr<CompressibleMomentumTransportModel>
(
static_cast<CompressibleMomentumTransportModel*>(
MomentumTransportModel
<
geometricOneField,
volScalarField,
compressibleMomentumTransportModel,
transportModel
>::New
(
geometricOneField(),
rho,
U,
phi,
phi,
transport
).ptr())
);
}

接下来调用 MomentumTransportModel::New

template
<
class Alpha,
class Rho,
class BasicMomentumTransportModel,
class TransportModel
>
Foam::autoPtr
<
Foam::MomentumTransportModel
<
Alpha,
Rho,
BasicMomentumTransportModel,
TransportModel
>
>
Foam::MomentumTransportModel
<
Alpha,
Rho,
BasicMomentumTransportModel,
TransportModel
>::New
(
const alphaField& alpha,
const rhoField& rho,
const volVectorField& U,
const surfaceScalarField& alphaRhoPhi,
const surfaceScalarField& phi,
const transportModel& transport
)
{
const word modelType
(
momentumTransportModel::readModelDict
(
U.db(),
alphaRhoPhi.group()
).lookup("simulationType")
);

Info<< "Selecting turbulence model type" << modelType << endl;

typename dictionaryConstructorTable::iterator cstrIter =
dictionaryConstructorTablePtr_->find(modelType);

if (cstrIter == dictionaryConstructorTablePtr_->end())
{
FatalErrorInFunction
<< "Unknown MomentumTransportModel type"
<< modelType << nl << nl
<< "Valid MomentumTransportModel types:" << endl
<<dictionaryConstructorTablePtr_->sortedToc()
<<exit(FatalError);
}

return autoPtr<MomentumTransportModel>
(
cstrIter()(alpha, rho, U, alphaRhoPhi, phi, transport)
);
}

接下来是 MomentumTransportModel 的构造函数

template
<
class Alpha,
class Rho,
class BasicMomentumTransportModel,
class TransportModel
>
Foam::MomentumTransportModel
<
Alpha,
Rho,
BasicMomentumTransportModel,
TransportModel
>::MomentumTransportModel
(
const alphaField& alpha,
const rhoField& rho,
const volVectorField& U,
const surfaceScalarField& alphaRhoPhi,
const surfaceScalarField& phi,
const transportModel& transport
)
:
BasicMomentumTransportModel
(
rho,
U,
alphaRhoPhi,
phi
),
alpha_(alpha),
transport_(transport)
{}

它的模板兼基类 BasicMomentumTransportModel 的实例化是 compressibleMomentumTransportModel,因此又调用了其构造函数

Foam::compressibleMomentumTransportModel::compressibleMomentumTransportModel
(
const volScalarField& rho,
const volVectorField& U,
const surfaceScalarField& alphaRhoPhi,
const surfaceScalarField& phi
)
:
momentumTransportModel
(
U,
alphaRhoPhi,
phi
),
rho_(rho)
{}

最后来到了 momentumTransportModel 的构造函数

Foam::momentumTransportModel::momentumTransportModel
(
const volVectorField& U,
const surfaceScalarField& alphaRhoPhi,
const surfaceScalarField& phi
)
:
IOdictionary(readModelDict(U.db(), alphaRhoPhi.group(), true)),

runTime_(U.time()),
mesh_(U.mesh()),

U_(U),
alphaRhoPhi_(alphaRhoPhi),
phi_(phi),
y_(mesh_)
{
// Ensure name of IOdictionary is typeName
rename(IOobject::groupName(typeName, alphaRhoPhi.group()));
}

题外话

初始化列表中:alphaRhoPhi_(alphaRhoPhi)
另有函数:

inline const surfaceScalarField& alphaRhoPhi() const
{
return alphaRhoPhi_;
}

combustionModel.H 中:

inline Foam::tmp<Foam::surfaceScalarField> Foam::combustionModel::phi() const
{
return turbulence().alphaRhoPhi();
}

就是说,solver#include "compressibleCreatePhi.H" 创建的 phi 逐级传到了湍流模型中,可以使用 Foam::combustionModel::phi() 来调用它。

输运模型构建

solver 中

Info<< "Creating thermophysical transport model\n" << endl;
autoPtr<psiReactionThermophysicalTransportModel> thermophysicalTransport
(
psiReactionThermophysicalTransportModel::New(turbulence(), thermo)
);

由 psiReactionThermophysicalTransportModel.H 可知:

typedef ThermophysicalTransportModel
<
compressible::momentumTransportModel,
psiReactionThermo
> psiReactionThermophysicalTransportModel;

因此这里调用的是 ThermophysicalTransportModel 的构造函数,参数则是 ThermophysicalTransportModel::New(turbulence(), thermo) 的返回值。
我们先看 New,再看构造函数。

template<class MomentumTransportModel, class ThermoModel>
Foam::autoPtr
<
Foam::ThermophysicalTransportModel<MomentumTransportModel, ThermoModel>
>
Foam::ThermophysicalTransportModel<MomentumTransportModel, ThermoModel>::New
(
const momentumTransportModel& momentumTransport,
const thermoModel& thermo
)
{
const word modelType
(
momentumTransport.lookup("simulationType")
);

Info<< "Selecting thermophysical transport type" << modelType << endl;

typename dictionaryConstructorTable::iterator cstrIter =
dictionaryConstructorTablePtr_->find(modelType);

if (cstrIter == dictionaryConstructorTablePtr_->end())
{
FatalErrorInFunction
<< "Unknown thermophysical transport type"
<< modelType << nl << nl
<< "Available types:" << endl
<<dictionaryConstructorTablePtr_->sortedToc()
<<exit(FatalError);
}

return autoPtr<ThermophysicalTransportModel>
(
cstrIter()(momentumTransport, thermo)
);
}

这里我们通过指定字典文件中的 simulationType 来决定创建 laminarThermophysicalTransportModel RASThermophysicalTransportModel``LESThermophysicalTransportModel 的其中之一。

template<class MomentumTransportModel, class ThermoModel>
Foam::ThermophysicalTransportModel<MomentumTransportModel, ThermoModel>::
ThermophysicalTransportModel
(
const momentumTransportModel& momentumTransport,
const thermoModel& thermo
)
:
thermophysicalTransportModel(momentumTransport),
momentumTransport_(momentumTransport),
thermo_(thermo)
{}

接下来进入基类的构造函数

Foam::thermophysicalTransportModel::thermophysicalTransportModel
(
const compressibleMomentumTransportModel& momentumTransport
)
:
IOdictionary
(
IOobject
(
IOobject::groupName
(
typeName, momentumTransport.alphaRhoPhi().group()
),
momentumTransport.time().constant(),
momentumTransport.mesh(),
//***HGW IOobject::MUST_READ_IF_MODIFIED,
IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE
)
),

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