首页/文章/ 详情

OpenFOAM|算例 06 motoBike

精品
作者优秀平台推荐
详细信息
文章亮点
作者优秀
优秀教师/意见领袖/博士学历/特邀专家
平台推荐
内容稀缺
3年前浏览4647

本算例利用OpenFOAM中的simpleFoam求解器计算摩托车外流场。

算例路径:$FOAM_TUTORIALS/incompressible/simpleFoam/motorBike/

1 文件准备

运行命令:

cd $FOAM_RUN
cp -r $FOAM_TUTORIALS/incompressible/simpleFoam/motorBike/ .
cd motorBick
cp $FOAM_TUTORIALS/resources/geometry/motorBike.obj.gz ./constant/triSurface/
gzip -d ./constant/triSurface/motorBike.obj.gz

本案例采用snappyHexMesh进行网格生成,几何文件放置在constant/triSurface文件夹中。可以利用ParaView打开此几何文件motorBike.obj文件,如下图所示。obj是一种通用几何格式文件,可以利用其它CAD打开进行查看及修改。

图片

注:用不惯SnappyHexMesh的话,可以在其它前处理软件中生成网格,然后再转换为OpenFOAM网格。

2 网格生成及边界条件指定

snappyHexMesh网格生成分为两步:首先利用blockMesh生成背景网格,然后使用snappyHexMesh生成最终网格。由于本案例几何较为复杂,网格生成时间较长,可以采用并行方式进行网格生成。

2.1 blockMesh生成背景网格

在进行网格生成之前,可以提取几何特征,采用surfaceFeatures进行提取。在system文件夹中包含字典文件surfaceFeaturesDict

FoamFile
{
   version     2.0;
   format      ascii;
   class       dictionary;
   object      surfaceFeaturesDict;
}
// * * * * * * * * * * * * * * * * * * * * * * //
// 指定几何文件名,几何文件需要放到文件夹/constant/triSurface中
surfaces ("motorBike.obj");
// 指定面识别角度。当两个面之间的夹角大于此处指定的角度时,会被认为是一个面
includedAngle       150;
subsetFeatures
{
   // 保留多重边(多重边指的是两个或两个以上的面的交线)
   nonManifoldEdges       no;
   // 指定是否保留开放的边界,yes表示保留
   openEdges       yes;
}

运行命令提取几何特征:

surfaceFeatures

运行命令blockMesh生成背景网格。

blockMesh

system文件夹中包含有字典文件blockMeshDict,其中规定了背景网格参数及边界。

FoamFile
{
   version     2.0;
   format      ascii;
   class       dictionary;
   object      blockMeshDict;
}
// * * * * * * * * * * * * * * //
convertToMeters 1;
// 这里指定了计算区域的大小
vertices
(
   (-5 -4 0)
   (15 -4 0)
   (15  4 0)
   (-5  4 0)
   (-5 -4 8)
   (15 -4 8)
   (15  4 8)
   (-5  4 8)
);
blocks
(
   hex (0 1 2 3 4 5 6 7) (20 8 8) simpleGrading (1 1 1)
);
edges
(
);
boundary
(
   frontAndBack
   {
       type patch;
       faces
       (
           (3 7 6 2)
           (1 5 4 0)
       );
   }
   inlet
   {
       type patch;
       faces
       (
           (0 4 7 3)
       );
   }
   outlet
   {
       type patch;
       faces
       (
           (2 6 5 1)
       );
   }
   lowerWall
   {
       type wall;
       faces
       (
           (0 3 2 1)
       );
   }
   upperWall
   {
       type patch;
       faces
       (
           (4 5 6 7)
       );
   }
);

利用blockMesh生成了一个尺寸20*8*8的方形计算空间,同时指定了5个边界:frontAndBack、inlet、outlet、lowerWall及upperWall。

2.2 指定边界条件

在定义边界条件时,可以利用#include指令随时加载需要的数据。

这里准备了三个文件(fixedInlet、frontBackUpperPatches、initialConditions),后面在不同的边界中直接包含。其实也可以在需要的地方直接写入。

1、fixedInlet文件

该文件放置了入口边界条件。

inlet
{
   type  fixedValue;
   value $internalField;
}

2、frontBackUpperPatches文件

此文件定义了上壁面与侧壁面边界。

upperWall
{
   type slip;
}
frontAndBack
{
   type slip;
}

3、initialConditions

该文件中存放了一些常数,如速度、压力等信息。

flowVelocity         (20 0 0);
pressure             0;
turbulentKE          0.24;
turbulentOmega       1.78;

4、U文件

FoamFile
{
   version     2.0;
   format      ascii;
   class       volVectorField;
   location    "0";
   object      U;
}
// * * * * * * * * * * * * * //
#include        "include/initialConditions"
dimensions      [0 1 -1 0 0 0 0];
// $flowVelocity的值在initialConditions文件中已经定义为 (20 0 0)
internalField   uniform $flowVelocity;
boundaryField
{
   // 直接包含caseDicts/setConstraintTypes文件,该文件定义了边界类型
   #includeEtc "caseDicts/setConstraintTypes"
   // 将定义了入口速度的文件包含进来
   #include "include/fixedInlet"
   outlet
   {
       type            inletOutlet;
       inletValue      uniform (0 0 0);
       value           $internalField;
   }
   lowerWall
   {
       type            fixedValue;
       value           $internalField;
   }
   motorBikeGroup
   {
       type            noSlip;
   }
   #include "include/frontBackUpperPatches"
}

5、p文件

p文件与U文件类似。

FoamFile
{
   version     2.0;
   format      ascii;
   class       volScalarField;
   object      p;
}
// * * * * * * * * * * * * * * //
#include        "include/initialConditions"
dimensions      [0 2 -2 0 0 0 0];
//$pressure在initialConditions文件中定义为0
internalField   uniform $pressure;
boundaryField
{
   //- Set patchGroups for constraint patches
   #includeEtc "caseDicts/setConstraintTypes"
   inlet
   {
       type            zeroGradient;
   }
   outlet
   {
       type            fixedValue;
       value           $internalField;
   }
   lowerWall
   {
       type            zeroGradient;
   }
   motorBikeGroup
   {
       type            zeroGradient;
   }
   #include "include/frontBackUpperPatches"
}

6、k文件

FoamFile
{
   version     2.0;
   format      ascii;
   class       volScalarField;
   object      k;
}
// * * * * * * * * * * * * * * * * * * * //
#include        "include/initialConditions"
dimensions      [0 2 -2 0 0 0 0];
internalField   uniform $turbulentKE;
boundaryField
{
   //- Set patchGroups for constraint patches
   #includeEtc "caseDicts/setConstraintTypes"
   //- Define inlet conditions
   #include "include/fixedInlet"
   outlet
   {
       type            inletOutlet;
       inletValue      $internalField;
       value           $internalField;
   }
   lowerWall
   {
       type            kqRWallFunction;
       value           $internalField;
   }
   motorBikeGroup
   {
       type            kqRWallFunction;
       value           $internalField;
   }
   #include "include/frontBackUpperPatches"
}

7、omega文件

FoamFile
{
   version     2.0;
   format      ascii;
   class       volScalarField;
   object      omega;
}
// * * * * * * * * * * * * * * * * * * * * //
#include        "include/initialConditions"
dimensions      [0 0 -1 0 0 0 0];
internalField   uniform $turbulentOmega;
boundaryField
{
   //- Set patchGroups for constraint patches
   #includeEtc "caseDicts/setConstraintTypes"
   #include "include/fixedInlet"
   outlet
   {
       type            inletOutlet;
       inletValue      $internalField;
       value           $internalField;
   }
   lowerWall
   {
       type            omegaWallFunction;
       value           $internalField;
   }
   motorBikeGroup
   {
       type            omegaWallFunction;
       value           $internalField;
   }
   #include "include/frontBackUpperPatches"
}

8、nut文件

FoamFile
{
   version     2.0;
   format      ascii;
   class       volScalarField;
   location    "0";
   object      nut;
}
// * * * * * * * * * * * * * * * * * * * //
dimensions      [0 2 -1 0 0 0 0];
internalField   uniform 0;
boundaryField
{
   //- Set patchGroups for constraint patches
   #includeEtc "caseDicts/setConstraintTypes"
   frontAndBack
   {
       type            calculated;
       value           uniform 0;
   }
   inlet
   {
       type            calculated;
       value           uniform 0;
   }
   outlet
   {
       type            calculated;
       value           uniform 0;
   }
   lowerWall
   {
       type            nutkWallFunction;
       value           uniform 0;
   }
   upperWall
   {
       type            calculated;
       value           uniform 0;
   }
   motorBikeGroup
   {
       type            nutkWallFunction;
       value           uniform 0;
   }
}

2.3 并行参数字典

并行参数字典decomposeParDict位于system文件夹下。

FoamFile
{
   version     2.0;
   format      ascii;
   class       dictionary;
   object      decomposeParDict;
}
// * * * * * * * * * * * * * * //
numberOfSubdomains 16;
method          hierarchical;
simpleCoeffs
{
   n               (4 1 1);
   delta           0.001;
}
hierarchicalCoeffs
{
   n               (4 4 1);
   delta           0.001;
   order           xyz;
}
manualCoeffs
{
   dataFile        "cellDecomposition";
}

其中主要设置两个参数:

  • method:区域分解算法,通常有四种方法simple、hierarchical、scotch、manual
  • numberOfSubdomains:区域分解数量,可设置为比CPU核数稍微小一点

详细设置参数可以参阅文档:https://cfd.direct/openfoam/user-guide/v8-running-applications-parallel/

字典文件准备完毕后就可以使用命令对区域进行分割了。

decomposePar -copyZero

2.4 网格生成

这里使用snappyHexMesh生成最终网格,需要准备网格参数字典文件snappyHexMeshDict,该文件位于system文件夹下。

此文件包含内容较多,这里就不详述了。

文件准备完毕后,可以采用并行方式运行snappyHexMesh。

mpirun -np 16 snappyHexMesh -overwrite -parallel

等待较长时间运行完毕后如下图所示。

图片

此时可以在ParaView中查看网格。

图片

4 执行计算

执行命令:

mpirun -np 16 potentialFoam -parallel
mpirun -np 16 simpleFoam -parallel

计算完毕后执行命令组装完成最终结果:

reconstructParMesh -constant
reconstructPar -latestTime

计算完毕可查看速度分布如下图所示。

图片

注:若觉得reconstructPar非常耗费时间的话,也可以直接使用paraFoam -builtin读入算例文件进行后处理。

---------------------------------------------------------------------------------------------

版权声明:

原创文章,来源CFD之道,本文已经授权,欢迎分享,如需转载请联系作者。

仿真体系科普代码&命令求解技术网格处理OpenFOAM
著作权归作者所有,欢迎分享,未经许可,不得转载
首次发布时间:2020-12-23
最近编辑:3年前
CFD之道
博士 | 教师 探讨CFD职场生活,闲谈CFD里外
获赞 2486粉丝 10661文章 682课程 27
点赞
收藏
作者推荐
未登录
还没有评论
课程
培训
服务
行家
VIP会员 学习 福利任务 兑换礼品
下载APP
联系我们
帮助与反馈