LZF
Articles9
Tags0
Categories0
of中functionObjects函数的使用及Gnuplot

of中functionObjects函数的使用及Gnuplot

1.postProcess与functionObjects

OpenFoam分为两种后处理方法,一种是传统的postProcess方法,在求解后使用;另一种方法是在运行时进行处理的Co-processing,方法是在controlDict文件夹之中添加functionObjests,但有时可能事先忘记了在controlDict字典中定义functionObject,导致计算完毕后数据并未提取出来。OpenFOAM允许用户在求解计算完毕后执行functionObject,此时可以在controlDict文件中添加functionObject,然后利用命令提取数据。这里总结几个经常使用的后处理实用程序。
1.sampleDict文件
functionObject可以在求解过程中输出指定的物理量信息。当求解计算完毕后,可以选择使用Sampling获取特定位置物理信息,此时主要使用postProcess程序来实现。
输入postProcess -list来进行查看可实行后处理的目录
在system文件夹下添加sampleDict文件,文件格式例子如下

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

type sets;

setFormat raw;

interpolationScheme cellPointFace;

fields
(
    U
);

sets
(

    l1
    {
        type            lineCellFace;
        axis            x;
        start           ( -1  0.5 0);
        end             ( 2  0.5 0);
    }

    l2
    {
        type            lineCellFace;
        axis            y;
        start           (0.5 -1 0);
        end             (0.5 2 0);
    }

);

// *********************************************************************** //

此文件指定两条箭头线,在在计算域中对线上进行取样```输入postProcess -func sampleDict -latestTime``命令进行对于最后一个时间步的采样工作,其结果会输出在postProcessing文件夹之中

建立gnuplot文件夹,在其下建立gnuplot_script文件去设置gnuplot脚本

set terminal qt 0//设置输出第一个窗口为0

#set multiplot layout 2,1

#set grid xtics//打网格
#set grid ytics
#set grid mxtics
#set grid mytics

set key left//图例放在左边,有left 和right两个选项;
set ylabel "Y centerline"//设置纵坐标
set xlabel "UX"//设置横坐标
plot 'gnuplot/UX_yline' u 2:1 w lp pt 7 title 'Ghia et al.','./postProcessing/sampleDict/50/l2_U.xy' u 2:1 pt 6 title 'Current solution'

#例子:plot  '.\line_rhoe1.xy' u 1:2  w lp lw 2 lt 2 pt 1 lc rgb "black" ,\
'.\line_rhoe2.xy' u 1:2  w l lw 2 lc rgb "black" 

#u 1:2 使用第一列数据为x轴,第二列数据为y轴 还可以进行运算 例如 u 1:($2)/($3)
#w lp 绘制数据点和数据线 w l 仅绘制数据线 w p仅绘制数据点
#lt/pt 2 点和线的绘制风格 lt0是虚线 可以使用dt命令设置其他点划线类型
# lc 线的颜色,同样会将该颜色设置给点
# 在gnuplot终端输入test可以快速查看所有电线风格



set terminal qt 1

set key default
set xlabel "X centerline"
set ylabel "UY"
plot 'gnuplot/UY_xline' u 1:2 w lp pt 7 title 'Ghia et al.','./postProcessing/sampleDict/50/l1_U.xy' u 1:3 pt 6 title 'Current solution'

#unset multiplot



pause -1

#    EOF

参考文献:[1]: https://blog.csdn.net/CloudBird07/article/details/106751196/

2.probesDict文件

FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      probesDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// 指定类型为probes
type probes;
// 指定需要提取的物理场
fields
(
    alpha.water
    U
    p_rgh
    p
);
// 取样点的坐标列表
probeLocations
(
    (0.292 0 0)
    (0.292 0.0240 0)
    (0.292 0.0480 0)
    (0.316 0.0480 0)
    (0.316 0.0240 0)
);

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 

之后在终端输入命令: postProcess -func probesDict
利用gnuplot进行绘制

3.几个functionObject

参考文献[2]: https://mp.weixin.qq.com/s/7t7IYaT0YCuJFhGeha0P6w

functionObject在controlDict字典文件中进行指定,且在预定义的时间点上执行操作。
functionObject在OpenFOAM求解计算的过程中可以实时修改。在OpenFOAM计算完毕后也可以执行
functionObject在controlDict字典文件中定义,打开controlDict文件。

FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      controlDict;
}
// * * * * * * * * * * * * * * * * //

application     simpleFoam;
startFrom       startTime;
startTime       0;
stopAt          endTime;
endTime         2000;
deltaT          1;
writeControl    runTime;
writeInterval   50;
purgeWrite      100;
writeFormat     binary;   
writePrecision  8;
writeCompression off;
timeFormat      general;
timePrecision   6;
runTimeModifiable yes;

//下面为functionObject的定义
functions
{
forces_object
{
    // 指定类型为forces,必须项
    type forces;
    // 加载functionObject库
    functionObjectLibs ("libforces.so");

    // 指定数据输出频率
    writeControl   timeStep;
    writetInterval  1;

    // 激活functionObject对象
    enabled true;

    // 指定参与计算的边界,必须项
    patches ("wall_slat" "wall_airfoil" "wall_flap");

    //// 指定压力场与速度场的变量名称
    pName p;
    Uname U;

    // 参考密度值。它仅需要针对不可压缩的流进行定义。
    // 对于可压缩流,将使用计算的密度代替
    rho rhoInf;
    rhoInf 1.0;

    //// 指定力矩计算所需的旋转中心
    CofR (0 0 0);
}
// 关于forces的写法,可参阅文档:
/* https://cpp.openfoam.org/v8/classFoam_1_1functionObjects_1_1forces.html*/
///////////////////////////////////////////

forceCoeffs_object
{
    // 指定类型为力系数,该项为必选项
    type forceCoeffs;

    functionObjectLibs ("libforces.so");
    // 激活此对象
    enabled true;
    // 指定参与计算的边界名称,此项为必选项
    patches ("wall_slat" "wall_airfoil" "wall_flap");
    // 指定变量名称
    pName p;
    Uname U;

    // 仅用于不可压缩流动
    rho rhoInf;
    rhoInf 1.0;

    // 将数据写入到文件中
    log true;
    // 指定旋转中心坐标
    CofR (0.0 0 0);
    // 用于计算系数的参考值,4个均为必选项
    pitchAxis (0 0 1);    // 俯仰轴
    magUInf 1.0;    // 参考速度
    lRef 1;        // 用于力矩计算的参考长度
    Aref 1;        // 用于系数计算的参考面积

    // 指定数据的写入频率
    writeControl   timeStep;
    writeInterval  1;

    // 指定升力方向与阻力方向,必选项
    // 对于升力来讲,其值为攻角的三角函数(-sin,cos,0)
    // 对于阻力,其值为攻角的三角函数(cos,sin,0)
    // 注意角度换算为弧度
    liftDir     (0 1 0);       
    dragDir     (1 0 0);           
}   
////////////////////////////////////////////
minmaxdomain
{
    // 指定类型为fieldMinMax,必选项
    // 用于输出计算域内指定物理量的最大最小值
    type fieldMinMax;

    functionObjectLibs ("libfieldFunctionObjects.so");

    enabled true;
    // 指定计算物理场的分量,这里还可以指定magnitude
    mode component;
    // 指定数据写入频率
    writeControl timeStep;
    writeInterval 1;

    log true;
    // 指定需要输出的物理场
    fields (p U nuTilda nut k omega);
}
fieldAverage1
{
    // 指定类型fieldAverage,输出物理场的平均值
    type            fieldAverage;
    libs ( "libfieldFunctionObjects.so" );
    writeControl    writeTime;

    enabled         true;
    log             true;
    timeStart       100;
    // 下面指定需要输出的物理场,包括U,p及nut
    fields
    (
        U
        {
                mean        on;
                prime2Mean  on;
                base        time;
        }

        p
        {
                mean        on;
                prime2Mean  on;
                base        time;
        }

        nut
        {
                mean        on;
                prime2Mean  on;
                base        time;
        }
    );
}


//若直接包含外部定义的functionObject
#include "externalFunctionObject"
};

externalFunctionObject文件

{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      functionObject;
}



//functions
//{
// 定义了监测点数据提取
probes_online
{
    type probes;
    functionObjectLibs ("libfieldFunctionObjects.so");
    enabled true;
    writeControl timeStep;
    writeInterval 1;

    probeLocations 
    (
        (1 0 0)
        (2 0 0)
        (2 0.25 0)
        (2 -0.25 0)
    );

    fields
    (  
        U
        p
    );

}

// 定义了涡量提取
vorticity
{
    type vorticity;
    functionObjectLibs ("libfieldFunctionObjects.so");
    enabled true;
    log    true;
    writeControl outputTime;  
}

有时可能事先忘记了在controlDict字典中定义functionObject,导致计算完毕后数据并未提取出来。OpenFOAM允许用户在求解计算完毕后执行functionObject,此时可以在controlDict文件中添加functionObject,然后利用命令:
name_of_the_solver -postProcess对参数进行输出
若定义了外在函数文件externalFunctionObject
则执行例如下命令:
interFoam-postProcess -dict system/externalFunctionObject –time 500:2000

El.Psy.Congroo!////

(以下为与自己相关的一些操作)

开始正题!

在of中用vof去模拟射流后处理是很难得出液滴直径PDF的(Probability Density Function概率密度分布函数),这个参数需要确定计算域里液滴的直径,而多相流直接数值模拟的方法没法通过设置计算的参数来确定液滴直径,这时候需要用几何捕捉的方法来确定液滴的属性。在OpenFoam中有效地从数值上检查整个雾化过程,欧拉方法和拉格朗日方法之间的转换是必要的。这种转变必须基于在欧拉VOF模拟的相场内检测到单独的流体粒子。结合检测,评估关于粒子的大小、位置和速度的信息。这个过程称为欧拉粒子检测。获得的信息然后可以作为初始值传递给拉格朗日框架中的点粒子。
从OpenFoam-v1612开始官方实现一个称为extractEulerianParticles的功能,这是一种基于2D耦合层的方法。具体的实现方法如下所示:
1.在system/controlDict 中添加如下

functions
{
    extractEulerianParticles1
    {
        // Mandatory entries
        type            extractEulerianParticles;
        libs            (fieldFunctionObjects);
        faceZone        collector;//你自己定义的面区域
        alpha           alpha.water;

        // Optional entries
        alphaThreshold  0.1;//相分数阈值
        nLocations      0;
        U               U;
        rho             rho;
        phi             phi;
        //minDiameter     1e-30;//可限定最大最小直径的阈值
        //maxDiameter     1e30;

        // Optional (inherited) entries
        writePrecision   6;
        writeToFile      true;
        useUserTime      false;

        region          region0;
        enabled         true;
        log             true;
        timeStart       0;
        timeEnd         1000;
        executeControl  timeStep;
        executeInterval 1;
        writeControl    writeTime;
        writeInterval   -1;
    }
}

此处需要注意的是,这个函数无法执行postProcess而且仅仅是在面上进行粒子的捕捉,如何放置这个面是2D耦合层需要考虑的棘手问题,故开发3D全场历遍液滴的算法是个解决的好办法。如果用这种方法去转化拉格朗日液滴是适合于几何结构上对称的射流的,来流雾化可能并不合适。但是对于处理某一个位置液滴直径的pdf还是一个非常好用的方法.

下面叙述一下toposet的用法:

FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      topoSetDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

// The topoSetDict comprises a list of actions to perform on different
// set types (cellSet, faceSet, pointSet, etc).
//
// Each action is a dictionary with e.g.
//     // Name of set
//     name    c0;
//
//     // type: pointSet/faceSet/cellSet/faceZoneSet/cellZoneSet
//     type    cellSet;
//
//     // action to perform on set. Two types:
//     // - require no source : clear/invert/remove
//     //       clear  : clears set or zone
//     //       invert : select all currently non-selected elements
//     //       remove : removes set or zone
//     // - require source    : new/add/subtract/subset
//     //       new    : create new set or zone from source
//     //       add    : add source to contents
//     //       subtract : subtract source from contents
//     //       subset : keeps elements both in contents and source
//     action  new;
//
// The source entry varies according to the type of set.
//
// In OpenFOAM 1806 and earlier, it was compulsory to use a 'sourceInfo'
// sub-dictionary to define the sources.
// In OpenFOAM 1812 and later, this sub-directory is optional, unless
// there would be a name clash (Eg, 'type' or 'name' appearing at both levels).
// In most cases, the source definitions have been adjusted to avoid such
// clashes.
//
// More detailed listing in the annotated topoSetSourcesDict

actions
(
    // Get all faces in cellSet
    {
        name    f0;
        type    faceSet;
        action  new;
        source  boxToFace;
        box     (0.099 0 0) (0.101 1 1);
    }

    // Determine inverse cellSet
    {
        name    fz1;
        type    faceZoneSet;
        action  new;
        source  setToFaceZone;
        faceSet f0;
    }
);

// ************************************************************************* //

这篇文章里写的很全,我不详细写了:参考文献 [3] ;http://www.xfy-learning.com/2020/05/19/OpenFOAM-topoSet/

Author:LZF
Link:http://example.com/2020/12/23/of%E4%B8%ADfunctionObjects%E5%87%BD%E6%95%B0%E7%9A%84%E4%BD%BF%E7%94%A8%E5%8F%8AGnuplot%EF%BC%8CSeaborn%E7%BB%98%E5%9B%BE%E6%80%BB%E7%BB%93/
版权声明:本文采用 CC BY-NC-SA 3.0 CN 协议进行许可