generateBoundaryLayers.C 3.93 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | cfMesh: A library for mesh generation
   \\    /   O peration     |
    \\  /    A nd           | Author: Franjo Juretic (franjo.juretic@c-fields.com)
     \\/     M anipulation  | Copyright (C) Creative Fields, Ltd.
-------------------------------------------------------------------------------
License
    This file is part of cfMesh.

    cfMesh is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the
    Free Software Foundation; either version 3 of the License, or (at your
    option) any later version.

    cfMesh is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with cfMesh.  If not, see <http://www.gnu.org/licenses/>.

Description
Franjo's avatar
Franjo committed
25 26
    Generates boundary layers in the existing mesh, based on the settings
    given in meshDict. It also performs necessary quality optimisation.
27 28 29 30 31 32

\*---------------------------------------------------------------------------*/

#include "argList.H"
#include "polyMeshGenModifier.H"
#include "meshOptimizer.H"
Franjo's avatar
Franjo committed
33 34
#include "boundaryLayers.H"
#include "refineBoundaryLayers.H"
35 36 37 38 39

using namespace Foam;

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

Franjo's avatar
Franjo committed
40 41 42 43 44 45
void generateLayer
(
    polyMeshGen& mesh,
    const dictionary& meshDict,
    const bool layers2D
)
46
{
Franjo's avatar
Franjo committed
47
    boundaryLayers bl(mesh);
48

Franjo's avatar
Franjo committed
49 50
    if( layers2D )
        bl.activate2DMode();
51

Franjo's avatar
Franjo committed
52
    if( meshDict.found("boundaryLayers") )
53
    {
Franjo's avatar
Franjo committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
        const dictionary& bndLayers = meshDict.subDict("boundaryLayers");

        if( bndLayers.found("nLayers") )
        {
            const label nLayers = readLabel(bndLayers.lookup("nLayers"));

            if( nLayers > 0 )
                bl.addLayerForAllPatches();
        }
        else if( bndLayers.found("patchBoundaryLayers") )
        {
            const dictionary& patchLayers =
                bndLayers.subDict("patchBoundaryLayers");
            const wordList createLayers = patchLayers.toc();

            forAll(createLayers, patchI)
                bl.addLayerForPatch(createLayers[patchI]);
        }
72 73 74
    }
    else
    {
Franjo's avatar
Franjo committed
75
        bl.addLayerForAllPatches();
76
    }
Franjo's avatar
Franjo committed
77
}
78

Franjo's avatar
Franjo committed
79 80 81
void meshOptimisation(polyMeshGen& mesh)
{
    meshOptimizer mOpt(mesh);
82

Franjo's avatar
Franjo committed
83 84 85 86 87 88
    mOpt.optimizeMeshFV();
    mOpt.optimizeLowQualityFaces();
    mOpt.untangleMeshFV();
    mOpt.optimizeBoundaryLayer();
    mOpt.untangleMeshFV();
}
89

Franjo's avatar
Franjo committed
90 91 92
void layerRefinement(polyMeshGen& mesh, const dictionary& meshDict)
{
    if( meshDict.isDict("boundaryLayers") )
93
    {
Franjo's avatar
Franjo committed
94
        refineBoundaryLayers refLayers(mesh);
95

Franjo's avatar
Franjo committed
96
        refineBoundaryLayers::readSettings(meshDict, refLayers);
97

Franjo's avatar
Franjo committed
98
        refLayers.refineLayers();
99

Franjo's avatar
Franjo committed
100 101 102
        meshOptimizer(mesh).untangleBoundaryLayer();
    }
}
103

Franjo's avatar
Franjo committed
104 105 106
int main(int argc, char *argv[])
{
    argList::validOptions.insert("2DLayers", "bool");
107

Franjo's avatar
Franjo committed
108 109
#   include "setRootCase.H"
#   include "createTime.H"
110

Franjo's avatar
Franjo committed
111 112 113 114 115 116 117 118 119 120 121
    IOdictionary meshDict
    (
        IOobject
        (
            "meshDict",
            runTime.system(),
            runTime,
            IOobject::MUST_READ,
            IOobject::NO_WRITE
        )
    );
122

Franjo's avatar
Franjo committed
123 124 125
    //- load the mesh from disk
    polyMeshGen pmg(runTime);
    pmg.read();
126

Franjo's avatar
Franjo committed
127 128 129
    bool is2DLayer(false);
    if( args.options().found("2DLayers") )
        is2DLayer = true;
130

Franjo's avatar
Franjo committed
131 132
    //- generate the initial boundary layer
    generateLayer(pmg, meshDict, is2DLayer);
133

Franjo's avatar
Franjo committed
134 135
    //- optimisation of mesh quality
    meshOptimisation(pmg);
136

Franjo's avatar
Franjo committed
137 138
    //- perform layer refinement
    layerRefinement(pmg, meshDict);
139 140 141 142 143 144 145 146 147

    Info << "Writing mesh" << endl;
    pmg.write();

    Info << "End\n" << endl;
    return 0;
}

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