关于调用 PtrDictionary<phaseModel> 类储存的场的数据
-
在 multiphaseEulerFoam,multiphaseInterFoam,compressibleMultiphaseInterFoam 等多相流求解器中,都会用到PtrDictionary<phaseModel>这个类来储存部分物理量的场的数据。
如果代码中要调用它所保存的物理量,比如体积分数场,怎么实现最方便?
-
换一种问法吧,以multiphaseEulerFoam为例,如何添加调用第n项的体积分数场的代码?
-
自己顶一下,
个人认为,最好的方法应该是用 .db().lookupObject<volScalarField>("xxxxx") ,比如要求水的体积分数,就在括号在填"alpha.water"。但有时不知道物理量被命名为什么,也就是说不知道"xxxxx"该填什么,比如compressibleMultiphaseInterFoam中的密度,填"rho.water"是无效的,这种情况下,可以用下面的代码:Foam::tmp<Foam::volScalarField> Foam::multiphaseMixtureThermo::rho3() const { PtrDictionary<phaseModel>::const_iterator phasei = phases_.begin(); ++phasei; ++phasei; tmp<volScalarField> trho(phasei().thermo().rho()); //换成 tmp<volScalarField> talpha(phasei()); 也可以求体积分数alpha return trho; }
该代码是用来第3相密度的成员函数。如果想求第n相的话,就进行n-1次++phasei。调用该函数,即可返回密度。虽然方法比较丑陋,但确实能用。
不知道大家还有什么更好的方法?
-
我觉得高亮的代码挺好了 有什么弊端么?