怎么才能在代码里快速找到函数的定义?
-
@李东岳 我目前在看官方版本4.1下的compressibleInterFoam求解器
在twoPhaseMixtureThermo类中,我没弄错的话它的定义是这个,有错还请纠正我。void Foam::twoPhaseMixtureThermo::correct() { thermo1_->he() = thermo1_->he(p_, T_); thermo1_->correct(); thermo2_->he() = thermo2_->he(p_, T_); thermo2_->correct(); psi_ = alpha1()*thermo1_->psi() + alpha2()*thermo2_->psi(); mu_ = alpha1()*thermo1_->mu() + alpha2()*thermo2_->mu(); alpha_ = alpha1()*thermo1_->alpha() + alpha2()*thermo2_->alpha(); }
我想看下 thermo1_->psi() 是怎么定义的,我在
psiThermo.C
下看到
Foam::psiThermo::psiThermo(const fvMesh& mesh, const word& phaseName)fluidThermo(mesh, phaseName), psi_ ( IOobject ( phasePropertyName("thermo:psi"), mesh.time().timeName(), mesh, IOobject::NO_READ, IOobject::NO_WRITE ), mesh, dimensionSet(0, -2, 2, 0, 0) ), mu_ ( IOobject ( phasePropertyName("thermo:mu"), mesh.time().timeName(), mesh, IOobject::NO_READ, IOobject::NO_WRITE ), mesh, dimensionSet(1, -1, -1, 0, 0) ) {}
找到这儿,我不是很清楚了接下来该怎么查看各相psi的s定义,我知道它的定义会在equation of state 里,就是不清楚怎么联系的。
-
@影川风
请看twoPhaseMixtureThermo.H 的59~63行,//- Thermo-package of phase 1 autoPtr<rhoThermo> thermo1_; //- Thermo-package of phase 2 autoPtr<rhoThermo> thermo2_;
如果没说错的话,thermo1_,thermo2_是指向rhoThermo类的智能指针,所以你应该参考的是rhoThermo类
那么,在rhoThermo.C 的 176~179行,const Foam::volScalarField& Foam::rhoThermo::psi() const { return psi_; }
而这个psi_,是rhoThermo类里面的成员变量
我不能理解的是,he( )定义在哪里?我仅仅在basicThermo类(rhoThermo基类)里面看到过这个纯虚函数。求问东岳老师此问题作何解答 @李东岳 -
@影川风
twoPhaseMixtureThermo.C里面确实有,但是,,void Foam::twoPhaseMixtureThermo::correct() { thermo1_->he() = thermo1_->he(p_, T_); thermo1_->correct(); thermo2_->he() = thermo2_->he(p_, T_); thermo2_->correct(); psi_ = alpha1()*thermo1_->psi() + alpha2()*thermo2_->psi(); mu_ = alpha1()*thermo1_->mu() + alpha2()*thermo2_->mu(); alpha_ = alpha1()*thermo1_->alpha() + alpha2()*thermo2_->alpha(); }
这里的thermo1_是指向rhoThermo类的,真的可以调用twoPhaseMixtureThermo类里面的函数吗?我在twoPhaseMixtureThermo::he()里面加了一句Info,运行求解器的时候貌似没有在终端里看到那句Info。c++基础不牢求指导
-
刚好最近在看thermophysicalmodels这一部分。感觉的确复杂,大家可以参考userguide中的定义部分。特别是1.x版本更接近C++的书写习惯,一步步查下去就能找到了。特别需要搞清楚的就是每一层到底定义了些什么
-
针对5楼 @影川风 的问题,如果下面是你双流体模型调用的热动力包:
thermoType { type heRhoThermo; mixture pureMixture; transport const; thermo hConst; equationOfState perfectGas; specie specie; energy sensibleInternalEnergy; }
在
perfectGasI.H
中,有inline Foam::scalar Foam::perfectGas<Specie>::psi(scalar p, scalar T) const { return 1.0/(this->R()*T); }
其中的
this->R()
定义在specieI.H
inline scalar specie::R() const { return RR/molWeight_; }
In the following I switch to English which is more convenient to code,
molWeight_
is the Molecular weight of specie which is the given by the user.RR
is the Universal gas constant which is defined inthermodynamicConstants.H
, it is calculated by the following (defined inthermodynamicConstants.C
):// Note: the 1e3 converts from /mol to /kmol for consistency with the // SI choice of kg rather than g for mass. // This is not appropriate for USCS and will be changed to an entry in // the DimensionedConstants dictionary in etc/controlDict const scalar RR = 1e3*physicoChemical::R.value();
where
R.value()
is calculated byphysicoChemical::NA*physicoChemical::k
which is defined in
physicoChemicalConstants.C
.physicoChemical::NA
is defined infundamentalConstants.C
:defineDimensionedConstantWithDefault ( physicoChemical::group, physicoChemical::NA, Foam::dimensionedScalar ( "NA", dimensionSet(0, 0, 0, 0, -1), //Foam::dimless/Foam::dimMoles, 6.0221417930e+23 ), constantphysicoChemicalNA, "NA" );
and
physicoChemical::k
is defined inetc/controlDict
:physicoChemical { mu mu [1 0 0 0 0 0 0] 1.66054e-27; k k [1 2 -2 -1 0 0 0] 1.38065e-23; }