Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / applications / utilities / mesh / generation / cfMesh / generateBoundaryLayers / generateBoundaryLayers.C
blob741420a21ef8bc5906008fc8ebf1b06a08ce6423
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | cfMesh: A library for mesh generation
4    \\    /   O peration     |
5     \\  /    A nd           | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6      \\/     M anipulation  | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
8 License
9     This file is part of cfMesh.
11     cfMesh is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 3 of the License, or (at your
14     option) any later version.
16     cfMesh is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with cfMesh.  If not, see <http://www.gnu.org/licenses/>.
24 Description
25     Generates boundary layers in the existing mesh, based on the settings
26     given in meshDict. It also performs necessary quality optimisation.
28 \*---------------------------------------------------------------------------*/
30 #include "argList.H"
31 #include "objectRegistry.H"
32 #include "foamTime.H"
33 #include "polyMeshGenModifier.H"
34 #include "meshOptimizer.H"
35 #include "boundaryLayers.H"
36 #include "refineBoundaryLayers.H"
38 using namespace Foam;
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 void generateLayer
44     polyMeshGen& mesh,
45     const dictionary& meshDict,
46     const bool layers2D
49     boundaryLayers bl(mesh);
51     if( layers2D )
52         bl.activate2DMode();
54     if( meshDict.found("boundaryLayers") )
55     {
56         const dictionary& bndLayers = meshDict.subDict("boundaryLayers");
58         if( bndLayers.found("nLayers") )
59         {
60             const label nLayers = readLabel(bndLayers.lookup("nLayers"));
62             if( nLayers > 0 )
63                 bl.addLayerForAllPatches();
64         }
65         else if( bndLayers.found("patchBoundaryLayers") )
66         {
67             const dictionary& patchLayers =
68                 bndLayers.subDict("patchBoundaryLayers");
69             const wordList createLayers = patchLayers.toc();
71             forAll(createLayers, patchI)
72                 bl.addLayerForPatch(createLayers[patchI]);
73         }
74     }
75     else
76     {
77         bl.addLayerForAllPatches();
78     }
81 void meshOptimisation(polyMeshGen& mesh)
83     meshOptimizer mOpt(mesh);
85     mOpt.optimizeMeshFV();
86     mOpt.optimizeLowQualityFaces();
87     mOpt.untangleMeshFV();
88     mOpt.optimizeBoundaryLayer();
89     mOpt.untangleMeshFV();
92 void layerRefinement(polyMeshGen& mesh, const dictionary& meshDict)
94     if( meshDict.isDict("boundaryLayers") )
95     {
96         refineBoundaryLayers refLayers(mesh);
98         refineBoundaryLayers::readSettings(meshDict, refLayers);
100         refLayers.refineLayers();
102         meshOptimizer(mesh).untangleBoundaryLayer();
103     }
106 int main(int argc, char *argv[])
108     argList::validOptions.insert("2DLayers", "bool");
110 #   include "setRootCase.H"
111 #   include "createTime.H"
113     IOdictionary meshDict
114     (
115         IOobject
116         (
117             "meshDict",
118             runTime.system(),
119             runTime,
120             IOobject::MUST_READ,
121             IOobject::NO_WRITE
122         )
123     );
125     //- load the mesh from disk
126     polyMeshGen pmg(runTime);
127     pmg.read();
129     bool is2DLayer(false);
130     if( args.options().found("2DLayers") )
131         is2DLayer = true;
133     //- generate the initial boundary layer
134     generateLayer(pmg, meshDict, is2DLayer);
136     //- optimisation of mesh quality
137     meshOptimisation(pmg);
139     //- perform layer refinement
140     layerRefinement(pmg, meshDict);
142     Info << "Writing mesh" << endl;
143     pmg.write();
145     Info << "End\n" << endl;
146     return 0;
149 // ************************************************************************* //