Moving cfMesh into place. Updated contibutors list
[foam-extend-3.2.git] / src / mesh / cfMesh / meshLibrary / cartesian2DMesh / cartesian2DMeshGenerator / cartesian2DMeshGenerator.C
blobb4179487a52fe913479fe7d9342134e553982962
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.
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
19     for more details.
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/>.
24 Description
26 \*---------------------------------------------------------------------------*/
28 #include "cartesian2DMeshGenerator.H"
29 #include "polyMeshGen2DEngine.H"
30 #include "triSurf.H"
31 #include "triSurfacePatchManipulator.H"
32 #include "demandDrivenData.H"
33 #include "Time.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"
51 //#define DEBUG
53 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 namespace Foam
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") )
66     {
67         if( readBool(meshDict_.lookup("decomposePolyhedraIntoTetsAndPyrs")) )
68             cme.decomposeSplitHexes();
69     }
71     cme.createMesh();
73     # ifdef DEBUG
74     mesh_.write();
75     //::exit(EXIT_FAILURE);
76     # endif
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
84     bool changed;
86     do
87     {
88         changed = false;
90         checkIrregularSurfaceConnections checkConnections(mesh_);
91         if( checkConnections.checkAndFixIrregularConnections() )
92             changed = true;
94         if( checkNonMappableCellConnections(mesh_).removeCells() )
95             changed = true;
97         if( checkCellConnectionsOverFaces(mesh_).checkCellGroups() )
98             changed = true;
99     } while( changed );
101     checkBoundaryFacesSharingTwoEdges(mesh_).improveTopology();
103     # ifdef DEBUG
104     mesh_.write();
105     //::exit(EXIT_FAILURE);
106     # endif
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();
121     # ifdef DEBUG
122     mesh_.write();
123     //::exit(EXIT_FAILURE);
124     # endif
126     //- map mesh surface on the geometry surface
127     mapper.mapVerticesOntoSurface();
129     # ifdef DEBUG
130     mesh_.write();
131     //::exit(EXIT_SUCCESS);
132     # endif
134     deleteDemandDrivenData(msePtr);
137 void cartesian2DMeshGenerator::mapEdgesAndCorners()
139     meshSurfaceEdgeExtractor2D(mesh_, *octreePtr_);
141     # ifdef DEBUG
142     mesh_.write();
143     //::exit(0);
144     # endif
147 void cartesian2DMeshGenerator::optimiseMeshSurface()
149     meshSurfaceEngine mse(mesh_);
150     meshSurfaceOptimizer optimizer(mse, *octreePtr_);
151     optimizer.optimizeSurface2D();
152     optimizer.untangleSurface2D();
154     # ifdef DEBUG
155     mesh_.write();
156     //::exit(0);
157     # endif
160 void cartesian2DMeshGenerator::generateBoundaryLayers()
162     boundaryLayers bl(mesh_);
164     bl.activate2DMode();
166     bl.addLayerForAllPatches();
168     # ifdef DEBUG
169     mesh_.write();
170     //::exit(0);
171     # endif
174 void cartesian2DMeshGenerator::refBoundaryLayers()
176     if( meshDict_.isDict("boundaryLayers") )
177     {
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();
190     }
193 void cartesian2DMeshGenerator::replaceBoundaries()
195     renameBoundaryPatches rbp(mesh_, meshDict_);
197     # ifdef DEBUG
198     mesh_.write();
199     //::exit(0);
200     # endif
203 void cartesian2DMeshGenerator::renumberMesh()
205     polyMeshGenModifier(mesh_).renumberMesh();
207     # ifdef DEBUG
208     mesh_.write();
209     //::exit(0);
210     # endif
213 void cartesian2DMeshGenerator::generateMesh()
215     createCartesianMesh();
217     surfacePreparation();
219     mapMeshToSurface();
221     mapEdgesAndCorners();
223     optimiseMeshSurface();
225     generateBoundaryLayers();
227     optimiseMeshSurface();
229     refBoundaryLayers();
231     renumberMesh();
233     replaceBoundaries();
236 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
238 // Construct from objectRegistry
239 cartesian2DMeshGenerator::cartesian2DMeshGenerator(const Time& time)
241     db_(time),
242     surfacePtr_(NULL),
243     meshDict_
244     (
245         IOobject
246         (
247             "meshDict",
248             db_.system(),
249             db_,
250             IOobject::MUST_READ,
251             IOobject::NO_WRITE
252         )
253     ),
254     octreePtr_(NULL),
255     mesh_(time)
257     if( true )
258     {
259         checkMeshDict cmd(meshDict_);
260     }
262     fileName surfaceFile = meshDict_.lookup("surfaceFile");
263     if( Pstream::parRun() )
264         surfaceFile = ".."/surfaceFile;
266     surfacePtr_ = new triSurf(db_.path()/surfaceFile);
268     if( true )
269     {
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);
276     }
278     if( surfacePtr_->featureEdges().size() != 0 )
279     {
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;
290     }
292     octreePtr_ = new meshOctree(*surfacePtr_, true);
294     meshOctreeCreator(*octreePtr_, meshDict_).createOctreeBoxes();
296     generateMesh();
299 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
301 cartesian2DMeshGenerator::~cartesian2DMeshGenerator()
303     deleteDemandDrivenData(surfacePtr_);
304     deleteDemandDrivenData(octreePtr_);
307 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
309 void cartesian2DMeshGenerator::writeMesh() const
311     mesh_.write();
314 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
316 } // End namespace Foam
318 // ************************************************************************* //