1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | cfMesh: A library for mesh generation
5 \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6 \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
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
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/>.
26 \*---------------------------------------------------------------------------*/
28 #include "refineBoundaryLayers.H"
29 #include "meshSurfaceEngine.H"
30 #include "demandDrivenData.H"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 const meshSurfaceEngine& refineBoundaryLayers::surfaceEngine() const
42 msePtr_ = new meshSurfaceEngine(mesh_);
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49 refineBoundaryLayers::refineBoundaryLayers(polyMeshGen& mesh)
54 globalThicknessRatio_(1.0),
55 globalMaxThicknessFirstLayer_(VGREAT),
57 thicknessRatioForPatch_(),
58 maxThicknessForPatch_(),
59 discontinuousLayersForPatch_(),
67 newVerticesForSplitEdge_(),
72 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
74 refineBoundaryLayers::~refineBoundaryLayers()
76 deleteDemandDrivenData(msePtr_);
79 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
81 void refineBoundaryLayers::avoidRefinement()
87 "void refineBoundaryLayers::avoidRefinement()"
88 ) << "refineLayers is already executed" << exit(FatalError);
92 numLayersForPatch_.clear();
95 void refineBoundaryLayers::activate2DMode()
101 "void refineBoundaryLayers::activate2DMode()"
102 ) << "refineLayers is already executed" << exit(FatalError);
108 void refineBoundaryLayers::setGlobalNumberOfLayers(const label nLayers)
114 "void refineBoundaryLayers::setGlobalNumberOfLayers(const label)"
115 ) << "refineLayers is already executed" << exit(FatalError);
122 "void refineBoundaryLayers::setGlobalNumberOfLayers(const label)"
123 ) << "The specified global number of boundary layers is less than 2"
129 globalNumLayers_ = nLayers;
132 void refineBoundaryLayers::setGlobalThicknessRatio(const scalar thicknessRatio)
138 "void refineBoundaryLayers::setGlobalThicknessRatio(const scalar)"
139 ) << "refineLayers is already executed" << exit(FatalError);
142 if( thicknessRatio < 1.0 )
146 "void refineBoundaryLayers::setGlobalThicknessRatio(const scalar)"
147 ) << "The specified global thickness ratio is less than 1.0" << endl;
152 globalThicknessRatio_ = thicknessRatio;
155 void refineBoundaryLayers::setGlobalMaxThicknessOfFirstLayer
157 const scalar maxThickness
164 "void refineBoundaryLayers::setGlobalMaxThicknessOfFirstLayer"
166 ) << "refineLayers is already executed" << exit(FatalError);
169 if( maxThickness <= 0.0 )
173 "void refineBoundaryLayers::setGlobalMaxThicknessOfFirstLayer"
175 ) << "The specified global maximum thickness of the first"
176 << " boundary layer is negative!!" << endl;
181 globalMaxThicknessFirstLayer_ = maxThickness;
184 void refineBoundaryLayers::setNumberOfLayersForPatch
186 const word& patchName,
194 "void refineBoundaryLayers::setNumberOfLayersForPatch"
195 "(const word&, const label)"
196 ) << "refineLayers is already executed" << exit(FatalError);
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;
209 const labelList matchedIDs = mesh_.findPatches(patchName);
211 forAll(matchedIDs, matchI)
213 numLayersForPatch_[mesh_.getPatchName(matchedIDs[matchI])] = nLayers;
217 void refineBoundaryLayers::setThicknessRatioForPatch
219 const word& patchName,
220 const scalar thicknessRatio
227 "void refineBoundaryLayers::setThicknessRatioForPatch"
228 "(const word&, const scalar)"
229 ) << "refineLayers is already executed" << exit(FatalError);
232 if( thicknessRatio < 1.0 )
236 "void refineBoundaryLayers::setThicknessRatioForPatch"
237 "(const word&, const scalar)"
238 ) << "The specified thickness ratio for patch " << patchName
239 << " is less than 1.0" << endl;
244 const labelList matchedIDs = mesh_.findPatches(patchName);
246 forAll(matchedIDs, matchI)
248 const word pName = mesh_.getPatchName(matchedIDs[matchI]);
249 thicknessRatioForPatch_[pName] = thicknessRatio;
253 void refineBoundaryLayers::setMaxThicknessOfFirstLayerForPatch
255 const word& patchName,
256 const scalar maxThickness
263 "void refineBoundaryLayers::setMaxThicknessOfFirstLayerForPatch"
264 "(const word&, const scalar)"
265 ) << "refineLayers is already executed" << exit(FatalError);
268 if( maxThickness <= 0.0 )
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;
280 const labelList matchedIDs = mesh_.findPatches(patchName);
282 forAll(matchedIDs, matchI)
284 const word pName = mesh_.getPatchName(matchedIDs[matchI]);
285 maxThicknessForPatch_[pName] = maxThickness;
289 void refineBoundaryLayers::setInteruptForPatch(const word& patchName)
295 "void refineBoundaryLayers::setInteruptForPatch(const word&)"
296 ) << "refineLayers is already executed" << exit(FatalError);
299 const labelList matchedIDs = mesh_.findPatches(patchName);
301 forAll(matchedIDs, matchI)
303 const word pName = mesh_.getPatchName(matchedIDs[matchI]);
304 discontinuousLayersForPatch_.insert(pName);
308 void refineBoundaryLayers::setCellSubset(const word subsetName)
314 "void refineBoundaryLayers::setCellSubset(const word)"
315 ) << "refineLayers is already executed" << exit(FatalError);
318 cellSubsetName_ = subsetName;
321 void refineBoundaryLayers::activateSpecialMode()
326 void refineBoundaryLayers::refineLayers()
328 bool refinePatch(false);
331 std::map<word, label>::const_iterator it=numLayersForPatch_.begin();
332 it!=numLayersForPatch_.end();
338 if( (globalNumLayers_ < 2) && !refinePatch )
341 Info << "Starting refining boundary layers" << endl;
347 "void refineBoundaryLayers::refineLayers()"
348 ) << "Boundary layers are already refined! "
349 << "Stopping refinement" << endl;
354 if( !analyseLayers() )
358 "void refineBoundaryLayers::refineLayers()"
359 ) << "Boundary layers do not exist in the mesh! Cannot refine" << endl;
364 generateNewVertices();
372 Info << "Finished refining boundary layers" << endl;
375 void refineBoundaryLayers::pointsInBndLayer(labelLongList& layerPoints)
379 boolList pointInLayer(mesh_.points().size(), false);
381 forAll(newVerticesForSplitEdge_, seI)
383 forAllRow(newVerticesForSplitEdge_, seI, i)
384 pointInLayer[newVerticesForSplitEdge_(seI, i)] = true;
387 forAll(pointInLayer, pointI)
388 if( pointInLayer[pointI] )
389 layerPoints.append(pointI);
392 void refineBoundaryLayers::pointsInBndLayer(const word subsetName)
394 label sId = mesh_.pointSubsetIndex(subsetName);
396 sId = mesh_.addPointSubset(subsetName);
398 forAll(newVerticesForSplitEdge_, seI)
400 forAllRow(newVerticesForSplitEdge_, seI, i)
401 mesh_.addPointToSubset(sId, newVerticesForSplitEdge_(seI, i));
405 void refineBoundaryLayers::readSettings
407 const dictionary& meshDict,
408 refineBoundaryLayers& refLayers
411 if( meshDict.isDict("boundaryLayers") )
413 const dictionary& bndLayers = meshDict.subDict("boundaryLayers");
415 //- read global properties
416 if( bndLayers.found("nLayers") )
418 const label nLayers = readLabel(bndLayers.lookup("nLayers"));
419 refLayers.setGlobalNumberOfLayers(nLayers);
421 if( bndLayers.found("thicknessRatio") )
424 readScalar(bndLayers.lookup("thicknessRatio"));
425 refLayers.setGlobalThicknessRatio(ratio);
427 if( bndLayers.found("maxFirstLayerThickness") )
429 const scalar maxFirstThickness =
430 readScalar(bndLayers.lookup("maxFirstLayerThickness"));
431 refLayers.setGlobalMaxThicknessOfFirstLayer(maxFirstThickness);
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") )
438 const wordList patchNames(bndLayers.lookup("excludedPatches"));
440 forAll(patchNames, patchI)
442 const word pName = patchNames[patchI];
444 refLayers.setNumberOfLayersForPatch(pName, 1);
448 //- patch-based properties
449 if( bndLayers.isDict("patchBoundaryLayers") )
451 const dictionary& patchBndLayers =
452 bndLayers.subDict("patchBoundaryLayers");
453 const wordList patchNames = patchBndLayers.toc();
455 forAll(patchNames, patchI)
457 const word pName = patchNames[patchI];
459 if( patchBndLayers.isDict(pName) )
461 const dictionary& patchDict =
462 patchBndLayers.subDict(pName);
464 if( patchDict.found("nLayers") )
466 const label nLayers =
467 readLabel(patchDict.lookup("nLayers"));
469 refLayers.setNumberOfLayersForPatch(pName, nLayers);
471 if( patchDict.found("thicknessRatio") )
474 readScalar(patchDict.lookup("thicknessRatio"));
475 refLayers.setThicknessRatioForPatch(pName, ratio);
477 if( patchDict.found("maxFirstLayerThickness") )
479 const scalar maxFirstThickness =
482 patchDict.lookup("maxFirstLayerThickness")
484 refLayers.setMaxThicknessOfFirstLayerForPatch
490 if( patchDict.found("allowDiscontinuity") )
492 const bool allowDiscontinuity =
493 readBool(patchDict.lookup("allowDiscontinuity"));
495 if( allowDiscontinuity )
496 refLayers.setInteruptForPatch(pName);
501 Warning << "Cannot refine layer for patch "
502 << patchNames[patchI] << endl;
509 //- the layer will not be refined
510 refLayers.avoidRefinement();
514 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
516 } // End namespace Foam
518 // ************************************************************************* //