OpenFOAM很多求解器时间步长都是恒定的,这使得我们在CFD计算的时候不得不一个一个的试。求解器时间步长的自动调整会节省我们很多时间。下面以icoFoam为例谈谈如何动态设定时间步长。其实OpenFOAM已经为我们定制了自动调节时间步长的功能,如果要使用这个功能,需要以下几个头文件。
//读入动态设定步长相关参数
# include
"readTimeControls.H"
//计算CourantNo
# include "CourantNo.H"
//初始化设定时间步长
# include
"setInitialDeltaT.H"
//根据CourantNo重新设定时间步长
#
include "setDeltaT.H"
要让程序自动调节时间步长,主要分4个步骤,下面在icoFoam中实例
#include "fvCFD.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * //
int main(int argc, char *argv[])
{
# include "setRootCase.H"
# include "createTime.H"
# include "createMesh.H"
# include
"createFields.H"
# include
"initContinuityErrs.H"
//步骤1:将前3个头文件加到这里。
//读入动态设定步长相关参数
#
include "readTimeControls.H"
//计算CourantNo
#
include "CourantNo.H"
//初始化设定时间步长
#
include "setInitialDeltaT.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * //
Info<< "nStarting time loopn"
<< endl;
//步骤2将for循环改成while循环
// for (runTime++;
!runTime.end(); runTime++)
while(runTime.run())
{
//
Info<< "Time = "
<< runTime.timeName()
<< nl
<< endl;
#
include "readPISOControls.H"
#
include "CourantNo.H"
//步骤3:将重新设定步长的头文件写到这,及其推移时间,将上面的Info挪下来。
#
include "setDeltaT.H"
runTime++;
Info<< "Time = "
<< runTime.timeName()
<< nl
<< endl;
fvVectorMatrix UEqn
(
fvm::ddt(U)
+ fvm::div(phi, U)
- fvm::laplacian(nu, U)
);
solve(UEqn == -fvc::grad(p));
// --- PISO loop
for (int corr=0; corr<nCorr; corr++)
{
volScalarField rUA = 1.0/UEqn.A();
U = rUA*UEqn.H();
phi = (fvc::interpolate(U) & mesh.Sf())
+ fvc::ddtPhiCorr(rUA, U, phi);
adjustPhi(phi, U, p);
for (int nonOrth=0; nonOrth<=nNonOrthCorr;
nonOrth++)
{
fvScalarMatrix pEqn
(