分析可压缩湍流部分的继承关系
OF-7继承关系:
solver 中:
Info << "Creating turbulence model.\n" << nl; autoPtr<compressible::turbulenceModel> turbulence ( compressible::turbulenceModel::New ( rho, U, phi, thermo ) );
其中 Foam::compressible::turbulenceModel
是 Foam::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
这里用到了 RTSNew
函数:
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::momentumTransportModel
是 CompressibleMomentumTransportModel<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) {}