refineBoundaryLayers.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 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "refineBoundaryLayers.H"
29 #include "meshSurfaceEngine.H"
30 #include "demandDrivenData.H"
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 
40 {
41  if( !msePtr_ )
43 
44  return *msePtr_;
45 }
46 
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 
50 :
51  mesh_(mesh),
52  msePtr_(NULL),
53  globalNumLayers_(1),
54  globalThicknessRatio_(1.0),
55  globalMaxThicknessFirstLayer_(VGREAT),
56  numLayersForPatch_(),
57  thicknessRatioForPatch_(),
58  maxThicknessForPatch_(),
59  discontinuousLayersForPatch_(),
60  cellSubsetName_(),
61  done_(false),
62  is2DMesh_(false),
63  specialMode_(false),
64  nLayersAtBndFace_(),
65  splitEdges_(),
66  splitEdgesAtPoint_(),
67  newVerticesForSplitEdge_(),
68  facesFromFace_(),
69  newFaces_()
70 {}
71 
72 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
73 
75 {
77 }
78 
79 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
80 
82 {
83  if( done_ )
84  {
86  (
87  "void refineBoundaryLayers::avoidRefinement()"
88  ) << "refineLayers is already executed" << exit(FatalError);
89  }
90 
91  globalNumLayers_ = 1;
92  numLayersForPatch_.clear();
93 }
94 
96 {
97  if( done_ )
98  {
100  (
101  "void refineBoundaryLayers::activate2DMode()"
102  ) << "refineLayers is already executed" << exit(FatalError);
103  }
104 
105  is2DMesh_ = true;
106 }
107 
109 {
110  if( done_ )
111  {
113  (
114  "void refineBoundaryLayers::setGlobalNumberOfLayers(const label)"
115  ) << "refineLayers is already executed" << exit(FatalError);
116  }
117 
118  if( nLayers < 2 )
119  {
120  WarningIn
121  (
122  "void refineBoundaryLayers::setGlobalNumberOfLayers(const label)"
123  ) << "The specified global number of boundary layers is less than 2"
124  << endl;
125 
126  return;
127  }
128 
129  globalNumLayers_ = nLayers;
130 }
131 
132 void refineBoundaryLayers::setGlobalThicknessRatio(const scalar thicknessRatio)
133 {
134  if( done_ )
135  {
137  (
138  "void refineBoundaryLayers::setGlobalThicknessRatio(const scalar)"
139  ) << "refineLayers is already executed" << exit(FatalError);
140  }
141 
142  if( thicknessRatio < 1.0 )
143  {
144  WarningIn
145  (
146  "void refineBoundaryLayers::setGlobalThicknessRatio(const scalar)"
147  ) << "The specified global thickness ratio is less than 1.0" << endl;
148 
149  return;
150  }
151 
152  globalThicknessRatio_ = thicknessRatio;
153 }
154 
156 (
157  const scalar maxThickness
158 )
159 {
160  if( done_ )
161  {
163  (
164  "void refineBoundaryLayers::setGlobalMaxThicknessOfFirstLayer"
165  "(const scalar)"
166  ) << "refineLayers is already executed" << exit(FatalError);
167  }
168 
169  if( maxThickness <= 0.0 )
170  {
171  WarningIn
172  (
173  "void refineBoundaryLayers::setGlobalMaxThicknessOfFirstLayer"
174  "(const scalar)"
175  ) << "The specified global maximum thickness of the first"
176  << " boundary layer is negative!!" << endl;
177 
178  return;
179  }
180 
181  globalMaxThicknessFirstLayer_ = maxThickness;
182 }
183 
185 (
186  const word& patchName,
187  const label nLayers
188 )
189 {
190  if( done_ )
191  {
193  (
194  "void refineBoundaryLayers::setNumberOfLayersForPatch"
195  "(const word&, const label)"
196  ) << "refineLayers is already executed" << exit(FatalError);
197  }
198 
199  if( nLayers < 2 )
200  {
201  WarningIn
202  (
203  "void refineBoundaryLayers::setNumberOfLayersForPatch"
204  "(const word&, const label)"
205  ) << "The specified number of boundary layers for patch " << patchName
206  << " is less than 2... boundary layers disabled for this patch!" << endl;
207  }
208 
209  const labelList matchedIDs = mesh_.findPatches(patchName);
210 
211  forAll(matchedIDs, matchI)
212  {
213  numLayersForPatch_[mesh_.getPatchName(matchedIDs[matchI])] = nLayers;
214  }
215 }
216 
218 (
219  const word& patchName,
220  const scalar thicknessRatio
221 )
222 {
223  if( done_ )
224  {
226  (
227  "void refineBoundaryLayers::setThicknessRatioForPatch"
228  "(const word&, const scalar)"
229  ) << "refineLayers is already executed" << exit(FatalError);
230  }
231 
232  if( thicknessRatio < 1.0 )
233  {
234  WarningIn
235  (
236  "void refineBoundaryLayers::setThicknessRatioForPatch"
237  "(const word&, const scalar)"
238  ) << "The specified thickness ratio for patch " << patchName
239  << " is less than 1.0" << endl;
240 
241  return;
242  }
243 
244  const labelList matchedIDs = mesh_.findPatches(patchName);
245 
246  forAll(matchedIDs, matchI)
247  {
248  const word pName = mesh_.getPatchName(matchedIDs[matchI]);
249  thicknessRatioForPatch_[pName] = thicknessRatio;
250  }
251 }
252 
254 (
255  const word& patchName,
256  const scalar maxThickness
257 )
258 {
259  if( done_ )
260  {
262  (
263  "void refineBoundaryLayers::setMaxThicknessOfFirstLayerForPatch"
264  "(const word&, const scalar)"
265  ) << "refineLayers is already executed" << exit(FatalError);
266  }
267 
268  if( maxThickness <= 0.0 )
269  {
270  WarningIn
271  (
272  "void refineBoundaryLayers::setGlobalMaxThicknessOfFirstLayer"
273  "(const word&, const scalar)"
274  ) << "The specified maximum thickness of the first boundary layer "
275  << "for patch " << patchName << " is negative!!" << endl;
276 
277  return;
278  }
279 
280  const labelList matchedIDs = mesh_.findPatches(patchName);
281 
282  forAll(matchedIDs, matchI)
283  {
284  const word pName = mesh_.getPatchName(matchedIDs[matchI]);
285  maxThicknessForPatch_[pName] = maxThickness;
286  }
287 }
288 
290 {
291  if( done_ )
292  {
294  (
295  "void refineBoundaryLayers::setInteruptForPatch(const word&)"
296  ) << "refineLayers is already executed" << exit(FatalError);
297  }
298 
299  const labelList matchedIDs = mesh_.findPatches(patchName);
300 
301  forAll(matchedIDs, matchI)
302  {
303  const word pName = mesh_.getPatchName(matchedIDs[matchI]);
304  discontinuousLayersForPatch_.insert(pName);
305  }
306 }
307 
309 {
310  if( done_ )
311  {
313  (
314  "void refineBoundaryLayers::setCellSubset(const word)"
315  ) << "refineLayers is already executed" << exit(FatalError);
316  }
317 
318  cellSubsetName_ = subsetName;
319 }
320 
322 {
323  specialMode_ = true;
324 }
325 
327 {
328  bool refinePatch(false);
329  for
330  (
331  std::map<word, label>::const_iterator it=numLayersForPatch_.begin();
332  it!=numLayersForPatch_.end();
333  ++it
334  )
335  if( it->second > 1 )
336  refinePatch = true;
337 
338  if( (globalNumLayers_ < 2) && !refinePatch )
339  return;
340 
341  Info << "Starting refining boundary layers" << endl;
342 
343  if( done_ )
344  {
345  WarningIn
346  (
347  "void refineBoundaryLayers::refineLayers()"
348  ) << "Boundary layers are already refined! "
349  << "Stopping refinement" << endl;
350 
351  return;
352  }
353 
354  if( !analyseLayers() )
355  {
356  WarningIn
357  (
358  "void refineBoundaryLayers::refineLayers()"
359  ) << "Boundary layers do not exist in the mesh! Cannot refine" << endl;
360 
361  return;
362  }
363 
365 
367 
369 
370  done_ = true;
371 
372  Info << "Finished refining boundary layers" << endl;
373 }
374 
376 {
377  layerPoints.clear();
378 
379  boolList pointInLayer(mesh_.points().size(), false);
380 
382  {
384  pointInLayer[newVerticesForSplitEdge_(seI, i)] = true;
385  }
386 
387  forAll(pointInLayer, pointI)
388  if( pointInLayer[pointI] )
389  layerPoints.append(pointI);
390 }
391 
393 {
394  label sId = mesh_.pointSubsetIndex(subsetName);
395  if( sId < 0 )
396  sId = mesh_.addPointSubset(subsetName);
397 
399  {
402  }
403 }
404 
406 (
407  const dictionary& meshDict,
408  refineBoundaryLayers& refLayers
409 )
410 {
411  if( meshDict.isDict("boundaryLayers") )
412  {
413  const dictionary& bndLayers = meshDict.subDict("boundaryLayers");
414 
415  //- read global properties
416  if( bndLayers.found("nLayers") )
417  {
418  const label nLayers = readLabel(bndLayers.lookup("nLayers"));
419  refLayers.setGlobalNumberOfLayers(nLayers);
420  }
421  if( bndLayers.found("thicknessRatio") )
422  {
423  const scalar ratio =
424  readScalar(bndLayers.lookup("thicknessRatio"));
425  refLayers.setGlobalThicknessRatio(ratio);
426  }
427  if( bndLayers.found("maxFirstLayerThickness") )
428  {
429  const scalar maxFirstThickness =
430  readScalar(bndLayers.lookup("maxFirstLayerThickness"));
431  refLayers.setGlobalMaxThicknessOfFirstLayer(maxFirstThickness);
432  }
433 
434  //- consider specified patches for exclusion from boundary layer creation
435  //- implemented by setting the number of layers to 1
436  if( bndLayers.found("excludedPatches") )
437  {
438  const wordList patchNames(bndLayers.lookup("excludedPatches"));
439 
440  forAll(patchNames, patchI)
441  {
442  const word pName = patchNames[patchI];
443 
444  refLayers.setNumberOfLayersForPatch(pName, 1);
445  }
446  }
447 
448  //- patch-based properties
449  if( bndLayers.isDict("patchBoundaryLayers") )
450  {
451  const dictionary& patchBndLayers =
452  bndLayers.subDict("patchBoundaryLayers");
453  const wordList patchNames = patchBndLayers.toc();
454 
455  forAll(patchNames, patchI)
456  {
457  const word pName = patchNames[patchI];
458 
459  if( patchBndLayers.isDict(pName) )
460  {
461  const dictionary& patchDict =
462  patchBndLayers.subDict(pName);
463 
464  if( patchDict.found("nLayers") )
465  {
466  const label nLayers =
467  readLabel(patchDict.lookup("nLayers"));
468 
469  refLayers.setNumberOfLayersForPatch(pName, nLayers);
470  }
471  if( patchDict.found("thicknessRatio") )
472  {
473  const scalar ratio =
474  readScalar(patchDict.lookup("thicknessRatio"));
475  refLayers.setThicknessRatioForPatch(pName, ratio);
476  }
477  if( patchDict.found("maxFirstLayerThickness") )
478  {
479  const scalar maxFirstThickness =
480  readScalar
481  (
482  patchDict.lookup("maxFirstLayerThickness")
483  );
485  (
486  pName,
487  maxFirstThickness
488  );
489  }
490  if( patchDict.found("allowDiscontinuity") )
491  {
492  const bool allowDiscontinuity =
493  readBool(patchDict.lookup("allowDiscontinuity"));
494 
495  if( allowDiscontinuity )
496  refLayers.setInteruptForPatch(pName);
497  }
498  }
499  else
500  {
501  Warning << "Cannot refine layer for patch "
502  << patchNames[patchI] << endl;
503  }
504  }
505  }
506  }
507  else
508  {
509  //- the layer will not be refined
510  refLayers.avoidRefinement();
511  }
512 }
513 
514 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
515 
516 } // End namespace Foam
517 
518 // ************************************************************************* //
Foam::refineBoundaryLayers::specialMode_
bool specialMode_
Definition: refineBoundaryLayers.H:100
Foam::refineBoundaryLayers::globalThicknessRatio_
scalar globalThicknessRatio_
global thickness ratio
Definition: refineBoundaryLayers.H:71
Foam::refineBoundaryLayers::refineLayers
void refineLayers()
performs refinement based on the given settings
Definition: refineBoundaryLayers.C:326
Foam::refineBoundaryLayers::generateNewFaces
void generateNewFaces()
map split edges onto a cell
Definition: refineBoundaryLayersFaces.C:815
Foam::refineBoundaryLayers::setGlobalThicknessRatio
void setGlobalThicknessRatio(const scalar thicknessRatio)
set the global thickness ratio (default is 1)
Definition: refineBoundaryLayers.C:132
Foam::LongList::append
void append(const T &e)
Append an element at the end of the list.
Definition: LongListI.H:265
Foam::refineBoundaryLayers::pointsInBndLayer
void pointsInBndLayer(labelLongList &)
provide the list of points in the boundary layer
Definition: refineBoundaryLayers.C:375
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::refineBoundaryLayers::surfaceEngine
const meshSurfaceEngine & surfaceEngine() const
Return reference to meshSurfaceEngine.
Definition: refineBoundaryLayers.C:39
Foam::refineBoundaryLayers::is2DMesh_
bool is2DMesh_
a flag whether a 2D mesh generation is active or not
Definition: refineBoundaryLayers.H:96
Foam::refineBoundaryLayers::msePtr_
meshSurfaceEngine * msePtr_
pointer to mesh surface engine
Definition: refineBoundaryLayers.H:65
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::polyMeshGenFaces::findPatches
labelList findPatches(const word &patchName) const
return a list of patch indices corresponding to the given
Definition: polyMeshGenFaces.C:247
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
Foam::Warning
messageStream Warning
Foam::LongList::clear
void clear()
Clear the list, i.e. set next free to zero.
Definition: LongListI.H:230
Foam::refineBoundaryLayers::numLayersForPatch_
std::map< word, label > numLayersForPatch_
number of boundary layers for user-selected patches
Definition: refineBoundaryLayers.H:77
Foam::refineBoundaryLayers::refineBoundaryLayers
refineBoundaryLayers(const refineBoundaryLayers &)
Disallow bitwise copy construct.
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
Foam::refineBoundaryLayers::generateNewVertices
void generateNewVertices()
generate new points on edges, faces and in cells
Definition: refineBoundaryLayersFunctions.C:322
Foam::refineBoundaryLayers::setMaxThicknessOfFirstLayerForPatch
void setMaxThicknessOfFirstLayerForPatch(const word &patchName, const scalar maxThickness)
set the maximum thickness of the first layer for a patch
Definition: refineBoundaryLayers.C:254
Foam::refineBoundaryLayers::setGlobalNumberOfLayers
void setGlobalNumberOfLayers(const label nLayers)
set the global number of boundary layers
Definition: refineBoundaryLayers.C:108
Foam::polyMeshGen
Definition: polyMeshGen.H:46
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::polyMeshGenPoints::points
const pointFieldPMG & points() const
access to points
Definition: polyMeshGenPointsI.H:44
Foam::refineBoundaryLayers::activateSpecialMode
void activateSpecialMode()
Definition: refineBoundaryLayers.C:321
Foam::refineBoundaryLayers::discontinuousLayersForPatch_
std::set< word > discontinuousLayersForPatch_
allow discontinuous layers for patch
Definition: refineBoundaryLayers.H:86
Foam::polyMeshGenPoints::pointSubsetIndex
label pointSubsetIndex(const word &) const
Definition: polyMeshGenPoints.C:135
Foam::dictionary::isDict
bool isDict(const word &) const
Check if entry is a sub-dictionary.
Definition: dictionary.C:600
Foam::refineBoundaryLayers::cellSubsetName_
word cellSubsetName_
Definition: refineBoundaryLayers.H:90
Foam::LongList< label >
Foam::deleteDemandDrivenData
void deleteDemandDrivenData(DataPtr &dataPtr)
Definition: demandDrivenData.H:40
refineBoundaryLayers.H
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::refineBoundaryLayers::done_
bool done_
check whether the refinement is already executed
Definition: refineBoundaryLayers.H:93
Foam::Info
messageStream Info
Foam::refineBoundaryLayers
Definition: refineBoundaryLayers.H:59
forAllRow
#define forAllRow(graph, rowI, index)
Definition: VRWGraph.H:277
Foam::polyMeshGenFaces::getPatchName
word getPatchName(const label patchID) const
return the name of a patch given its ID
Definition: polyMeshGenFaces.C:233
patchNames
wordList patchNames(nPatches)
Foam::refineBoundaryLayers::setNumberOfLayersForPatch
void setNumberOfLayersForPatch(const word &patchName, const label nLayers)
Definition: refineBoundaryLayers.C:185
Foam::pointFieldPMG::size
label size() const
return the number of used elements
Definition: pointFieldPMGI.H:71
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::refineBoundaryLayers::globalNumLayers_
label globalNumLayers_
global number of boundary layers
Definition: refineBoundaryLayers.H:68
Foam::polyMeshGenPoints::addPointToSubset
void addPointToSubset(const label, const label)
Definition: polyMeshGenPointsI.H:60
Foam::refineBoundaryLayers::setThicknessRatioForPatch
void setThicknessRatioForPatch(const word &patchName, const scalar thicknessRatio)
Definition: refineBoundaryLayers.C:218
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
meshSurfaceEngine.H
Foam::refineBoundaryLayers::setCellSubset
void setCellSubset(const word subsetName="layerCells")
set the flag to store the boundary layer cells in a subset
Definition: refineBoundaryLayers.C:308
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::refineBoundaryLayers::~refineBoundaryLayers
~refineBoundaryLayers()
Definition: refineBoundaryLayers.C:74
Foam::refineBoundaryLayers::analyseLayers
bool analyseLayers()
analyse layers to check their topology
Definition: refineBoundaryLayersFunctions.C:57
Foam::readScalar
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
Definition: doubleScalar.H:63
Foam::refineBoundaryLayers::setGlobalMaxThicknessOfFirstLayer
void setGlobalMaxThicknessOfFirstLayer(const scalar maxThickness)
set the maximum thickness of the first boundary layer
Definition: refineBoundaryLayers.C:156
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::refineBoundaryLayers::generateNewCells
void generateNewCells()
generate new cells and add them to the mesh
Definition: refineBoundaryLayersCells.C:1325
Foam::readLabel
label readLabel(Istream &is)
Definition: label.H:64
Foam::refineBoundaryLayers::setInteruptForPatch
void setInteruptForPatch(const word &patchName)
Definition: refineBoundaryLayers.C:289
FatalErrorIn
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:313
WarningIn
#define WarningIn(functionName)
Report a warning using Foam::Warning.
Definition: messageStream.H:254
Foam::readBool
bool readBool(Istream &)
Definition: boolIO.C:60
Foam::dictionary::toc
wordList toc() const
Return the table of contents.
Definition: dictionary.C:697
Foam::refineBoundaryLayers::activate2DMode
void activate2DMode()
activate 2D layer refinement
Definition: refineBoundaryLayers.C:95
Foam::refineBoundaryLayers::readSettings
static void readSettings(const dictionary &, refineBoundaryLayers &)
read the settings from dictionary
Definition: refineBoundaryLayers.C:406
Foam::refineBoundaryLayers::avoidRefinement
void avoidRefinement()
set no refinement flag
Definition: refineBoundaryLayers.C:81
Foam::dictionary::subDict
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:631
Foam::refineBoundaryLayers::mesh_
polyMeshGen & mesh_
Reference to the mesh.
Definition: refineBoundaryLayers.H:62
Foam::polyMeshGenPoints::addPointSubset
label addPointSubset(const word &)
point subsets
Definition: polyMeshGenPoints.C:88
Foam::refineBoundaryLayers::newVerticesForSplitEdge_
VRWGraph newVerticesForSplitEdge_
new vertices for on edges which shall be refined
Definition: refineBoundaryLayers.H:120
Foam::meshSurfaceEngine
Definition: meshSurfaceEngine.H:54