PrimitivePatchMeshData.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | foam-extend: Open Source CFD
4  \\ / O peration | Version: 3.2
5  \\ / A nd | Web: http://www.foam-extend.org
6  \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9  This file is part of foam-extend.
10 
11  foam-extend 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  foam-extend is distributed in the hope that it will be useful, but
17  WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "PrimitivePatchTemplate.H"
27 #include "Map.H"
28 
29 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
30 
31 template
32 <
33  class Face,
34  template<class> class FaceList,
35  class PointField,
36  class PointType
37 >
38 void
40 calcMeshData() const
41 {
42  if (debug)
43  {
44  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
45  "calcMeshData() : "
46  "calculating mesh data in PrimitivePatch"
47  << endl;
48  }
49 
50  // It is considered an error to attempt to recalculate meshPoints
51  // if they have already been calculated.
52  if (meshPointsPtr_ || localFacesPtr_)
53  {
55  (
56  "PrimitivePatch<Face, FaceList, PointField, PointType>::"
57  "calcMeshData()"
58  ) << "meshPointsPtr_ or localFacesPtr_ already allocated"
59  << abort(FatalError);
60  }
61 
62  // If there are no faces in the patch, set both lists to zero size
63  // HJ, 22/Nov/2006
64  if (this->size() == 0)
65  {
66  meshPointsPtr_ = new labelList(0);
67  localFacesPtr_ = new List<Face>(0);
68 
69  return;
70  }
71 
72  // Create a map for marking points. Estimated size is 4 times the
73  // number of faces in the patch
74  Map<label> markedPoints(4*this->size());
75 
76 
77  // Important:
78  // ~~~~~~~~~~
79  // In <= 1.5 the meshPoints would be in increasing order but this gives
80  // problems in processor point synchronisation where we have to find out
81  // how the opposite side would have allocated points.
82 
83  // Note:
84  // ~~~~~
85  // This is all garbage. All -ext versions will preserve strong ordering
86  // HJ, 17/Aug/2010
87 
88  //- 1.5 code:
89  // If the point is used, set the mark to 1
90  forAll(*this, facei)
91  {
92  const Face& curPoints = this->operator[](facei);
93 
94  forAll(curPoints, pointi)
95  {
96  markedPoints.insert(curPoints[pointi], -1);
97  }
98  }
99 
100  // Create the storage and store the meshPoints. Mesh points are
101  // the ones marked by the usage loop above
102  meshPointsPtr_ = new labelList(markedPoints.toc());
103  labelList& pointPatch = *meshPointsPtr_;
104 
105  // Sort the list to preserve compatibility with the old ordering
106  sort(pointPatch);
107 
108  // For every point in map give it its label in mesh points
109  forAll(pointPatch, pointi)
110  {
111  markedPoints.find(pointPatch[pointi])() = pointi;
112  }
113 
114  forAll(*this, faceI)
115  {
116  const Face& curPoints = this->operator[](faceI);
117 
118  forAll (curPoints, pointI)
119  {
120  markedPoints.insert(curPoints[pointI], -1);
121  }
122  }
123 
124  // Create local faces. Note that we start off from copy of original face
125  // list (even though vertices are overwritten below). This is done so
126  // additional data gets copied (e.g. region number of labelledTri)
127  localFacesPtr_ = new List<Face>(*this);
128  List<Face>& lf = *localFacesPtr_;
129 
130  forAll (*this, faceI)
131  {
132  const Face& curFace = this->operator[](faceI);
133  lf[faceI].setSize(curFace.size());
134 
135  forAll (curFace, labelI)
136  {
137  lf[faceI][labelI] = markedPoints.find(curFace[labelI])();
138  }
139  }
140 
141  if (debug)
142  {
143  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
144  "calcMeshData() : "
145  "finished calculating mesh data in PrimitivePatch"
146  << endl;
147  }
148 }
149 
150 
151 template
152 <
153  class Face,
154  template<class> class FaceList,
155  class PointField,
156  class PointType
157 >
158 void
161 {
162  if (debug)
163  {
164  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
165  "calcMeshPointMap() : "
166  "calculating mesh point map in PrimitivePatch"
167  << endl;
168  }
169 
170  // It is considered an error to attempt to recalculate meshPoints
171  // if they have already been calculated.
172  if (meshPointMapPtr_)
173  {
175  (
176  "PrimitivePatch<Face, FaceList, PointField, PointType>::"
177  "calcMeshPointMap()"
178  ) << "meshPointMapPtr_ already allocated"
179  << abort(FatalError);
180  }
181 
182  const labelList& mp = meshPoints();
183 
184  meshPointMapPtr_ = new Map<label>(2*mp.size());
185  Map<label>& mpMap = *meshPointMapPtr_;
186 
187  forAll (mp, i)
188  {
189  mpMap.insert(mp[i], i);
190  }
191 
192  if (debug)
193  {
194  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
195  "calcMeshPointMap() : "
196  "finished calculating mesh point map in PrimitivePatch"
197  << endl;
198  }
199 }
200 
201 
202 template
203 <
204  class Face,
205  template<class> class FaceList,
206  class PointField,
207  class PointType
208 >
209 void
212 {
213  if (debug)
214  {
215  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
216  "calcLocalPoints() : "
217  "calculating localPoints in PrimitivePatch"
218  << endl;
219  }
220 
221  // It is considered an error to attempt to recalculate localPoints
222  // if they have already been calculated.
223  if (localPointsPtr_)
224  {
226  (
227  "PrimitivePatch<Face, FaceList, PointField, PointType>::"
228  "calcLocalPoints()"
229  ) << "localPointsPtr_ already allocated"
230  << abort(FatalError);
231  }
232 
233  const labelList& meshPts = meshPoints();
234 
235  localPointsPtr_ = new Field<PointType>(meshPts.size());
236 
237  Field<PointType>& locPts = *localPointsPtr_;
238 
239  forAll (meshPts, pointI)
240  {
241  locPts[pointI] = points_[meshPts[pointI]];
242  }
243 
244  if (debug)
245  {
246  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
247  << "calcLocalPoints() : "
248  << "finished calculating localPoints in PrimitivePatch"
249  << endl;
250  }
251 }
252 
253 
254 template
255 <
256  class Face,
257  template<class> class FaceList,
258  class PointField,
259  class PointType
260 >
261 void
264 {
265  if (debug)
266  {
267  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
268  "calcPointNormals() : "
269  "calculating pointNormals in PrimitivePatch"
270  << endl;
271  }
272 
273  // It is considered an error to attempt to recalculate pointNormals
274  // if they have already been calculated.
275  if (pointNormalsPtr_)
276  {
278  (
279  "PrimitivePatch<Face, FaceList, PointField, PointType>::"
280  "calcPointNormals()"
281  ) << "pointNormalsPtr_ already allocated"
282  << abort(FatalError);
283  }
284 
285  const Field<PointType>& faceUnitNormals = faceNormals();
286 
287  const labelListList& pf = pointFaces();
288 
289  pointNormalsPtr_ = new Field<PointType>
290  (
291  meshPoints().size(),
292  PointType::zero
293  );
294 
295  Field<PointType>& n = *pointNormalsPtr_;
296 
297  forAll (pf, pointI)
298  {
299  PointType& curNormal = n[pointI];
300 
301  const labelList& curFaces = pf[pointI];
302 
303  forAll (curFaces, faceI)
304  {
305  curNormal += faceUnitNormals[curFaces[faceI]];
306  }
307 
308  curNormal /= mag(curNormal) + VSMALL;
309  }
310 
311  if (debug)
312  {
313  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
314  "calcPointNormals() : "
315  "finished calculating pointNormals in PrimitivePatch"
316  << endl;
317  }
318 }
319 
320 template
321 <
322  class Face,
323  template<class> class FaceList,
324  class PointField,
325  class PointType
326 >
327 void
330 {
331  if (debug)
332  {
333  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
334  "calcFaceCentres() : "
335  "calculating faceCentres in PrimitivePatch"
336  << endl;
337  }
338 
339  // It is considered an error to attempt to recalculate faceCentres
340  // if they have already been calculated.
341  if (faceCentresPtr_)
342  {
344  (
345  "PrimitivePatch<Face, FaceList, PointField, PointType>::"
346  "calcFaceCentres()"
347  ) << "faceCentresPtr_already allocated"
348  << abort(FatalError);
349  }
350 
351  faceCentresPtr_ = new Field<PointType>(this->size());
352 
353  Field<PointType>& c = *faceCentresPtr_;
354 
355  forAll(c, facei)
356  {
357  c[facei] = this->operator[](facei).centre(points_);
358  }
359 
360  if (debug)
361  {
362  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
363  "calcFaceCentres() : "
364  "finished calculating faceCentres in PrimitivePatch"
365  << endl;
366  }
367 }
368 
369 
370 template
371 <
372  class Face,
373  template<class> class FaceList,
374  class PointField,
375  class PointType
376 >
377 void
380 {
381  if (debug)
382  {
383  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
384  "calcFaceNormals() : "
385  "calculating faceNormals in PrimitivePatch"
386  << endl;
387  }
388 
389  // It is considered an error to attempt to recalculate faceNormals
390  // if they have already been calculated.
391  if (faceNormalsPtr_)
392  {
394  (
395  "PrimitivePatch<Face, FaceList, PointField, PointType>::"
396  "calcFaceNormals()"
397  ) << "faceNormalsPtr_ already allocated"
398  << abort(FatalError);
399  }
400 
401  faceNormalsPtr_ = new Field<PointType>(this->size());
402 
403  Field<PointType>& n = *faceNormalsPtr_;
404 
405  forAll (n, faceI)
406  {
407  n[faceI] = this->operator[](faceI).normal(points_);
408  n[faceI] /= mag(n[faceI]) + VSMALL;
409  }
410 
411  if (debug)
412  {
413  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
414  "calcFaceNormals() : "
415  "finished calculating faceNormals in PrimitivePatch"
416  << endl;
417  }
418 }
419 
420 
421 // ************************************************************************* //
Foam::PrimitivePatch::calcPointNormals
void calcPointNormals() const
Calculate unit point normals.
Definition: PrimitivePatchMeshData.C:263
Foam::constant::atomic::mp
const dimensionedScalar mp
Proton mass.
Foam::PrimitivePatch::calcFaceNormals
void calcFaceNormals() const
Calculate unit face normals.
Definition: PrimitivePatchMeshData.C:379
Foam::labelList
List< label > labelList
A List of labels.
Definition: labelList.H:56
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::PrimitivePatch::calcMeshData
void calcMeshData() const
Calculate mesh addressing.
Definition: PrimitivePatchMeshData.C:40
Foam::Map< label >
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::pointPatch
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:56
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
PrimitivePatchTemplate.H
Map.H
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::PrimitivePatch::calcMeshPointMap
void calcMeshPointMap() const
Calculate mesh point map.
Definition: PrimitivePatchMeshData.C:160
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::PrimitivePatch::calcLocalPoints
void calcLocalPoints() const
Calculate local points.
Definition: PrimitivePatchMeshData.C:211
Foam::Pout
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
Foam::List< Face >
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::PrimitivePatch::calcFaceCentres
void calcFaceCentres() const
Calculate face centres.
Definition: PrimitivePatchMeshData.C:329
FatalErrorIn
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:313
Foam::sort
void sort(UList< T > &)
Definition: UList.C:107
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::labelI
static const labelSphericalTensor labelI(1)
Identity labelTensor.