可以在目录WM_PROJECT_DIR/applications/utilities/mesh中找到处理网格操作的实用程序应用程序(或只是简短的实用程序)。网格实用程序分为以下类别:生成、操纵、推进和转换。这种分类在最新版本中完全没有改变。生成网格并将其从不同格式转换为OpenFOAM格式已在第2.2节和第2.3节中描述。本节介绍如何在生成基础网格后操纵网格以及诸如网格细化等高级操作。

2.4.1 按指定标准细化网格

在此示例中,网格细化应用程序refineHexMesh用于细化interFoam解算器的damBreak教程的网格。这样做的目的是细化初始自由表面周围的区域,其中两相标志场(\alpha_{water}\nabla(\alpha_{water}\alpha_{water}FOAM_TUTORIALS/multiphase/interFoam/laminar/damBreak . ?> cd damBreak ?> blockMesh ?> setFields


现在用blockMesh生成网格,并使用setFields前处理实用程序设置$\alpha_{water}$场。 setfields实用工具在3.2节中进行了描述。 基本的计算工具foamCalc可以用来计算和存储$\alpha_{water}$的梯度。

```bash
?>  foamCalc magGrad alpha.water

这将把梯度幅度的以单元为中心的标量场存储在名为magGradalphaWater.的初始时间目录0中。 要使用refineMesh应用程序根据梯度大小细化网格,必须将该实用程序的配置字典文件复制到dambreake案例的系统目录中。

?>  cp <span class="katex"><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.02778em;">FO</span><span class="mord mathnormal">A</span><span class="mord"><span class="mord mathnormal" style="margin-right:0.10903em;">M</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3283em;"><span style="top:-2.55em;margin-left:-0.109em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">A</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord mathnormal" style="margin-right:0.13889em;">PP</span><span class="mord">/</span><span class="mord mathnormal">u</span><span class="mord mathnormal">t</span><span class="mord mathnormal">i</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">i</span><span class="mord mathnormal">t</span><span class="mord mathnormal">i</span><span class="mord mathnormal">es</span><span class="mord">/</span><span class="mord mathnormal">m</span><span class="mord mathnormal">es</span><span class="mord mathnormal">h</span><span class="mord">/</span><span class="mord mathnormal">mani</span><span class="mord mathnormal">p</span><span class="mord mathnormal">u</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">a</span><span class="mord mathnormal">t</span><span class="mord mathnormal">i</span><span class="mord mathnormal">o</span><span class="mord mathnormal">n</span><span class="mord">/</span><span class="mord mathnormal">re</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">in</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.10903em;">M</span><span class="mord mathnormal">es</span><span class="mord mathnormal">h</span><span class="mord">/</span><span class="mord mathnormal">re</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">in</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.10903em;">M</span><span class="mord mathnormal">es</span><span class="mord mathnormal">h</span><span class="mord mathnormal" style="margin-right:0.02778em;">D</span><span class="mord mathnormal">i</span><span class="mord mathnormal">c</span><span class="mord mathnormal">t</span><span class="mord mathnormal">sys</span><span class="mord mathnormal">t</span><span class="mord mathnormal">e</span><span class="mord mathnormal">m</span><span class="mord">/</span><span class="mclose">?</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">&gt;</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">ssys</span><span class="mord mathnormal">t</span><span class="mord mathnormal">e</span><span class="mord mathnormal">m</span><span class="mord">/</span><span class="mord mathnormal">co</span><span class="mord mathnormal">n</span><span class="mord mathnormal">t</span><span class="mord mathnormal">ro</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal" style="margin-right:0.02778em;">D</span><span class="mord mathnormal">i</span><span class="mord mathnormal">c</span><span class="mord mathnormal">t</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="mord mathnormal" style="margin-right:0.05764em;">S</span><span class="mord mathnormal">c</span><span class="mord mathnormal">h</span><span class="mord mathnormal">e</span><span class="mord mathnormal">m</span><span class="mord mathnormal">esre</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">in</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.10903em;">M</span><span class="mord mathnormal">es</span><span class="mord mathnormal">h</span><span class="mord mathnormal" style="margin-right:0.02778em;">D</span><span class="mord mathnormal">i</span><span class="mord mathnormal">c</span><span class="mord mathnormal">t</span><span class="mord mathnormal">d</span><span class="mord mathnormal">eco</span><span class="mord mathnormal">m</span><span class="mord mathnormal">p</span><span class="mord mathnormal">ose</span><span class="mord mathnormal" style="margin-right:0.13889em;">P</span><span class="mord mathnormal">a</span><span class="mord mathnormal" style="margin-right:0.02778em;">rD</span><span class="mord mathnormal">i</span><span class="mord mathnormal">c</span><span class="mord mathnormal">t</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="mord mathnormal" style="margin-right:0.05764em;">S</span><span class="mord mathnormal">o</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">u</span><span class="mord mathnormal">t</span><span class="mord mathnormal">i</span><span class="mord mathnormal">o</span><span class="mord mathnormal">n</span><span class="mord mathnormal">se</span><span class="mord mathnormal" style="margin-right:0.13889em;">tF</span><span class="mord mathnormal">i</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">d</span><span class="mord mathnormal" style="margin-right:0.02778em;">sD</span><span class="mord mathnormal">i</span><span class="mord mathnormal">c</span><span class="mord mathnormal">t</span><span class="mord">‘‘‘</span><span class="mord cjk_fallback">在</span><span class="mord mathnormal">sys</span><span class="mord mathnormal">t</span><span class="mord mathnormal">e</span><span class="mord mathnormal">m</span><span class="mord cjk_fallback">目录中的配置中,</span><span class="mord mathnormal">re</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">in</span><span class="mord mathnormal">eHe</span><span class="mord mathnormal">x</span><span class="mord mathnormal" style="margin-right:0.10903em;">M</span><span class="mord mathnormal">es</span><span class="mord mathnormal">h</span><span class="mord cjk_fallback">对某个网格集中的所有网格进行细化。</span><span class="mord">‘‘‘</span><span class="mord mathnormal">c</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">+</span><span class="mord">//</span><span class="mord mathnormal" style="margin-right:0.07153em;">C</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">ll</span><span class="mord mathnormal">s</span><span class="mord mathnormal">t</span><span class="mord mathnormal">ore</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">in</span><span class="mord mathnormal">e</span><span class="mpunct">;</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathnormal">nam</span><span class="mord mathnormal">eo</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">ce</span><span class="mord mathnormal" style="margin-right:0.01968em;">ll</span><span class="mord mathnormal">se</span><span class="mord mathnormal">t</span><span class="mord mathnormal">se</span><span class="mord mathnormal">t</span><span class="mord mathnormal">c</span><span class="mord">0</span><span class="mpunct">;</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord">‘‘‘</span><span class="mord cjk_fallback">创建此</span><span class="mord mathnormal" style="margin-right:0.07153em;">C</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.05764em;">llS</span><span class="mord mathnormal">e</span><span class="mord mathnormal">t</span><span class="mord cjk_fallback">时,将存储在</span><span class="mord mathnormal">co</span><span class="mord mathnormal">n</span><span class="mord mathnormal">s</span><span class="mord mathnormal">t</span><span class="mord mathnormal">an</span><span class="mord mathnormal">t</span><span class="mord">/</span><span class="mord mathnormal">p</span><span class="mord mathnormal">o</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mord mathnormal">m</span><span class="mord mathnormal">es</span><span class="mord mathnormal">h</span><span class="mord cjk_fallback">中,</span><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">in</span><span class="mord mathnormal">eHe</span><span class="mord mathnormal">x</span><span class="mord mathnormal">m</span><span class="mord mathnormal">es</span><span class="mord mathnormal">h</span><span class="mord cjk_fallback">将使用它来细化单元格。在本例中,</span><span class="mord mathnormal">t</span><span class="mord mathnormal">o</span><span class="mord mathnormal">p</span><span class="mord mathnormal">o</span><span class="mord mathnormal" style="margin-right:0.05764em;">S</span><span class="mord mathnormal">e</span><span class="mord mathnormal">t</span><span class="mord cjk_fallback">用于生成</span><span class="mord mathnormal">ce</span><span class="mord mathnormal" style="margin-right:0.05764em;">llS</span><span class="mord mathnormal">e</span><span class="mord mathnormal">t</span><span class="mord cjk_fallback">。这要求</span><span class="mord mathnormal">t</span><span class="mord mathnormal">o</span><span class="mord mathnormal">p</span><span class="mord mathnormal">o</span><span class="mord mathnormal" style="margin-right:0.05764em;">S</span><span class="mord mathnormal">e</span><span class="mord mathnormal">t</span><span class="mord mathnormal" style="margin-right:0.02778em;">D</span><span class="mord mathnormal">i</span><span class="mord mathnormal">c</span><span class="mord mathnormal">t</span><span class="mord cjk_fallback">存在于系统目录中并正确配置。因此,随后会复制并更改现有的文件。</span><span class="mord">‘‘‘</span><span class="mord mathnormal">ba</span><span class="mord mathnormal">s</span><span class="mord mathnormal">h</span><span class="mclose">?</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">&gt;</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.625em;vertical-align:-0.1944em;"></span><span class="mord mathnormal">c</span><span class="mord mathnormal">p</span></span></span></span>FOAM_APP/utilities/mesh/manipulation/topoSet/topoSetDict system/

Toposetdict的示例操作子字典必须由以下内容替换:

actions
(
    {
        name c0;
        type cellSet;
        action new;
        source fieldToCell;
        sourceInfo
        {
            fieldName magGradalpha1;
            min 20;
            max 100;
        }
    }
);

现在可以根据System/Toposetdict中的定义生成cellset:

?>  topoSet
?>  refineHexMesh c0

当网格现在使用Paraview查看时,自由表面的区域现在应该有额外的分辨率。

2.4.2 变换点

在OpenFOAM网格格式中,与网格的比例和位置有关的唯一信息位于点位置向量中。如前所述,所有剩余的存储的网格信息是纯粹基于连通性的。也就是说,网格大小、位置和方向可以通过单独变换点位置来改变。为此,transformPoints网格实用程序随OpenFOAM提供。由于此实用程序相对简单,因此只显示了所需的语法。变换网格时最常用的选项是-rotate、-translate和-scale选项。

也可以在括号周围使用双引号而不是单引号。 执行任务的顺序是硬编码的,用户不能更改。 如果要确保在转换之前执行缩放,请运行TransformPoints两次。

  • scale。按指定的标量量在任意或所有基本方向上缩放网格的点。-scale '(1.0 1.0 1.0)'不会变更点位置,而-scale '(2.0 2.0 2.0)'会在所有方向上将点位置均匀加倍。任何非均匀缩放都将沿给定方向拉伸或压缩网格。
  • translate。按给定向量移动网格,有效地将此向量添加到网格中的每个点位置向量。
  • rotate。旋转网格。旋转由输入向量定义。网格将经历使用第二个向量定向第一个向量所需的旋转。旋转网格时,也可以通过添加-rotateFields选项来旋转任何初始或边界向量与张量值。

这三个点转换的语法如下所示。

?>  transformPoints -scale '(x y z)'
?>  transformPoints -translate '(x y z)'
?>  transformPoints -rotateFields -rotate '( (x0 y0 z0) (x1 y1 z1) )'

2.4.3 镜像网格

有时,用对称平面生成网格,然后执行镜面反射比在一个步骤中网格化整个几何结构更容易。 mirrorMesh实用程序正是这样做的。 关于镜像进程本身的所有参数都是从位于system/mirrorMeshDict中的字典中读取的。

为了成功镜像网格,镜像平面必须是平面。在本例中,四分之一网格被镜像到全域中。首先,下面的固析例必须复制到选择的目录中并重新命名,以防以后混淆。mirrorMeshDict需要从现有案例复制到案例系统目录中。

?>  cp -r <span class="katex"><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.02778em;">FO</span><span class="mord mathnormal">A</span><span class="mord"><span class="mord mathnormal" style="margin-right:0.10903em;">M</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3283em;"><span style="top:-2.55em;margin-left:-0.109em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight" style="margin-right:0.13889em;">T</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord mathnormal" style="margin-right:0.10903em;">U</span><span class="mord mathnormal" style="margin-right:0.00773em;">TOR</span><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="mord mathnormal">A</span><span class="mord mathnormal">L</span><span class="mord mathnormal" style="margin-right:0.05764em;">S</span><span class="mord">/</span><span class="mord mathnormal">s</span><span class="mord mathnormal">t</span><span class="mord mathnormal">ress</span><span class="mord mathnormal">A</span><span class="mord mathnormal">na</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">ys</span><span class="mord mathnormal">i</span><span class="mord mathnormal">s</span><span class="mord">/</span><span class="mord mathnormal">so</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">i</span><span class="mord mathnormal">d</span><span class="mord mathnormal" style="margin-right:0.02778em;">D</span><span class="mord mathnormal">i</span><span class="mord mathnormal">s</span><span class="mord mathnormal" style="margin-right:0.01968em;">pl</span><span class="mord mathnormal">a</span><span class="mord mathnormal">ce</span><span class="mord mathnormal">m</span><span class="mord mathnormal">e</span><span class="mord mathnormal">n</span><span class="mord mathnormal" style="margin-right:0.13889em;">tF</span><span class="mord mathnormal">o</span><span class="mord mathnormal">am</span><span class="mord">/</span><span class="mord mathnormal" style="margin-right:0.01968em;">pl</span><span class="mord mathnormal">a</span><span class="mord mathnormal">t</span><span class="mord mathnormal">eHo</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">e</span><span class="mord">.</span><span class="mclose">?</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">&gt;</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal">m</span><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="mord mathnormal" style="margin-right:0.01968em;">pl</span><span class="mord mathnormal">a</span><span class="mord mathnormal">t</span><span class="mord mathnormal">eHo</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">e</span><span class="mord mathnormal">mi</span><span class="mord mathnormal" style="margin-right:0.02778em;">rror</span><span class="mord mathnormal" style="margin-right:0.10903em;">M</span><span class="mord mathnormal">es</span><span class="mord mathnormal">h</span><span class="mord mathnormal" style="margin-right:0.05764em;">E</span><span class="mord mathnormal">x</span><span class="mord mathnormal">am</span><span class="mord mathnormal" style="margin-right:0.01968em;">pl</span><span class="mord mathnormal">e</span><span class="mclose">?</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">&gt;</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal">c</span><span class="mord mathnormal">d</span><span class="mord mathnormal">mi</span><span class="mord mathnormal" style="margin-right:0.02778em;">rror</span><span class="mord mathnormal" style="margin-right:0.10903em;">M</span><span class="mord mathnormal">es</span><span class="mord mathnormal">h</span><span class="mord mathnormal" style="margin-right:0.05764em;">E</span><span class="mord mathnormal">x</span><span class="mord mathnormal">am</span><span class="mord mathnormal" style="margin-right:0.01968em;">pl</span><span class="mord mathnormal">e</span><span class="mclose">?</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">&gt;</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.7778em;vertical-align:-0.1944em;"></span><span class="mord mathnormal">c</span><span class="mord mathnormal">p</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:0.4306em;"></span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span></span></span></span>FOAM_APP/utilities/mesh/manipulation/mirrorMesh/mirrorMeshDict system/

下一步是定义将作为镜像平面的平面。这样的平面可以由原点和法向向量定义,在mirrorMeshDict中如下所示。发生镜像的patch会自动移除。

图2.26 镜像前后的1/4网格

pointAndNormalDict
{
    basePoint    (0 0 0);
    normalVector (0 -1 0);
}

正确定义后,可以执行mirrorMesh,并检查网格是否存在错误:

?>  mirrorMesh
?>  checkMesh

这会产生半网格。对于第二次镜像,必须更改字典以说明不同的镜像平面:

pointAndNormalDict
{
    basePoint    (0 0 0);
    normalVector (-1 0 0);
}

再次运行mirrorMesh并使用checkMesh检查网格本身是否存在任何错误:

?>  mirrorMesh
?>  checkMesh

这将生成一个全域网格。