PrimitivePatchMeshData.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2015 OpenFOAM Foundation
9  Copyright (C) 2016 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "PrimitivePatch.H"
30 #include "Map.H"
31 
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 
34 template
35 <
36  class Face,
37  template<class> class FaceList,
38  class PointField,
39  class PointType
40 >
41 void
43 calcMeshData() const
44 {
45  if (debug)
46  {
47  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
48  "calcMeshData() : "
49  "calculating mesh data in PrimitivePatch"
50  << endl;
51  }
52 
53  if (meshPointsPtr_ || localFacesPtr_)
54  {
55  // An error to recalculate if already allocated
57  << "meshPointsPtr_ or localFacesPtr_ already allocated"
58  << abort(FatalError);
59  }
60 
61  // Create a map for marking points. Estimated size is 4 times the
62  // number of faces in the patch
63  Map<label> markedPoints(4*this->size());
64 
65 
66  // Important:
67  // ~~~~~~~~~~
68  // In <= 1.5 the meshPoints would be in increasing order but this gives
69  // problems in processor point synchronisation where we have to find out
70  // how the opposite side would have allocated points.
71 
74  //forAll(*this, facei)
75  //{
76  // const Face& curPoints = this->operator[](facei);
77  //
78  // forAll(curPoints, pointi)
79  // {
80  // markedPoints.insert(curPoints[pointi], -1);
81  // }
82  //}
83  //
86  //meshPointsPtr_ = new labelList(markedPoints.toc());
87  //labelList& pointPatch = *meshPointsPtr_;
88  //
90  //sort(pointPatch);
91  //
93  //forAll(pointPatch, pointi)
94  //{
95  // markedPoints.find(pointPatch[pointi])() = pointi;
96  //}
97 
98  //- Unsorted version:
99  DynamicList<label> meshPoints(2*this->size());
100  forAll(*this, facei)
101  {
102  const Face& curPoints = this->operator[](facei);
103 
104  forAll(curPoints, pointi)
105  {
106  if (markedPoints.insert(curPoints[pointi], meshPoints.size()))
107  {
108  meshPoints.append(curPoints[pointi]);
109  }
110  }
111  }
112  // Transfer to straight list (reuses storage)
113  meshPointsPtr_ = new labelList(meshPoints, true);
114 
115 
116  // Create local faces. Note that we start off from copy of original face
117  // list (even though vertices are overwritten below). This is done so
118  // additional data gets copied (e.g. region number of labelledTri)
119  localFacesPtr_ = new List<Face>(*this);
120  List<Face>& lf = *localFacesPtr_;
121 
122  forAll(*this, facei)
123  {
124  const Face& curFace = this->operator[](facei);
125  lf[facei].setSize(curFace.size());
126 
127  forAll(curFace, labelI)
128  {
129  lf[facei][labelI] = markedPoints.find(curFace[labelI])();
130  }
131  }
132 
133  if (debug)
134  {
135  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
136  "calcMeshData() : "
137  "finished calculating mesh data in PrimitivePatch"
138  << endl;
139  }
140 }
141 
142 
143 template
144 <
145  class Face,
146  template<class> class FaceList,
147  class PointField,
148  class PointType
149 >
150 void
152 calcMeshPointMap() const
153 {
154  if (debug)
155  {
156  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
157  "calcMeshPointMap() : "
158  "calculating mesh point map in PrimitivePatch"
159  << endl;
160  }
161 
162  if (meshPointMapPtr_)
163  {
164  // An error to recalculate if already allocated
166  << "meshPointMapPtr_ already allocated"
167  << abort(FatalError);
168  }
169 
170  const labelList& mp = meshPoints();
171 
172  meshPointMapPtr_ = new Map<label>(2*mp.size());
173  Map<label>& mpMap = *meshPointMapPtr_;
174 
175  forAll(mp, i)
176  {
177  mpMap.insert(mp[i], i);
178  }
179 
180  if (debug)
181  {
182  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
183  "calcMeshPointMap() : "
184  "finished calculating mesh point map in PrimitivePatch"
185  << endl;
186  }
187 }
188 
189 
190 template
191 <
192  class Face,
193  template<class> class FaceList,
194  class PointField,
195  class PointType
196 >
197 void
199 calcLocalPoints() const
200 {
201  if (debug)
202  {
203  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
204  "calcLocalPoints() : "
205  "calculating localPoints in PrimitivePatch"
206  << endl;
207  }
208 
209  if (localPointsPtr_)
210  {
211  // An error to recalculate if already allocated
213  << "localPointsPtr_ already allocated"
214  << abort(FatalError);
215  }
216 
217  const labelList& meshPts = meshPoints();
218 
219  localPointsPtr_ = new Field<PointType>(meshPts.size());
220 
221  Field<PointType>& locPts = *localPointsPtr_;
222 
223  forAll(meshPts, pointi)
224  {
225  locPts[pointi] = points_[meshPts[pointi]];
226  }
227 
228  if (debug)
229  {
230  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
231  << "calcLocalPoints() : "
232  << "finished calculating localPoints in PrimitivePatch"
233  << endl;
234  }
235 }
236 
237 
238 template
239 <
240  class Face,
241  template<class> class FaceList,
242  class PointField,
243  class PointType
244 >
245 void
247 calcPointNormals() const
248 {
249  if (debug)
250  {
251  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
252  "calcPointNormals() : "
253  "calculating pointNormals in PrimitivePatch"
254  << endl;
255  }
256 
257  if (pointNormalsPtr_)
258  {
259  // An error to recalculate if already allocated
261  << "pointNormalsPtr_ already allocated"
262  << abort(FatalError);
263  }
264 
265  const Field<PointType>& faceUnitNormals = faceNormals();
266 
267  const labelListList& pf = pointFaces();
268 
269  pointNormalsPtr_ = new Field<PointType>
270  (
271  meshPoints().size(),
272  PointType::zero
273  );
274 
275  Field<PointType>& n = *pointNormalsPtr_;
276 
277  forAll(pf, pointi)
278  {
279  PointType& curNormal = n[pointi];
280 
281  const labelList& curFaces = pf[pointi];
282 
283  for (const label facei : curFaces)
284  {
285  curNormal += faceUnitNormals[facei];
286  }
287 
288  curNormal.normalise();
289  }
290 
291  if (debug)
292  {
293  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
294  "calcPointNormals() : "
295  "finished calculating pointNormals in PrimitivePatch"
296  << endl;
297  }
298 }
299 
300 
301 template
302 <
303  class Face,
304  template<class> class FaceList,
305  class PointField,
306  class PointType
307 >
308 void
310 calcFaceCentres() const
311 {
312  if (debug)
313  {
314  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
315  "calcFaceCentres() : "
316  "calculating faceCentres in PrimitivePatch"
317  << endl;
318  }
319 
320  if (faceCentresPtr_)
321  {
322  // An error to recalculate if already allocated
324  << "faceCentresPtr_ already allocated"
325  << abort(FatalError);
326  }
327 
328  faceCentresPtr_ = new Field<PointType>(this->size());
329 
330  Field<PointType>& c = *faceCentresPtr_;
331 
332  forAll(c, facei)
333  {
334  c[facei] = this->operator[](facei).centre(points_);
335  }
336 
337  if (debug)
338  {
339  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
340  "calcFaceCentres() : "
341  "finished calculating faceCentres in PrimitivePatch"
342  << endl;
343  }
344 }
345 
346 
347 template
348 <
349  class Face,
350  template<class> class FaceList,
351  class PointField,
352  class PointType
353 >
354 void
356 calcMagFaceAreas() const
357 {
358  if (debug)
359  {
360  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
361  "calcMagFaceAreas() : "
362  "calculating magFaceAreas in PrimitivePatch"
363  << endl;
364  }
365 
366  if (magFaceAreasPtr_)
367  {
368  // An error to recalculate if already allocated
370  << "magFaceAreasPtr_ already allocated"
371  << abort(FatalError);
372  }
373 
374  magFaceAreasPtr_ = new Field<scalar>(this->size());
375  Field<scalar>& a = *magFaceAreasPtr_;
376 
377  forAll(a, facei)
378  {
379  a[facei] = this->operator[](facei).mag(points_);
380  }
381 
382  if (debug)
383  {
384  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
385  "calcMagFaceAreas() : "
386  "finished calculating magFaceAreas in PrimitivePatch"
387  << endl;
388  }
389 }
390 
391 
392 template
393 <
394  class Face,
395  template<class> class FaceList,
396  class PointField,
397  class PointType
398 >
399 void
401 calcFaceAreas() const
402 {
403  if (debug)
404  {
405  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
406  "calcFaceAreas() : "
407  "calculating faceAreas in PrimitivePatch"
408  << endl;
409  }
410 
411  if (faceAreasPtr_)
412  {
413  // An error to recalculate if already allocated
415  << "faceAreasPtr_ already allocated"
416  << abort(FatalError);
417  }
418 
419  faceAreasPtr_ = new Field<PointType>(this->size());
420 
421  Field<PointType>& n = *faceAreasPtr_;
422 
423  forAll(n, facei)
424  {
425  n[facei] = this->operator[](facei).areaNormal(points_);
426  }
427 
428  if (debug)
429  {
430  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
431  "calcFaceAreas() : "
432  "finished calculating faceAreas in PrimitivePatch"
433  << endl;
434  }
435 }
436 
437 
438 template
439 <
440  class Face,
441  template<class> class FaceList,
442  class PointField,
443  class PointType
444 >
445 void
447 calcFaceNormals() const
448 {
449  if (debug)
450  {
451  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
452  "calcFaceNormals() : "
453  "calculating faceNormals in PrimitivePatch"
454  << endl;
455  }
456 
457  if (faceNormalsPtr_)
458  {
459  // An error to recalculate if already allocated
461  << "faceNormalsPtr_ already allocated"
462  << abort(FatalError);
463  }
464 
465  faceNormalsPtr_ = new Field<PointType>(this->size());
466 
467  Field<PointType>& n = *faceNormalsPtr_;
468 
469  forAll(n, facei)
470  {
471  n[facei] = this->operator[](facei).unitNormal(points_);
472  }
473 
474  if (debug)
475  {
476  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
477  "calcFaceNormals() : "
478  "finished calculating faceNormals in PrimitivePatch"
479  << endl;
480  }
481 }
482 
483 
484 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:74
Foam::constant::atomic::mp
const dimensionedScalar mp
Proton mass.
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::Pout
prefixOSstream Pout
An Ostream wrapper for parallel output to std::cout.
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Map.H
n
label n
Definition: TABSMDCalcMethod2.H:31
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:62
faceNormals
surfaceVectorField faceNormals(mesh.Sf()/mesh.magSf())
PrimitivePatch.H
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:137
Foam::labelListList
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:56
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatch.H:90
Foam::labelI
static const labelSphericalTensor labelI(1)
Identity labelTensor.