meshOptimizer.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 "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"
35 
36 // #define DEBUGSmoothing
37 
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 
40 namespace Foam
41 {
42 
43 // * * * * * * * * Private member functions * * * * * * * * * * * * * * * * * //
44 
46 {
47  if( !msePtr_ )
49 
50  return *msePtr_;
51 }
52 
54 {
56 }
57 
59 (
60  labelHashSet& badFaces,
61  const boolList& changedFace
62 ) const
63 {
64  badFaces.clear();
65 
67  (
68  mesh_,
69  false,
70  VSMALL,
71  &badFaces,
72  &changedFace
73  );
74 
76  (
77  mesh_,
78  false,
79  0.8,
80  &badFaces,
81  &changedFace
82  );
83 
85  (
86  mesh_,
87  false,
88  VSMALL,
89  &badFaces,
90  &changedFace
91  );
92 
94  (
95  mesh_,
96  false,
97  VSMALL,
98  &badFaces,
99  &changedFace
100  );
101 
102  const label nBadFaces = returnReduce(badFaces.size(), sumOp<label>());
103 
104  return nBadFaces;
105 }
106 
108 (
109  labelHashSet& badFaces,
110  const boolList& /*changedFace*/
111 ) const
112 {
113  badFaces.clear();
114 
116  (
117  mesh_,
118  false,
119  70.0,
120  &badFaces
121  );
122 
124  (
125  mesh_,
126  false,
127  2.0,
128  &badFaces
129  );
130 
131  const label nBadFaces = returnReduce(badFaces.size(), sumOp<label>());
132 
133  return nBadFaces;
134 }
135 
137 {
140 
141  const meshSurfaceEngine& mse = meshSurface();
142  const labelList& bPoints = mse.boundaryPoints();
143 
144  //- mark boundary vertices
145  forAll(bPoints, bpI)
146  vertexLocation_[bPoints[bpI]] = BOUNDARY;
147 
148  //- mark edge vertices
149  meshSurfacePartitioner mPart(mse);
151  vertexLocation_[bPoints[it.key()]] = EDGE;
152 
153  //- mark corner vertices
154  forAllConstIter(labelHashSet, mPart.corners(), it)
155  vertexLocation_[bPoints[it.key()]] = CORNER;
156 
157  if( Pstream::parRun() )
158  {
159  const polyMeshGenAddressing& addresing = mesh_.addressingData();
160  const VRWGraph& pointAtProcs = addresing.pointAtProcs();
161 
162  forAll(pointAtProcs, pointI)
163  if( pointAtProcs.sizeOfRow(pointI) != 0 )
165  }
166 }
167 
168 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
169 
170 // Construct from mesh
172 :
173  mesh_(mesh),
174  vertexLocation_(),
175  lockedFaces_(),
176  msePtr_(NULL),
177  enforceConstraints_(false),
178  badPointsSubsetName_()
179 {
181 }
182 
183 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
184 
186 {
187  clearSurface();
188 }
189 
190 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
191 
193 {
194  enforceConstraints_ = true;
195 
196  badPointsSubsetName_ = subsetName;
197 }
198 
199 void meshOptimizer::lockCellsInSubset(const word& subsetName)
200 {
201  //- lock the points in the cell subset with the given name
202  label subsetI = mesh_.cellSubsetIndex(subsetName);
203  if( subsetI >= 0 )
204  {
205  labelLongList lc;
206  mesh_.cellsInSubset(subsetI, lc);
207 
208  lockCells(lc);
209  }
210  else
211  {
212  Warning << "Subset " << subsetName << " is not a cell subset!"
213  << " Cannot lock cells!" << endl;
214  }
215 }
216 
217 void meshOptimizer::lockFacesInSubset(const word& subsetName)
218 {
219  //- lock the points in the face subset with the given name
220  label subsetI = mesh_.faceSubsetIndex(subsetName);
221  if( subsetI >= 0 )
222  {
223  labelLongList lf;
224  mesh_.facesInSubset(subsetI, lf);
225 
226  lockFaces(lf);
227  }
228  else
229  {
230  Warning << "Subset " << subsetName << " is not a face subset!"
231  << " Cannot lock faces!" << endl;
232  }
233 }
234 
236 {
237  //- lock the points in the point subset with the given name
238  label subsetI = mesh_.pointSubsetIndex(subsetName);
239  if( subsetI >= 0 )
240  {
241  labelLongList lp;
242  mesh_.pointsInSubset(subsetI, lp);
243 
244  lockCells(lp);
245  }
246  else
247  {
248  Warning << "Subset " << subsetName << " is not a point subset!"
249  << " Cannot lock points!" << endl;
250  }
251 }
252 
254 {
256 
257  //- unlock points
258  # ifdef USE_OMP
259  # pragma omp parallel for schedule(dynamic, 50)
260  # endif
262  {
263  if( vertexLocation_[i] & LOCKED )
264  vertexLocation_[i] ^= LOCKED;
265  }
266 }
267 
268 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
269 
270 } // End namespace Foam
271 
272 // ************************************************************************* //
Foam::meshOptimizer::lockCells
void lockCells(const labelListType &)
lock the cells which shall not be modified
Definition: meshOptimizerI.H:39
Foam::polyMeshGenCells::addressingData
const polyMeshGenAddressing & addressingData() const
addressing which may be needed
Definition: polyMeshGenCells.C:327
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::polyMeshGenChecks::checkFaceSkewness
void checkFaceSkewness(const polyMeshGen &, scalarField &, const boolList *changedFacePtr=NULL)
Check face skewness.
Definition: polyMeshGenChecksGeometry.C:1138
Foam::returnReduce
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Definition: PstreamReduceOps.H:86
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
Foam::meshOptimizer::vertexLocation_
List< direction > vertexLocation_
location of vertex (internal, boundary, edge, corner)
Definition: meshOptimizer.H:67
Foam::polyMeshGenFaces::faceSubsetIndex
label faceSubsetIndex(const word &) const
Definition: polyMeshGenFaces.C:313
Foam::Warning
messageStream Warning
Foam::UPstream::parRun
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:377
Foam::polyMeshGen
Definition: polyMeshGen.H:46
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::meshOptimizer::lockCellsInSubset
void lockCellsInSubset(const word &subsetName)
Definition: meshOptimizer.C:199
Foam::polyMeshGenPoints::points
const pointFieldPMG & points() const
access to points
Definition: polyMeshGenPointsI.H:44
Foam::meshOptimizer::CORNER
@ CORNER
Definition: meshOptimizer.H:196
Foam::polyMeshGenFaces::facesInSubset
void facesInSubset(const label, ListType &) const
Definition: polyMeshGenFacesI.H:178
Foam::polyMeshGenChecks::checkFaceAreas
bool checkFaceAreas(const polyMeshGen &, const bool report=false, const scalar minFaceArea=VSMALL, labelHashSet *setPtr=NULL, const boolList *changedFacePtr=NULL)
Check for negative face areas.
Definition: polyMeshGenChecksGeometry.C:362
Foam::polyMeshGenAddressing
Definition: polyMeshGenAddressing.H:69
Foam::polyMeshGenPoints::pointSubsetIndex
label pointSubsetIndex(const word &) const
Definition: polyMeshGenPoints.C:135
Foam::HashSet< label, Hash< label > >
Foam::polyMeshGenChecks::checkFaceFlatness
bool checkFaceFlatness(const polyMeshGen &, const bool report, const scalar warnFlatness, labelHashSet *setPtr=NULL, const boolList *changedFacePtr=NULL)
Check face warpage: decompose face and check ratio between.
Definition: polyMeshGenChecksGeometry.C:1777
polyMeshGenChecks.H
Foam::meshOptimizer::lockFaces
void lockFaces(const labelListType &)
lock the faces whih shall not be modified
Definition: meshOptimizerI.H:123
Foam::polyMeshGenAddressing::pointAtProcs
const VRWGraph & pointAtProcs() const
Definition: polyMeshGenAddressingParallelAddressing.C:775
forAllConstIter
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
Foam::LongList::setSize
void setSize(const label)
Reset size of List.
Definition: LongListI.H:223
Foam::meshOptimizer::enforceConstraints_
bool enforceConstraints_
enforce constraints
Definition: meshOptimizer.H:76
Foam::LongList< label >
Foam::deleteDemandDrivenData
void deleteDemandDrivenData(DataPtr &dataPtr)
Definition: demandDrivenData.H:40
Foam::meshOptimizer::BOUNDARY
@ BOUNDARY
Definition: meshOptimizer.H:194
Foam::meshOptimizer::lockPointsInSubset
void lockPointsInSubset(const word &subsetName)
Definition: meshOptimizer.C:235
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::meshOptimizer::findLowQualityFaces
label findLowQualityFaces(labelHashSet &, const boolList &) const
Definition: meshOptimizer.C:108
Foam::meshOptimizer::msePtr_
meshSurfaceEngine * msePtr_
mesh surface
Definition: meshOptimizer.H:73
Foam::meshOptimizer::lockFacesInSubset
void lockFacesInSubset(const word &subsetName)
Definition: meshOptimizer.C:217
Foam::polyMeshGenChecks::checkFaceDotProduct
void checkFaceDotProduct(const polyMeshGen &, scalarField &, const boolList *changedFacePtr=NULL)
Check for non-orthogonality.
Definition: polyMeshGenChecksGeometry.C:630
Foam::meshOptimizer::clearSurface
void clearSurface()
Definition: meshOptimizer.C:53
Foam::pointFieldPMG::size
label size() const
return the number of used elements
Definition: pointFieldPMGI.H:71
Foam::meshOptimizer::lockedFaces_
labelLongList lockedFaces_
locked faces which shall not be changed
Definition: meshOptimizer.H:70
Foam::meshOptimizer::INSIDE
@ INSIDE
Definition: meshOptimizer.H:193
Foam::VRWGraph::sizeOfRow
label sizeOfRow(const label rowI) const
Returns the number of elements in the given row.
Definition: VRWGraphI.H:127
Foam::meshOptimizer::~meshOptimizer
~meshOptimizer()
Definition: meshOptimizer.C:185
Foam::HashTable::size
label size() const
Return number of elements in table.
Definition: HashTableI.H:65
Foam::polyMeshGenChecks::checkCellPartTetrahedra
bool checkCellPartTetrahedra(const polyMeshGen &, const bool report=false, const scalar minPartTet=VSMALL, labelHashSet *setPtr=NULL, const boolList *changedFacePtr=NULL)
Definition: polyMeshGenChecksGeometry.C:467
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
meshSurfaceEngine.H
Foam::meshOptimizer::mesh_
polyMeshGen & mesh_
reference to the mesh
Definition: meshOptimizer.H:64
Foam::meshOptimizer::meshOptimizer
meshOptimizer(const meshOptimizer &)
Disallow default bitwise copy construct.
Foam::meshOptimizer::enforceConstraints
void enforceConstraints(const word subsetName="badPoints")
Definition: meshOptimizer.C:192
Foam::meshSurfacePartitioner
Definition: meshSurfacePartitioner.H:52
Foam::meshOptimizer::LOCKED
@ LOCKED
Definition: meshOptimizer.H:198
Foam::polyMeshGenPoints::pointsInSubset
void pointsInSubset(const label, ListType &) const
Definition: polyMeshGenPointsI.H:122
Foam::polyMeshGenChecks::checkFacePyramids
bool checkFacePyramids(const polyMeshGen &, const bool report=false, const scalar minPyrVol=-SMALL, labelHashSet *setPtr=NULL, const boolList *changedFacePtr=NULL)
Check face pyramid volume.
Definition: polyMeshGenChecksGeometry.C:962
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::meshOptimizer::badPointsSubsetName_
word badPointsSubsetName_
name of the subset contaning tangled points
Definition: meshOptimizer.H:79
Foam::meshSurfacePartitioner::edgePoints
const labelHashSet & edgePoints() const
return labels of edge points (from the list of boundary points)
Definition: meshSurfacePartitioner.H:135
Foam::meshOptimizer::findBadFaces
label findBadFaces(labelHashSet &, const boolList &) const
find problematic faces
Definition: meshOptimizer.C:59
Foam::sumOp
Definition: ops.H:162
Foam::HashTable::clear
void clear()
Clear all entries from table.
Definition: HashTable.C:473
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
meshOptimizer.H
labelLongList.H
Foam::meshOptimizer::calculatePointLocations
void calculatePointLocations()
mark point locations
Definition: meshOptimizer.C:136
Foam::polyMeshGenCells::cellsInSubset
void cellsInSubset(const label, ListType &) const
Definition: polyMeshGenCellsI.H:107
Foam::meshSurfaceEngine::boundaryPoints
const labelList & boundaryPoints() const
Definition: meshSurfaceEngineI.H:84
Foam::meshOptimizer::meshSurface
const meshSurfaceEngine & meshSurface() const
return mesh surface
Definition: meshOptimizer.C:45
Foam::meshOptimizer::EDGE
@ EDGE
Definition: meshOptimizer.H:195
Foam::meshSurfacePartitioner::corners
const labelHashSet & corners() const
return labels of corner points (from the list of boundary points)
Definition: meshSurfacePartitioner.H:129
Foam::VRWGraph
Definition: VRWGraph.H:101
Foam::meshOptimizer::removeUserConstraints
void removeUserConstraints()
reset to default constraints
Definition: meshOptimizer.C:253
polyMeshGenAddressing.H
Foam::meshSurfaceEngine
Definition: meshSurfaceEngine.H:54
Foam::polyMeshGenCells::cellSubsetIndex
label cellSubsetIndex(const word &) const
Definition: polyMeshGenCells.C:402
meshSurfacePartitioner.H
Foam::meshOptimizer::PARALLELBOUNDARY
@ PARALLELBOUNDARY
Definition: meshOptimizer.H:197