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 "cartesian2DMeshGenerator.H"
29 #include "polyMeshGen2DEngine.H"
31 #include "triSurfacePatchManipulator.H"
32 #include "demandDrivenData.H"
34 #include "meshOctreeCreator.H"
35 #include "cartesianMeshExtractor.H"
36 #include "meshSurfaceEngine.H"
37 #include "meshSurfaceMapper2D.H"
38 #include "meshSurfaceEdgeExtractor2D.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"
45 #include "checkCellConnectionsOverFaces.H"
46 #include "checkIrregularSurfaceConnections.H"
47 #include "checkNonMappableCellConnections.H"
48 #include "checkBoundaryFacesSharingTwoEdges.H"
49 #include "triSurfaceMetaData.H"
53 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
58 // * * * * * * * * * * * * Private member functions * * * * * * * * * * * * //
60 void cartesian2DMeshGenerator::createCartesianMesh()
62 //- create polyMesh from octree boxes
63 cartesianMeshExtractor cme(*octreePtr_, meshDict_, mesh_);
65 if( meshDict_.found("decomposePolyhedraIntoTetsAndPyrs") )
67 if( readBool(meshDict_.lookup("decomposePolyhedraIntoTetsAndPyrs")) )
68 cme.decomposeSplitHexes();
75 //::exit(EXIT_FAILURE);
79 void cartesian2DMeshGenerator::surfacePreparation()
81 //- removes unnecessary cells and morph the boundary
82 //- such that there is only one boundary face per cell
83 //- It also checks topology of cells after morphing is performed
90 checkIrregularSurfaceConnections checkConnections(mesh_);
91 if( checkConnections.checkAndFixIrregularConnections() )
94 if( checkNonMappableCellConnections(mesh_).removeCells() )
97 if( checkCellConnectionsOverFaces(mesh_).checkCellGroups() )
101 checkBoundaryFacesSharingTwoEdges(mesh_).improveTopology();
105 //::exit(EXIT_FAILURE);
109 void cartesian2DMeshGenerator::mapMeshToSurface()
111 //- calculate mesh surface
112 meshSurfaceEngine* msePtr = new meshSurfaceEngine(mesh_);
114 //- pre-map mesh surface
115 meshSurfaceMapper2D mapper(*msePtr, *octreePtr_);
117 mapper.adjustZCoordinates();
119 mapper.preMapVertices();
123 //::exit(EXIT_FAILURE);
126 //- map mesh surface on the geometry surface
127 mapper.mapVerticesOntoSurface();
131 //::exit(EXIT_SUCCESS);
134 deleteDemandDrivenData(msePtr);
137 void cartesian2DMeshGenerator::mapEdgesAndCorners()
139 meshSurfaceEdgeExtractor2D(mesh_, *octreePtr_);
147 void cartesian2DMeshGenerator::optimiseMeshSurface()
149 meshSurfaceEngine mse(mesh_);
150 meshSurfaceOptimizer optimizer(mse, *octreePtr_);
151 optimizer.optimizeSurface2D();
152 optimizer.untangleSurface2D();
160 void cartesian2DMeshGenerator::generateBoundaryLayers()
162 boundaryLayers bl(mesh_);
166 bl.addLayerForAllPatches();
174 void cartesian2DMeshGenerator::refBoundaryLayers()
176 if( meshDict_.isDict("boundaryLayers") )
178 refineBoundaryLayers refLayers(mesh_);
180 refineBoundaryLayers::readSettings(meshDict_, refLayers);
182 refLayers.activate2DMode();
184 refLayers.refineLayers();
186 meshSurfaceEngine mse(mesh_);
187 meshSurfaceOptimizer optimizer(mse, *octreePtr_);
189 optimizer.untangleSurface2D();
193 void cartesian2DMeshGenerator::replaceBoundaries()
195 renameBoundaryPatches rbp(mesh_, meshDict_);
203 void cartesian2DMeshGenerator::renumberMesh()
205 polyMeshGenModifier(mesh_).renumberMesh();
213 void cartesian2DMeshGenerator::generateMesh()
215 createCartesianMesh();
217 surfacePreparation();
221 mapEdgesAndCorners();
223 optimiseMeshSurface();
225 generateBoundaryLayers();
227 optimiseMeshSurface();
236 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
238 // Construct from objectRegistry
239 cartesian2DMeshGenerator::cartesian2DMeshGenerator(const Time& time)
259 checkMeshDict cmd(meshDict_);
262 fileName surfaceFile = meshDict_.lookup("surfaceFile");
263 if( Pstream::parRun() )
264 surfaceFile = ".."/surfaceFile;
266 surfacePtr_ = new triSurf(db_.path()/surfaceFile);
270 //- save meta data with the mesh (surface mesh + its topology info)
271 triSurfaceMetaData sMetaData(*surfacePtr_);
272 const dictionary& surfMetaDict = sMetaData.metaData();
274 mesh_.metaData().add("surfaceFile", surfaceFile);
275 mesh_.metaData().add("surfaceMeta", surfMetaDict);
278 if( surfacePtr_->featureEdges().size() != 0 )
280 //- create surface patches based on the feature edges
281 //- and update the meshDict based on the given data
282 triSurfacePatchManipulator manipulator(*surfacePtr_);
284 const triSurf* surfaceWithPatches =
285 manipulator.surfaceWithPatches(&meshDict_);
287 //- delete the old surface and assign the new one
288 deleteDemandDrivenData(surfacePtr_);
289 surfacePtr_ = surfaceWithPatches;
292 octreePtr_ = new meshOctree(*surfacePtr_, true);
294 meshOctreeCreator(*octreePtr_, meshDict_).createOctreeBoxes();
299 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
301 cartesian2DMeshGenerator::~cartesian2DMeshGenerator()
303 deleteDemandDrivenData(surfacePtr_);
304 deleteDemandDrivenData(octreePtr_);
307 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
309 void cartesian2DMeshGenerator::writeMesh() const
314 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
316 } // End namespace Foam
318 // ************************************************************************* //