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 "polyMeshGen2DEngine.H"
29 #include "polyMeshGenAddressing.H"
30 #include "demandDrivenData.H"
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 void polyMeshGen2DEngine::findActiveFaces() const
45 const faceListPMG& faces = mesh_.faces();
46 const boolList& zMinPoints = this->zMinPoints();
47 const boolList& zMaxPoints = this->zMaxPoints();
49 activeFacePtr_ = new boolList(faces.size());
52 # pragma omp parallel for schedule(dynamic, 50)
56 bool hasZMin(false), hasZMax(false);
58 const face& f = faces[faceI];
61 hasZMin |= zMinPoints[f[pI]];
62 hasZMax |= zMaxPoints[f[pI]];
65 activeFacePtr_->operator[](faceI) = (hasZMin && hasZMax);
69 void polyMeshGen2DEngine::findActiveFaceLabels() const
71 const boolList& activeFace = this->activeFace();
75 forAll(activeFace, faceI)
76 if( activeFace[faceI] )
79 activeFaceLabelsPtr_ = new labelList(counter);
82 forAll(activeFace, faceI)
83 if( activeFace[faceI] )
84 activeFaceLabelsPtr_->operator[](counter++) = faceI;
87 void polyMeshGen2DEngine::findZMinPoints() const
89 const pointFieldPMG& points = mesh_.points();
91 zMinPointPtr_ = new boolList(points.size());
93 const scalar tZ = 0.05 * (bb_.max().z() - bb_.min().z());;
96 # pragma omp parallel for schedule(dynamic, 50)
98 forAll(points, pointI)
100 if( Foam::mag(points[pointI].z() - bb_.min().z()) < tZ )
102 zMinPointPtr_->operator[](pointI) = true;
106 zMinPointPtr_->operator[](pointI) = false;
111 void polyMeshGen2DEngine::findZMinPointLabels() const
113 const boolList& zMinPoints = this->zMinPoints();
117 forAll(zMinPoints, pointI)
118 if( zMinPoints[pointI] )
121 if( 2 * counter != zMinPoints.size() )
125 "void polyMeshGen2DEngine::findZMinPointLabels()"
126 ) << "The number of points at smallest z coordinate is"
127 << " not half of the total number of points."
128 << " This is not a 2D mesh or is not aligned with the z axis"
132 zMinPointLabelsPtr_ = new labelList(counter);
135 forAll(zMinPoints, pointI)
136 if( zMinPoints[pointI] )
137 zMinPointLabelsPtr_->operator[](counter++) = pointI;
140 void polyMeshGen2DEngine::findZMinOffsetPoints() const
142 const boolList& zMinPoints = this->zMinPoints();
143 const labelList& zMinPointLabels = this->zMinPointLabels();
145 zMinToZMaxPtr_ = new labelList(zMinPointLabels.size());
147 const VRWGraph& pointPoints = mesh_.addressingData().pointPoints();
149 # pragma omp parallel for schedule(dynamic, 50)
151 forAll(zMinPointLabels, pI)
153 const label pointI = zMinPointLabels[pI];
155 label nInactive(0), offsetPoint(-1);
156 forAllRow(pointPoints, pointI, ppI)
158 if( !zMinPoints[pointPoints(pointI, ppI)] )
161 offsetPoint = pointPoints(pointI, ppI);
167 zMinToZMaxPtr_->operator[](pI) = offsetPoint;
173 "void polyMeshGen2DEngine::findZMinOffsetPoints()"
174 ) << "This cannot be a 2D mesh" << exit(FatalError);
179 void polyMeshGen2DEngine::findZMaxPoints() const
181 const pointFieldPMG& points = mesh_.points();
183 zMaxPointPtr_ = new boolList(points.size());
185 const scalar tZ = 0.05 * (bb_.max().z() - bb_.min().z());
188 # pragma omp parallel for schedule(dynamic, 50)
190 forAll(points, pointI)
192 if( Foam::mag(points[pointI].z() - bb_.max().z()) < tZ )
194 zMaxPointPtr_->operator[](pointI) = true;
198 zMaxPointPtr_->operator[](pointI) = false;
203 void polyMeshGen2DEngine::findZMaxPointLabels() const
205 const boolList& zMaxPoints = this->zMaxPoints();
209 forAll(zMaxPoints, pointI)
210 if( zMaxPoints[pointI] )
213 if( 2 * counter != zMaxPoints.size() )
217 "void polyMeshGen2DEngine::findZMaxPointLabels()"
218 ) << "The number of points at largest z coordinate is"
219 << " not half of the total number of points."
220 << " This is not a 2D mesh or is not aligned with the z axis"
224 zMaxPointLabelsPtr_ = new labelList(counter);
227 forAll(zMaxPoints, pointI)
228 if( zMaxPoints[pointI] )
229 zMaxPointLabelsPtr_->operator[](counter++) = pointI;
232 void polyMeshGen2DEngine::findZMaxOffsetPoints() const
234 const boolList& zMaxPoints = this->zMaxPoints();
235 const labelList& zMaxPointLabels = this->zMaxPointLabels();
237 zMaxToZMinPtr_ = new labelList(zMaxPointLabels.size());
239 const VRWGraph& pointPoints = mesh_.addressingData().pointPoints();
241 # pragma omp parallel for schedule(dynamic, 50)
243 forAll(zMaxPointLabels, pI)
245 const label pointI = zMaxPointLabels[pI];
247 label nInactive(0), offsetPoint(-1);
248 forAllRow(pointPoints, pointI, ppI)
250 if( !zMaxPoints[pointPoints(pointI, ppI)] )
253 offsetPoint = pointPoints(pointI, ppI);
259 zMaxToZMinPtr_->operator[](pI) = offsetPoint;
265 "void polyMeshGen2DEngine::findZMaxOffsetPoints()"
266 ) << "This cannot be a 2D mesh" << exit(FatalError);
271 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
273 polyMeshGen2DEngine::polyMeshGen2DEngine(const polyMeshGen& mesh)
277 activeFacePtr_(NULL),
278 activeFaceLabelsPtr_(NULL),
280 zMinPointLabelsPtr_(NULL),
281 zMinToZMaxPtr_(NULL),
283 zMaxPointLabelsPtr_(NULL),
286 const pointFieldPMG& points = mesh_.points();
288 bb_.min() = point(VGREAT, VGREAT, VGREAT);
289 bb_.max() = point(-VGREAT, -VGREAT, -VGREAT);
292 # pragma omp parallel
295 point localMin(VGREAT, VGREAT, VGREAT);
296 point localMax(-VGREAT, -VGREAT, -VGREAT);
299 # pragma omp for schedule(dynamic, 50)
301 forAll(points, pointI)
303 localMin = Foam::min(localMin, points[pointI]);
304 localMax = Foam::max(localMax, points[pointI]);
308 # pragma omp critical
311 bb_.min() = Foam::min(bb_.min(), localMin);
312 bb_.max() = Foam::max(bb_.max(), localMax);
316 if( Pstream::parRun() )
318 reduce(bb_.min(), minOp<point>());
319 reduce(bb_.max(), maxOp<point>());
323 polyMeshGen2DEngine::~polyMeshGen2DEngine()
328 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
330 void polyMeshGen2DEngine::correctPoints()
332 pointFieldPMG& points = const_cast<pointFieldPMG&>(mesh_.points());
334 const labelList& zMinPointLabels = this->zMinPointLabels();
335 const labelList& zMinOffset = this->zMinToZMax();
338 # pragma omp parallel for schedule(dynamic, 50)
340 forAll(zMinPointLabels, apI)
342 point& p = points[zMinPointLabels[apI]];
343 point& op = points[zMinOffset[apI]];
347 p.z() = bb_.min().z();
348 op.z() = bb_.max().z();
352 void polyMeshGen2DEngine::clearOut()
354 deleteDemandDrivenData(activeFacePtr_);
355 deleteDemandDrivenData(activeFaceLabelsPtr_);
356 deleteDemandDrivenData(zMinPointPtr_);
357 deleteDemandDrivenData(zMinPointLabelsPtr_);
358 deleteDemandDrivenData(zMinToZMaxPtr_);
359 deleteDemandDrivenData(zMaxPointPtr_);
360 deleteDemandDrivenData(zMaxPointLabelsPtr_);
361 deleteDemandDrivenData(zMaxToZMinPtr_);
364 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
366 } // End namespace Foam
368 // ************************************************************************* //