scalarTransportFoam
控制方程
∂
T
∂
t
+
∇
⋅
(
U
⃗
T
)
−
∇
⋅
(
∇
D
T
T
)
=
S
\frac{\partial T}{\partial t} + \nabla \cdot (\vec U T) - \nabla \cdot (\nabla D_TT) = S
∂t∂T+∇⋅(UT)−∇⋅(∇DTT)=S
scalarTransportFoam.C
#include "fvCFD.H"
#include "fvOptions.H"
#include "simpleControl.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
{
#include "setRootCase.H"
#include "createTime.H"
#include "createMesh.H"
simpleControl simple(mesh);
#include "createFields.H"
#include "createFvOptions.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Info<< "\nCalculating scalar transport\n" << endl;
#include "CourantNo.H"
while (simple.loop())
{
Info<< "Time = " << runTime.timeName() << nl << endl;
while (simple.correctNonOrthogonal())
{
fvScalarMatrix TEqn
(
fvm::ddt(T)
+ fvm::div(phi, T)
- fvm::laplacian(DT, T)
==
fvOptions(T) //fvOptions定义的源项,应该是在算例case目录下设置的,这里如果没有源项,加不加
//应该都不影响计算结果的
);
TEqn.relax();//方程松弛,这里跟一些版本是不同的,写法上游 TEqn().relax()的写法,应该是Extent
//laplacianFoam中没有这个
fvOptions.constrain(TEqn);//源项的限定
TEqn.solve();//方程求解
fvOptions.correct(T);//对T进行修正
}
runTime.write();
}
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 field U\n" << endl;
volVectorField U
(
IOobject
(
"U",
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")
);
#include "createPhi.H"