generateBoundaryLayers.C 4.06 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

using namespace Foam;
37
using namespace Foam::Module;
38
39
40

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

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

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

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

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

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

Andrew Heather's avatar
Andrew Heather committed
81

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

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

Andrew Heather's avatar
Andrew Heather committed
93

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

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

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

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

Andrew Heather's avatar
Andrew Heather committed
108

Franjo's avatar
Franjo committed
109
110
int main(int argc, char *argv[])
{
Mark Olesen's avatar
Mark Olesen committed
111
112
113
114
115
116
117
    argList::addNote
    (
        "(cfmesh)\n"
        "Generate boundary layers in the existing mesh,"
        " based on the settings given in meshDict."
    );

Mark Olesen's avatar
Mark Olesen committed
118
    argList::addBoolOption("2DLayers");
119

120
121
    #include "setRootCase.H"
    #include "createTime.H"
122

Franjo's avatar
Franjo committed
123
124
125
126
127
128
129
130
131
132
133
    IOdictionary meshDict
    (
        IOobject
        (
            "meshDict",
            runTime.system(),
            runTime,
            IOobject::MUST_READ,
            IOobject::NO_WRITE
        )
    );
134

Andrew Heather's avatar
Andrew Heather committed
135
    // load the mesh from disk
Franjo's avatar
Franjo committed
136
137
    polyMeshGen pmg(runTime);
    pmg.read();
138

139
    const bool is2DLayer = args.found("2DLayers");
140

Andrew Heather's avatar
Andrew Heather committed
141
    // generate the initial boundary layer
Franjo's avatar
Franjo committed
142
    generateLayer(pmg, meshDict, is2DLayer);
143

Andrew Heather's avatar
Andrew Heather committed
144
    // optimisation of mesh quality
Franjo's avatar
Franjo committed
145
    meshOptimisation(pmg);
146

Andrew Heather's avatar
Andrew Heather committed
147
    // perform layer refinement
Franjo's avatar
Franjo committed
148
    layerRefinement(pmg, meshDict);
149

Andrew Heather's avatar
Andrew Heather committed
150
    Info<< "Writing mesh" << endl;
151
152
    pmg.write();

Andrew Heather's avatar
Andrew Heather committed
153
    Info<< "End\n" << endl;
154
155
156
    return 0;
}

Andrew Heather's avatar
Andrew Heather committed
157

158
// ************************************************************************* //