OpenFOAM 拉格朗日库 solidParticle 简介及应用

拉格朗日法常用来求解颗粒、气泡等离散介质在连续介质中的运动,OpenFOAM 提供了基础的拉格朗日法类库,可满足一些常见需求,可实现流体-颗粒双向耦合加上颗粒之间的相互作用,它提供了独特的MPPIC(Multiphase Particles in Cell)算法,可以在计算精度和代价之间取得平衡。但在处理不规则颗粒方面还缺少高效的方案,无法和专业的DEM(Discrete Element Method)软件媲美。

solidParticle 库是一个简单的示例,结构简单,抽象层次较低,容易理解,适合作为初学拉格朗日方法的切入点。solidParticle 库并未应用于任何原生的 OpenFOAM 求解器,一个原因是 solidParticle 的功能可通过 MPPIC 简化后实现,OpenFOAM 原生的求解器更注重通用性,因而提供了 MPPICFoam 和 MPPICInterFoam(仅ESI)。

solidParticle 的这些特点使得二次开发较 MPPIC 容易,本文的目标是在水气两相流求解器 interFoam 中的适配 solidParticle 库,求解水气两相流的同时求解颗粒运动。

第一步,将原生的interFoam源代码拷贝到用户目录,并重命名、编译。

cd $WM_PROJECT_DIR
cp -r --parents applications/solvers/multiphase/interFoam $WM_PROJECT_USER_DIR
cd $WM_PROJECT_USER_DIR/applications/solvers/multiphase
mv interFoam solidParticleInterFoam
cd solidParticleInterFoam
rm -r interMixingFoam overInterDyMFoam
wclean
rm -rf Make/linux*
mv interFoam.C solidParticleInterFoam.C
sed -i.orig s/interFoam/solidParticleInterFoam/g Make/files
sed -i s/FOAM_APPBIN/FOAM_USER_APPBIN/g Make/files
sed -i s/"..\/VoF"/"\$(FOAM_SOLVERS)\/multiphase\/VoF"/g Make/options
wmakeCode language: PHP (php)

完成操作后,检查新编译的求解器 solidParticleInterFoam 能否运行 damBreak 算例。

第二步,将 solidParticle 添加到求解器。

Open and modify solidParticleInterFoam.C:
Include the class declarations of solidParticleCloud.H+.
At the header, add:
#include "solidParticleCloud.H"
Create a solidParticleCloud object.
After the if-statement with #include "setInitialDeltaT.H", add:
solidParticleCloud particles(mesh);
Move the particles.
Before runTime.write();, add:
particles.move(g);Code language: CSS (css)

源代码只需修改上述部分,接下来修改 make 配置文件后编译。

Make sure that Make/options has the following lines (where ’...’ is the original lines):
EXE_INC = \
... \
-I$(LIB_SRC)/lagrangian/basic/lnInclude \
-I$(LIB_SRC)/lagrangian/solidParticle/lnInclude
EXE_LIBS = \
... \
-llagrangian \
-lsolidParticle
Compile:
wmakeCode language: JavaScript (javascript)

第三步,修改原生的 damBreak 算例,添加拉格朗日场。

Base the case on the original damBreak case:
run
cp -r $FOAM_TUTORIALS/multiphase/interFoam/RAS/damBreak/damBreak solidParticleDamBreak
cd solidParticleDamBreak
The modifations that need to be made are not obvious. There are no examples using the solidParticle class in the original code. I looked at examples for similar classes, as well as the source
code. Some time between v1706 and v1806 there was a significant change in the required files,
and here we set it up for v2006.
Create a directory for info of the particles:
mkdir -p 0/lagrangian/defaultCloud
We will add files for diameter (d), positions (positions), velocity (U), original ID (origId) and
original processor ID (origProcId).
Create a directory for the particle cloud properties, which we will only use to specify the format
of positions of the particles (the default in v2006 seems to be coordinates, be but we will use
the old positions):
mkdir -p 0/uniform/lagrangian/defaultCloud
We will set the particle properties in constant/particleProperties.

接下来,逐个新建、编辑拉格朗日场的0文件,设置初始条件

Diameter file (0/lagrangian/defaultCloud/d):
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v1806 |
| \\ / A nd | Web: www.OpenFOAM.com |
| \\/ M anipulation | | \*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class scalarField;
location "0/lagrangian/defaultCloud";
object d;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
2{2.0e-3}
// ************************************************************************* //
The number of particles is 2, and since they have the same diameter their diameters are in a
list given by the curly brackets.Code language: JavaScript (javascript)
Positions file (0/lagrangian/defaultCloud/positions):
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v1806 |
| \\ / A nd | Web: www.OpenFOAM.com |
| \\/ M anipulation | | \*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class Cloud<solidParticle>;
location "0/lagrangian/defaultCloud";
object positions;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
2(
(2e-2 0.56 0.005) -1
(3e-2 0.56 0.005) -1
)
// ************************************************************************* //
The particles start at different positions, so the list is given with regular brackets. The -1 at
the end of the line means that the class will have to find the cells that they are located in. In
the time directories it will be stated which cell they are in.Code language: JavaScript (javascript)
Velocity file (0/lagrangian/defaultCloud/U):
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v1806 |
| \\ / A nd | Web: www.OpenFOAM.com |
| \\/ M anipulation | | \*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class vectorField;
location "0/lagrangian/defaultCloud";
object U;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
2(
(1.7e-1 0 0)
(1.7 0 0)
)
// ************************************************************************* //
The particles start with different velocities.Code language: JavaScript (javascript)
Original ID file (0/lagrangian/defaultCloud/origId):
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v1806 |
| \\ / A nd | Web: www.OpenFOAM.com |
| \\/ M anipulation | | \*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class labelField;
location "0/lagrangian/defaultCloud";
object origId;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
2(01)
// ************************************************************************* //
The particles are numbered with labels.Code language: JavaScript (javascript)
Original processor ID file (0/lagrangian/defaultCloud/origProcId):
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v1806 |
| \\ / A nd | Web: www.OpenFOAM.com |
| \\/ M anipulation | | \*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class labelField;
location "0/lagrangian/defaultCloud";
object origProcId;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
2{0}
// ************************************************************************* //
Both particles originate in the processor0 region (I only tested this running sequentially, so I
have not checked how this is affected when running in parallel).Code language: JavaScript (javascript)
cloudProperties file (0/uniform/lagrangian/defaultCloud/cloudProperties):
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v1806 |
| \\ / A nd | Web: www.OpenFOAM.com |
| \\/ M anipulation | | \*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
location "0/uniform/lagrangian/defaultCloud";
object cloudProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
geometry positions;
// ************************************************************************* //
I interpret the purpose of this file (for this class) to define if we use a positions file or a
coordinates file for the particle positions. It may be the case that the case set-up would be
simpler with the coordinates option, but I have not checked that up. The class writes out
coordinates files in addition to the positions files in the time directories.Code language: JavaScript (javascript)

接着添加颗粒的物理性质参数

Particle properties file (constant/particleProperties):
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v1806 |
| \\ / A nd | Web: www.OpenFOAM.com |
| \\/ M anipulation | | \*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object particleProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
rhop rhop [ 1 -3 0 0 0 0 0] 1000;
e e [ 0 0 0 0 0 0 0] 0.8; //Shifted for copy-paste reasons
mu mu [ 0 0 0 0 0 0 0] 0.2; //Shifted for copy-paste reasons
// ************************************************************************* //
These are the particle density, and the coefficients of normal and tangential restitution as the
particles hit the walls. The class does not include particle-particle collisions. You would have to
use the kinematicParticle class or some more advanced class.Code language: JavaScript (javascript)

最后,运行求解器并进行后处理。

blockMesh
setFields
solidParticleInterFoam 2>&1 | tee log_solidParticleInterFoam

部分内容来自 Chalmers CFD with OpenSource Software 课程讲义(Proceedings of CFD with OpenSource Software, 2020, Edited by Nilsson H. http://dx.doi.org/10.17196/OS_CFD#YEAR_2020)

常恭

作者: 常恭

略懂 OpenFOAM

发表评论