使用createPatch生成OpenFOAM可用的cyclic边界


前言

遇到的问题是:使用Gambit生成网格之后,欲生成OpenFOAM可用的cyclic边界条件,直接应用fluentMeshToFoam转换是不行的,还需要使用createPatch。
参考CFD Online的一个回答:

https://www.cfd-online.com/Forums/openfoam-meshing/107664-usage-createpatchdict.html


二维周期边界

本文代码和case均基于OpenFOAM v8.0,分以下几个步骤介绍:

  1. 基础网格生成
  2. 网格转换
  3. 创建cyclic边界

1. 基础网格生成

使用Gambit划分如下二维计算域的网格,并给各个边界命名。
计算域

需要注意的是,生成网格之前必须用Gambit的link功能将配对的边界链接起来,以保证配对的两个边界上的网格保持一致。生成网格之后导出为 tri.msh 网格文件,边界条件的类型设为 wall 即可。

2. 网格转换

应用fluentMeshToFoam将 tri.msh 转换为OpenFOAM的网格文件,所得 case/constant/polyMesh/boundary 文件如下

/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  8
     \\/     M anipulation  |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       polyBoundaryMesh;
    location    "constant/polyMesh";
    object      boundary;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

5
(
    upperWall
    {
        type            wall;
        inGroups        List<word> 1(wall);
        nFaces          160;
        startFace       85726;
    }
    rightWall
    {
        type            wall;
        inGroups        List<word> 1(wall);
        nFaces          160;
        startFace       85886;
    }
    leftWall
    {
        type            wall;
        inGroups        List<word> 1(wall);
        nFaces          160;
        startFace       86046;
    }
    lowerWall
    {
        type            wall;
        inGroups        List<word> 1(wall);
        nFaces          160;
        startFace       86206;
    }
    frontAndBackPlanes
    {
        type            empty;
        inGroups        List<word> 1(empty);
        nFaces          114728;
        startFace       86366;
    }
)

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

生成cyclic边界之前还需要做点准备工作,那就是修改上述boundary文件为

/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  8
     \\/     M anipulation  |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       polyBoundaryMesh;
    location    "constant/polyMesh";
    object      boundary;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

5
(
    upperWall
    {
        type            cyclic;
        inGroups        List<word> 1(cyclic);
        nFaces          160;
        startFace       85726;
        matchTolerance  0.0001;
        neighbourPatch  lowerWall;
    }
    rightWall
    {
        type            cyclic;
        inGroups        List<word> 1(cyclic);
        nFaces          160;
        startFace       85886;
        matchTolerance  0.0001;
        neighbourPatch  leftWall;
    }
    leftWall
    {
        type            cyclic;
        inGroups        List<word> 1(cyclic);
        nFaces          160;
        startFace       86046;
        matchTolerance  0.0001;
        neighbourPatch  rightWall;
    }
    lowerWall
    {
        type            cyclic;
        inGroups        List<word> 1(cyclic);
        nFaces          160;
        startFace       86206;
        matchTolerance  0.0001;
        neighbourPatch  upperWall;
    }
    frontAndBackPlanes
    {
        type            empty;
        inGroups        List<word> 1(empty);
        nFaces          114728;
        startFace       86366;
    }
)

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

主要是将 wall 边界类型改为 cyclic边界类型,并用neighbourPatch指定各个cyclic边界之间的配对关系,用matchTolerance指定配对的精度。

3. 创建cyclic边界

在 case/system 文件夹中新建控制文件 createPatchDict ,文件内容如下

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

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

// This application/dictionary controls:
// - optional: create new patches from boundary faces (either given as
//   a set of patches or as a faceSet)
// - always: order faces on coupled patches such that they are opposite. This
//   is done for all coupled faces, not just for any patches created.
// - optional: synchronise points on coupled patches.

// 1. Create cyclic:
// - specify where the faces should come from
// - specify the type of cyclic. If a rotational specify the rotationAxis
//   and centre to make matching easier
// - always create both halves in one invocation with correct 'neighbourPatch'
//   setting.
// - optionally pointSync true to guarantee points to line up.

// 2. Correct incorrect cyclic:
// This will usually fail upon loading:
//  "face 0 area does not match neighbour 2 by 0.0100005%"
//  " -- possible face ordering problem."
// - in polyMesh/boundary file:
//      - loosen matchTolerance of all cyclics to get case to load
//      - or change patch type from 'cyclic' to 'patch'
//        and regenerate cyclic as above


// Do a synchronisation of coupled points after creation of any patches.
// Note: this does not work with points that are on multiple coupled patches
//       with transformations (i.e. cyclics).
pointSync false;

// Patches to create.
patches
(

    {
        // Name of new patch
        name lowerWall;

        // Type of new patch
        patchInfo
        {
            type        cyclic;
            neighbourPatch  upperWall;
            transform translational;
            seprationVector (0 1 0);
        }

        constructFrom  patches;
        patches (lowerWall);
        set f0;
    }
    {
        // Name of new patch
        name upperWall;

        // Type of new patch
        patchInfo
        {
            type        cyclic;
            neighbourPatch  lowerWall;
            transform translational;
            seprationVector (0 1 0);
        }

        constructFrom  patches;
        patches (upperWall);
        set f0;
    }
    {
        // Name of new patch
        name rightWall;

        // Type of new patch
        patchInfo
        {
            type        cyclic;
            neighbourPatch  leftWall;
            transform translational;
            seprationVector (1 0 0);
        }

        constructFrom  patches;
        patches (rightWall);
        set f0;
    }
    {
        // Name of new patch
        name leftWall;

        // Type of new patch
        patchInfo
        {
            type        cyclic;
            neighbourPatch  rightWall;
            transform translational;
            seprationVector (1 0 0);
        }

        constructFrom  patches;
        patches (leftWall);
        set f0;
    }
);

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

最后运行createPatch,即可生成带正确 cyclic 边界的网格文件。

/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  8
     \\/     M anipulation  |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       polyBoundaryMesh;
    location    "0.002/polyMesh";
    object      boundary;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

5
(
    upperWall
    {
        type            cyclic;
        inGroups        List<word> 1(cyclic);
        nFaces          160;
        startFace       85726;
        matchTolerance  0.0001;
        neighbourPatch  lowerWall;
        transformType   translational;
        separation      (0 1 0);
    }
    rightWall
    {
        type            cyclic;
        inGroups        List<word> 1(cyclic);
        nFaces          160;
        startFace       85886;
        matchTolerance  0.0001;
        neighbourPatch  leftWall;
        transformType   translational;
        separation      (1 0 0);
    }
    leftWall
    {
        type            cyclic;
        inGroups        List<word> 1(cyclic);
        nFaces          160;
        startFace       86046;
        matchTolerance  0.0001;
        neighbourPatch  rightWall;
        transformType   translational;
        separation      (-1 -0 -0);
    }
    lowerWall
    {
        type            cyclic;
        inGroups        List<word> 1(cyclic);
        nFaces          160;
        startFace       86206;
        matchTolerance  0.0001;
        neighbourPatch  upperWall;
        transformType   translational;
        separation      (-0 -1 -0);
    }
    frontAndBackPlanes
    {
        type            empty;
        inGroups        List<word> 1(empty);
        nFaces          114728;
        startFace       86366;
    }
)

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

三维周期边界

1. Gambit网格划分

采用link功能建立对应面的映射关系,注意选中 Reverse orientation 和 Periodic,
生成网格的时候,Gambit会保证对应面上的网格一致性。

在这里插入图片描述

生成网格之后检查一下各个对应面的网格是否一致:

在这里插入图片描述

2. 网格转换

注意:必须使用 Fluent3DMeshToFoam转换网格,否则在生成cyclic边界时会遇到问题

网格转换完成之后,将周期边界的类型都先调整为 patch

/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  7
     \\/     M anipulation  |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       polyBoundaryMesh;
    location    "constant/polyMesh";
    object      boundary;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

6
(
    upper
    {
        type            patch;
        inGroups        List<word> 1(patch);
        nFaces          3596;
        startFace       938740;
    }
    lower
    {
        type            patch;
        inGroups        List<word> 1(patch);
        nFaces          3596;
        startFace       942336;
    }
    back
    {
        type            patch;
        inGroups        List<word> 1(patch);
        nFaces          3618;
        startFace       945932;
    }
    front
    {
        type            patch;
        inGroups        List<word> 1(patch);
        nFaces          3618;
        startFace       949550;
    }
    right
    {
        type            patch;
        inGroups        List<word> 1(patch);
        nFaces          3606;
        startFace       953168;
    }
    left
    {
        type            patch;
        inGroups        List<word> 1(patch);
        nFaces          3606;
        startFace       956774;
    }
)

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

3. 生成周期边界

编写 system/createPatchDict 文件如下

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

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

pointSync false;

// Patches to create.
patches
(

    {
        // Name of new patch
        name lowerWall;

        // Type of new patch
        patchInfo
        {
            type        cyclic;
            neighbourPatch  upperWall;
            transform translational;
            separationVector (0 6.283185308 0);
			matchTolerance 1E-5;
        }

        constructFrom  patches;
        patches (lower);
        set f0;
    }
    {
        // Name of new patch
        name upperWall;

        // Type of new patch
        patchInfo
        {
            type        cyclic;
            neighbourPatch  lowerWall;
            transform translational;
            separationVector (0 -6.283185308 0);
			matchTolerance 1E-5;
        }

        constructFrom  patches;
        patches (upper);
        set f0;
    }
    {
        // Name of new patch
        name rightWall;

        // Type of new patch
        patchInfo
        {
            type        cyclic;
            neighbourPatch  leftWall;
            transform translational;
            separationVector (-6.283185308 0 0);
			matchTolerance 1E-5;
        }

        constructFrom  patches;
        patches (right);
        set f0;
    }
    {
        // Name of new patch
        name leftWall;

        // Type of new patch
        patchInfo
        {
            type        cyclic;
            neighbourPatch  rightWall;
            transform translational;
            separationVector (6.283185308 0 0);
			matchTolerance 1E-5;
        }

        constructFrom  patches;
        patches (left);
        set f0;
    }
	{
        // Name of new patch
        name frontWall;

        // Type of new patch
        patchInfo
        {
            type        cyclic;
            neighbourPatch  backWall;
            transform translational;
            separationVector (0 0 -6.283185308);
			matchTolerance 1E-5;
        }

        constructFrom  patches;
        patches (front);
        set f0;
    }
    {
        // Name of new patch
        name backWall;

        // Type of new patch
        patchInfo
        {
            type        cyclic;
            neighbourPatch  frontWall;
            transform translational;
            separationVector (0 0 6.283185308);
			matchTolerance 1E-5;
        }

        constructFrom  patches;
        patches (back);
        set f0;
    }
);

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

这里需要注意以下几点:

(1) name of new patch 最好与源面的名字不同,例如示例中的 backWall (new) 和 back (source)
(2) separationVector 在相对的两个面上是一正一负,可以先自己根据面的法向量给定一个向量,如果计算的时候求解器提示如下 warning

Specified separationVector (0 1 0) differs from computed separation vector 1((0 6.2831853 0))

可以根据提示调整 separationVector。

编写好上述文件之后,执行 createPatch,生成周期边界条件。

Enjoy!

Contact me
E-mail: 18810577380@163.com

  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值