openFOAM中时间步长计算参数是怎样读进程序的——Time类

接着前面的内容,在createTime.H中创建了Time类的对象runTime

Foam::Info<< "Create time\\n" << Foam::endl;
Foam::Time runTime(Foam::Time::controlDictName, args);

这里,我们尝试解读这第二行代码中更加具体的内容。

Time类的内容

源码有500+行,这里不粘贴了,只给出大概的内容,首先文件使用了一系列的头文件,后面会陆续解读:

#include "TimePaths.H"
#include "objectRegistry.H"
#include "unwatchedIOdictionary.H"
#include "FIFOStack.H"
#include "clock.H"
#include "cpuTime.H"
#include "TimeState.H"
#include "Switch.H"
#include "instantList.H"
#include "NamedEnum.H"
#include "typeInfo.H"
#include "dlLibraryTable.H"
#include "functionObjectList.H"
#include "sigWriteNow.H"
#include "sigStopAtWriteNow.H"

而当前的Time类的继承关系如下:

Time <— clock
         <— cpuTime
         <— TimePaths
         <— TimeState
         <— objectRegistry  <— regIOobject <— IOobject
                                        <— HashTable<regIOobject>

内部定义了枚举类型

writeControl {timeStep, runTime, adjustableRunTime, clockTime, cpuTime}
stopAtControl {endTime, noWriteNow, writeNow, nextWrite}
format {general    = 0, fixed      = ios_base::fixed, scientific = ios_base::scientific}

然后给出了一系列存储和时间设置相关的变量,

libs_   controlDict_  startTimeIndex_  startTime_  endTime_   stopAtControlNames_  stopAt_
writeControlNames_   writeControl_  writeInterval_  purgeWrite_  previousWriteTimes_
writeOnce_    subCycling_  prevTimeState_  sigWriteNow_   sigStopAtWriteNow_ format_
precision_   maxPrecision_  writeFormat_  writeVersion_  writeCompression_  graphFormat_
 runTimeModifiable_   functionObjects_

变量命名已经基本上可以看出具体的功能,程序在定义时也给出了注释,这里不全部解释

之后程序给出了构造函数和析构函数,然后是一系列的功能性函数,最后是操作符重定义。

我们这里对我们代码中使用的构造函数的内容进行解读。

当前使用的构造函数

其实就是第一个构造函数

Time
(
const word& name,
const argList& args,
const word& systemName = "system", //文件夹名字
const word& constantName = "constant"
);

Foam::Time::Time
(
    const word& controlDictName,
    const argList& args,
    const word& systemName,
    const word& constantName
)
:
    TimePaths
    (
        args.parRunControl().parRun(),
        args.rootPath(),
        args.globalCaseName(),
        args.caseName(),
        systemName,
        constantName
    ),

    objectRegistry(*this),

    libs_(),

    controlDict_ //unwatchedIOdictionary controlDict_;
    (
        IOobject
        (
            controlDictName,
            system(),
            *this,
            IOobject::MUST_READ_IF_MODIFIED,
            IOobject::NO_WRITE,
            false
        )
    ),

    startTimeIndex_(0), //一些内部量的初始化
    startTime_(0),
    endTime_(0),

    stopAt_(stopAtControl::endTime),
    writeControl_(writeControl::timeStep),
    writeInterval_(great),
    purgeWrite_(0),
    writeOnce_(false),
    subCycling_(false),
    sigWriteNow_(true, *this),
    sigStopAtWriteNow_(true, *this),

    writeFormat_(IOstream::ASCII),
    writeVersion_(IOstream::currentVersion),
    writeCompression_(IOstream::UNCOMPRESSED),
    graphFormat_("raw"),
    runTimeModifiable_(false),

    functionObjects_
    (
        *this,
        argList::validOptions.found("withFunctionObjects")
      ? args.optionFound("withFunctionObjects")
      : !args.optionFound("noFunctionObjects")
    )
{
    libs_.open(controlDict_, "libs");

    // Explicitly set read flags on objectRegistry so anything constructed
    // from it reads as well (e.g. fvSolution).
    readOpt() = IOobject::MUST_READ_IF_MODIFIED;

    setControls();

    // Time objects not registered so do like objectRegistry::checkIn ourselves.
    if (runTimeModifiable_)
    {
        // Monitor all files that controlDict depends on
        fileHandler().addWatches(controlDict_, controlDict_.files());
    }

    // Clear dependent files since not needed
    controlDict_.files().clear();
}

就是说构造函数在使用的时候,systemName="system"constantName = "constant"是默认值。函数调用时,对TimePaths objectRegistry libs_ controlDict_ startTimeIndex_ startTime_ endTime_ stopAt_ writeControl_ writeInterval_ purgeWrite_ writeOnce_ subCycling_ sigWriteNow_ sigStopAtWriteNow_ writeFormat_ writeVersion_ writeCompression_ graphFormat_ runTimeModifiable_ functionObjects_这些类进行了初始化。

其中,我们需要关注输入的量Foam::Time::controlDictName,这个量在注释中有说

//- The default control dictionary name (normally "controlDict")
static word controlDictName;

该量,大概是在初始化当前类之前,就已经对这个静态变量的内容进行了初始化,但是具体的位置当前还并未找到。

为了解读这部分内容,我们需要了解到另外一个类对象unwatchedIOdictionary controlDict_;

这个部分先到这里,等到解读unwatchedIOdictionary之后再回来。

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片