laplacianFoam
控制方程 ∂ T ∂ t − ∇ 2 ( D T T ) = 0 \frac{\partial T}{ \partial t} - \nabla^2(D_T T) = 0 ∂t∂T−∇2(DTT)=0
laplacianFoam.C
#include "fvCFD.H"
#include "fvOptions.H"//--------------------------------------------------------------------
#include "simpleControl.H"///simple头文件
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
{
#include "setRootCase.H"
#include "createTime.H"
#include "createMesh.H"
simpleControl simple(mesh);//对于采用simple算法的算例,创建simple对象
#include "createFields.H"
#include "createFvOptions.H"//----------------------------------------------fvOption的两个文件
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Info<< "\nCalculating temperature distribution\n" << endl;
while (simple.loop())
{
Info<< "Time = " << runTime.timeName() << nl << endl;
while (simple.correctNonOrthogonal())
{
fvScalarMatrix TEqn
(
fvm::ddt(T) - fvm::laplacian(DT, T)
==
fvOptions(T) //这里==相当于于一个减号优先级低于减号或者加号,这我忘了在哪看到过
); //fvOption的操作感觉像是预留一个源项的接口,控制方程中并没有这一项
//包括后面的pisoFoam、simpleFoam等也都用到了,但方程中的粘性项
//的离散是包含在了湍流模型的处理中
fvOptions.constrain(TEqn);//这里在东岳流体中scalarTranportFoam中讲到一点,对方程
//系数源项进行进行限定
TEqn.solve(); //求解方程,slove函数对应的求解量应该在fvSolution中进行相关定义
fvOptions.correct(T); //对求解量T进行限定
}
#include "write.H" //输出的头文件,区别于runTime.write(),这里除了createField中定义的
//自动输出的量之外,还额外定义了一些其他的量
Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
<< " ClockTime = " << runTime.elapsedClockTime() << " s"
<< nl << endl;
}
Info<< "End\n" << endl;
return 0;
}
参考链接:fvOption
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")//物性参数的读取方式,应该是要放在transportProperties
//的读取之后的
);
write.H
if (runTime.writeTime()) //输出时间的判定
{
volVectorField gradT(fvc::grad(T)); //定义温度梯度场,这里在当前时间步内,温度T已完成求解,
//为已知量,直接进行显式计算
volScalarField gradTx
(
IOobject
(
"gradTx",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
gradT.component(vector::X) //X方向温度梯度的赋值
);
volScalarField gradTy
(
IOobject
(
"gradTy",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
gradT.component(vector::Y)
);
volScalarField gradTz
(
IOobject
(
"gradTz",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
gradT.component(vector::Z)
);
runTime.write(); //createField中的输出
}