cartesian2DMeshGenerator.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 
29 #include "triSurface2DCheck.H"
30 #include "polyMeshGen2DEngine.H"
31 #include "triSurf.H"
34 #include "demandDrivenData.H"
35 #include "meshOctreeCreator.H"
36 #include "cartesianMeshExtractor.H"
37 #include "meshSurfaceEngine.H"
38 #include "meshSurfaceMapper2D.H"
40 #include "meshSurfaceOptimizer.H"
41 #include "topologicalCleaner.H"
42 #include "boundaryLayers.H"
43 #include "refineBoundaryLayers.H"
44 #include "renameBoundaryPatches.H"
45 #include "checkMeshDict.H"
50 #include "triSurfaceMetaData.H"
53 
54 //#define DEBUG
55 
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 
58 namespace Foam
59 {
60 
61 // * * * * * * * * * * * * Private member functions * * * * * * * * * * * * //
62 
64 {
65  //- create polyMesh from octree boxes
67 
68  if( meshDict_.found("decomposePolyhedraIntoTetsAndPyrs") )
69  {
70  if( readBool(meshDict_.lookup("decomposePolyhedraIntoTetsAndPyrs")) )
71  cme.decomposeSplitHexes();
72  }
73 
74  cme.createMesh();
75 }
76 
78 {
79  //- removes unnecessary cells and morph the boundary
80  //- such that there is only one boundary face per cell
81  //- It also checks topology of cells after morphing is performed
82  bool changed;
83 
84  do
85  {
86  changed = false;
87 
88  checkIrregularSurfaceConnections checkConnections(mesh_);
89  if( checkConnections.checkAndFixIrregularConnections() )
90  changed = true;
91 
93  changed = true;
94 
95  if( checkCellConnectionsOverFaces(mesh_).checkCellGroups() )
96  changed = true;
97  } while( changed );
98 
100 }
101 
103 {
104  //- calculate mesh surface
106 
107  //- pre-map mesh surface
108  meshSurfaceMapper2D mapper(*msePtr, *octreePtr_);
109 
110  mapper.adjustZCoordinates();
111 
112  mapper.preMapVertices();
113 
114  //- map mesh surface on the geometry surface
115  mapper.mapVerticesOntoSurface();
116 
117  deleteDemandDrivenData(msePtr);
118 }
119 
121 {
123 }
124 
126 {
128 }
129 
131 {
133  meshSurfaceOptimizer optimizer(mse, *octreePtr_);
134  optimizer.optimizeSurface2D();
135  optimizer.untangleSurface2D();
136 }
137 
139 {
140  boundaryLayers bl(mesh_);
141 
142  bl.activate2DMode();
143 
145 
146  if( modSurfacePtr_ )
147  {
149 
150  //- revert the mesh into the original space
151  meshMod.revertGeometryModification();
152 
153  //- delete modified surface mesh
155 
156  //- delete the octree
158 
159  //- contruct a new octree from the input surface
160  octreePtr_ = new meshOctree(*surfacePtr_, true);
162 
164 
166  }
167 }
168 
170 {
171  if( meshDict_.isDict("boundaryLayers") )
172  {
173  refineBoundaryLayers refLayers(mesh_);
174 
176 
177  refLayers.activate2DMode();
178 
179  refLayers.refineLayers();
180 
182  meshSurfaceOptimizer optimizer(mse, *octreePtr_);
183 
184  optimizer.untangleSurface2D();
185  }
186 }
187 
189 {
191 }
192 
194 {
196 }
197 
199 {
200  try
201  {
202  if( controller_.runCurrentStep("templateGeneration") )
203  {
205  }
206 
207  if( controller_.runCurrentStep("surfaceTopology") )
208  {
210  }
211 
212  if( controller_.runCurrentStep("surfaceProjection") )
213  {
215  }
216 
217  if( controller_.runCurrentStep("patchAssignment") )
218  {
219  extractPatches();
220  }
221 
222  if( controller_.runCurrentStep("edgeExtraction") )
223  {
225 
227  }
228 
229  if( controller_.runCurrentStep("boundaryLayerGeneration") )
230  {
232  }
233 
234  if( controller_.runCurrentStep("meshOptimisation") )
235  {
237  }
238 
239  if( controller_.runCurrentStep("boundaryLayerRefinement") )
240  {
242  }
243 
244  renumberMesh();
245 
247 
249  }
250  catch(const std::string& message)
251  {
252  Info << message << endl;
253  }
254  catch(...)
255  {
256  WarningIn
257  (
258  "void cartesian2DMeshGenerator::generateMesh()"
259  ) << "Meshing process terminated!" << endl;
260  }
261 }
262 
263 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
264 
266 :
267  db_(time),
268  surfacePtr_(NULL),
269  modSurfacePtr_(NULL),
270  meshDict_
271  (
272  IOobject
273  (
274  "meshDict",
275  db_.system(),
276  db_,
277  IOobject::MUST_READ,
278  IOobject::NO_WRITE
279  )
280  ),
281  octreePtr_(NULL),
282  mesh_(time),
283  controller_(mesh_)
284 {
285  if( true )
286  {
288  }
289 
290  fileName surfaceFile = meshDict_.lookup("surfaceFile");
291  if( Pstream::parRun() )
292  surfaceFile = ".."/surfaceFile;
293 
294  surfacePtr_ = new triSurf(db_.path()/surfaceFile);
295 
296  if( true )
297  {
298  //- save meta data with the mesh (surface mesh + its topology info)
299  triSurfaceMetaData sMetaData(*surfacePtr_);
300  const dictionary& surfMetaDict = sMetaData.metaData();
301 
302  mesh_.metaData().add("surfaceFile", surfaceFile, true);
303  mesh_.metaData().add("surfaceMeta", surfMetaDict, true);
304 
305  triSurface2DCheck surfCheck(*surfacePtr_);
306  if( !surfCheck.is2DSurface() )
307  {
308  surfCheck.createSubsets();
309 
310  Info << "Writting surface with subsets to file "
311  << "badSurfaceWithSubsets.fms" << endl;
312  surfacePtr_->writeSurface("badSurfaceWithSubsets.fms");
313  }
314  }
315 
316  if( surfacePtr_->featureEdges().size() != 0 )
317  {
318  //- get rid of duplicate triangles as they cause strange problems
320 
321  //- create surface patches based on the feature edges
322  //- and update the meshDict based on the given data
324 
325  const triSurf* surfaceWithPatches =
326  manipulator.surfaceWithPatches(&meshDict_);
327 
328  //- delete the old surface and assign the new one
330  surfacePtr_ = surfaceWithPatches;
331  }
332 
333  if( meshDict_.found("anisotropicSources") )
334  {
336 
337  modSurfacePtr_ = surfMod.modifyGeometry();
338 
339  octreePtr_ = new meshOctree(*modSurfacePtr_, true);
340  }
341  else
342  {
343  octreePtr_ = new meshOctree(*surfacePtr_, true);
344  }
345 
347 
348  generateMesh();
349 }
350 
351 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
352 
354 {
358 }
359 
360 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
361 
363 {
364  mesh_.write();
365 }
366 
367 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
368 
369 } // End namespace Foam
370 
371 // ************************************************************************* //
Foam::workflowControls::runCurrentStep
bool runCurrentStep(const word &)
shall the process run the current step
Definition: workflowControls.C:276
Foam::meshSurfaceEdgeExtractor2D
Definition: meshSurfaceEdgeExtractor2D.H:53
Foam::cartesian2DMeshGenerator::generateBoundaryLayers
void generateBoundaryLayers()
add boundary layers
Definition: cartesian2DMeshGenerator.C:138
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::cartesian2DMeshGenerator::surfacePtr_
const triSurf * surfacePtr_
pointer to the surface
Definition: cartesian2DMeshGenerator.H:62
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
triSurf.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
Foam::cartesian2DMeshGenerator::mapEdgesAndCorners
void mapEdgesAndCorners()
capture edges and corners
Definition: cartesian2DMeshGenerator.C:125
Foam::triSurface2DCheck
Definition: triSurface2DCheck.H:49
triSurfacePatchManipulator.H
Foam::checkBoundaryFacesSharingTwoEdges
Definition: checkBoundaryFacesSharingTwoEdges.H:56
Foam::cartesian2DMeshGenerator::~cartesian2DMeshGenerator
~cartesian2DMeshGenerator()
Definition: cartesian2DMeshGenerator.C:353
Foam::removeCells
Given list of cells to remove insert all the topology changes.
Definition: removeCells.H:59
Foam::checkCellConnectionsOverFaces
Definition: checkCellConnectionsOverFaces.H:48
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::checkIrregularSurfaceConnections
Definition: checkIrregularSurfaceConnections.H:51
Foam::checkMeshDict
Definition: checkMeshDict.H:50
Foam::cartesian2DMeshGenerator::mapMeshToSurface
void mapMeshToSurface()
map mesh to the surface and untangle surface
Definition: cartesian2DMeshGenerator.C:102
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::cartesian2DMeshGenerator::generateMesh
void generateMesh()
generate mesh
Definition: cartesian2DMeshGenerator.C:198
Foam::cartesian2DMeshGenerator::renumberMesh
void renumberMesh()
renumber the mesh
Definition: cartesian2DMeshGenerator.C:193
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::cartesian2DMeshGenerator::cartesian2DMeshGenerator
cartesian2DMeshGenerator(const cartesian2DMeshGenerator &)
Disallow default bitwise copy construct.
Foam::boundaryLayers
Definition: boundaryLayers.H:60
topologicalCleaner.H
Foam::triSurfFeatureEdges::featureEdges
const edgeLongList & featureEdges() const
access to feature edges
Definition: triSurfFeatureEdgesI.H:44
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
checkNonMappableCellConnections.H
Foam::polyMeshGenGeometryModification
Definition: polyMeshGenGeometryModification.H:53
Foam::deleteDemandDrivenData
void deleteDemandDrivenData(DataPtr &dataPtr)
Definition: demandDrivenData.H:40
polyMeshGenGeometryModification.H
meshSurfaceEdgeExtractor2D.H
refineBoundaryLayers.H
Foam::cartesian2DMeshGenerator::modSurfacePtr_
const triSurf * modSurfacePtr_
pointer to the modified surface mesh
Definition: cartesian2DMeshGenerator.H:65
Foam::cartesian2DMeshGenerator::refBoundaryLayers
void refBoundaryLayers()
refine boundary layers
Definition: cartesian2DMeshGenerator.C:169
checkMeshDict.H
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
Foam::cartesian2DMeshGenerator::octreePtr_
meshOctree * octreePtr_
pointer to the octree
Definition: cartesian2DMeshGenerator.H:71
Foam::meshSurfaceOptimizer::optimizeSurface2D
void optimizeSurface2D(const label nIterations=5)
optimize the surface of a 2D mesh
Definition: meshSurfaceOptimizerOptimizeSurface.C:658
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::meshSurfaceOptimizer::untangleSurface2D
void untangleSurface2D()
untangle the surface of a 2D mesh
Definition: meshSurfaceOptimizerOptimizeSurface.C:759
Foam::workflowControls::workflowCompleted
void workflowCompleted()
set the workflow completed flag
Definition: workflowControls.C:323
Foam::meshSurfaceEdgeExtractor2D::remapBoundaryPoints
void remapBoundaryPoints()
re-map points after edges have been extracted
Definition: meshSurfaceEdgeExtractor2DDistributeFaces.C:157
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::meshSurfaceMapper2D
Definition: meshSurfaceMapper2D.H:62
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::meshSurfaceMapper2D::preMapVertices
void preMapVertices(const label nIterations=2)
Definition: meshSurfaceMapper2DPremapVertices.C:49
Foam::triSurfaceCleanupDuplicateTriangles
Definition: triSurfaceCleanupDuplicateTriangles.H:52
Foam::surfaceMeshGeometryModification
Definition: surfaceMeshGeometryModification.H:55
Foam::meshSurfaceMapper2D::mapVerticesOntoSurface
void mapVerticesOntoSurface()
Definition: meshSurfaceMapper2DMapVertices.C:262
Foam::cartesian2DMeshGenerator::meshDict_
IOdictionary meshDict_
IOdictionary containing information about cell sizes, etc..
Definition: cartesian2DMeshGenerator.H:68
checkBoundaryFacesSharingTwoEdges.H
triSurfaceCleanupDuplicateTriangles.H
polyMeshGen2DEngine.H
Foam::checkNonMappableCellConnections
Definition: checkNonMappableCellConnections.H:53
Foam::cartesian2DMeshGenerator::db_
const Time & db_
reference to Time
Definition: cartesian2DMeshGenerator.H:59
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
meshSurfaceEngine.H
Foam::cartesian2DMeshGenerator::controller_
workflowControls controller_
workflow controller
Definition: cartesian2DMeshGenerator.H:77
Foam::polyMeshGenModifier::renumberMesh
void renumberMesh()
reorder the cells and faces to reduce the matrix bandwidth
Definition: polyMeshGenModifierRenumberMesh.C:42
Foam::cartesian2DMeshGenerator::extractPatches
void extractPatches()
capture edges and corners
Definition: cartesian2DMeshGenerator.C:120
Foam::polyMeshGenGeometryModification::revertGeometryModification
void revertGeometryModification()
revert modification of coorinates
Definition: polyMeshGenGeometryModification.C:97
triSurface2DCheck.H
Foam::cartesian2DMeshGenerator::mesh_
polyMeshGen mesh_
mesh
Definition: cartesian2DMeshGenerator.H:74
Foam::cartesian2DMeshGenerator::writeMesh
void writeMesh() const
write the mesh
Definition: cartesian2DMeshGenerator.C:362
Foam::polyMeshGenModifier
Definition: polyMeshGenModifier.H:52
Foam::triSurfacePatchManipulator
Definition: triSurfacePatchManipulator.H:52
Foam::Time::path
fileName path() const
Return path.
Definition: Time.H:281
Foam::meshSurfaceOptimizer
Definition: meshSurfaceOptimizer.H:63
Foam::surfaceMeshGeometryModification::modifyGeometry
const triSurf * modifyGeometry() const
modify coordinates
Definition: surfaceMeshGeometryModification.C:77
Foam::polyMeshGen::write
void write() const
Definition: polyMeshGen.C:126
Foam::meshOctree
Definition: meshOctree.H:55
Foam::boundaryLayers::activate2DMode
void activate2DMode()
Definition: boundaryLayers.C:604
Foam::triSurface2DCheck::is2DSurface
bool is2DSurface() const
checks if the surface is a 2D triangulation
Definition: triSurface2DCheck.C:70
Foam::triSurface2DCheck::createSubsets
void createSubsets()
create subset containing invalid facets
Definition: triSurface2DCheck.C:130
cartesian2DMeshGenerator.H
Foam::triSurf::writeSurface
void writeSurface(const fileName &) const
Definition: triSurf.C:430
Foam::cartesian2DMeshGenerator::surfacePreparation
void surfacePreparation()
prepare mesh surface
Definition: cartesian2DMeshGenerator.C:77
Foam::cartesian2DMeshGenerator::createCartesianMesh
void createCartesianMesh()
create cartesian mesh
Definition: cartesian2DMeshGenerator.C:63
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::refineBoundaryLayers::activate2DMode
void activate2DMode()
activate 2D layer refinement
Definition: refineBoundaryLayers.C:95
Foam::triSurfaceMetaData::metaData
const dictionary & metaData() const
return a constant reference to meta data
Definition: triSurfaceMetaData.H:88
Foam::cartesian2DMeshGenerator::replaceBoundaries
void replaceBoundaries()
replace boundaries
Definition: cartesian2DMeshGenerator.C:188
Foam::refineBoundaryLayers::readSettings
static void readSettings(const dictionary &, refineBoundaryLayers &)
read the settings from dictionary
Definition: refineBoundaryLayers.C:406
Foam::cartesian2DMeshGenerator::optimiseMeshSurface
void optimiseMeshSurface()
optimise surface mesh
Definition: cartesian2DMeshGenerator.C:130
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::meshSurfaceEngine
Definition: meshSurfaceEngine.H:54
Foam::meshSurfaceMapper2D::adjustZCoordinates
void adjustZCoordinates()
adjust z coordinates of the mesh to the ones in the surface mesh
Definition: meshSurfaceMapper2DMapVertices.C:219
Foam::dictionary::add
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:729
surfaceMeshGeometryModification.H
meshSurfaceMapper2D.H
triSurfaceMetaData.H
Foam::meshSurfaceEdgeExtractor2D::distributeBoundaryFaces
void distributeBoundaryFaces()
distribute boundary faces into patches
Definition: meshSurfaceEdgeExtractor2DDistributeFaces.C:50