在rhoPimpleFoam中添加一个被动运输方程,作为OpenFOAM修改求解器的练习,版本为10。
参考网站里讲得更清晰:OpenFOAM求解器开发 - 作业部落 Cmd Markdown 编辑阅读器 (zybuluo.com)https://www.zybuluo.com/daidezhi/note/385554
step1. 拷贝
将原有求解器rhoPimpleFoam的文件夹拷贝到自己的目录下,并重命名为toyFoam
cp -r $FOAM_SOLVERS/compressible/rhoPimpleFoam/ $WM_PROJECT_USER_DIR/toyFoam
step2. 重命名
进入toyFoam目录
cd $WM_PROJECT_USER_DIR/toyFoam/
wclean删除已有的依赖项文件
wclean
(1) *重命名rhoPimpleFoam.C为toyFoam.C
mv rhoPimpleFoam.C toyFoam.C
(2) *修改配置文件Make/files中的求解器名称(第一行)和可执行文件的路径与名称(第二行)
toyFoam.C
EXE = $(FOAM_USER_APPBIN)/toyFoam
(3) toyFoam.C修改求解器说明(不影响运行)
\*---------------------------------------------------------------------------*/
......
Application
toyFoam
Description
Transient solver for turbulent flow of compressible fluids for HVAC and
similar applications, with optional mesh motion, mesh topology changes,
and additional passive scalar transport equation.
Uses the flexible PIMPLE (PISO-SIMPLE) solution for time-resolved and
pseudo-transient simulations.
\*---------------------------------------------------------------------------*/
(4) 配置文件Make/options的内容一般不需要修改
文件options里的内容:
EXE_INC = \
-I$(LIB_SRC)/physicalProperties/lnInclude \
-I$(LIB_SRC)/thermophysicalModels/basic/lnInclude \
-I$(LIB_SRC)/MomentumTransportModels/momentumTransportModels/lnInclude \
-I$(LIB_SRC)/MomentumTransportModels/compressible/lnInclude \
-I$(LIB_SRC)/ThermophysicalTransportModels/lnInclude \
-I$(LIB_SRC)/finiteVolume/cfdTools \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/sampling/lnInclude
EXE_LIBS = \
-lfluidThermophysicalModels \
-lspecie \
-lmomentumTransportModels \
-lcompressibleMomentumTransportModels \
-lthermophysicalTransportModels \
-lfiniteVolume \
-lmeshTools \
-lsampling \
-lfvModels \
-lfvConstraints
① EXE_INC:.C文件中头文件的位置。
例如对于第一个路径-I$(LIB_SRC)/physicalProperties/lnInclude,进入$FOAM_SRC/physicalProperties/lnInclude,可以在该目录下找到相关的头文件:
cd $FOAM_SRC/physicalProperties/lnInclude
ls
② EXE_LIBS:现有的库,可以在编译过程中链接
step3. 编译
重命名完成后,编译一下以检查是否有效。
在toyFoam目录下输入“wmake”进行编译
cd $WM_PROJECT_USER_DIR/toyFoam
wmake
去用户应用目录下可以看到成功生成了可执行文件toyFoam
cd $FOAM_USER_APPBIN
ls
step 4. 写入方程
被动标量输运方程:
在toyFoam.C写入:
......
fvScalarMatrix WEqn
(
fvm::ddt(rho,W)
+ fvm::div(phi, W)
- fvm::laplacian(rho*gammaW, W)
==
fvModels.source(rho,W)
);
WEqn.relax();
WEqn.solve();
runTime.write();
......
读写标量W和扩散系数gammaW ,在creatFields.H中写入:
Info<< "Reading physicalProperties\n" << endl;
IOdictionary physicalProperties
(
IOobject
(
"physicalProperties",
runTime.constant(),
mesh,
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE
)
);
Info<< "Reading diffusivity gammaW\n" << endl;
dimensionedScalar gammaW
(
physicalProperties.lookup("gammaW")
);
Info<< "Reading field W\n" << endl;
volScalarField W
(
IOobject
(
"W",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);
step 5. 编译
wmake
step 6. 算例
一个简单的测试模型:
圆柱绕流+圆柱表面产生被动标量W
(1) 网格
圆圈里的数字表示block编号,同时也是frontAndBack里的face编号,红色数字是frontAndBack里的face编号,NX、NY等为网格数。
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 10
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
format ascii;
class dictionary;
location "system";
object blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
convertToMeters 0.001;
L 100.;
W 80.;
R1 30.;
R2 55.;
Z 1.;
theta #calc "45.*3.14159/180.";
X1 #calc "$R1*cos($theta)";
Y1 #calc "$R1*sin($theta)";
X2 #calc "$R2*cos($theta)";
Y2 #calc "$R2*sin($theta)";
Lm #calc "-$L";
Y1m #calc "-$Y1";
Y2m #calc "-$Y2";
R1m #calc "-$R1";
R2m #calc "-$R2";
vertices
(
//right,up,front
($R1 0 0) //0
($R2 0 0) //1
($W 0 0) //2
($W $Y2 0) //3
($X2 $Y2 0) //4
($X1 $Y1 0) //5
($W $L 0) //6
($X2 $L 0) //7
(0 $L 0) //8
(0 $R2 0) //9
(0 $R1 0) //10
//right,down,front
($W $Y2m 0) //11
($X2 $Y2m 0) //12
($X1 $Y1m 0) //13
($W $Lm 0) //14
($X2 $Lm 0) //15
(0 $Lm 0) //16
(0 $R2m 0) //17
(0 $R1m 0) //18
//right,up,back
($R1 0 $Z) //19
($R2 0 $Z) //20
($W 0 $Z) //21
($W $Y2 $Z) //22
($X2 $Y2 $Z) //23
($X1 $Y1 $Z) //24
($W $L $Z) //25
($X2 $L $Z) //26
(0 $L $Z) //27
(0 $R2 $Z) //28
(0 $R1 $Z) //29
//right,down,back
($W $Y2m $Z) //30
($X2 $Y2m $Z) //31
($X1 $Y1m $Z) //32
($W $Lm $Z) //33
($X2 $Lm $Z) //34
(0 $Lm $Z) //35
(0 $R2m $Z) //36
(0 $R1m $Z) //37
);
NX 10;
NY 10;
NYarc 10;
NXcor 10;
NYcor 10;
blocks
(
hex (5 4 9 10 24 23 28 29) ($NX $NYarc 1) simpleGrading (1 1 1) //0
hex (0 1 4 5 19 20 23 24) ($NX $NY 1) simpleGrading (1 1 1) //1
hex (1 2 3 4 20 21 22 23) ($NXcor $NY 1) simpleGrading (1 1 1) //2
hex (4 3 6 7 23 22 25 26) ($NXcor $NYcor 1) simpleGrading (1 1 1) //3
hex (9 4 7 8 28 23 26 27) ($NYarc $NYcor 1) simpleGrading (1 1 1) //4
hex (18 17 12 13 37 36 31 32) ($NX $NYarc 1) simpleGrading (1 1 1) //5
hex (13 12 1 0 32 31 20 19) ($NX $NY 1) simpleGrading (1 1 1) //6
hex (1 12 11 2 20 31 30 21) ($NY $NXcor 1) simpleGrading (1 1 1) //7
hex (12 15 14 11 31 34 33 30) ($NYcor $NXcor 1) simpleGrading (1 1 1) //8
hex (17 16 15 12 36 35 34 31) ($NYcor $NYarc 1) simpleGrading (1 1 1) //9
);
theta2 #calc "22.5*3.14159/180.";
R1_COS #calc "$R1*cos($theta2)";
R1_SIN #calc "$R1*sin($theta2)";
R2_COS #calc "$R2*cos($theta2)";
R2_SIN #calc "$R2*sin($theta2)";
R1m_COS #calc "$R1m*cos($theta2)";
R1m_SIN #calc "$R1m*sin($theta2)";
R2m_COS #calc "$R2m*cos($theta2)";
R2m_SIN #calc "$R2m*sin($theta2)";
edges
(
arc 0 5 ($R1_COS $R1_SIN 0) //0
arc 5 10 ($R1_SIN $R1_COS 0) //1
arc 1 4 ($R2_COS $R2_SIN 0) //2
arc 4 9 ($R2_SIN $R2_COS 0) //3
arc 0 13 ($R1_COS $R1m_SIN 0) //4
arc 13 18 ($R1_SIN $R1m_COS 0) //5
arc 1 12 ($R2_COS $R2m_SIN 0) //6
arc 12 17 ($R2_SIN $R2m_COS 0) //7
arc 19 24 ($R1_COS $R1_SIN $Z) //8
arc 24 29 ($R1_SIN $R1_COS $Z) //9
arc 20 23 ($R2_COS $R2_SIN $Z) //10
arc 23 28 ($R2_SIN $R2_COS $Z) //11
arc 19 32 ($R1_COS $R1m_SIN $Z) //12
arc 32 37 ($R1_SIN $R1m_COS $Z) //13
arc 20 31 ($R2_COS $R2m_SIN $Z) //14
arc 31 36 ($R2_SIN $R2m_COS $Z) //15
);
boundary
(
walls
{
type wall;
faces
(
(3 6 25 22)
(2 3 22 21)
(11 2 21 30)
(14 11 30 33)
);
}
inlet
{
type patch;
faces
(
(16 15 34 35)
(34 33 14 15)
);
}
outlet
{
type patch;
faces
(
(8 7 26 27)
(7 6 25 26)
);
}
hole
{
type patch;
faces
(
(5 10 29 24)
(0 5 24 19)
(0 13 32 19)
(13 18 37 32)
);
}
symmetry
{
type symmetryPlane;
faces
(
(8 9 28 27)
(9 10 29 28)
(18 17 36 37)
(17 16 35 36)
);
}
frontAndBack
{
type empty;
faces
(
(4 9 10 5) //0
(1 4 5 0) //1
(3 4 1 2) //2
(7 4 3 6) //3
(8 9 4 7) //4
(13 18 17 12) //5
(13 12 1 0) //6
(1 12 11 2) //7
(12 15 14 11) //8
(12 17 16 15) //9
(23 28 29 24) //10
(23 24 19 20) //11
(23 20 21 22) //12
(23 22 25 26) //13
(23 26 27 28) //14
(31 32 37 36) //15
(31 20 19 32) //16
(31 30 21 20) //17
(31 34 33 30) //18
(31 36 35 34) //19
);
}
);
mergePatchPairs
(
);
// ************************************************************************* //