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 | Copyright (C) 2011-2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM 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 OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "PrimitivePatch.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  << "meshPointsPtr_ or localFacesPtr_already allocated"
56  << abort(FatalError);
57  }
58 
59  // Create a map for marking points. Estimated size is 4 times the
60  // number of faces in the patch
61  Map<label> markedPoints(4*this->size());
62 
63 
64  // Important:
65  // ~~~~~~~~~~
66  // In <= 1.5 the meshPoints would be in increasing order but this gives
67  // problems in processor point synchronisation where we have to find out
68  // how the opposite side would have allocated points.
69 
72  //forAll(*this, facei)
73  //{
74  // const Face& curPoints = this->operator[](facei);
75  //
76  // forAll(curPoints, pointi)
77  // {
78  // markedPoints.insert(curPoints[pointi], -1);
79  // }
80  //}
81  //
84  //meshPointsPtr_ = new labelList(markedPoints.toc());
85  //labelList& pointPatch = *meshPointsPtr_;
86  //
88  //sort(pointPatch);
89  //
91  //forAll(pointPatch, pointi)
92  //{
93  // markedPoints.find(pointPatch[pointi])() = pointi;
94  //}
95 
96  //- Unsorted version:
97  DynamicList<label> meshPoints(2*this->size());
98  forAll(*this, facei)
99  {
100  const Face& curPoints = this->operator[](facei);
101 
102  forAll(curPoints, pointi)
103  {
104  if (markedPoints.insert(curPoints[pointi], meshPoints.size()))
105  {
106  meshPoints.append(curPoints[pointi]);
107  }
108  }
109  }
110  // Transfer to straight list (reuses storage)
111  meshPointsPtr_ = new labelList(meshPoints, true);
112 
113 
114  // Create local faces. Note that we start off from copy of original face
115  // list (even though vertices are overwritten below). This is done so
116  // additional data gets copied (e.g. region number of labelledTri)
117  localFacesPtr_ = new List<Face>(*this);
118  List<Face>& lf = *localFacesPtr_;
119 
120  forAll(*this, facei)
121  {
122  const Face& curFace = this->operator[](facei);
123  lf[facei].setSize(curFace.size());
124 
125  forAll(curFace, labelI)
126  {
127  lf[facei][labelI] = markedPoints.find(curFace[labelI])();
128  }
129  }
130 
131  if (debug)
132  {
133  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
134  "calcMeshData() : "
135  "finished calculating mesh data in PrimitivePatch"
136  << endl;
137  }
138 }
139 
140 
141 template
142 <
143  class Face,
144  template<class> class FaceList,
145  class PointField,
146  class PointType
147 >
148 void
150 calcMeshPointMap() const
151 {
152  if (debug)
153  {
154  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
155  "calcMeshPointMap() : "
156  "calculating mesh point map in PrimitivePatch"
157  << endl;
158  }
159 
160  // It is considered an error to attempt to recalculate meshPoints
161  // if they have already been calculated.
162  if (meshPointMapPtr_)
163  {
165  << "meshPointMapPtr_ already allocated"
166  << abort(FatalError);
167  }
168 
169  const labelList& mp = meshPoints();
170 
171  meshPointMapPtr_ = new Map<label>(2*mp.size());
172  Map<label>& mpMap = *meshPointMapPtr_;
173 
174  forAll(mp, i)
175  {
176  mpMap.insert(mp[i], i);
177  }
178 
179  if (debug)
180  {
181  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
182  "calcMeshPointMap() : "
183  "finished calculating mesh point map in PrimitivePatch"
184  << endl;
185  }
186 }
187 
188 
189 template
190 <
191  class Face,
192  template<class> class FaceList,
193  class PointField,
194  class PointType
195 >
196 void
198 calcLocalPoints() const
199 {
200  if (debug)
201  {
202  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
203  "calcLocalPoints() : "
204  "calculating localPoints in PrimitivePatch"
205  << endl;
206  }
207 
208  // It is considered an error to attempt to recalculate localPoints
209  // if they have already been calculated.
210  if (localPointsPtr_)
211  {
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  // It is considered an error to attempt to recalculate pointNormals
258  // if they have already been calculated.
259  if (pointNormalsPtr_)
260  {
262  << "pointNormalsPtr_already allocated"
263  << abort(FatalError);
264  }
265 
266  const Field<PointType>& faceUnitNormals = faceNormals();
267 
268  const labelListList& pf = pointFaces();
269 
270  pointNormalsPtr_ = new Field<PointType>
271  (
272  meshPoints().size(),
273  PointType::zero
274  );
275 
276  Field<PointType>& n = *pointNormalsPtr_;
277 
278  forAll(pf, pointi)
279  {
280  PointType& curNormal = n[pointi];
281 
282  const labelList& curFaces = pf[pointi];
283 
284  forAll(curFaces, facei)
285  {
286  curNormal += faceUnitNormals[curFaces[facei]];
287  }
288 
289  curNormal /= mag(curNormal) + VSMALL;
290  }
291 
292  if (debug)
293  {
294  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
295  "calcPointNormals() : "
296  "finished calculating pointNormals in PrimitivePatch"
297  << endl;
298  }
299 }
300 
301 
302 template
303 <
304  class Face,
305  template<class> class FaceList,
306  class PointField,
307  class PointType
308 >
309 void
311 calcFaceCentres() const
312 {
313  if (debug)
314  {
315  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
316  "calcFaceCentres() : "
317  "calculating faceCentres in PrimitivePatch"
318  << endl;
319  }
320 
321  // It is considered an error to attempt to recalculate faceCentres
322  // if they have already been calculated.
323  if (faceCentresPtr_)
324  {
326  << "faceCentresPtr_already allocated"
327  << abort(FatalError);
328  }
329 
330  faceCentresPtr_ = new Field<PointType>(this->size());
331 
332  Field<PointType>& c = *faceCentresPtr_;
333 
334  forAll(c, facei)
335  {
336  c[facei] = this->operator[](facei).centre(points_);
337  }
338 
339  if (debug)
340  {
341  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
342  "calcFaceCentres() : "
343  "finished calculating faceCentres in PrimitivePatch"
344  << endl;
345  }
346 }
347 
348 
349 template
350 <
351  class Face,
352  template<class> class FaceList,
353  class PointField,
354  class PointType
355 >
356 void
358 calcFaceNormals() const
359 {
360  if (debug)
361  {
362  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
363  "calcFaceNormals() : "
364  "calculating faceNormals in PrimitivePatch"
365  << endl;
366  }
367 
368  // It is considered an error to attempt to recalculate faceNormals
369  // if they have already been calculated.
370  if (faceNormalsPtr_)
371  {
373  << "faceNormalsPtr_already allocated"
374  << abort(FatalError);
375  }
376 
377  faceNormalsPtr_ = new Field<PointType>(this->size());
378 
379  Field<PointType>& n = *faceNormalsPtr_;
380 
381  forAll(n, facei)
382  {
383  n[facei] = this->operator[](facei).normal(points_);
384  n[facei] /= mag(n[facei]) + VSMALL;
385  }
386 
387  if (debug)
388  {
389  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
390  "calcFaceNormals() : "
391  "finished calculating faceNormals in PrimitivePatch"
392  << endl;
393  }
394 }
395 
396 
397 // ************************************************************************* //
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
A list of faces which address into the list of points.
static const labelSphericalTensor labelI(1)
Identity labelTensor.
List< label > labelList
A List of labels.
Definition: labelList.H:56
errorManip< error > abort(error &err)
Definition: errorManip.H:131
prefixOSstream Pout(cout,"Pout")
Definition: IOstreams.H:53
dimensioned< scalar > mag(const dimensioned< Type > &)