generateBoundaryLayers.C 3.88 KB
Newer Older
1 2 3 4 5 6 7 8
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  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
Andrew Heather's avatar
Andrew Heather committed
9
    This file is part of OpenFOAM.
10

Andrew Heather's avatar
Andrew Heather committed
11 12 13 14
    OpenFOAM 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.
15

Andrew Heather's avatar
Andrew Heather committed
16
    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 18 19 20 21
    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
Andrew Heather's avatar
Andrew Heather committed
22
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
23 24

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

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

Andrew Heather's avatar
Andrew Heather committed
52
    if (meshDict.found("boundaryLayers"))
53
    {
Franjo's avatar
Franjo committed
54 55
        const dictionary& bndLayers = meshDict.subDict("boundaryLayers");

Mark Olesen's avatar
Mark Olesen committed
56 57
        label nLayers;
        if (bndLayers.readIfPresent("nLayers", nLayers))
Franjo's avatar
Franjo committed
58
        {
Andrew Heather's avatar
Andrew Heather committed
59
            if (nLayers > 0)
Mark Olesen's avatar
Mark Olesen committed
60
            {
Franjo's avatar
Franjo committed
61
                bl.addLayerForAllPatches();
Mark Olesen's avatar
Mark Olesen committed
62
            }
Franjo's avatar
Franjo committed
63
        }
Andrew Heather's avatar
Andrew Heather committed
64
        else if (bndLayers.found("patchBoundaryLayers"))
Franjo's avatar
Franjo committed
65 66 67 68 69 70 71 72
        {
            const dictionary& patchLayers =
                bndLayers.subDict("patchBoundaryLayers");
            const wordList createLayers = patchLayers.toc();

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

Andrew Heather's avatar
Andrew Heather committed
80

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

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

Andrew Heather's avatar
Andrew Heather committed
92

Franjo's avatar
Franjo committed
93 94
void layerRefinement(polyMeshGen& mesh, const dictionary& meshDict)
{
Andrew Heather's avatar
Andrew Heather committed
95
    if (meshDict.isDict("boundaryLayers"))
96
    {
Franjo's avatar
Franjo committed
97
        refineBoundaryLayers refLayers(mesh);
98

Franjo's avatar
Franjo committed
99
        refineBoundaryLayers::readSettings(meshDict, refLayers);
100

Franjo's avatar
Franjo committed
101
        refLayers.refineLayers();
102

Franjo's avatar
Franjo committed
103 104 105
        meshOptimizer(mesh).untangleBoundaryLayer();
    }
}
106

Andrew Heather's avatar
Andrew Heather committed
107

Franjo's avatar
Franjo committed
108 109
int main(int argc, char *argv[])
{
Mark Olesen's avatar
Mark Olesen committed
110
    argList::addBoolOption("2DLayers");
111

Franjo's avatar
Franjo committed
112 113
#   include "setRootCase.H"
#   include "createTime.H"
114

Franjo's avatar
Franjo committed
115 116 117 118 119 120 121 122 123 124 125
    IOdictionary meshDict
    (
        IOobject
        (
            "meshDict",
            runTime.system(),
            runTime,
            IOobject::MUST_READ,
            IOobject::NO_WRITE
        )
    );
126

Andrew Heather's avatar
Andrew Heather committed
127
    // load the mesh from disk
Franjo's avatar
Franjo committed
128 129
    polyMeshGen pmg(runTime);
    pmg.read();
130

Mark Olesen's avatar
Mark Olesen committed
131
    const bool is2DLayer = args.optionFound("2DLayers");
132

Andrew Heather's avatar
Andrew Heather committed
133
    // generate the initial boundary layer
Franjo's avatar
Franjo committed
134
    generateLayer(pmg, meshDict, is2DLayer);
135

Andrew Heather's avatar
Andrew Heather committed
136
    // optimisation of mesh quality
Franjo's avatar
Franjo committed
137
    meshOptimisation(pmg);
138

Andrew Heather's avatar
Andrew Heather committed
139
    // perform layer refinement
Franjo's avatar
Franjo committed
140
    layerRefinement(pmg, meshDict);
141

Andrew Heather's avatar
Andrew Heather committed
142
    Info<< "Writing mesh" << endl;
143 144
    pmg.write();

Andrew Heather's avatar
Andrew Heather committed
145
    Info<< "End\n" << endl;
146 147 148
    return 0;
}

Andrew Heather's avatar
Andrew Heather committed
149

150
// ************************************************************************* //