|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
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 loop\n"<< 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:将重新设定步长的头文件写到这
# include "setDeltaT.H"
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
(
fvm::laplacian(rUA, p) == fvc::div(phi)
);
pEqn.setReference(pRefCell, pRefValue);
pEqn.solve();
if (nonOrth == nNonOrthCorr)
{
phi -= pEqn.flux();
}
}
# include "continuityErrs.H"
U -= rUA*fvc::grad(p);
U.correctBoundaryConditions();
}
runTime.write();
Info<< "ExecutionTime = "<< runTime.elapsedCpuTime()<< " s"
<< " ClockTime = "<< runTime.elapsedClockTime()<< " s"
<< nl<< endl;
}
Info<< "End\n"<< endl;
return(0);
}
//步骤4:进入控制台重新编译程序
打开控制台,进入/applications/solvers/incompressible/icoFoam/
wmake
如何使用自动调节步长功能呢?
打开case文件夹下system/controDict
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ** * * * * //
application icoFoam;
startFrom startTime;
startTime 0;
stopAt endTime;
endTime 2;
deltaT 0.1;
writeControl runTime;
writeInterval 0.1;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression uncompressed;
timeFormat general;
timePrecision 6;
runTimeModifiable yes;
//加入下面的就行了
adjustTimeStep yes; //想变成静态步长,no即可
maxCo 0.5; //如果Co 数大于 0.5则减小步长
maxDeltaT 1; //最大时间步长
运行程序测试一下。
如何让程序自动调节步长的介绍已经完毕,是不是很简单?
转自OpenFOAM研究:http://blog.sina.com.cn/openfoamresearch
|
|