generateBoundaryLayers.C
Go to the documentation of this file.
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.
10 
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.
15 
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.
20 
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/>.
23 
24 Description
25  Generates boundary layers in the existing mesh, based on the settings
26  given in meshDict. It also performs necessary quality optimisation.
27 
28 \*---------------------------------------------------------------------------*/
29 
30 #include "argList.H"
31 #include "polyMeshGenModifier.H"
32 #include "meshOptimizer.H"
33 #include "boundaryLayers.H"
34 #include "refineBoundaryLayers.H"
35 
36 using namespace Foam;
37 
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 
40 void generateLayer
41 (
43  const dictionary& meshDict,
44  const bool layers2D
45 )
46 {
47  boundaryLayers bl(mesh);
48 
49  if( layers2D )
50  bl.activate2DMode();
51 
52  if( meshDict.found("boundaryLayers") )
53  {
54  const dictionary& bndLayers = meshDict.subDict("boundaryLayers");
55 
56  if( bndLayers.found("nLayers") )
57  {
58  const label nLayers = readLabel(bndLayers.lookup("nLayers"));
59 
60  if( nLayers > 0 )
62  }
63  else if( bndLayers.found("patchBoundaryLayers") )
64  {
65  const dictionary& patchLayers =
66  bndLayers.subDict("patchBoundaryLayers");
67  const wordList createLayers = patchLayers.toc();
68 
69  forAll(createLayers, patchI)
70  bl.addLayerForPatch(createLayers[patchI]);
71  }
72  }
73  else
74  {
76  }
77 }
78 
80 {
81  meshOptimizer mOpt(mesh);
82 
83  mOpt.optimizeMeshFV();
85  mOpt.untangleMeshFV();
86  mOpt.optimizeBoundaryLayer();
87  mOpt.untangleMeshFV();
88 }
89 
90 void layerRefinement(polyMeshGen& mesh, const dictionary& meshDict)
91 {
92  if( meshDict.isDict("boundaryLayers") )
93  {
94  refineBoundaryLayers refLayers(mesh);
95 
96  refineBoundaryLayers::readSettings(meshDict, refLayers);
97 
98  refLayers.refineLayers();
99 
101  }
102 }
103 
104 int main(int argc, char *argv[])
105 {
106  argList::validOptions.insert("2DLayers", "bool");
107 
108 # include "setRootCase.H"
109 # include "createTime.H"
110 
111  IOdictionary meshDict
112  (
113  IOobject
114  (
115  "meshDict",
116  runTime.system(),
117  runTime,
120  )
121  );
122 
123  //- load the mesh from disk
124  polyMeshGen pmg(runTime);
125  pmg.read();
126 
127  bool is2DLayer(false);
128  if( args.options().found("2DLayers") )
129  is2DLayer = true;
130 
131  //- generate the initial boundary layer
132  generateLayer(pmg, meshDict, is2DLayer);
133 
134  //- optimisation of mesh quality
135  meshOptimisation(pmg);
136 
137  //- perform layer refinement
138  layerRefinement(pmg, meshDict);
139 
140  Info << "Writing mesh" << endl;
141  pmg.write();
142 
143  Info << "End\n" << endl;
144  return 0;
145 }
146 
147 // ************************************************************************* //
Foam::meshOptimizer::optimizeMeshFV
void optimizeMeshFV(const label numLaplaceIterations=5, const label maxNumGlobalIterations=10, const label maxNumIterations=50, const label maxNumSurfaceIterations=2)
final optimisation
Definition: optimizeMeshFV.C:557
Foam::meshOptimizer
Definition: meshOptimizer.H:60
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::refineBoundaryLayers::refineLayers
void refineLayers()
performs refinement based on the given settings
Definition: refineBoundaryLayers.C:326
Foam::meshOptimizer::optimizeLowQualityFaces
void optimizeLowQualityFaces(const label maxNumIterations=10)
Definition: optimizeMeshFV.C:469
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::meshOptimizer::untangleBoundaryLayer
void untangleBoundaryLayer()
Definition: optimizeMeshFV.C:405
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
polyMeshGenModifier.H
Foam::IOobject::MUST_READ
@ MUST_READ
Definition: IOobject.H:108
Foam::polyMeshGen
Definition: polyMeshGen.H:46
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
meshOptimisation
void meshOptimisation(polyMeshGen &mesh)
Definition: generateBoundaryLayers.C:79
Foam::boundaryLayers
Definition: boundaryLayers.H:60
Foam::polyMeshGen::read
void read()
Definition: polyMeshGen.C:121
Foam::IOobject::NO_WRITE
@ NO_WRITE
Definition: IOobject.H:118
Foam::dictionary::isDict
bool isDict(const word &) const
Check if entry is a sub-dictionary.
Definition: dictionary.C:600
refineBoundaryLayers.H
main
int main(int argc, char *argv[])
Definition: generateBoundaryLayers.C:104
Foam::argList::options
const Foam::HashTable< string > & options() const
Return options.
Definition: argListI.H:90
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::dictionary::found
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:304
Foam::Info
messageStream Info
argList.H
Foam::boundaryLayers::addLayerForPatch
void addLayerForPatch(const label patchLabel)
create a bnd layer for a given patch
Definition: boundaryLayers.C:494
Foam::refineBoundaryLayers
Definition: refineBoundaryLayers.H:59
generateLayer
void generateLayer(polyMeshGen &mesh, const dictionary &meshDict, const bool layers2D)
Definition: generateBoundaryLayers.C:41
Foam::boundaryLayers::addLayerForAllPatches
void addLayerForAllPatches()
add layers for all patches
Definition: boundaryLayers.C:653
Foam::argList::validOptions
static HashTable< string > validOptions
A list of valid options.
Definition: argList.H:146
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
setRootCase.H
Foam::meshOptimizer::untangleMeshFV
void untangleMeshFV(const label maxNumGlobalIterations=10, const label maxNumIterations=50, const label maxNumSurfaceIterations=2, const bool relaxedCheck=false)
Definition: optimizeMeshFV.C:57
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::polyMeshGen::write
void write() const
Definition: polyMeshGen.C:126
Foam::boundaryLayers::activate2DMode
void activate2DMode()
Definition: boundaryLayers.C:604
meshOptimizer.H
Foam::meshOptimizer::optimizeBoundaryLayer
void optimizeBoundaryLayer(const bool addBufferLayer=true)
Definition: optimizeMeshFV.C:302
createTime.H
Foam::readLabel
label readLabel(Istream &is)
Definition: label.H:64
Foam::dictionary::toc
wordList toc() const
Return the table of contents.
Definition: dictionary.C:697
Foam::refineBoundaryLayers::readSettings
static void readSettings(const dictionary &, refineBoundaryLayers &)
read the settings from dictionary
Definition: refineBoundaryLayers.C:406
Foam::dictionary::subDict
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:631
args
Foam::argList args(argc, argv)
layerRefinement
void layerRefinement(polyMeshGen &mesh, const dictionary &meshDict)
Definition: generateBoundaryLayers.C:90
boundaryLayers.H