cartesianMeshGenerator.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 "cartesianMeshGenerator.H"
29 #include "triSurf.H"
31 #include "demandDrivenData.H"
32 #include "meshOctreeCreator.H"
33 #include "cartesianMeshExtractor.H"
34 #include "meshSurfaceEngine.H"
35 #include "meshSurfaceMapper.H"
36 #include "edgeExtractor.H"
38 #include "meshOptimizer.H"
39 #include "meshSurfaceOptimizer.H"
40 #include "topologicalCleaner.H"
41 #include "boundaryLayers.H"
42 #include "refineBoundaryLayers.H"
43 #include "renameBoundaryPatches.H"
44 #include "checkMeshDict.H"
49 #include "triSurfaceMetaData.H"
52 
53 //#define DEBUG
54 
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 
57 namespace Foam
58 {
59 
60 // * * * * * * * * * * * * Private member functions * * * * * * * * * * * * //
61 
63 {
64  //- create polyMesh from octree boxes
66 
67  if( meshDict_.found("decomposePolyhedraIntoTetsAndPyrs") )
68  {
69  if( readBool(meshDict_.lookup("decomposePolyhedraIntoTetsAndPyrs")) )
70  cme.decomposeSplitHexes();
71  }
72 
73  cme.createMesh();
74 }
75 
77 {
78  //- removes unnecessary cells and morph the boundary
79  //- such that there is only one boundary face per cell
80  //- It also checks topology of cells after morphing is performed
81  bool changed;
82 
83  do
84  {
85  changed = false;
86 
87  checkIrregularSurfaceConnections checkConnections(mesh_);
88  if( checkConnections.checkAndFixIrregularConnections() )
89  changed = true;
90 
92  changed = true;
93 
94  if( checkCellConnectionsOverFaces(mesh_).checkCellGroups() )
95  changed = true;
96  } while( changed );
97 
99 }
100 
102 {
103  //- calculate mesh surface
105 
106  //- pre-map mesh surface
107  meshSurfaceMapper mapper(mse, *octreePtr_);
108  mapper.preMapVertices();
109 
110  //- map mesh surface on the geometry surface
111  mapper.mapVerticesOntoSurface();
112 
113  //- untangle surface faces
115 }
116 
118 {
119  edgeExtractor extractor(mesh_, *octreePtr_);
120 
121  Info << "Extracting edges" << endl;
122  extractor.extractEdges();
123 
124  extractor.updateMeshPatches();
125 }
126 
128 {
130 }
131 
133 {
136 }
137 
139 {
140  //- add boundary layers
141  boundaryLayers bl(mesh_);
143 }
144 
146 {
147  if( meshDict_.isDict("boundaryLayers") )
148  {
149  refineBoundaryLayers refLayers(mesh_);
150 
152 
153  refLayers.refineLayers();
154 
155  labelLongList pointsInLayer;
156  refLayers.pointsInBndLayer(pointsInLayer);
157 
158  meshOptimizer mOpt(mesh_);
159  mOpt.lockPoints(pointsInLayer);
160  mOpt.untangleBoundaryLayer();
161  }
162 }
163 
165 {
166  //- untangle the surface if needed
167  bool enforceConstraints(false);
168  if( meshDict_.found("enforceGeometryConstraints") )
169  {
170  enforceConstraints =
171  readBool(meshDict_.lookup("enforceGeometryConstraints"));
172  }
173 
174  if( true )
175  {
177  meshSurfaceOptimizer surfOpt(mse, *octreePtr_);
178 
179  if( enforceConstraints )
180  surfOpt.enforceConstraints();
181 
182  surfOpt.optimizeSurface();
183  }
184 
186 
187  //- final optimisation
188  meshOptimizer optimizer(mesh_);
189  if( enforceConstraints )
190  optimizer.enforceConstraints();
191 
192  optimizer.optimizeMeshFV();
193  optimizer.optimizeLowQualityFaces();
194  optimizer.optimizeBoundaryLayer(modSurfacePtr_==NULL);
195  optimizer.untangleMeshFV();
196 
198 
199  if( modSurfacePtr_ )
200  {
202 
203  //- revert the mesh into the original space
204  meshMod.revertGeometryModification();
205 
206  //- delete modified surface mesh
208  }
209 }
210 
212 {
213  if( !meshDict_.found("anisotropicSources") )
214  return;
215 
218 
220  (
221  *octreePtr_,
222  meshDict_
224 
225  //- calculate mesh surface
227 
228  //- pre-map mesh surface
229  meshSurfaceMapper mapper(mse, *octreePtr_);
230 
231  //- map mesh surface on the geometry surface
232  mapper.mapVerticesOntoSurface();
233 
235 }
236 
238 {
240 }
241 
243 {
245 }
246 
248 {
249  try
250  {
251  if( controller_.runCurrentStep("templateGeneration") )
252  {
254  }
255 
256  if( controller_.runCurrentStep("surfaceTopology") )
257  {
259  }
260 
261  if( controller_.runCurrentStep("surfaceProjection") )
262  {
264  }
265 
266  if( controller_.runCurrentStep("patchAssignment") )
267  {
268  extractPatches();
269  }
270 
271  if( controller_.runCurrentStep("edgeExtraction") )
272  {
274 
276  }
277 
278  if( controller_.runCurrentStep("boundaryLayerGeneration") )
279  {
281  }
282 
283  if( controller_.runCurrentStep("meshOptimisation") )
284  {
286 
288  }
289 
290  if( controller_.runCurrentStep("boundaryLayerRefinement") )
291  {
293  }
294 
295  renumberMesh();
296 
298 
300  }
301  catch(const std::string& message)
302  {
303  Info << message << endl;
304  }
305  catch(...)
306  {
307  WarningIn
308  (
309  "void cartesianMeshGenerator::generateMesh()"
310  ) << "Meshing process terminated!" << endl;
311  }
312 }
313 
314 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
315 
317 :
318  db_(time),
319  surfacePtr_(NULL),
320  modSurfacePtr_(NULL),
321  meshDict_
322  (
323  IOobject
324  (
325  "meshDict",
326  db_.system(),
327  db_,
328  IOobject::MUST_READ,
329  IOobject::NO_WRITE
330  )
331  ),
332  octreePtr_(NULL),
333  mesh_(time),
334  controller_(mesh_)
335 {
336  if( true )
337  {
339  }
340 
341  fileName surfaceFile = meshDict_.lookup("surfaceFile");
342  if( Pstream::parRun() )
343  surfaceFile = ".."/surfaceFile;
344 
345  surfacePtr_ = new triSurf(db_.path()/surfaceFile);
346 
347  if( true )
348  {
349  //- save meta data with the mesh (surface mesh + its topology info)
350  triSurfaceMetaData sMetaData(*surfacePtr_);
351  const dictionary& surfMetaDict = sMetaData.metaData();
352 
353  mesh_.metaData().add("surfaceFile", surfaceFile, true);
354  mesh_.metaData().add("surfaceMeta", surfMetaDict, true);
355  }
356 
357  if( surfacePtr_->featureEdges().size() != 0 )
358  {
359  //- create surface patches based on the feature edges
360  //- and update the meshDict based on the given data
362 
363  const triSurf* surfaceWithPatches =
364  manipulator.surfaceWithPatches(&meshDict_);
365 
366  //- delete the old surface and assign the new one
368  surfacePtr_ = surfaceWithPatches;
369  }
370 
371  if( meshDict_.found("anisotropicSources") )
372  {
374 
375  modSurfacePtr_ = surfMod.modifyGeometry();
376 
378  }
379  else
380  {
382  }
383 
385 
386  generateMesh();
387 }
388 
389 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
390 
392 {
396 }
397 
398 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
399 
401 {
402  mesh_.write();
403 }
404 
405 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
406 
407 } // End namespace Foam
408 
409 // ************************************************************************* //
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::cartesianMeshGenerator::projectSurfaceAfterBackScaling
void projectSurfaceAfterBackScaling()
re-project points back on the surface mesh after back-scaling
Definition: cartesianMeshGenerator.C:211
cartesianMeshGenerator.H
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::cartesianMeshGenerator::extractPatches
void extractPatches()
capture edges and corners
Definition: cartesianMeshGenerator.C:117
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::cartesianMeshExtractor
Definition: cartesianMeshExtractor.H:51
Foam::meshOctreeCreator
Definition: meshOctreeCreator.H:57
triSurfacePatchManipulator.H
Foam::checkBoundaryFacesSharingTwoEdges
Definition: checkBoundaryFacesSharingTwoEdges.H:56
Foam::meshOptimizer::untangleBoundaryLayer
void untangleBoundaryLayer()
Definition: optimizeMeshFV.C:405
Foam::removeCells
Given list of cells to remove insert all the topology changes.
Definition: removeCells.H:59
Foam::cartesianMeshGenerator::controller_
workflowControls controller_
workflow controller
Definition: cartesianMeshGenerator.H:78
Foam::checkCellConnectionsOverFaces
Definition: checkCellConnectionsOverFaces.H:48
Foam::cartesianMeshGenerator::surfacePtr_
const triSurf * surfacePtr_
pointer to the surface
Definition: cartesianMeshGenerator.H:63
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
checkIrregularSurfaceConnections.H
renameBoundaryPatches.H
Foam::checkIrregularSurfaceConnections::checkAndFixIrregularConnections
bool checkAndFixIrregularConnections()
find invalid connections and fix them on the fly
Definition: checkIrregularSurfaceConnections.C:73
Foam::meshOptimizer::lockPoints
void lockPoints(const labelListType &)
lock points which shall not be moved
Definition: meshOptimizerI.H:203
Foam::checkIrregularSurfaceConnections
Definition: checkIrregularSurfaceConnections.H:51
Foam::cartesianMeshGenerator::replaceBoundaries
void replaceBoundaries()
replace boundaries
Definition: cartesianMeshGenerator.C:237
Foam::checkMeshDict
Definition: checkMeshDict.H:50
Foam::UPstream::parRun
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:377
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::cartesianMeshGenerator::cartesianMeshGenerator
cartesianMeshGenerator(const cartesianMeshGenerator &)
Disallow default bitwise copy construct.
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::checkBoundaryFacesSharingTwoEdges::improveTopology
bool improveTopology()
Definition: checkBoundaryFacesSharingTwoEdges.C:457
Foam::LongList::size
label size() const
Size of the active part of the list.
Definition: LongListI.H:203
Foam::cartesianMeshGenerator::mesh_
polyMeshGen mesh_
mesh
Definition: cartesianMeshGenerator.H:75
Foam::boundaryLayers
Definition: boundaryLayers.H:60
topologicalCleaner.H
Foam::triSurfFeatureEdges::featureEdges
const edgeLongList & featureEdges() const
access to feature edges
Definition: triSurfFeatureEdgesI.H:44
Foam::cartesianMeshGenerator::db_
const Time & db_
reference to Time
Definition: cartesianMeshGenerator.H:60
cartesianMeshExtractor.H
Foam::cartesianMeshExtractor::decomposeSplitHexes
void decomposeSplitHexes()
decompose split hexes into standard cells
Definition: cartesianMeshExtractor.C:71
Foam::dictionary::isDict
bool isDict(const word &) const
Check if entry is a sub-dictionary.
Definition: dictionary.C:600
Foam::cartesianMeshGenerator::generateBoundaryLayers
void generateBoundaryLayers()
add boundary layers
Definition: cartesianMeshGenerator.C:138
checkNonMappableCellConnections.H
Foam::LongList< label >
Foam::polyMeshGenGeometryModification
Definition: polyMeshGenGeometryModification.H:53
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::cartesianMeshGenerator::generateMesh
void generateMesh()
generate mesh
Definition: cartesianMeshGenerator.C:247
checkMeshDict.H
Foam::cartesianMeshGenerator::optimiseMeshSurface
void optimiseMeshSurface()
optimise surface mesh
Definition: cartesianMeshGenerator.C:132
Foam::cartesianMeshGenerator::mapEdgesAndCorners
void mapEdgesAndCorners()
map points at feature edges and corners
Definition: cartesianMeshGenerator.C:127
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::polyMeshGenCells::clearAddressingData
void clearAddressingData() const
clear addressing data
Definition: polyMeshGenCells.C:346
Foam::refineBoundaryLayers
Definition: refineBoundaryLayers.H:59
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::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::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::cartesianMeshGenerator::~cartesianMeshGenerator
~cartesianMeshGenerator()
Definition: cartesianMeshGenerator.C:391
Foam::cartesianMeshGenerator::meshDict_
IOdictionary meshDict_
IOdictionary containing information about cell sizes, etc..
Definition: cartesianMeshGenerator.H:69
Foam::meshSurfaceMapper::preMapVertices
void preMapVertices(const label nIterations=3)
Definition: meshSurfaceMapperPremapVertices.C:51
Foam::cartesianMeshGenerator::modSurfacePtr_
const triSurf * modSurfacePtr_
pointer to the modified surface
Definition: cartesianMeshGenerator.H:66
checkBoundaryFacesSharingTwoEdges.H
Foam::cartesianMeshGenerator::mapMeshToSurface
void mapMeshToSurface()
map mesh to the surface and untangle surface
Definition: cartesianMeshGenerator.C:101
Foam::cartesianMeshGenerator::renumberMesh
void renumberMesh()
renumber the mesh
Definition: cartesianMeshGenerator.C:242
Foam::checkNonMappableCellConnections
Definition: checkNonMappableCellConnections.H:53
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::cartesianMeshGenerator::surfacePreparation
void surfacePreparation()
prepare mesh surface
Definition: cartesianMeshGenerator.C:76
Foam::meshSurfaceOptimizer::optimizeSurface
void optimizeSurface(const label nIterations=5)
optimize boundary nodes after boundary regions are created
Definition: meshSurfaceOptimizerOptimizeSurface.C:581
Foam::cartesianMeshGenerator::octreePtr_
meshOctree * octreePtr_
pointer to the octree
Definition: cartesianMeshGenerator.H:72
Foam::polyMeshGenGeometryModification::revertGeometryModification
void revertGeometryModification()
revert modification of coorinates
Definition: polyMeshGenGeometryModification.C:97
Foam::meshSurfaceOptimizer::enforceConstraints
void enforceConstraints(const word subsetName="badPoints")
Definition: meshSurfaceOptimizer.C:163
Foam::polyMeshGenModifier
Definition: polyMeshGenModifier.H:52
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::meshSurfaceMapper
Definition: meshSurfaceMapper.H:59
Foam::polyMeshGen::write
void write() const
Definition: polyMeshGen.C:126
Foam::cartesianMeshGenerator::createCartesianMesh
void createCartesianMesh()
create cartesian mesh
Definition: cartesianMeshGenerator.C:62
Foam::meshOctree
Definition: meshOctree.H:55
Foam::cartesianMeshGenerator::optimiseFinalMesh
void optimiseFinalMesh()
mesh optimisation
Definition: cartesianMeshGenerator.C:164
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::meshSurfaceMapper::mapVerticesOntoSurface
void mapVerticesOntoSurface()
Definition: meshSurfaceMapperMapVertices.C:202
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::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::triSurf
Definition: triSurf.H:59
checkCellConnectionsOverFaces.H
Foam::cartesianMeshExtractor::createMesh
void createMesh()
create the mesh with the above options
Definition: cartesianMeshExtractor.C:76
meshSurfaceOptimizer.H
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
Foam::cartesianMeshGenerator::writeMesh
void writeMesh() const
write the mesh
Definition: cartesianMeshGenerator.C:400
Foam::cartesianMeshGenerator::refBoundaryLayers
void refBoundaryLayers()
refine boundary layers
Definition: cartesianMeshGenerator.C:145
triSurfaceMetaData.H