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<class FaceList, class PointField>
35 void
37 {
38  if (debug)
39  {
40  Pout<< "PrimitivePatch<FaceList, PointField>::"
41  "calcMeshData() : "
42  "calculating mesh data in PrimitivePatch"
43  << endl;
44  }
45 
46  if (meshPointsPtr_ || localFacesPtr_)
47  {
48  // An error to recalculate if already allocated
50  << "meshPointsPtr_ or localFacesPtr_ already allocated"
51  << abort(FatalError);
52  }
53 
54  // Create a map for marking points. Estimated size is 4 times the
55  // number of faces in the patch
56  Map<label> markedPoints(4*this->size());
57 
58 
59  // Important:
60  // ~~~~~~~~~~
61  // In <= 1.5 the meshPoints would be in increasing order but this gives
62  // problems in processor point synchronisation where we have to find out
63  // how the opposite side would have allocated points.
64 
67  //forAll(*this, facei)
68  //{
69  // const face_type& curPoints = this->operator[](facei);
70  //
71  // forAll(curPoints, pointi)
72  // {
73  // markedPoints.insert(curPoints[pointi], -1);
74  // }
75  //}
76  //
79  //meshPointsPtr_.reset(new labelList(markedPoints.toc()));
80  //auto& pointPatch = *meshPointsPtr_;
81  //
83  //sort(pointPatch);
84  //
86  //forAll(pointPatch, pointi)
87  //{
88  // markedPoints.find(pointPatch[pointi])() = pointi;
89  //}
90 
91  //- Unsorted version:
92  DynamicList<label> meshPoints(2*this->size());
93  for (const face_type& f : *this)
94  {
95  for (const label pointi : f)
96  {
97  if (markedPoints.insert(pointi, meshPoints.size()))
98  {
99  meshPoints.append(pointi);
100  }
101  }
102  }
103  // Transfer to straight list (reuses storage)
104  meshPointsPtr_.reset(new labelList(meshPoints, true));
105 
106  // Create local faces. Deep-copy original faces to retain additional
107  // data (e.g. region number of labelledTri)
108  // The vertices will be overwritten later
109  localFacesPtr_.reset(new List<face_type>(*this));
110  auto& locFaces = *localFacesPtr_;
111 
112  for (face_type& f : locFaces)
113  {
114  for (label& pointi : f)
115  {
116  pointi = *(markedPoints.cfind(pointi));
117  }
118  }
119 
120  if (debug)
121  {
122  Pout<< "PrimitivePatch<FaceList, PointField>::"
123  "calcMeshData() : "
124  "finished calculating mesh data in PrimitivePatch"
125  << endl;
126  }
127 }
128 
129 
130 template<class FaceList, class PointField>
131 void
133 {
134  if (debug)
135  {
136  Pout<< "PrimitivePatch<FaceList, PointField>::"
137  "calcMeshPointMap() : "
138  "calculating mesh point map in PrimitivePatch"
139  << endl;
140  }
141 
142  if (meshPointMapPtr_)
143  {
144  // An error to recalculate if already allocated
146  << "meshPointMapPtr_ already allocated"
147  << abort(FatalError);
148  }
149 
150  const labelList& mp = meshPoints();
151 
152  meshPointMapPtr_.reset(new Map<label>(2*mp.size()));
153  auto& mpMap = *meshPointMapPtr_;
154 
155  forAll(mp, i)
156  {
157  mpMap.insert(mp[i], i);
158  }
159 
160  if (debug)
161  {
162  Pout<< "PrimitivePatch<FaceList, PointField>::"
163  "calcMeshPointMap() : "
164  "finished calculating mesh point map in PrimitivePatch"
165  << endl;
166  }
167 }
168 
169 
170 template<class FaceList, class PointField>
171 void
173 {
174  if (debug)
175  {
176  Pout<< "PrimitivePatch<FaceList, PointField>::"
177  "calcLocalPoints() : "
178  "calculating localPoints in PrimitivePatch"
179  << endl;
180  }
181 
182  if (localPointsPtr_)
183  {
184  // An error to recalculate if already allocated
186  << "localPointsPtr_ already allocated"
187  << abort(FatalError);
188  }
189 
190  const labelList& meshPts = meshPoints();
191 
192  localPointsPtr_.reset(new Field<point_type>(meshPts.size()));
193  auto& locPts = *localPointsPtr_;
194 
195  forAll(meshPts, pointi)
196  {
197  locPts[pointi] = points_[meshPts[pointi]];
198  }
199 
200  if (debug)
201  {
202  Pout<< "PrimitivePatch<FaceList, PointField>::"
203  << "calcLocalPoints() : "
204  << "finished calculating localPoints in PrimitivePatch"
205  << endl;
206  }
207 }
208 
209 
210 template<class FaceList, class PointField>
211 void
213 {
214  if (debug)
215  {
216  Pout<< "PrimitivePatch<FaceList, PointField>::"
217  "calcPointNormals() : "
218  "calculating pointNormals in PrimitivePatch"
219  << endl;
220  }
221 
222  if (pointNormalsPtr_)
223  {
224  // An error to recalculate if already allocated
226  << "pointNormalsPtr_ already allocated"
227  << abort(FatalError);
228  }
229 
230  const auto& faceUnitNormals = faceNormals();
231 
232  const labelListList& pf = pointFaces();
233 
234  pointNormalsPtr_.reset(new Field<point_type>(meshPoints().size(), Zero));
235  auto& n = *pointNormalsPtr_;
236 
237  forAll(pf, pointi)
238  {
239  point_type& curNormal = n[pointi];
240 
241  const labelList& curFaces = pf[pointi];
242 
243  for (const label facei : curFaces)
244  {
245  curNormal += faceUnitNormals[facei];
246  }
247 
248  curNormal.normalise();
249  }
250 
251  if (debug)
252  {
253  Pout<< "PrimitivePatch<FaceList, PointField>::"
254  "calcPointNormals() : "
255  "finished calculating pointNormals in PrimitivePatch"
256  << endl;
257  }
258 }
259 
260 
261 template<class FaceList, class PointField>
262 void
264 {
265  if (debug)
266  {
267  Pout<< "PrimitivePatch<FaceList, PointField>::"
268  "calcFaceCentres() : "
269  "calculating faceCentres in PrimitivePatch"
270  << endl;
271  }
272 
273  if (faceCentresPtr_)
274  {
275  // An error to recalculate if already allocated
277  << "faceCentresPtr_ already allocated"
278  << abort(FatalError);
279  }
280 
281  faceCentresPtr_.reset(new Field<point_type>(this->size()));
282  auto& c = *faceCentresPtr_;
283 
284  forAll(c, facei)
285  {
286  c[facei] = this->operator[](facei).centre(points_);
287  }
288 
289  if (debug)
290  {
291  Pout<< "PrimitivePatch<FaceList, PointField>::"
292  "calcFaceCentres() : "
293  "finished calculating faceCentres in PrimitivePatch"
294  << endl;
295  }
296 }
297 
298 
299 template<class FaceList, class PointField>
300 void
302 {
303  if (debug)
304  {
305  Pout<< "PrimitivePatch<FaceList, PointField>::"
306  "calcMagFaceAreas() : "
307  "calculating magFaceAreas in PrimitivePatch"
308  << endl;
309  }
310 
311  if (magFaceAreasPtr_)
312  {
313  // An error to recalculate if already allocated
315  << "magFaceAreasPtr_ already allocated"
316  << abort(FatalError);
317  }
318 
319  magFaceAreasPtr_.reset(new Field<scalar>(this->size()));
320  auto& a = *magFaceAreasPtr_;
321 
322  forAll(a, facei)
323  {
324  a[facei] = this->operator[](facei).mag(points_);
325  }
326 
327  if (debug)
328  {
329  Pout<< "PrimitivePatch<FaceList, PointField>::"
330  "calcMagFaceAreas() : "
331  "finished calculating magFaceAreas in PrimitivePatch"
332  << endl;
333  }
334 }
335 
336 
337 template<class FaceList, class PointField>
338 void
340 {
341  if (debug)
342  {
343  Pout<< "PrimitivePatch<FaceList, PointField>::"
344  "calcFaceAreas() : "
345  "calculating faceAreas in PrimitivePatch"
346  << endl;
347  }
348 
349  if (faceAreasPtr_)
350  {
351  // An error to recalculate if already allocated
353  << "faceAreasPtr_ already allocated"
354  << abort(FatalError);
355  }
356 
357  faceAreasPtr_.reset(new Field<point_type>(this->size()));
358  auto& n = *faceAreasPtr_;
359 
360  forAll(n, facei)
361  {
362  n[facei] = this->operator[](facei).areaNormal(points_);
363  }
364 
365  if (debug)
366  {
367  Pout<< "PrimitivePatch<FaceList, PointField>::"
368  "calcFaceAreas() : "
369  "finished calculating faceAreas in PrimitivePatch"
370  << endl;
371  }
372 }
373 
374 
375 template<class FaceList, class PointField>
376 void
378 {
379  if (debug)
380  {
381  Pout<< "PrimitivePatch<FaceList, PointField>::"
382  "calcFaceNormals() : "
383  "calculating faceNormals in PrimitivePatch"
384  << endl;
385  }
386 
387  if (faceNormalsPtr_)
388  {
389  // An error to recalculate if already allocated
391  << "faceNormalsPtr_ already allocated"
392  << abort(FatalError);
393  }
394 
395  faceNormalsPtr_.reset(new Field<point_type>(this->size()));
396  auto& n = *faceNormalsPtr_;
397 
398  forAll(n, facei)
399  {
400  n[facei] = this->operator[](facei).unitNormal(points_);
401  }
402 
403  if (debug)
404  {
405  Pout<< "PrimitivePatch<FaceList, PointField>::"
406  "calcFaceNormals() : "
407  "finished calculating faceNormals in PrimitivePatch"
408  << endl;
409  }
410 }
411 
412 
413 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:71
Foam::constant::atomic::mp
const dimensionedScalar mp
Proton mass.
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::Pout
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Map.H
n
label n
Definition: TABSMDCalcMethod2.H:31
faceNormals
surfaceVectorField faceNormals(mesh.Sf()/mesh.magSf())
PrimitivePatch.H
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
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:381
f
labelList f(nPoints)
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:85