tetMeshGenerator.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 "tetMeshGenerator.H"
29 #include "triSurf.H"
30 #include "demandDrivenData.H"
31 #include "meshOctreeCreator.H"
32 #include "tetMeshExtractorOctree.H"
33 #include "meshSurfaceEngine.H"
34 #include "meshSurfaceMapper.H"
35 #include "edgeExtractor.H"
37 #include "surfaceMorpherCells.H"
38 #include "meshOptimizer.H"
39 #include "meshSurfaceOptimizer.H"
40 #include "topologicalCleaner.H"
41 #include "boundaryLayers.H"
42 #include "renameBoundaryPatches.H"
43 #include "checkMeshDict.H"
45 #include "refineBoundaryLayers.H"
46 #include "triSurfaceMetaData.H"
49 
50 //#define DEBUG
51 
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 
54 namespace Foam
55 {
56 
57 // * * * * * * * * * * * * Private member functions * * * * * * * * * * * * //
58 
60 {
61  //- create tet Mesh from octree and Delaunay tets
63 
64  tme.createMesh();
65 }
66 
68 {
69  //- removes unnecessary cells and morph the boundary
70  //- such that there is only one boundary face per cell
71  //- It also checks topology of cells after morphing is performed
72  do
73  {
75  cmPtr->morphMesh();
77  }
78  while( topologicalCleaner(mesh_).cleanTopology() );
79 }
80 
82 {
83  //- calculate mesh surface
85 
86  //- map mesh surface on the geometry surface
88 
89  //- untangle surface faces
91 
92  deleteDemandDrivenData(msePtr);
93 }
94 
96 {
97  edgeExtractor extractor(mesh_, *octreePtr_);
98 
99  Info << "Extracting edges" << endl;
100  extractor.extractEdges();
101 
102  extractor.updateMeshPatches();
103 }
104 
106 {
108 }
109 
111 {
114 }
115 
117 {
118  if( meshDict_.found("boundaryLayers") )
119  {
120  boundaryLayers bl(mesh_);
121 
122  const dictionary& bndLayers = meshDict_.subDict("boundaryLayers");
123 
124  if( bndLayers.found("nLayers") )
125  {
126  const label nLayers = readLabel(bndLayers.lookup("nLayers"));
127 
128  if( nLayers > 0 )
130  }
131  else if( bndLayers.found("patchBoundaryLayers") )
132  {
133  const dictionary& patchLayers =
134  bndLayers.subDict("patchBoundaryLayers");
135  const wordList createLayers = patchLayers.toc();
136 
137  forAll(createLayers, patchI)
138  bl.addLayerForPatch(createLayers[patchI]);
139  }
140  }
141 }
142 
144 {
145  //- final optimisation
146  bool enforceConstraints(false);
147  if( meshDict_.found("enforceGeometryConstraints") )
148  {
149  enforceConstraints =
150  readBool(meshDict_.lookup("enforceGeometryConstraints"));
151  }
152 
153  meshOptimizer optimizer(mesh_);
154  if( enforceConstraints )
155  optimizer.enforceConstraints();
156 
157  optimizer.optimizeSurface(*octreePtr_);
158 
159  optimizer.optimizeMeshFV();
160  optimizer.optimizeLowQualityFaces();
161  optimizer.optimizeBoundaryLayer(false);
162  optimizer.untangleMeshFV();
163 
165 
167 
168  if( modSurfacePtr_ )
169  {
171 
172  //- revert the mesh into the original space
173  meshMod.revertGeometryModification();
174 
175  //- delete modified surface mesh
177  }
178 }
179 
181 {
182  if( !meshDict_.found("anisotropicSources") )
183  return;
184 
187 
189  (
190  *octreePtr_,
191  meshDict_
193 
194  //- calculate mesh surface
196 
197  //- pre-map mesh surface
198  meshSurfaceMapper mapper(mse, *octreePtr_);
199 
200  //- map mesh surface on the geometry surface
201  mapper.mapVerticesOntoSurface();
202 
204 }
205 
207 {
208  if( meshDict_.isDict("boundaryLayers") )
209  {
210  refineBoundaryLayers refLayers(mesh_);
211 
213 
214  refLayers.refineLayers();
215 
216  labelLongList pointsInLayer;
217  refLayers.pointsInBndLayer(pointsInLayer);
218 
219  meshOptimizer opt(mesh_);
220  opt.lockPoints(pointsInLayer);
221  opt.untangleBoundaryLayer();
222  }
223 }
224 
226 {
228 }
229 
231 {
233 }
234 
236 {
237  try
238  {
239  if( controller_.runCurrentStep("templateGeneration") )
240  {
241  createTetMesh();
242  }
243 
244  if( controller_.runCurrentStep("surfaceTopology") )
245  {
247  }
248 
249  if( controller_.runCurrentStep("surfaceProjection") )
250  {
252  }
253 
254  if( controller_.runCurrentStep("patchAssignment") )
255  {
256  extractPatches();
257  }
258 
259  if( controller_.runCurrentStep("edgeExtraction") )
260  {
262 
264  }
265 
266  if( controller_.runCurrentStep("boundaryLayerGeneration") )
267  {
269  }
270 
271  if( controller_.runCurrentStep("meshOptimisation") )
272  {
274 
276  }
277 
278  if( controller_.runCurrentStep("boundaryLayerRefinement") )
279  {
281  }
282 
283  renumberMesh();
284 
286 
288  }
289  catch(const std::string& message)
290  {
291  Info << message << endl;
292  }
293  catch(...)
294  {
295  WarningIn
296  (
297  "void tetMeshGenerator::generateMesh()"
298  ) << "Meshing process terminated!" << endl;
299  }
300 }
301 
302 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
303 
304 // Construct from Time
306 :
307  runTime_(time),
308  surfacePtr_(NULL),
309  modSurfacePtr_(NULL),
310  meshDict_
311  (
312  IOobject
313  (
314  "meshDict",
315  runTime_.system(),
316  runTime_,
317  IOobject::MUST_READ,
318  IOobject::NO_WRITE
319  )
320  ),
321  octreePtr_(NULL),
322  mesh_(time),
323  controller_(mesh_)
324 {
325  if( true )
326  {
328  }
329 
330  const fileName surfaceFile = meshDict_.lookup("surfaceFile");
331 
332  surfacePtr_ = new triSurf(runTime_.path()/surfaceFile);
333 
334  if( true )
335  {
336  //- save meta data with the mesh (surface mesh + its topology info)
337  triSurfaceMetaData sMetaData(*surfacePtr_);
338  const dictionary& surfMetaDict = sMetaData.metaData();
339 
340  mesh_.metaData().add("surfaceFile", surfaceFile, true);
341  mesh_.metaData().add("surfaceMeta", surfMetaDict, true);
342  }
343 
344  if( surfacePtr_->featureEdges().size() != 0 )
345  {
346  //- create surface patches based on the feature edges
347  //- and update the meshDict based on the given data
349 
350  const triSurf* surfaceWithPatches =
351  manipulator.surfaceWithPatches(&meshDict_);
352 
353  //- delete the old surface and assign the new one
355  surfacePtr_ = surfaceWithPatches;
356  }
357 
358  if( meshDict_.found("anisotropicSources") )
359  {
361 
362  modSurfacePtr_ = surfMod.modifyGeometry();
363 
365  }
366  else
367  {
369  }
370 
372 
373  generateMesh();
374 }
375 
376 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
377 
379 {
383 }
384 
385 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
386 
388 {
389  mesh_.write();
390 }
391 
392 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
393 
394 } // End namespace Foam
395 
396 // ************************************************************************* //
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::workflowControls::runCurrentStep
bool runCurrentStep(const word &)
shall the process run the current step
Definition: workflowControls.C:276
Foam::tetMeshGenerator::createTetMesh
void createTetMesh()
create cartesian mesh
Definition: tetMeshGenerator.C:59
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::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
triSurf.H
Foam::refineBoundaryLayers::pointsInBndLayer
void pointsInBndLayer(labelLongList &)
provide the list of points in the boundary layer
Definition: refineBoundaryLayers.C:375
Foam::meshOptimizer::optimizeLowQualityFaces
void optimizeLowQualityFaces(const label maxNumIterations=10)
Definition: optimizeMeshFV.C:469
meshSurfaceMapper.H
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::meshOctreeCreator
Definition: meshOctreeCreator.H:57
triSurfacePatchManipulator.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::tetMeshGenerator::optimiseFinalMesh
void optimiseFinalMesh()
mesh optimisation
Definition: tetMeshGenerator.C:143
Foam::meshOptimizer::untangleBoundaryLayer
void untangleBoundaryLayer()
Definition: optimizeMeshFV.C:405
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
renameBoundaryPatches.H
Foam::meshOptimizer::lockPoints
void lockPoints(const labelListType &)
lock points which shall not be moved
Definition: meshOptimizerI.H:203
Foam::checkMeshDict
Definition: checkMeshDict.H:50
Foam::tetMeshGenerator::~tetMeshGenerator
~tetMeshGenerator()
Definition: tetMeshGenerator.C:378
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
tetMeshGenerator.H
Foam::tetMeshGenerator::generateMesh
void generateMesh()
generate mesh
Definition: tetMeshGenerator.C:235
Foam::tetMeshGenerator::runTime_
const Time & runTime_
reference to Time
Definition: tetMeshGenerator.H:60
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::LongList::size
label size() const
Size of the active part of the list.
Definition: LongListI.H:203
Foam::boundaryLayers
Definition: boundaryLayers.H:60
Foam::tetMeshGenerator::replaceBoundaries
void replaceBoundaries()
replace boundaries
Definition: tetMeshGenerator.C:225
Foam::tetMeshGenerator::optimiseMeshSurface
void optimiseMeshSurface()
optimise surface mesh
Definition: tetMeshGenerator.C:110
topologicalCleaner.H
Foam::triSurfFeatureEdges::featureEdges
const edgeLongList & featureEdges() const
access to feature edges
Definition: triSurfFeatureEdgesI.H:44
Foam::tetMeshGenerator::refBoundaryLayers
void refBoundaryLayers()
refine boundary layers
Definition: tetMeshGenerator.C:206
Foam::dictionary::isDict
bool isDict(const word &) const
Check if entry is a sub-dictionary.
Definition: dictionary.C:600
Foam::tetMeshExtractorOctree
Definition: tetMeshExtractorOctree.H:51
Foam::LongList< label >
Foam::polyMeshGenGeometryModification
Definition: polyMeshGenGeometryModification.H:53
Foam::tetMeshGenerator::writeMesh
void writeMesh() const
write the mesh
Definition: tetMeshGenerator.C:387
Foam::deleteDemandDrivenData
void deleteDemandDrivenData(DataPtr &dataPtr)
Definition: demandDrivenData.H:40
polyMeshGenGeometryModification.H
refineBoundaryLayers.H
Foam::meshSurfaceOptimizer::untangleSurface
bool untangleSurface(const labelLongList &activeBoundaryPoints, const label nAdditionalLayers=0)
runs a surface smoother on the selected boundary points
Definition: meshSurfaceOptimizerOptimizeSurface.C:327
Foam::tetMeshGenerator::renumberMesh
void renumberMesh()
renumber the mesh
Definition: tetMeshGenerator.C:230
Foam::tetMeshGenerator::extractPatches
void extractPatches()
capture edges and corners
Definition: tetMeshGenerator.C:95
checkMeshDict.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::Info
messageStream Info
meshSurfaceEdgeExtractorNonTopo.H
Foam::boundaryLayers::addLayerForPatch
void addLayerForPatch(const label patchLabel)
create a bnd layer for a given patch
Definition: boundaryLayers.C:494
Foam::polyMeshGenCells::clearAddressingData
void clearAddressingData() const
clear addressing data
Definition: polyMeshGenCells.C:346
Foam::refineBoundaryLayers
Definition: refineBoundaryLayers.H:59
Foam::tetMeshGenerator::mesh_
polyMeshGen mesh_
mesh
Definition: tetMeshGenerator.H:75
surfaceMorpherCells.H
Foam::renameBoundaryPatches
Definition: renameBoundaryPatches.H:51
Foam::triSurfacePatchManipulator::surfaceWithPatches
const triSurf * surfaceWithPatches(IOdictionary *meshDictPtr=NULL, const word prefix="patch_", const bool forceOverwrite=false) const
store regions into subsets with a given prefix
Definition: triSurfacePatchManipulator.C:86
Foam::meshOctreeCreator::createOctreeWithRefinedBoundary
void createOctreeWithRefinedBoundary(const direction maxLevel, const label nTrianglesInLeaf=15)
Definition: meshOctreeCreatorCreateOctreeBoxes.C:498
Foam::tetMeshGenerator::meshDict_
IOdictionary meshDict_
IOdictionary containing information about cell sizes, etc..
Definition: tetMeshGenerator.H:69
Foam::topologicalCleaner
Definition: topologicalCleaner.H:50
Foam::workflowControls::workflowCompleted
void workflowCompleted()
set the workflow completed flag
Definition: workflowControls.C:323
Foam::boundaryLayers::addLayerForAllPatches
void addLayerForAllPatches()
add layers for all patches
Definition: boundaryLayers.C:653
Foam::meshOctreeCreator::createOctreeBoxes
void createOctreeBoxes()
create octree boxes
Definition: meshOctreeCreatorCreateOctreeBoxes.C:448
Foam::polyMeshGen::metaData
const dictionary & metaData() const
return a constant reference to metaDict
Definition: polyMeshGen.H:86
Foam::tetMeshExtractorOctree::createMesh
void createMesh()
Definition: tetMeshExtractorOctree.C:262
Foam::triSurfaceMetaData
Definition: triSurfaceMetaData.H:54
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::surfaceMeshGeometryModification
Definition: surfaceMeshGeometryModification.H:55
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
meshSurfaceEngine.H
Foam::meshSurfaceEdgeExtractorNonTopo
Definition: meshSurfaceEdgeExtractorNonTopo.H:51
Foam::meshOptimizer::enforceConstraints
void enforceConstraints(const word subsetName="badPoints")
Definition: meshOptimizer.C:192
Foam::edgeExtractor::updateMeshPatches
void updateMeshPatches()
update mesh with selected patches
Definition: edgeExtractor.C:2544
Foam::polyMeshGenModifier::renumberMesh
void renumberMesh()
reorder the cells and faces to reduce the matrix bandwidth
Definition: polyMeshGenModifierRenumberMesh.C:42
Foam::surfaceMorpherCells::morphMesh
void morphMesh()
Definition: surfaceMorpherCells.C:81
Foam::surfaceMorpherCells
Definition: surfaceMorpherCells.H:51
Foam::meshSurfaceOptimizer::optimizeSurface
void optimizeSurface(const label nIterations=5)
optimize boundary nodes after boundary regions are created
Definition: meshSurfaceOptimizerOptimizeSurface.C:581
Foam::polyMeshGenGeometryModification::revertGeometryModification
void revertGeometryModification()
revert modification of coorinates
Definition: polyMeshGenGeometryModification.C:97
Foam::tetMeshGenerator::tetMeshGenerator
tetMeshGenerator(const tetMeshGenerator &)
Disallow default bitwise copy construct.
Foam::polyMeshGenModifier
Definition: polyMeshGenModifier.H:52
Foam::tetMeshGenerator::surfacePtr_
const triSurf * surfacePtr_
pointer to the surface
Definition: tetMeshGenerator.H:63
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::triSurfacePatchManipulator
Definition: triSurfacePatchManipulator.H:52
Foam::Time::path
fileName path() const
Return path.
Definition: Time.H:281
edgeExtractor.H
Foam::meshSurfaceOptimizer
Definition: meshSurfaceOptimizer.H:63
Foam::surfaceMeshGeometryModification::modifyGeometry
const triSurf * modifyGeometry() const
modify coordinates
Definition: surfaceMeshGeometryModification.C:77
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::meshSurfaceMapper
Definition: meshSurfaceMapper.H:59
Foam::polyMeshGen::write
void write() const
Definition: polyMeshGen.C:126
Foam::meshOctree
Definition: meshOctree.H:55
meshOptimizer.H
edgeExtractor
A class with a functions used to detect feature edges in the surface of the volume mesh and to detect...
Foam::meshOptimizer::optimizeBoundaryLayer
void optimizeBoundaryLayer(const bool addBufferLayer=true)
Definition: optimizeMeshFV.C:302
Foam::tetMeshGenerator::controller_
workflowControls controller_
workflow controller
Definition: tetMeshGenerator.H:78
Foam::readLabel
label readLabel(Istream &is)
Definition: label.H:64
Foam::meshOptimizer::optimizeSurface
void optimizeSurface(const meshOctree &)
smooth surface vertices
Definition: meshOptimizerOptimizeSurface.C:44
Foam::tetMeshGenerator::surfacePreparation
void surfacePreparation()
prepare mesh surface
Definition: tetMeshGenerator.C:67
Foam::meshSurfaceMapper::mapVerticesOntoSurface
void mapVerticesOntoSurface()
Definition: meshSurfaceMapperMapVertices.C:202
Foam::tetMeshGenerator::projectSurfaceAfterBackScaling
void projectSurfaceAfterBackScaling()
re-project points back on the surface mesh after back-scaling
Definition: tetMeshGenerator.C:180
Foam::tetMeshGenerator::octreePtr_
meshOctree * octreePtr_
pointer to the octree
Definition: tetMeshGenerator.H:72
Foam::tetMeshGenerator::mapMeshToSurface
void mapMeshToSurface()
map mesh to the surface and untangle surface
Definition: tetMeshGenerator.C:81
WarningIn
#define WarningIn(functionName)
Report a warning using Foam::Warning.
Definition: messageStream.H:254
Foam::readBool
bool readBool(Istream &)
Definition: boolIO.C:60
meshOctreeCreator.H
Foam::dictionary::toc
wordList toc() const
Return the table of contents.
Definition: dictionary.C:697
Foam::triSurfaceMetaData::metaData
const dictionary & metaData() const
return a constant reference to meta data
Definition: triSurfaceMetaData.H:88
Foam::refineBoundaryLayers::readSettings
static void readSettings(const dictionary &, refineBoundaryLayers &)
read the settings from dictionary
Definition: refineBoundaryLayers.C:406
Foam::tetMeshGenerator::modSurfacePtr_
const triSurf * modSurfacePtr_
pointer to the modified surface mesh
Definition: tetMeshGenerator.H:66
tetMeshExtractorOctree.H
Foam::dictionary::subDict
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:631
Foam::tetMeshGenerator::mapEdgesAndCorners
void mapEdgesAndCorners()
capture edges and corners
Definition: tetMeshGenerator.C:105
Foam::triSurf
Definition: triSurf.H:59
meshSurfaceOptimizer.H
Foam::tetMeshGenerator::generateBoundaryLayers
void generateBoundaryLayers()
add boundary layers
Definition: tetMeshGenerator.C:116
Foam::system
int system(const std::string &command)
Execute the specified command.
Definition: POSIX.C:1155
boundaryLayers.H
Foam::edgeExtractor::extractEdges
void extractEdges()
assemble the above functionality into a workflow
Definition: edgeExtractor.C:2398
Foam::meshSurfaceEngine
Definition: meshSurfaceEngine.H:54
Foam::dictionary::add
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:729
surfaceMeshGeometryModification.H
triSurfaceMetaData.H