FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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 <OpenFOAM/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  // Create a map for marking points. Estimated size is 4 times the
63  // number of faces in the patch
64  Map<label> markedPoints(4*this->size());
65 
66 
67  // Important:
68  // ~~~~~~~~~~
69  // In <= 1.5 the meshPoints would be in increasing order but this gives
70  // problems in processor point synchronisation where we have to find out
71  // how the opposite side would have allocated points.
72 
75  //forAll(*this, facei)
76  //{
77  // const Face& curPoints = this->operator[](facei);
78  //
79  // forAll(curPoints, pointi)
80  // {
81  // markedPoints.insert(curPoints[pointi], -1);
82  // }
83  //}
84  //
87  //meshPointsPtr_ = new labelList(markedPoints.toc());
88  //labelList& pointPatch = *meshPointsPtr_;
89  //
91  //sort(pointPatch);
92  //
94  //forAll(pointPatch, pointi)
95  //{
96  // markedPoints.find(pointPatch[pointi])() = pointi;
97  //}
98 
99  //- Unsorted version:
100  DynamicList<label> meshPoints(2*this->size());
101  forAll(*this, facei)
102  {
103  const Face& curPoints = this->operator[](facei);
104 
105  forAll(curPoints, pointi)
106  {
107  if (markedPoints.insert(curPoints[pointi], meshPoints.size()))
108  {
109  meshPoints.append(curPoints[pointi]);
110  }
111  }
112  }
113  // Transfer to straight list (reuses storage)
114  meshPointsPtr_ = new labelList(meshPoints, true);
115 
116 
117  // Create local faces. Note that we start off from copy of original face
118  // list (even though vertices are overwritten below). This is done so
119  // additional data gets copied (e.g. region number of labelledTri)
120  localFacesPtr_ = new List<Face>(*this);
121  List<Face>& lf = *localFacesPtr_;
122 
123  forAll(*this, facei)
124  {
125  const Face& curFace = this->operator[](facei);
126  lf[facei].setSize(curFace.size());
127 
128  forAll(curFace, labelI)
129  {
130  lf[facei][labelI] = markedPoints.find(curFace[labelI])();
131  }
132  }
133 
134  if (debug)
135  {
136  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
137  "calcMeshData() : "
138  "finished calculating mesh data in PrimitivePatch"
139  << endl;
140  }
141 }
142 
143 
144 template
145 <
146  class Face,
147  template<class> class FaceList,
148  class PointField,
149  class PointType
150 >
151 void
153 calcMeshPointMap() const
154 {
155  if (debug)
156  {
157  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
158  "calcMeshPointMap() : "
159  "calculating mesh point map in PrimitivePatch"
160  << endl;
161  }
162 
163  // It is considered an error to attempt to recalculate meshPoints
164  // if they have already been calculated.
165  if (meshPointMapPtr_)
166  {
168  (
169  "PrimitivePatch<Face, FaceList, PointField, PointType>::"
170  "calcMeshPointMap()"
171  ) << "meshPointMapPtr_ already allocated"
172  << abort(FatalError);
173  }
174 
175  const labelList& mp = meshPoints();
176 
177  meshPointMapPtr_ = new Map<label>(2*mp.size());
178  Map<label>& mpMap = *meshPointMapPtr_;
179 
180  forAll(mp, i)
181  {
182  mpMap.insert(mp[i], i);
183  }
184 
185  if (debug)
186  {
187  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
188  "calcMeshPointMap() : "
189  "finished calculating mesh point map in PrimitivePatch"
190  << endl;
191  }
192 }
193 
194 
195 template
196 <
197  class Face,
198  template<class> class FaceList,
199  class PointField,
200  class PointType
201 >
202 void
204 calcLocalPoints() const
205 {
206  if (debug)
207  {
208  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
209  "calcLocalPoints() : "
210  "calculating localPoints in PrimitivePatch"
211  << endl;
212  }
213 
214  // It is considered an error to attempt to recalculate localPoints
215  // if they have already been calculated.
216  if (localPointsPtr_)
217  {
219  (
220  "PrimitivePatch<Face, FaceList, PointField, PointType>::"
221  "calcLocalPoints()"
222  ) << "localPointsPtr_already allocated"
223  << abort(FatalError);
224  }
225 
226  const labelList& meshPts = meshPoints();
227 
228  localPointsPtr_ = new Field<PointType>(meshPts.size());
229 
230  Field<PointType>& locPts = *localPointsPtr_;
231 
232  forAll(meshPts, pointi)
233  {
234  locPts[pointi] = points_[meshPts[pointi]];
235  }
236 
237  if (debug)
238  {
239  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
240  << "calcLocalPoints() : "
241  << "finished calculating localPoints in PrimitivePatch"
242  << endl;
243  }
244 }
245 
246 
247 template
248 <
249  class Face,
250  template<class> class FaceList,
251  class PointField,
252  class PointType
253 >
254 void
256 calcPointNormals() const
257 {
258  if (debug)
259  {
260  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
261  "calcPointNormals() : "
262  "calculating pointNormals in PrimitivePatch"
263  << endl;
264  }
265 
266  // It is considered an error to attempt to recalculate pointNormals
267  // if they have already been calculated.
268  if (pointNormalsPtr_)
269  {
271  (
272  "PrimitivePatch<Face, FaceList, PointField, PointType>::"
273  "calcPointNormals()"
274  ) << "pointNormalsPtr_already allocated"
275  << abort(FatalError);
276  }
277 
278  const Field<PointType>& faceUnitNormals = faceNormals();
279 
280  const labelListList& pf = pointFaces();
281 
282  pointNormalsPtr_ = new Field<PointType>
283  (
284  meshPoints().size(),
285  PointType::zero
286  );
287 
288  Field<PointType>& n = *pointNormalsPtr_;
289 
290  forAll(pf, pointi)
291  {
292  PointType& curNormal = n[pointi];
293 
294  const labelList& curFaces = pf[pointi];
295 
296  forAll(curFaces, facei)
297  {
298  curNormal += faceUnitNormals[curFaces[facei]];
299  }
300 
301  curNormal /= mag(curNormal) + VSMALL;
302  }
303 
304  if (debug)
305  {
306  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
307  "calcPointNormals() : "
308  "finished calculating pointNormals in PrimitivePatch"
309  << endl;
310  }
311 }
312 
313 
314 template
315 <
316  class Face,
317  template<class> class FaceList,
318  class PointField,
319  class PointType
320 >
321 void
323 calcFaceCentres() const
324 {
325  if (debug)
326  {
327  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
328  "calcFaceCentres() : "
329  "calculating faceCentres in PrimitivePatch"
330  << endl;
331  }
332 
333  // It is considered an error to attempt to recalculate faceCentres
334  // if they have already been calculated.
335  if (faceCentresPtr_)
336  {
338  (
339  "PrimitivePatch<Face, FaceList, PointField, PointType>::"
340  "calcFaceCentres()"
341  ) << "faceCentresPtr_already allocated"
342  << abort(FatalError);
343  }
344 
345  faceCentresPtr_ = new Field<PointType>(this->size());
346 
347  Field<PointType>& c = *faceCentresPtr_;
348 
349  forAll(c, facei)
350  {
351  c[facei] = this->operator[](facei).centre(points_);
352  }
353 
354  if (debug)
355  {
356  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
357  "calcFaceCentres() : "
358  "finished calculating faceCentres in PrimitivePatch"
359  << endl;
360  }
361 }
362 
363 
364 template
365 <
366  class Face,
367  template<class> class FaceList,
368  class PointField,
369  class PointType
370 >
371 void
373 calcFaceNormals() const
374 {
375  if (debug)
376  {
377  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
378  "calcFaceNormals() : "
379  "calculating faceNormals in PrimitivePatch"
380  << endl;
381  }
382 
383  // It is considered an error to attempt to recalculate faceNormals
384  // if they have already been calculated.
385  if (faceNormalsPtr_)
386  {
388  (
389  "PrimitivePatch<Face, FaceList, PointField, PointType>::"
390  "calcFaceNormals()"
391  ) << "faceNormalsPtr_already allocated"
392  << abort(FatalError);
393  }
394 
395  faceNormalsPtr_ = new Field<PointType>(this->size());
396 
397  Field<PointType>& n = *faceNormalsPtr_;
398 
399  forAll(n, facei)
400  {
401  n[facei] = this->operator[](facei).normal(points_);
402  n[facei] /= mag(n[facei]) + VSMALL;
403  }
404 
405  if (debug)
406  {
407  Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
408  "calcFaceNormals() : "
409  "finished calculating faceNormals in PrimitivePatch"
410  << endl;
411  }
412 }
413 
414 
415 // ************************ vim: set sw=4 sts=4 et: ************************ //