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 "demandDrivenData.H"
29 #include "meshOptimizer.H"
30 #include "meshSurfaceEngine.H"
31 #include "meshSurfacePartitioner.H"
32 #include "polyMeshGenAddressing.H"
33 #include "polyMeshGenChecks.H"
34 #include "labelLongList.H"
36 // #define DEBUGSmoothing
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 // * * * * * * * * Private member functions * * * * * * * * * * * * * * * * * //
45 const meshSurfaceEngine& meshOptimizer::meshSurface() const
48 msePtr_ = new meshSurfaceEngine(mesh_);
53 void meshOptimizer::clearSurface()
55 deleteDemandDrivenData(msePtr_);
58 label meshOptimizer::findBadFaces
60 labelHashSet& badFaces,
61 const boolList& changedFace
66 polyMeshGenChecks::checkFacePyramids
75 polyMeshGenChecks::checkFaceFlatness
84 polyMeshGenChecks::checkCellPartTetrahedra
93 polyMeshGenChecks::checkFaceAreas
102 const label nBadFaces = returnReduce(badFaces.size(), sumOp<label>());
107 label meshOptimizer::findLowQualityFaces
109 labelHashSet& badFaces,
110 const boolList& changedFace
115 polyMeshGenChecks::checkFaceDotProduct
123 polyMeshGenChecks::checkFaceSkewness
131 const label nBadFaces = returnReduce(badFaces.size(), sumOp<label>());
136 void meshOptimizer::calculatePointLocations()
138 vertexLocation_.setSize(mesh_.points().size());
139 vertexLocation_ = INSIDE;
141 const meshSurfaceEngine& mse = meshSurface();
142 const labelList& bPoints = mse.boundaryPoints();
144 //- mark boundary vertices
146 vertexLocation_[bPoints[bpI]] = BOUNDARY;
148 //- mark edge vertices
149 meshSurfacePartitioner mPart(mse);
150 forAllConstIter(labelHashSet, mPart.edgePoints(), it)
151 vertexLocation_[bPoints[it.key()]] = EDGE;
153 //- mark corner vertices
154 forAllConstIter(labelHashSet, mPart.corners(), it)
155 vertexLocation_[bPoints[it.key()]] = CORNER;
157 if( Pstream::parRun() )
159 const polyMeshGenAddressing& addresing = mesh_.addressingData();
160 const VRWGraph& pointAtProcs = addresing.pointAtProcs();
162 forAll(pointAtProcs, pointI)
163 if( pointAtProcs.sizeOfRow(pointI) != 0 )
164 vertexLocation_[pointI] |= PARALLELBOUNDARY;
168 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
170 // Construct from mesh
171 meshOptimizer::meshOptimizer(polyMeshGen& mesh)
177 enforceConstraints_(false),
178 badPointsSubsetName_()
180 calculatePointLocations();
183 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
185 meshOptimizer::~meshOptimizer()
190 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
192 void meshOptimizer::enforceConstraints(const word subsetName)
194 enforceConstraints_ = true;
196 badPointsSubsetName_ = subsetName;
199 void meshOptimizer::lockCellsInSubset(const word& subsetName)
201 //- lock the points in the cell subset with the given name
202 label subsetI = mesh_.cellSubsetIndex(subsetName);
206 mesh_.cellsInSubset(subsetI, lc);
212 Warning << "Subset " << subsetName << " is not a cell subset!"
213 << " Cannot lock cells!" << endl;
217 void meshOptimizer::lockFacesInSubset(const word& subsetName)
219 //- lock the points in the face subset with the given name
220 label subsetI = mesh_.faceSubsetIndex(subsetName);
224 mesh_.facesInSubset(subsetI, lf);
230 Warning << "Subset " << subsetName << " is not a face subset!"
231 << " Cannot lock faces!" << endl;
235 void meshOptimizer::lockPointsInSubset(const word& subsetName)
237 //- lock the points in the point subset with the given name
238 label subsetI = mesh_.pointSubsetIndex(subsetName);
242 mesh_.pointsInSubset(subsetI, lp);
248 Warning << "Subset " << subsetName << " is not a point subset!"
249 << " Cannot lock points!" << endl;
253 void meshOptimizer::removeUserConstraints()
255 lockedFaces_.setSize(0);
259 # pragma omp parallel for schedule(dynamic, 50)
261 forAll(vertexLocation_, i)
263 if( vertexLocation_[i] & LOCKED )
264 vertexLocation_[i] ^= LOCKED;
268 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
270 } // End namespace Foam
272 // ************************************************************************* //