OpenFOAM中的FOAM
是Field Operation and Manipulation
的缩写, 所以其实质是对标量场和矢量场进行运算和处理.
OpenFOAM中的场的定义方式如下.
方式一:从文件中读取场信息
volScalarField T
(
IOobject
(
"T", //输入输出的文件名称
runTime.timeName(), //输入输出的文件夹名称
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE //自动输出场信息
),
mesh
);
方式二:在代码中初始化场
volScalarField source1(
IOobject(
"source1",
runTime.timeName(),
mesh,
IOobject::NO_READ, //不从文件中读,而是直接在代码中生成
IOobject::NO_WRITE),
mesh,
dimensionedScalar("tmp", mydimension, 1.0));
求解如下非线性方程
∂ T ∂ t = α ▽ 2 T + κ ( 1 − ∣ ▽ T ∣ ) \frac{\partial T}{\partial t} =\alpha \bigtriangledown^2T+\kappa \left ( 1-\left | \bigtriangledown T \right | \right ) ∂t∂T=α▽2T+κ(1−∣▽T∣)其物理意义是波的平行层传播, T T T表示传播的距离, t t t表示伪时间, κ \kappa κ用于调整单位. 这里的非稳态项是用于增强迭代过程的稳定性.
pefFoam.C文件包含main函数
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see .
Application
pefFoam
Description
Solves a simple Possion equation to finish the burn-back analysis
of propellant grain.
\*---------------------------------------------------------------------------*/
#include "fvCFD.H"
#include "simpleControl.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
{
#include "setRootCaseLists.H"
#include "createTime.H"
#include "createMesh.H"
simpleControl simple(mesh);
#include "createFields.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Info << "\nCalculating temperature distribution\n"
<< endl;
//定义单位m/s
const dimensionSet mydimension(0, 1, -1, 0, 0, 0, 0);
//定义源项souce1
volScalarField source1(
IOobject(
"source1",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE),
mesh,
dimensionedScalar("tmp", mydimension, 1.0));
//初始化源项souce2
volScalarField source2(
IOobject(
"source2",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE),
mesh,
dimensionedScalar("tmp", mydimension, 0.0));
//开始计算
while (simple.loop(runTime))
{
Info << "Time = " << runTime.timeName() << nl << endl;
source2 = mag(fvc::grad(T)) * dimensionedScalar("tmp", mydimension, 1.0);
while (simple.correctNonOrthogonal())
{
fvScalarMatrix TEqn(
fvm::ddt(T) == fvm::laplacian(DT, T) + source1 - source2);
TEqn.solve();
}
runTime.write();
Info << "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
<< " ClockTime = " << runTime.elapsedClockTime() << " s"
<< nl << endl;
}
Info << "End\n"
<< endl;
return 0;
}
// ************************************************************************* //
createFields.H包含场的初始化读取
Info<< "Reading field T\n" << endl;
volScalarField T
(
IOobject
(
"T",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);
Info<< "Reading transportProperties\n" << endl;
IOdictionary transportProperties
(
IOobject
(
"transportProperties",
runTime.constant(),
mesh,
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE
)
);
Info<< "Reading diffusivity DT\n" << endl;
dimensionedScalar DT
(
transportProperties.lookup("DT")
);
使用OpenFOAM自带的wmake
命令编译
源代码和案例文件见https://gitee.com/jedi-knight/pef-foam