人気ブログランキング
人気ブログランキング
OPEN FOAMあれこれ指南 PR

OpenFOAM snappyHexMeshDict の全設定を徹底解説!

記事内に商品プロモーションを含む場合があります

CFD解析で STL 形状からの高品質なメッシュ作成を行う際に欠かせないのが snappyHexMesh
その設定ファイルである snappyHexMeshDict には多くのパラメータがありますが、初心者から上級者まで「結局この項目って何を意味するの?」と迷いがち。

この記事では、OpenFOAM の snappyHexMeshDict行ごとに詳細に解説し、攪拌槽など複雑なジオメトリにも対応できるように説明していきます。

📦 基本構造と役割

castellatedMesh    true;
snap               true;
addLayers          false;
パラメータ意味
castellatedMeshSTL形状を元に粗メッシュから細分化メッシュを生成する
snapメッシュを形状表面に吸着させて形状精度を高める
addLayers境界層メッシュ(プリズム層)を追加するか

🗺 geometry セクション

STLファイルを読み込み、メッシュ対象のパッチ名を登録します。

geometry
{
    Vessel.stl
    {
        type triSurfaceMesh;
        name vessel;
    }

    coil.stl
    {
        type triSurfaceMesh;
        name coil;
    }
    ...
}
  • type triSurfaceMesh: STL形式の3角形面を読み込む
  • ・name: メッシュ生成時のパッチ名として使用

🧩 castellatedMeshControls セクション

ここでメッシュの粗さや細かさを決定します。

maxLocalCells 1000000;      // 並列時にプロセスごとの最大セル数
maxGlobalCells 2000000;     // 全体での最大セル数(超えるとエラー)
minRefinementCells 0;       // 最小分割セル数(通常0)
nCellsBetweenLevels 3;      // 細分化レベルの境界に置く遷移セル数
resolveFeatureAngle 30;          // 30度以上の角を強制的に再分割
locationInMesh (0 0 0.5);        // STL形状の内側にある点を指定
features ();                // エッジフィーチャの読み込み設定(使用しない場合は空)
refinementSurfaces
{
    vessel
    {
        level (2 2);
        patchInfo { type wall; }
    }
    overmesh
    {
        level (2 3);
        patchInfo { type overset; }
    }
}

※features の例(※surfaceFeatureExtractDictで作成するファイル”.eMesh”を使う)

features
(
    {
        file "vessel.eMesh";
        level 2;
    }
   {
        file "coil.eMesh";
        level 2;
    }
);

refinementSurfaces の設定について

設定名意味
level(最小レベル 最大レベル) でSTLに沿った細分化の度合いを指定
patchInfowall, patch, overset などで境界条件の種類を示す

🧲 snapControls セクション

メッシュの表面を STL にできる限り一致させるための処理です。

snapControls
{
    nSmoothPatch 3;          // 表面スムージングの回数
    tolerance 2.0;               // スナップ許容誤差
    nSolveIter 100;            // 吸着位置を解く反復回数
    nRelaxIter 5;                // 緩和反復
}

📏 addLayersControls セクション(境界層)

最初に記載した設定は addLayers false のため無効として記載していますが、記述例だけ示しておきます。(addLayersControlsはあまり使わない設定です)

addLayersControls
{
    relativeSizes true;             // 境界層厚みを相対指定
    layers {};                      // どのパッチに追加するか(今回は空)
    expansionRatio 1.0;             // 境界層の成長率
    finalLayerThickness 0.3;        // 境界層の最大厚み
    ...
}

✅ meshQualityControls セクション(オプション設定)

メッシュ品質が悪いと、計算が発散することもあるため必要に応じて設定します。

meshQualityControls
{
    #include "meshQualityDict"
    maxNonOrtho 65;                 // 非直交度の上限
    maxBoundarySkewness 20;         // 境界セルのスキュー
    maxInternalSkewness 4;          // 内部セルのスキュー
    minVol 1e-13;                   // 最小セル体積
    minTetQuality 1e-9;             // テトラメッシュの品質指標
    ...
}

✅ その他設定(オプション設定)

よく使う設定を記載します。

debug 0;                            // メッシュ処理中のデバッグ情報の出力レベル
mergeTolerance 1e-6;               // 点同士のマージ許容距離(重複ノードを結合)

全文表示(サンプル)

この記事で紹介した設定の全文を表示します。

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

castellatedMesh true;
snap            true;
addLayers       true;

geometry
{
    Vessel.stl
    {
        type triSurfaceMesh;
        name vessel;
    }
    coil.stl
    {
        type triSurfaceMesh;
        name coil;
    }
    Atomosface.stl
    {
        type triSurfaceMesh;
        name Atomosface;
    }

}

castellatedMeshControls
{
    maxLocalCells 1000000;

    maxGlobalCells 5000000;

    minRefinementCells 10;

    maxLoadUnbalance 0.10;

    nCellsBetweenLevels 3;

    features
    (
        {
            file "vessel.eMesh";
            level 2;
        }
        {
            file "coil.eMesh";
            level 2;
        }
        {
            file "Atomosface.eMesh";
            level 2;
        }
    );

    refinementSurfaces
    {
        vessel
        {
            level (2 2);
            patchInfo
            {
                type wall;
            }
        }
        coil
        {
            level (2 3);
            patchInfo
            {
                type wall;
            }
        }
        Atomosface
        {
            level (2 3);
            patchInfo
            {
                type patch;
            }
        }
    }

    resolveFeatureAngle 30;

    refinementRegions
    {

    }

    locationInMesh (0.0 0.0 0.1);

    allowFreeStandingZoneFaces true;
}


// Settings for the snapping.
snapControls
{
    //- Number of patch smoothing iterations before finding correspondence
    //  to surface
    nSmoothPatch 3;

    //- Relative distance for points to be attracted by surface feature point
    //  or edge. True distance is this factor times local
    //  maximum edge length.
    tolerance 0.3;

    //- Number of mesh displacement relaxation iterations.
    nSolveIter 100;

    //- Maximum number of snapping relaxation iterations. Should stop
    //  before upon reaching a correct mesh.
    nRelaxIter 5;

    // Feature snapping

        //- Number of feature edge snapping iterations.
        //  Leave out altogether to disable.
        nFeatureSnapIter 10;

        //- Detect (geometric only) features by sampling the surface
        //  (default=false).
        implicitFeatureSnap false;

        //- Use castellatedMeshControls::features (default = true)
        explicitFeatureSnap true;

        //- Detect points on multiple surfaces (only for explicitFeatureSnap)
        //multiRegionFeatureSnap false;
        multiRegionFeatureSnap true;
}


// Settings for the layer addition.
addLayersControls
{
    // Are the thickness parameters below relative to the undistorted
    // size of the refined cell outside layer (true) or absolute sizes (false).
    relativeSizes true;

    // Per final patch (so not geometry!) the layer information
    layers//壁に1層貼る
    {
        vessel { nSurfaceLayers 1; }
    }

    // Expansion factor for layer mesh
    expansionRatio 1.2;

    // Wanted thickness of final added cell layer. If multiple layers
    // is the thickness of the layer furthest away from the wall.
    // Relative to undistorted size of cell outside layer.
    // See relativeSizes parameter.
    finalLayerThickness 0.3;

    // Minimum thickness of cell layer. If for any reason layer
    // cannot be above minThickness do not add layer.
    // Relative to undistorted size of cell outside layer.
    minThickness 0.1;

    // If points get not extruded do nGrow layers of connected faces that are
    // also not grown. This helps convergence of the layer addition process
    // close to features.
    // Note: changed(corrected) w.r.t 1.7.x! (didn't do anything in 1.7.x)
    nGrow 0;

    // Advanced settings

    // When not to extrude surface. 0 is flat surface, 90 is when two faces
    // are perpendicular
    featureAngle 60;

    // At non-patched sides allow mesh to slip if extrusion direction makes
    // angle larger than slipFeatureAngle.
    slipFeatureAngle 30;

    // Maximum number of snapping relaxation iterations. Should stop
    // before upon reaching a correct mesh.
    nRelaxIter 5;

    // Number of smoothing iterations of surface normals
    nSmoothSurfaceNormals 1;

    // Number of smoothing iterations of interior mesh movement direction
    nSmoothNormals 3;

    // Smooth layer thickness over surface patches
    nSmoothThickness 10;

    // Stop layer growth on highly warped cells
    maxFaceThicknessRatio 0.5;

    // Reduce layer growth where ratio thickness to medial
    // distance is large
    maxThicknessToMedialRatio 0.3;

    // Angle used to pick up medial axis points
    // Note: changed(corrected) w.r.t 1.7.x! 90 degrees corresponds to 130
    // in 1.7.x.
    minMedialAxisAngle 90;

    // Create buffer region for new layer terminations
    nBufferCellsNoExtrude 0;

    // Overall max number of layer addition iterations. The mesher will exit
    // if it reaches this number of iterations; possibly with an illegal
    // mesh.
    nLayerIter 50;
}

meshQualityControls
{
    #include "meshQualityDict"
    maxNonOrtho 65;
    maxBoundarySkewness 20;
    maxInternalSkewness 4;
    maxConcave 80;
    minFlatness 0.5;
    minVol 1e-13;
    minTetQuality 1e-9;
    minArea -1;
    minTwist 0.02;
    minDeterminant 0.001;
    minFaceWeight 0.02;
    minVolRatio 0.01;
    minTriangleTwist -1;
    nSmoothScale 4;
    errorReduction 0.75;
}

writeFlags
(
    scalarLevels
    layerSets
    layerFields     // write volScalarField for layer coverage
);

debug 0;
mergeTolerance 1e-6;

📌 まとめ

このように snappyHexMeshDict は複雑な設定ファイルですが、各項目の意味を理解すれば非常に強力です。

✨この記事のまとめ

  • STLの読み込みとパッチの定義が最初の基本
  • refinementSurfaces で形状ごとの細分化レベルを調整
  • snapControls で吸着制度を高めて精度を上げる
  • meshQualityControls は計算の発散防止に有効です
ABOUT ME
den
完全独学でWEBデザインやpythonアプリ製作や流体解析を無謀にも挑戦している中年男。生成AIのおかげで独学が出来る世の中に感謝。 工場勤務の会社員で3児の父。 チャレンジを忘れず、妻に怒られても心はおれず。 有益な情報を発信し、これを見ている人の為になればと思っています。
関連記事一覧