controlDict学习

个人学习用,总结、整理了网上一些controlDict解析

1 文件结构

一个例子:


//文件说明
{
    version     2.0;                //版本号
    format      ascii;              //文本格式
    class       dictionary;         //类型为字典文件
    location    "system";           //所在目录
    object      controlDict;        //对象名
}
application     interFoam;          //求解器名称
//时间控制
startFrom       startTime;          //设置计算开始时间为startTime
startTime       0;                  //定义startTime
stopAt          endTime;            //设置计算结束时间为endTime
endTime         3;                  //定义endTime
deltaT          0.005;              //设置时间步长
//计算结果输出控制
writeControl    adjustableRunTime;  //按照计算时间控制输出
writeInterval   0.1;                //输出时间间隔,单位秒[s],与writeControl配合使用
purgeWrite      0;                  //输出是否覆盖先前记录,0为不覆盖,1可用于稳态计算,默认0
writeFormat     ascii;              //计算结果输出文件格式指定
writePrecision  10;                 //控制输出有效数字位数,与writeFormat配合使用,默认6
writeCompression uncompressed;      //是否压缩
timeFormat      general;            //时间目录名称指定
timePrecision   6;                  //时间目录名称有效数字位数,与timeFormat配合使用,默认6
//时间步长自适应控制
adjustTimeStep  yes;                //是否开启时间步长自适应
maxCo           0.5;                //最大库郎数
maxDeltaT       1.0;                //最大时间步长
//字典读取控制
runTimeModifiable yes;              //每个时间步是否读取所修改的字典文件设定

2 逐项分析

system目录下的controlDict文件用来设置 时间和输入输出控制,包括 时间控制计算结果输出控制时间步长自适应控制字典读取控制运行时加载库或者函数控制 五个部分。

2.1 application

查看$FOAM_TUTORIALS里所用到的求解器,输入命令:

foamSearch $FOAM_TUTORIALS controlDict application
//结果显示:
application     adjointShapeOptimizationFoam;
application     blockMesh;
application     boundaryFoam;
application     buoyantPimpleFoam;
application     buoyantSimpleFoam;
application     cavitatingFoam;
application     chemFoam;
application     chtMultiRegionFoam;
application     coalChemistryFoam;
application     coldEngineFoam;
application     compressibleInterFoam;
application     compressibleMultiphaseInterFoam;
application     dnsFoam;
application     DPMFoam;
application     driftFluxFoam;
application     dsmcFoam;
application     electrostaticFoam;
application     financialFoam;
application     fireFoam;
application     foamyHexMesh;
application     icoFoam;
application     icoUncoupledKinematicParcelFoam;
application     interFoam;
application     interMixingFoam;
application     interPhaseChangeFoam;
application     laplacianFoam;
application     mdEquilibrationFoam;
application     mdFoam;
application     mhdFoam;
application     moveDynamicMesh;
application     MPPICFoam;
application     multiphaseEulerFoam;
application     multiphaseInterFoam;
application     nonNewtonianIcoFoam;
application     PDRFoam;
application     pimpleFoam;
application     pisoFoam;
application     porousSimpleFoam;
application     potentialFoam;
application     potentialFreeSurfaceFoam;
application     reactingFoam;
application     reactingMultiphaseEulerFoam;
application     reactingParcelFoam;
application     reactingTwoPhaseEulerFoam;
application     rhoCentralFoam;
application     rhoPimpleFoam;
application     rhoPorousSimpleFoam;
application     rhoSimpleFoam;
application     scalarTransportFoam;
application     shallowWaterFoam;
application     simpleFoam;
application     simpleReactingParcelFoam;
application     snappyHexMesh;
application     solidDisplacementFoam;
application     solidEquilibriumDisplacementFoam;
application     sprayFoam;
application     SRFPimpleFoam;
application     SRFSimpleFoam;
application     twoLiquidMixingFoam;
application     twoPhaseEulerFoam;
application     XiEngineFoam;
application     XiFoam;

tutorial里基本上平时常用到的、不常用的solver都有,根据自己的研究方向选几个相关的再慢慢研究细节吧。

2.2 时间控制

2.2.1 startFrom, startTime

startFrom 说明
firstTime 所有时间目录中最早的时间步
latestTime 所有时间目录中最近的时间步
startTime 用户指定开始时间,需指定startTime的值

2.2.2 stopAt, endTime

stopAt 说明
endTime 用户指定结束时间,需指定endTime的值
writeNow 当前时间步完成时结束计算并且输出计算结果
noWriteNow 当前时间步完成时结束计算但不输出计算结果
nextWrite 下一个时间步完成时结束计算并且输出计算结果

2.2.3 deltaT

时间步长控制,有时需要控制 $Co=\frac{\delta t|U|}{\delta x}<1$ $\delta t$ 为时间步、就是这的deltaT; $|U|$ 为某网格单元内的速度矢量的模 $\delta x$ 为速度方向的网格长度。

2.3 输出控制

2.3.1 writeControl,writeInterval

writeControl 说明
timeStep 按照时间步输出,间隔由关键字writeInterval指定
runTime 按照计算时间输出,间隔由关键字writeInterval指定
adjustableRunTime 时间自适应下按照计算时间输出,间隔由关键字writeInterval指定
cpuTime 按照CPU时间输出,间隔由关键字writeInterval指定
clockTime 按照挂钟时间(真实时间)输出,间隔由关键字writeInterval指定

2.3.2 purgeWrite

0 关闭该功能,不覆盖输出结果
n(n为大于0的整数) 输出n次数据后,自动覆盖先前输出结果

2.3.3 writeFormat,writePrecision

writeFormat 说明
ascii 文本格式,由writePrecision控制有效数字位数,方便阅读
binary 二进制格式,直接将内存内容写入文件,能够减小文件存储空间,提高读写效率

2.3.4 writeCompression, timeFormat, timePrecision

writeCompression 说明
off 不压缩
on gzip 压缩格式
timeFormat 说明
fixed ±m.dddddd,其中dtimePrecision来控制
scientific ±m.dddddd±xx,其中dtimePrecision来控制
general 使用scientific格式,默认小数点后有4位有效位数,也可通过timePrecision来调节

2.3.5 runTimeModifiable

Switch for whether dictionaries, e.g. controlDict, are re-read during a simulation at the beginning of each time step, allowing the user to modify parameters during a simulation.

2.3.6 graphFormat

raw 采用原ASCII格式输出
gnuplot 采用gunplot格式输出
xmgr 采用Grace/xmgr格式输出
jplot 采用jPlot格式输出

2.4 时间步长自适应控制

参数名参数值说明
adjustTimeStepyes允许依据最大Courant数自动调节时间步长
no不允许程序自动调节时间步长
maxCo0.5最大允许的Courant数,若Co数大于指定值,自动缩小时间步长
maxDeltaT0.1自动调整时间步长时,最大允许的时间步长
runTimeModifiable (设置在求解过程中是否允许修改以上参数)yes允许,求解器会在每个时间步计算的开始读入controlDict文件
no不允许,求解器不会在每个时间步开始读入controlDict文件

2.5 运行时加载库或者函数控制

设置运行时需要加载的库或函数如下所示:

libs libgroovyBC.so 调用的动态库文件列表
functions probes, singleGraph等 调用的附加函数列表

举个例子,incompressible/pimpleFoam/RAS/TJunction/system/controlDict中相关部分:

functions
{
    probes
    {
        // Where to load it from
        libs            ("libsampling.so");

        type            probes;

        // Name of the directory for probe data
        name            probes;

        // Write at same frequency as fields
        writeControl    writeTime;
        writeInterval   1;

        // Fields to be probed
        fields          (p U);

        probeLocations
        (
            ( 1e-06 0 0.01 )        // at inlet
            (0.21 -0.20999 0.01)  // at outlet1
            (0.21 0.20999 0.01)   // at outlet2
            (0.21 0 0.01)         // at central block
        );
    }
}

下面介绍最常用的probes和singleGraph函数的使用方法。

2.5.1 probes函数

该函数功能为程序运行时监测:q指定坐标点场数据随时间的变化。首先在controlDict文件内添加以下语句,调用probes功能的相关函数。

functions 
 { 
   #includeFunc probes   // 在functions列表中添加probes函数
 }

接着运行以下命令,复制probes文件至system文件夹下,

cp -r $FOAM_ETC/caseDicts/postProcessing/probes/probes system

probes文件的内容如下,

通过修改fields参数中可添加需监测的场,修改probeLocations的坐标值可添加监测点的坐标值。运行求解器后,指定坐标点的监测场随时间变化的数据输出至postProcessing/probes/0文件夹。

2.5.2 singleGraph函数

该函数功能为对计算结果数据取样并可视化。首先在controlDict文件内的functions列表中添加singleGraph函数,接着运行以下命令,复制singleGraph文件至system文件夹,

cp -r $FOAM_ETC/caseDicts/postProcessing/graphs/singleGraph system

singleGraph文件的内容如下,

 start  (0.01 0.025 0);  // 取样的起始点坐标
  end   (0.01 -0.025 0);  // 取样的终点坐标
  fields (U p);   // 取样场的名称

  // Sampling and I/O settings 
  #includeEtc ”caseDicts/postProcessing/graphs/sampleDict.cfg” 

  // Override settings here, e.g. 
  // setConfig { type midPoint; } 

  // Must be last entry 
  #includeEtc ”caseDicts/postProcessing/graphs/graph.cfg” 

修改fields参数中可添加需采样的场,修改start 和end参数可设置取样点的坐标范围。计算完成后,在算例文件夹下输入命令postProcess -func singleGraph,可对数据取样并输出至postProcessing/singleGraph文件夹。输出数据文件可直接通过gnuplot软件(需预先安装)处理实现可视化。

2.5.3 foreCoeffs

翼型模拟时常需要得到 $C_{p},C_{L},C_{D}$ 等数据,可以利用OpenFOAM的相关工具,推荐在controlDict里直接include然后在system文件夹里重新写一个文件。

//controlDict里加入
functions 
{
    #include "forceCoeffs"
};

新文件内容如下:

//文件名forceCoeffs
/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  dev
     \\/     M anipulation  |
-------------------------------------------------------------------------------
Description
    Calculates lift, drag and moment coefficients by summing forces on
    specified patches for a case where the solver is incompressible (pressure
    is kinematic, e.g. m^2/s^2).

\*---------------------------------------------------------------------------*/

forceCoeffs
{
    // Mandatory entries
    type            forceCoeffs;
    libs            ("libforces.so");
    patches         (airfoil-l1 airfoil-l2 airfoil-h1 airfoil-h2);


    // Optional entries

    // Field names
    p               p;
    U               U;
    rho     rhoInf;
    log         true;
    rhoInf      1.225;
    // Reference pressure [Pa]
    pRef            0;

    // Include porosity effects?
    porosity        yes;

    // Store and write volume field representations of forces and moments
    writeFields     yes;

    // Centre of rotation for moment calculations
    CofR            (0.25 0 0);

    // Lift direction
    liftDir         (0 1 0);

    // Drag direction
    dragDir         (1 0 0);

    // Pitch axis
    pitchAxis       (0 0 1);

    // Freestream velocity magnitude [m/s]
    magUInf         50;

    // Reference length [m]
    lRef            1;

    // Reference area [m2]
    Aref            1.2;

    // Spatial data binning
    // - extents given by the bounds of the input geometry
    binData
    {
        nBin        21;
        direction   (1 0 0);
        cumulative  yes;
    }
}

具体内容可参考OpenFOAM在线文档

Author: zcp
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint polocy. If reproduced, please indicate source zcp !
评论
Valine utteranc.es
 Previous
Next 
Airfoil optimization for Vertical Axis Hydrokinetic Turbine using genetic algorithm(1)---airfoil parametrization
1 Airfoil parametrizationThe numerical search for the optimum shape of an airfoil is of great interest for aircraft
  TOC