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

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

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

```.wp-block-code {
border: 0;
}

.wp-block-code > div {
overflow: auto;
}

.shcb-language {
border: 0;
clip: rect(1px, 1px, 1px, 1px);
-webkit-clip-path: inset(50%);
clip-path: inset(50%);
height: 1px;
margin: -1px;
overflow: hidden;
position: absolute;
width: 1px;
word-wrap: normal;
word-break: normal;
}

.hljs {
box-sizing: border-box;
}

.hljs.shcb-code-table {
display: table;
width: 100%;
}

.hljs.shcb-code-table > .shcb-loc {
color: inherit;
display: table-row;
width: 100%;
}

.hljs.shcb-code-table .shcb-loc > span {
display: table-cell;
}

.wp-block-code code.hljs:not(.shcb-wrap-lines) {
white-space: pre;
}

.wp-block-code code.hljs.shcb-wrap-lines {
white-space: pre-wrap;
}

.hljs.shcb-line-numbers {
border-spacing: 0;
counter-reset: line;
}

.hljs.shcb-line-numbers > .shcb-loc {
counter-increment: line;
}

.hljs.shcb-line-numbers .shcb-loc > span {
}

.hljs.shcb-line-numbers .shcb-loc::before {
border-right: 1px solid #ddd;
content: counter(line);
display: table-cell;
text-align: right;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
white-space: nowrap;
width: 1%;
}
```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
wmake```Code language: PHP (php)```

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

``````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:
wmake```Code language: JavaScript (javascript)```

``````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 solidParticle 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.``````

``````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)
)
// ************************************************************************* //
``````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``````