polyMeshGen2DEngine.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 "polyMeshGen2DEngine.H"
29 #include "polyMeshGenAddressing.H"
30 #include "demandDrivenData.H"
31 
32 # ifdef USE_OMP
33 #include <omp.h>
34 # endif
35 
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
44 {
45  const faceListPMG& faces = mesh_.faces();
46  const boolList& zMinPoints = this->zMinPoints();
47  const boolList& zMaxPoints = this->zMaxPoints();
48 
49  activeFacePtr_ = new boolList(faces.size());
50 
51  # ifdef USE_OMP
52  # pragma omp parallel for schedule(dynamic, 50)
53  # endif
54  forAll(faces, faceI)
55  {
56  bool hasZMin(false), hasZMax(false);
57 
58  const face& f = faces[faceI];
59  forAll(f, pI)
60  {
61  hasZMin |= zMinPoints[f[pI]];
62  hasZMax |= zMaxPoints[f[pI]];
63  }
64 
65  activeFacePtr_->operator[](faceI) = (hasZMin && hasZMax);
66  }
67 }
68 
70 {
71  const boolList& activeFace = this->activeFace();
72 
73  label counter(0);
74 
75  forAll(activeFace, faceI)
76  if( activeFace[faceI] )
77  ++counter;
78 
79  activeFaceLabelsPtr_ = new labelList(counter);
80 
81  counter = 0;
82  forAll(activeFace, faceI)
83  if( activeFace[faceI] )
84  activeFaceLabelsPtr_->operator[](counter++) = faceI;
85 }
86 
88 {
89  const pointFieldPMG& points = mesh_.points();
90 
91  zMinPointPtr_ = new boolList(points.size());
92 
93  const scalar tZ = 0.05 * (bb_.max().z() - bb_.min().z());;
94 
95  # ifdef USE_OMP
96  # pragma omp parallel for schedule(dynamic, 50)
97  # endif
98  forAll(points, pointI)
99  {
100  if( Foam::mag(points[pointI].z() - bb_.min().z()) < tZ )
101  {
102  zMinPointPtr_->operator[](pointI) = true;
103  }
104  else
105  {
106  zMinPointPtr_->operator[](pointI) = false;
107  }
108  }
109 }
110 
112 {
113  const boolList& zMinPoints = this->zMinPoints();
114 
115  label counter(0);
116 
117  forAll(zMinPoints, pointI)
118  if( zMinPoints[pointI] )
119  ++counter;
120 
121  if( 2 * counter != zMinPoints.size() )
122  {
124  (
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"
129  << exit(FatalError);
130  }
131 
132  zMinPointLabelsPtr_ = new labelList(counter);
133 
134  counter = 0;
135  forAll(zMinPoints, pointI)
136  if( zMinPoints[pointI] )
137  zMinPointLabelsPtr_->operator[](counter++) = pointI;
138 }
139 
141 {
142  const boolList& zMinPoints = this->zMinPoints();
143  const labelList& zMinPointLabels = this->zMinPointLabels();
144 
145  zMinToZMaxPtr_ = new labelList(zMinPointLabels.size());
146 
147  const VRWGraph& pointPoints = mesh_.addressingData().pointPoints();
148  # ifdef USE_OMP
149  # pragma omp parallel for schedule(dynamic, 50)
150  # endif
152  {
153  const label pointI = zMinPointLabels[pI];
154 
155  label nInactive(0), offsetPoint(-1);
156  forAllRow(pointPoints, pointI, ppI)
157  {
158  if( !zMinPoints[pointPoints(pointI, ppI)] )
159  {
160  ++nInactive;
161  offsetPoint = pointPoints(pointI, ppI);
162  }
163  }
164 
165  if( nInactive == 1 )
166  {
167  zMinToZMaxPtr_->operator[](pI) = offsetPoint;
168  }
169  else
170  {
172  (
173  "void polyMeshGen2DEngine::findZMinOffsetPoints()"
174  ) << "This cannot be a 2D mesh" << exit(FatalError);
175  }
176  }
177 }
178 
180 {
181  const pointFieldPMG& points = mesh_.points();
182 
183  zMaxPointPtr_ = new boolList(points.size());
184 
185  const scalar tZ = 0.05 * (bb_.max().z() - bb_.min().z());
186 
187  # ifdef USE_OMP
188  # pragma omp parallel for schedule(dynamic, 50)
189  # endif
190  forAll(points, pointI)
191  {
192  if( Foam::mag(points[pointI].z() - bb_.max().z()) < tZ )
193  {
194  zMaxPointPtr_->operator[](pointI) = true;
195  }
196  else
197  {
198  zMaxPointPtr_->operator[](pointI) = false;
199  }
200  }
201 }
202 
204 {
205  const boolList& zMaxPoints = this->zMaxPoints();
206 
207  label counter(0);
208 
209  forAll(zMaxPoints, pointI)
210  if( zMaxPoints[pointI] )
211  ++counter;
212 
213  if( 2 * counter != zMaxPoints.size() )
214  {
216  (
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"
221  << exit(FatalError);
222  }
223 
224  zMaxPointLabelsPtr_ = new labelList(counter);
225 
226  counter = 0;
227  forAll(zMaxPoints, pointI)
228  if( zMaxPoints[pointI] )
229  zMaxPointLabelsPtr_->operator[](counter++) = pointI;
230 }
231 
233 {
234  const boolList& zMaxPoints = this->zMaxPoints();
235  const labelList& zMaxPointLabels = this->zMaxPointLabels();
236 
237  zMaxToZMinPtr_ = new labelList(zMaxPointLabels.size());
238 
239  const VRWGraph& pointPoints = mesh_.addressingData().pointPoints();
240  # ifdef USE_OMP
241  # pragma omp parallel for schedule(dynamic, 50)
242  # endif
244  {
245  const label pointI = zMaxPointLabels[pI];
246 
247  label nInactive(0), offsetPoint(-1);
248  forAllRow(pointPoints, pointI, ppI)
249  {
250  if( !zMaxPoints[pointPoints(pointI, ppI)] )
251  {
252  ++nInactive;
253  offsetPoint = pointPoints(pointI, ppI);
254  }
255  }
256 
257  if( nInactive == 1 )
258  {
259  zMaxToZMinPtr_->operator[](pI) = offsetPoint;
260  }
261  else
262  {
264  (
265  "void polyMeshGen2DEngine::findZMaxOffsetPoints()"
266  ) << "This cannot be a 2D mesh" << exit(FatalError);
267  }
268  }
269 }
270 
271 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
272 
274 :
275  mesh_(mesh),
276  bb_(),
277  activeFacePtr_(NULL),
278  activeFaceLabelsPtr_(NULL),
279  zMinPointPtr_(NULL),
280  zMinPointLabelsPtr_(NULL),
281  zMinToZMaxPtr_(NULL),
282  zMaxPointPtr_(NULL),
283  zMaxPointLabelsPtr_(NULL),
284  zMaxToZMinPtr_(NULL)
285 {
286  const pointFieldPMG& points = mesh_.points();
287 
288  bb_.min() = point(VGREAT, VGREAT, VGREAT);
289  bb_.max() = point(-VGREAT, -VGREAT, -VGREAT);
290 
291  # ifdef USE_OMP
292  # pragma omp parallel
293  # endif
294  {
295  point localMin(VGREAT, VGREAT, VGREAT);
296  point localMax(-VGREAT, -VGREAT, -VGREAT);
297 
298  # ifdef USE_OMP
299  # pragma omp for schedule(dynamic, 50)
300  # endif
301  forAll(points, pointI)
302  {
303  localMin = Foam::min(localMin, points[pointI]);
304  localMax = Foam::max(localMax, points[pointI]);
305  }
306 
307  # ifdef USE_OMP
308  # pragma omp critical
309  # endif
310  {
311  bb_.min() = Foam::min(bb_.min(), localMin);
312  bb_.max() = Foam::max(bb_.max(), localMax);
313  }
314  }
315 
316  if( Pstream::parRun() )
317  {
318  reduce(bb_.min(), minOp<point>());
319  reduce(bb_.max(), maxOp<point>());
320  }
321 }
322 
324 {
325  clearOut();
326 }
327 
328 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
329 
331 {
332  pointFieldPMG& points = const_cast<pointFieldPMG&>(mesh_.points());
333 
334  const labelList& zMinPointLabels = this->zMinPointLabels();
335  const labelList& zMinOffset = this->zMinToZMax();
336 
337  # ifdef USE_OMP
338  # pragma omp parallel for schedule(dynamic, 50)
339  # endif
340  forAll(zMinPointLabels, apI)
341  {
342  point& p = points[zMinPointLabels[apI]];
343  point& op = points[zMinOffset[apI]];
344 
345  op.x() = p.x();
346  op.y() = p.y();
347  p.z() = bb_.min().z();
348  op.z() = bb_.max().z();
349  }
350 }
351 
353 {
362 }
363 
364 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
365 
366 } // End namespace Foam
367 
368 // ************************************************************************* //
Foam::polyMeshGen2DEngine::findZMaxPoints
void findZMaxPoints() const
find points at maximum z
Definition: polyMeshGen2DEngine.C:179
Foam::maxOp
Definition: ops.H:172
Foam::polyMeshGen2DEngine::activeFacePtr_
boolList * activeFacePtr_
which faces are not in the x-y plane
Definition: polyMeshGen2DEngine.H:61
Foam::polyMeshGenCells::addressingData
const polyMeshGenAddressing & addressingData() const
addressing which may be needed
Definition: polyMeshGenCells.C:327
p
p
Definition: pEqn.H:62
Foam::labelList
List< label > labelList
A List of labels.
Definition: labelList.H:56
Foam::boundBox::max
const point & max() const
Maximum describing the bounding box.
Definition: boundBoxI.H:60
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::polyMeshGen2DEngine::activeFace
const boolList & activeFace() const
const access to active faces
Definition: polyMeshGen2DEngineI.H:48
Foam::polyMeshGen2DEngine::activeFaceLabelsPtr_
labelList * activeFaceLabelsPtr_
labels of active faces
Definition: polyMeshGen2DEngine.H:64
Foam::localMin
LocalMin-mean differencing scheme class.
Definition: localMin.H:54
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
Foam::minOp
Definition: ops.H:173
Foam::polyMeshGen2DEngine::bb_
boundBox bb_
bounding box
Definition: polyMeshGen2DEngine.H:58
Foam::UPstream::parRun
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:377
Foam::polyMeshGen2DEngine::mesh_
const polyMeshGen & mesh_
const reference to the mesh
Definition: polyMeshGen2DEngine.H:55
Foam::polyMeshGen2DEngine::zMaxPointPtr_
boolList * zMaxPointPtr_
which points are in the x-y plane and at largest z
Definition: polyMeshGen2DEngine.H:76
Foam::polyMeshGen
Definition: polyMeshGen.H:46
Foam::polyMeshGenPoints::points
const pointFieldPMG & points() const
access to points
Definition: polyMeshGenPointsI.H:44
Foam::polyMeshGen2DEngine::findActiveFaces
void findActiveFaces() const
find active faces
Definition: polyMeshGen2DEngine.C:43
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
Foam::polyMeshGen2DEngine::zMinToZMax
const labelList & zMinToZMax() const
offset points of points at minimum z
Definition: polyMeshGen2DEngineI.H:80
Foam::polyMeshGen2DEngine::findZMinOffsetPoints
void findZMinOffsetPoints() const
find offset point to each zMin point
Definition: polyMeshGen2DEngine.C:140
Foam::polyMeshGen2DEngine::zMinPoints
const boolList & zMinPoints() const
Definition: polyMeshGen2DEngineI.H:64
Foam::polyMeshGen2DEngine::zMinPointLabelsPtr_
labelList * zMinPointLabelsPtr_
labels of points at minimum z
Definition: polyMeshGen2DEngine.H:70
Foam::polyMeshGenFaces::faces
const faceListPMG & faces() const
access to faces
Definition: polyMeshGenFacesI.H:43
Foam::polyMeshGen2DEngine::~polyMeshGen2DEngine
~polyMeshGen2DEngine()
Definition: polyMeshGen2DEngine.C:323
Foam::deleteDemandDrivenData
void deleteDemandDrivenData(DataPtr &dataPtr)
Definition: demandDrivenData.H:40
Foam::reduce
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Definition: PstreamReduceOps.H:43
Foam::localMax
LocalMax-mean differencing scheme class.
Definition: localMax.H:54
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::polyMeshGen2DEngine::zMaxToZMinPtr_
labelList * zMaxToZMinPtr_
labels of zMin points of zMax points
Definition: polyMeshGen2DEngine.H:82
Foam::polyMeshGen2DEngine::correctPoints
void correctPoints()
Definition: polyMeshGen2DEngine.C:330
forAllRow
#define forAllRow(graph, rowI, index)
Definition: VRWGraph.H:277
Foam::boundBox::min
const point & min() const
Minimum describing the bounding box.
Definition: boundBoxI.H:54
Foam::polyMeshGen2DEngine::zMaxPoints
const boolList & zMaxPoints() const
Definition: polyMeshGen2DEngineI.H:88
Foam::Vector::x
const Cmpt & x() const
Definition: VectorI.H:65
Foam::FatalError
error FatalError
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
polyMeshGen2DEngine.H
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::Vector::z
const Cmpt & z() const
Definition: VectorI.H:77
Foam::polyMeshGen2DEngine::zMaxPointLabelsPtr_
labelList * zMaxPointLabelsPtr_
labels of points at maximum z
Definition: polyMeshGen2DEngine.H:79
Foam::boolList
List< bool > boolList
Bool container classes.
Definition: boolList.H:50
Foam::polyMeshGen2DEngine::zMinToZMaxPtr_
labelList * zMinToZMaxPtr_
labels of offset points of zMin points
Definition: polyMeshGen2DEngine.H:73
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::polyMeshGen2DEngine::zMinPointLabels
const labelList & zMinPointLabels() const
labels of points in the x-y with the smallest z coordinate
Definition: polyMeshGen2DEngineI.H:72
Foam::max
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::polyMeshGen2DEngine::clearOut
void clearOut()
delete all dynamically allocated data
Definition: polyMeshGen2DEngine.C:352
f
labelList f(nPoints)
Foam::faceListPMG::size
label size() const
return the number of used elements
Definition: faceListPMGI.H:73
Foam::polyMeshGen2DEngine::findActiveFaceLabels
void findActiveFaceLabels() const
find active face labels
Definition: polyMeshGen2DEngine.C:69
Foam::Vector< scalar >
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
Foam::polyMeshGen2DEngine::findZMinPointLabels
void findZMinPointLabels() const
find labels of points at minimum z
Definition: polyMeshGen2DEngine.C:111
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::Vector::y
const Cmpt & y() const
Definition: VectorI.H:71
FatalErrorIn
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:313
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
Foam::polyMeshGen2DEngine::findZMaxOffsetPoints
void findZMaxOffsetPoints() const
find offset point to each zMin point
Definition: polyMeshGen2DEngine.C:232
Foam::polyMeshGenAddressing::pointPoints
const VRWGraph & pointPoints() const
Definition: polyMeshGenAddressingPointPoints.C:124
Foam::polyMeshGen2DEngine::findZMinPoints
void findZMinPoints() const
find points at minimum z
Definition: polyMeshGen2DEngine.C:87
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::point
vector point
Point is a vector.
Definition: point.H:41
Foam::faceListPMG
Definition: faceListPMG.H:50
Foam::pointFieldPMG
Definition: pointFieldPMG.H:50
Foam::VRWGraph
Definition: VRWGraph.H:101
Foam::polyMeshGen2DEngine::findZMaxPointLabels
void findZMaxPointLabels() const
find labels of points at minimum z
Definition: polyMeshGen2DEngine.C:203
polyMeshGenAddressing.H
Foam::min
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::polyMeshGen2DEngine::polyMeshGen2DEngine
polyMeshGen2DEngine(const polyMeshGen2DEngine &)
disallow copy construct
Foam::polyMeshGen2DEngine::zMaxPointLabels
const labelList & zMaxPointLabels() const
labels of points in the x-y with the largest z coordinate
Definition: polyMeshGen2DEngineI.H:96
Foam::polyMeshGen2DEngine::zMinPointPtr_
boolList * zMinPointPtr_
which points are in the x-y plane and at smallest z
Definition: polyMeshGen2DEngine.H:67