Euler-Lagrange的一些解析,sprayFoam
-
因为要写给project partner关于我的一部分工作,所以写了这个东西,仅涉及了默认的OpenFOAM的一些东西,不能说是本着开源精神,毕竟自己做的东西并没有involve,但是希望能对论坛里做欧拉拉格朗日的小伙伴们一些帮助,尤其是新手。此贴会长期更新,一点一点来。
本人也是资历有限,在OF里一番摸爬滚打,不免会有理解错误,望见谅~
因为工作不涉及到thermo部分,所以这部分基本不会。。哈哈
This document is just for the explaination of the sprayFoam.pdf
-
-
Parcel和Particle的区别,两者并不相同
在使用Parcel概念的时候一定要注意Parcel 和Particle 是有区别的
Parcel是Particle的合集,所以diameter和velocity是相同的,但是质量是所有particle的和$m_{parcel} = \sum m_{particles}= \rho_p V * np$
所以再考虑到parcel质量的时候一定别忘了np
在考虑mass的时候也别忘了体积和直径是立方关系。
再做统计的时候一定要考虑好到底是做parcel的统计还是particle的统计。统计某一个平面的parcel的相关信息
因为of里是单独将lagrangianfield 拿出来的,所以说,再paraview中是无法使用plot over line查看拉格朗日场的。于是解决方法通常有两种
1. 将拉格朗日场转到Euler场
template<class CloudType> Foam::volScalarField& Foam::IVT8_StochasticCollisionModel_2022<CloudType>::PPC() { if (!PPCPtr_.valid() ) { const fvMesh& mesh = this->owner().mesh(); PPCPtr_.reset ( new volScalarField ( IOobject ( this->owner().name() + ":PPC", mesh.time().timeName(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE ), mesh, dimensionedScalar ("zero", dimless, 0.0), zeroGradientFvPatchScalarField::typeName ) ); } return PPCPtr_(); } 然后再调用的时候这么调用即可 scalar& PPC = PPCPtr_->primitiveFieldRef() [cellI]; PPC += 1.0;
2. 输出文件
然后用python或者什么后处理。
具体可以参阅ParticleCollector,再particleCollector下的postMove中添加如下code, 具体参数就根据自己的具体要求添加把。forAll (hitFaceIDs_, i) { std::ofstream outfile; outfile.setf (ios_base::fixed, ios_base::floatfield); outfile.precision (8); outfile.open ("output.txt", ios_base::app); outfile << this->owner().db().time().timeName() << tab << p.origId() << tab << p.typeId() << tab << p.age() << tab << p.position().component (0) << tab << p.position().component (1) << tab << p.position().component (2) << tab << p.U().component (0) << tab << p.U().component (1) << tab << p.U().component (2) << tab << p.d() << tab << p.Rep() << tab << p.nParticle() << tab << p.mass() * 1e18 << tab << nl; }
两种方法利弊:
方法1,
pro: 简单快捷,不需要大量的算力,会吃一些内存,但是完全取决于你的cell,可以再parview中简单直接的看到随时间的变化
con: 当你需要进行一些统计学的运算的话,需要建立一些fields,而且无法精确统计每个parcel, 另外如果需要做时均的话,会损失一些信息。。(血与泪的教训)方法2,
pro: 每一条输出就是一条数据,你可以输出任何你想要的数据,做任何统计学上的后处理
con: 需要后处理,可能会输出几十上百G的file,python或者matlab等后处理,需要一定的时间。 -
@chengan-wang 1-way 就是 parcel收到流场的影响,2way的话就是流场也收到parcel的影响
newFormat 就是chemkin库,具体这部分你要去thermo查,
如何计算某个温度下的表面张力和粘度什么的 polynomial 还是什么的,具体参数都是什么,都需要你自己查的。 这玩意是有标准库的。
chemkin不是很熟,我平时都不用这个,文件里面写了 -
@星星星星晴 非常感谢帮忙,我就是输出水雾就行,不用考虑化学反应,我感觉newFormat没啥用,就注释掉了。目前能生成水雾了,正在琢磨怎么提取质量分布的数据等等。
paraview 处理Lagrangian数据 -
@chengan-wang 上面已写具体做法
-
@星星星星晴 您好,我参考了GOFUN2017_ParticleSimulations_slides.pdf ,建立一个文件夹,并把文件拷过来。
mkdir lagrangian cp -r $FOAM_SRC/lagrangian/intermediate/ lagrangian/
采用输出文件方法2,修改particleCollector,然后编译也成功了,
但是输出文件中没有看到output.txt文件,
我还需要在算例中设置什么命令才能调用particleCollector?
谢谢 -
@chengan-wang 这个是cloudfunction,在sprayproperties里面添加cloudfunction。
-
@星星星星晴 谢谢指点!
我这两天大概改了一下cloudfunction,似乎能运行了,但是从重新编译的求解器log文件上看,应该有一些问题,我好像重复调用了一些库函数:Duplicate entry facePostProcessing in runtime selection table CloudFunctionObject #0 /home/chengan/OpenFOAM/OpenFOAM-2.4.0/platforms/linux64GccDPOpt/lib/libOpenFOAM.so(_ZN4Foam5error14safePrintStackERSo+0x3e) [0x7f28ae2ae0ae] #1 /home/chengan/OpenFOAM/chengan-2.4.0/platforms/linux64GccDPOpt/lib/libstatisticslagrangianIntermediate.so(_ZN4Foam19CloudFunctionObjectINS_14KinematicCloudINS_5CloudINS_15KinematicParcelINS_8particleEEEEEEEE31adddictionaryConstructorToTableINS_18FacePostProcessingIS7_EEEC1ERKNS_4wordE+0xfb) [0x7f28b4ff288b] #2 /home/chengan/OpenFOAM/chengan-2.4.0/platforms/linux64GccDPOpt/lib/libstatisticslagrangianIntermediate.so(+0x2410f5) [0x7f28b4fbe0f5] #3 /lib64/ld-linux-x86-64.so.2(+0x108d3) [0x7f28b55618d3] #4 /lib64/ld-linux-x86-64.so.2(+0x10ca) [0x7f28b55520ca] Duplicate entry particleCollector in runtime selection table CloudFunctionObject #0 /home/chengan/OpenFOAM/OpenFOAM-2.4.0/platforms/linux64GccDPOpt/lib/libOpenFOAM.so(_ZN4Foam5error14safePrintStackERSo+0x3e) [0x7f28ae2ae0ae] #1 /home/chengan/OpenFOAM/chengan-2.4.0/platforms/linux64GccDPOpt/lib/libstatisticslagrangianIntermediate.so(_ZN4Foam19CloudFunctionObjectINS_14KinematicCloudINS_5CloudINS_15KinematicParcelINS_8particleEEEEEEEE31adddictionaryConstructorToTableINS_17ParticleCollectorIS7_EEEC2ERKNS_4wordE+0xfb) [0x7f28b4ff29cb] #2 /home/chengan/OpenFOAM/chengan-2.4.0/platforms/linux64GccDPOpt/lib/libstatisticslagrangianIntermediate.so(+0x24115c) [0x7f28b4fbe15c] #3 /lib64/ld-linux-x86-64.so.2(+0x108d3) [0x7f28b55618d3] #4 /lib64/ld-linux-x86-64.so.2(+0x10ca) [0x7f28b55520ca] Duplicate entry particleErosion in runtime selection table CloudFunctionObject #0 /home/chengan/OpenFOAM/OpenFOAM-2.4.0/platforms/linux64GccDPOpt/lib/libOpenFOAM.so(_ZN4Foam5error14safePrintStackERSo+0x3e) [0x7f28ae2ae0ae] #1 /home/chengan/OpenFOAM/chengan-2.4.0/platforms/linux64GccDPOpt/lib/libstatisticslagrangianIntermediate.so(_ZN4Foam19CloudFunctionObjectINS_14KinematicCloudINS_5CloudINS_15KinematicParcelINS_8particleEEEEEEEE31adddictionaryConstructorToTableINS_15ParticleErosionIS7_EEEC1ERKNS_4wordE+0xfb) [0x7f28b4ff2b0b]
我又看了一下求解器Make文件夹的options文件:
EXE_INC = \ -Ilagrangian/intermediate/lnInclude \ -I$(LIB_SRC)/finiteVolume/lnInclude \ -I${LIB_SRC}/meshTools/lnInclude \ -I${LIB_SRC}/sampling/lnInclude \ -I$(LIB_SRC)/turbulenceModels/compressible/turbulenceModel \ -I$(LIB_SRC)/lagrangian/basic/lnInclude \ -I$(LIB_SRC)/lagrangian/spray/lnInclude \ -I$(LIB_SRC)/lagrangian/distributionModels/lnInclude \ -I$(LIB_SRC)/thermophysicalModels/specie/lnInclude \ -I$(LIB_SRC)/thermophysicalModels/basic/lnInclude \ -I$(LIB_SRC)/thermophysicalModels/properties/liquidProperties/lnInclude \ -I$(LIB_SRC)/thermophysicalModels/properties/liquidMixtureProperties/lnInclude \ -I$(LIB_SRC)/thermophysicalModels/properties/solidProperties/lnInclude \ -I$(LIB_SRC)/thermophysicalModels/properties/solidMixtureProperties/lnInclude \ -I$(LIB_SRC)/thermophysicalModels/thermophysicalFunctions/lnInclude \ -I$(LIB_SRC)/thermophysicalModels/reactionThermo/lnInclude \ -I$(LIB_SRC)/thermophysicalModels/SLGThermo/lnInclude \ -I$(LIB_SRC)/thermophysicalModels/chemistryModel/lnInclude \ -I$(LIB_SRC)/thermophysicalModels/radiationModels/lnInclude \ -I$(LIB_SRC)/ODE/lnInclude \ -I$(LIB_SRC)/regionModels/regionModel/lnInclude \ -I$(LIB_SRC)/regionModels/surfaceFilmModels/lnInclude \ -I$(LIB_SRC)/fvOptions/lnInclude \ -I$(LIB_SRC)/combustionModels/lnInclude EXE_LIBS = \ -L$(FOAM_USER_LIBBIN) \ -lstatisticslagrangianIntermediate \ -lfiniteVolume \ -lmeshTools \ -lsampling \ -lcompressibleTurbulenceModel \ -lcompressibleRASModels \ -lcompressibleLESModels \ -llagrangian \ -llagrangianTurbulence \ -llagrangianSpray \ -lspecie \ -lfluidThermophysicalModels \ -lliquidProperties \ -lliquidMixtureProperties \ -lsolidProperties \ -lsolidMixtureProperties \ -lthermophysicalFunctions \ -lreactionThermophysicalModels \ -lSLGThermo \ -lchemistryModel \ -lradiationModels \ -lODE \ -lregionModels \ -lsurfaceFilmModels \ -lfvOptions \ -lcombustionModels
没看出来我编译的intermediate文件夹跟哪个冲突。(我在求解器文件夹中建立lagrangian文件夹,然后把原始的intermediate文件夹拷进去,修改particleCollector,然后编译,编译过程中没有报错)。
麻烦您啦! -
@chengan-wang 看来你这个是祖传代码,我也看不出来你这个问题到底在哪。。虽然of的基础变化不大,但是你还用的是2.4。。
你这个编译方法看起来是可以使用的,但是你只编译了intermediate这个文件夹是么,你确定其他关联到intermediate的库的都关联这个了么?
建议你自己一点一点查吧
-
@chengan-wang 就是普通的 教程上的方法。。。一板一眼
-
@星星星星晴 您好,我这次直接在OpenFOAM-2.4.0下面的ParticleCollector.C文件修改,wclean, wmake libso,编译成功,避免了冲突问题。
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template<class CloudType> void Foam::ParticleCollector<CloudType>::postMove ( parcelType& p, const label cellI, const scalar dt, const point& position0, bool& keepParticle ) { if ((parcelType_ != -1) && (parcelType_ != p.typeId())) { return; } // slightly extend end position to avoid falling within tracking tolerances const point position1 = position0 + 1.0001*(p.position() - position0); hitFaceIDs_.clear(); switch (mode_) { case mtPolygon: { collectParcelPolygon(position0, position1); break; } case mtConcentricCircle: { collectParcelConcentricCircles(position0, position1); break; } default: { } } forAll(hitFaceIDs_, i) { label faceI = hitFaceIDs_[i]; scalar m = p.nParticle()*p.mass(); if (negateParcelsOppositeNormal_) { vector Uhat = p.U(); Uhat /= mag(Uhat) + ROOTVSMALL; if ((Uhat & normal_[faceI]) < 0) { m *= -1.0; } } // add mass contribution mass_[faceI] += m; if (nSector_ == 1) { mass_[faceI + 1] += m; mass_[faceI + 2] += m; mass_[faceI + 3] += m; } if (removeCollected_) { keepParticle = false; } } //******add by myself****** forAll(hitFaceIDs_, i) { std::ofstream outfile; outfile.setf(ios_base::fixed, ios_base::floatfield); outfile.precision(8); outfile.open("output.txt", ios_base::app); outfile << this->owner().db().time().timeName() << tab << p.origId() << tab << p.typeId() << tab << p.age() << tab << p.position().component(0) << tab << p.position().component(1) << tab << p.position().component(2) << tab << p.U().component(0) << tab << p.U().component(1) << tab << p.U().component(2) << tab << p.d() << tab << p.nParticle() << tab << p.mass()*1e18 << tab << nl; } //******add by myself****** }
之后,我在sprayCloudProperties文件中定义(用的是ParticleCollector.H自带例子)
cloudFunctions { particleCollector2 { type particleCollector; mode polygon; polygons ( ( (-0.01 0.05 -0.01) (-0.01 0.05 0.01) (0.01 0.05 0.01) (0.01 0.05 -0.01) ) ); normal (0 0 1); negateParcelsOppositeNormal no; removeCollected no; surfaceFormat vtk; resetOnWrite no; log yes; } }
运行至第一个时间步长就报错了
[2] --> FOAM FATAL IO ERROR: [13] [13] [13] --> FOAM FATAL IO ERROR: [13] wrong token type - expected Scalar, found on line 0 the punctuation token '-' [13] [13] file: /home/chengan/OpenFOAM/chengan-2.4.0/run/sprayFoam/watermist/processor13/0/uniform/lagrangian/sprayCloud/sprayCloudOutputProperties.cloudFunctionObject.particleCollector2.massFlowRate at line 0. [13] [13] From function operator>>(Istream&, Scalar&) [13] in file lnInclude/Scalar.C at line 93. [13] FOAM parallel run exiting [13] [2] wrong token type - expected Scalar, found on line 0 the punctuation token '-' [2] [2] file: /home/chengan/OpenFOAM/chengan-2.4.0/run/sprayFoam/watermist/processor2/0/uniform/lagrangian/sprayCloud/sprayCloudOutputProperties.cloudFunctionObject.particleCollector2.massFlowRate at line 0. [2] [2] From function operator>>(Istream&, Scalar&) [2] in file lnInclude/Scalar.C at line 93. [2] FOAM parallel run exiting [2] particleCollector output: -------------------------------------------------------------------------- MPI_ABORT was invoked on rank 2 in communicator MPI_COMM_WORLD with errorcode 1. NOTE: invoking MPI_ABORT causes Open MPI to kill all MPI processes. You may or may not see output from other processes, depending on exactly when Open MPI kills them. -------------------------------------------------------------------------- [chengan-MS-7C80:26316] 1 more process has sent help message help-mpi-api.txt / mpi-abort [chengan-MS-7C80:26316] Set MCA parameter "orte_base_help_aggregate" to 0 to see all help / error messages
如果不用particleCollector,直接使用cloudFunctions{}算例可以运行。
我没有搞明白到底什么地方出了问题
-
这部分你可以删掉,particlecollector总是有些问题,我也遇到过,后来不必要的东西全删掉了
forAll(hitFaceIDs_, i) { label faceI = hitFaceIDs_[i]; scalar m = p.nParticle()*p.mass(); if (negateParcelsOppositeNormal_) { vector Uhat = p.U(); Uhat /= mag(Uhat) + ROOTVSMALL; if ((Uhat & normal_[faceI]) < 0) { m *= -1.0; } } // add mass contribution mass_[faceI] += m; if (nSector_ == 1) { mass_[faceI + 1] += m; mass_[faceI + 2] += m; mass_[faceI + 3] += m; } if (removeCollected_) { keepParticle = false; } }