OpenFOAM检测一个面上的平均值

1.通过blockMesh创建网格。

blockMesh文件内容如下:

/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  5                                     |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
convertToMeters 1;

radius      0.11;//圆柱半径
radiusNeg  -0.11;
box         0.04;//box和boxNeg定义中间长方体block的范围
boxNeg     -0.04;
zMax        3.0;//zMax和zMin定义圆柱体的长度
zMin        0.0;

nR          12;//扇形block半径上的节点数
nBox        16;//矩形block正方形边上的节点数
nZ          300;//轴向方向上的节点数

verbose no;

geometry
{
    cylinder
    {
        type      searchableCylinder;
        point1    (0 0 -0.1);//由point1和point2构成的区域要大于zMax和zMin构成的区域
        point2    (0 0  6.1);
        radius    $radius;
    }
}

scale 1;


vertices
(
    // Inner
    ($boxNeg $boxNeg $zMin)//0
    ($box    $boxNeg $zMin)//1
    ($boxNeg $box    $zMin)//2
    ($box    $box    $zMin)//3

    // Outer block points
    project ($radiusNeg $radiusNeg $zMin) (cylinder)//4
    project ($radius    $radiusNeg $zMin) (cylinder)//5
    project ($radiusNeg $radius    $zMin) (cylinder)//6
    project ($radius    $radius    $zMin) (cylinder)//7

    // Inner
    ($boxNeg $boxNeg $zMax)//8
    ($box    $boxNeg $zMax)//9
    ($boxNeg $box    $zMax)//10
    ($box    $box    $zMax)//11

    // Outer block points
    project ($radiusNeg $radiusNeg $zMax) (cylinder)//12
    project ($radius    $radiusNeg $zMax) (cylinder)//13
    project ($radiusNeg $radius    $zMax) (cylinder)//14
    project ($radius    $radius    $zMax) (cylinder)//15
);

blocks
(
    hex ( 4  5  1  0 12 13  9  8) ($nBox $nR   $nZ) simpleGrading (1 1 1)
    hex ( 4  0  2  6 12  8 10 14) ($nR   $nBox $nZ) simpleGrading (1 1 1)
    hex ( 1  5  7  3  9 13 15 11) ($nR   $nBox $nZ) simpleGrading (1 1 1)
    hex ( 2  3  7  6 10 11 15 14) ($nBox $nR   $nZ) simpleGrading (1 1 1)
    hex ( 0  1  3  2  8  9 11 10) ($nBox $nBox $nZ) simpleGrading (1 1 1)
);

edges
(
    project  4  5 (cylinder)
    project  7  5 (cylinder)
    project  6  7 (cylinder)
    project  4  6 (cylinder)
    project 12 13 (cylinder)
    project 13 15 (cylinder)
    project 12 14 (cylinder)
    project 14 15 (cylinder)
);

//boundary
boundary
(
    inlet
    {
        type cyclic;//cyclicAMI;
        neighbourPatch outlet;
        // transform translational;
        // separationVector (0.4 0 0);
        faces
        (
            (0 1 3 2)
            (0 2 6 4)
            (0 1 5 4)
            (1 5 7 3)
            (2 3 7 6)
        );
    }

    outlet
    {
        type cyclic;//cyclicAMI;
        neighbourPatch inlet;
        // transform translational;
        // separationVector (-0.4 0 0);
        faces
        (
            (8   9  11  10)
            (8  10  14  12)
            (8   9  13  12)
            (9  13  15  11)
            (10 11  15  14)
        );
    }

    wall
    {
        type wall;
        faces
        (
            (4  12  14  6)
            (4   5  13 12)
            (5  13  15  7)
            (6   7  15 14)
        );
    }
);

mergePatchPairs
(
);

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

2.创建一个topoSetDict,内容如下:

OpenFOAM 中有一个专门的工具来帮助用户管理 “指定区域”,叫 topoSettopoSet 含义是 topology set(集合),该工具作用是将一些点、面、或者体网格提取出来存放在指定名字的 set 里,用以辅助前后处理。topoSet 可以生成的“集合”包括 pointSet,faceSet,cellSet,pointZone,faceZone,cellZone。set 和 zone 在概念上基本上是一致的,都是包含一系列点(或者面,或者体)的集合,只是由于历史原因,目前 set 和 zone 并存于 OpenFOAM 中,有的前后处理工具可能同时支持使用 set 或 zone,但也有的只支持其中一种。

/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  5                                     |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    location    "system";
    object      topoSetDict.1;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

actions
(
    // 创建faceSet
    {
        name    faceSet_1;//需要生成的集合的名字
        type    faceSet;//集合的类型,包括pointSet, pointZoneSet,faceSet, faceZoneSet, pointSet, pointZoneSet, cellSet, cellZoneSet等等
        action  new;//操作类型,new, add, delete, subset(交集) 
        source  boxToFace;//操作对象,boxToFace的含义是将box内的所有face作为本次操作的对象
        sourceInfo    //要操作的对象的信息
        {
            box (-0.12 -0.12 1.499) (0.12 0.12 1.501);//box的范围信息。这两个点的范围内只能有一层网格面
        }
    }
    // 根据faceSet创建faceZone
    {
        name    faceZone_1;//需要生成的集合的名字
        type    faceZoneSet;//这里表示需要生成一个faceZone的集合
        action  new;//new表示新建一个
        source  setToFaceZone;//表示将前面定义的某个集合作为操作对象
        sourceInfo
        {
            faceSet faceSet_1;//操作对象是上面定义的faceSet_1
        }
    }
);

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

3.修改controlDict文件

在controlDict的最后加上下面的内容:

functions
{
  // - 包含外部定义的functionObject
  #include "externalFunctionObject"
}

在case/system/目录下,创建一个externalFunctionObject文件,文件的内容如下:

// 检测一个面上的平均值
voidfraction_average_zplane
{
    type            surfaceFieldValue;
    functionObjectLibs ("libfieldFunctionObjects.so");
    outputControl   timeStep;
    outputInterval  1;
    log             false;
    writeFields     false;
    valueOutput     false;
    regionType      faceZone;//patch;
    name            faceZone_1;
    operation       average;
    fields
    (
        voidfraction
    );
}

// 定义了监测点数据提取
probes
{
    type        probes;
    // Where to load it from
    functionObjectLibs ( "libsampling.so" );  
    // Name of the directory for probe data
    name        probes;
    probeLocations
    (
        (0.00000 0.000000 0.000001)
        (0.00000 0.000000 1.500000)
        (0.00000 0.000000 2.999999)
    );

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

    // Write at same frequency as fields
    outputControl   timeStep;//outputTime;
    outputInterval  1;
}

//检测壁面wall的y+(最大值,最小值,平均值)
yPLus_wall
    {
        libs            ("libfieldFunctionObjects.so");
        type            yPlus;
        // executeControl  writeTime;
        writeControl    timeStep;//writeTime;
    }
 

4.其他的操作

在经过上面的设置之后,通过:

blockMesh      //生成网格
topoSet      //生成面
foamToVTK    //将面转化为“.vtk”格式

然后就可以在paraview中查看了升成的面了。

参考链接:

OpenFOAM 中的 topoSet 及其应用 (qq.com)

[OpenFOAM] Visualize a faceZone in paraView -- CFD Online Discussion Forums (cfd-online.com)

OF如何创建内部面,该面不影响流场,但可以监测流量 (cfd-china.com)

OpenFOAM 中使用 functionObject | OpenFOAM 成长之路

posted @ 2024-04-21 11:54  希望先生  阅读(22)  评论(0编辑  收藏  举报