PrimitivePatchMeshData.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 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<class FaceList, class PointField>
33 {
34  if (debug)
35  {
36  Pout<< "PrimitivePatch<FaceList, PointField>::calcMeshData() : "
37  "calculating mesh data in PrimitivePatch"
38  << endl;
39  }
40 
41  // It is considered an error to attempt to recalculate meshPoints
42  // if they have already been calculated.
43  if (meshPointsPtr_ || localFacesPtr_)
44  {
46  << "meshPointsPtr_ or localFacesPtr_already allocated"
47  << abort(FatalError);
48  }
49 
50  // Create a map for marking points. Estimated size is 4 times the
51  // number of faces in the patch
52  Map<label> markedPoints(4*this->size());
53 
54 
55  // Important:
56  // ~~~~~~~~~~
57  // In <= 1.5 the meshPoints would be in increasing order but this gives
58  // problems in processor point synchronisation where we have to find out
59  // how the opposite side would have allocated points.
60 
63  // forAll(*this, facei)
64  //{
65  // const FaceType& curPoints = this->operator[](facei);
66  //
67  // forAll(curPoints, pointi)
68  // {
69  // markedPoints.insert(curPoints[pointi], -1);
70  // }
71  //}
72  //
75  // meshPointsPtr_ = new labelList(markedPoints.toc());
76  // labelList& pointPatch = *meshPointsPtr_;
77  //
79  // sort(pointPatch);
80  //
82  // forAll(pointPatch, pointi)
83  //{
84  // markedPoints.find(pointPatch[pointi])() = pointi;
85  //}
86 
87  //- Unsorted version:
88  DynamicList<label> meshPoints(2*this->size());
89  forAll(*this, facei)
90  {
91  const FaceType& curPoints = this->operator[](facei);
92 
93  forAll(curPoints, pointi)
94  {
95  if (markedPoints.insert(curPoints[pointi], meshPoints.size()))
96  {
97  meshPoints.append(curPoints[pointi]);
98  }
99  }
100  }
101  // Transfer to straight list (reuses storage)
102  meshPointsPtr_ = new labelList(meshPoints, true);
103 
104 
105  // Create local faces. Note that we start off from copy of original face
106  // list (even though vertices are overwritten below). This is done so
107  // additional data gets copied (e.g. region number of labelledTri)
108  localFacesPtr_ = new List<FaceType>(*this);
109  List<FaceType>& lf = *localFacesPtr_;
110 
111  forAll(*this, facei)
112  {
113  const FaceType& curFace = this->operator[](facei);
114  lf[facei].setSize(curFace.size());
115 
116  forAll(curFace, labelI)
117  {
118  lf[facei][labelI] = markedPoints.find(curFace[labelI])();
119  }
120  }
121 
122  if (debug)
123  {
124  Pout<< "PrimitivePatch<FaceList, PointField>::calcMeshData() : "
125  "finished calculating mesh data in PrimitivePatch"
126  << endl;
127  }
128 }
129 
130 
131 template<class FaceList, class PointField>
133 {
134  if (debug)
135  {
136  Pout<< "PrimitivePatch<FaceList, PointField>::calcMeshPointMap() : "
137  "calculating mesh point map in PrimitivePatch"
138  << endl;
139  }
140 
141  // It is considered an error to attempt to recalculate meshPoints
142  // if they have already been calculated.
143  if (meshPointMapPtr_)
144  {
146  << "meshPointMapPtr_ already allocated"
147  << abort(FatalError);
148  }
149 
150  const labelList& mp = meshPoints();
151 
152  meshPointMapPtr_ = new Map<label>(2*mp.size());
153  Map<label>& 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>::calcMeshPointMap() : "
163  "finished calculating mesh point map in PrimitivePatch"
164  << endl;
165  }
166 }
167 
168 
169 template<class FaceList, class PointField>
171 {
172  if (debug)
173  {
174  Pout<< "PrimitivePatch<FaceList, PointField>::calcLocalPoints() : "
175  "calculating localPoints in PrimitivePatch"
176  << endl;
177  }
178 
179  // It is considered an error to attempt to recalculate localPoints
180  // if they have already been calculated.
181  if (localPointsPtr_)
182  {
184  << "localPointsPtr_already allocated"
185  << abort(FatalError);
186  }
187 
188  const labelList& meshPts = meshPoints();
189 
190  localPointsPtr_ = new Field<PointType>(meshPts.size());
191 
192  Field<PointType>& locPts = *localPointsPtr_;
193 
194  forAll(meshPts, pointi)
195  {
196  locPts[pointi] = points_[meshPts[pointi]];
197  }
198 
199  if (debug)
200  {
201  Pout<< "PrimitivePatch<FaceList, PointField>::calcLocalPoints() : "
202  << "finished calculating localPoints in PrimitivePatch"
203  << endl;
204  }
205 }
206 
207 
208 template<class FaceList, class PointField>
210 {
211  if (debug)
212  {
213  Pout<< "PrimitivePatch<FaceList, PointField>::calcPointNormals() : "
214  "calculating pointNormals in PrimitivePatch"
215  << endl;
216  }
217 
218  // It is considered an error to attempt to recalculate pointNormals
219  // if they have already been calculated.
220  if (pointNormalsPtr_)
221  {
223  << "pointNormalsPtr_already allocated"
224  << abort(FatalError);
225  }
226 
227  const Field<PointType>& faceUnitNormals = faceNormals();
228 
229  const labelListList& pf = pointFaces();
230 
231  pointNormalsPtr_ = new Field<PointType>
232  (
233  meshPoints().size(),
234  PointType::zero
235  );
236 
237  Field<PointType>& n = *pointNormalsPtr_;
238 
239  forAll(pf, pointi)
240  {
241  PointType& curNormal = n[pointi];
242 
243  const labelList& curFaces = pf[pointi];
244 
245  forAll(curFaces, facei)
246  {
247  curNormal += faceUnitNormals[curFaces[facei]];
248  }
249 
250  curNormal /= mag(curNormal) + vSmall;
251  }
252 
253  if (debug)
254  {
255  Pout<< "PrimitivePatch<FaceList, PointField>::calcPointNormals() : "
256  "finished calculating pointNormals in PrimitivePatch"
257  << endl;
258  }
259 }
260 
261 
262 template<class FaceList, class PointField>
264 {
265  if (debug)
266  {
267  Pout<< "PrimitivePatch<FaceList, PointField>::calcFaceCentres() : "
268  "calculating faceCentres in PrimitivePatch"
269  << endl;
270  }
271 
272  // It is considered an error to attempt to recalculate faceCentres
273  // if they have already been calculated.
274  if (faceCentresPtr_)
275  {
277  << "faceCentresPtr_already allocated"
278  << abort(FatalError);
279  }
280 
281  faceCentresPtr_ = new Field<PointType>(this->size());
282 
283  Field<PointType>& c = *faceCentresPtr_;
284 
285  forAll(c, facei)
286  {
287  c[facei] = this->operator[](facei).centre(points_);
288  }
289 
290  if (debug)
291  {
292  Pout<< "PrimitivePatch<FaceList, PointField>::calcFaceCentres() : "
293  "finished calculating faceCentres in PrimitivePatch"
294  << endl;
295  }
296 }
297 
298 
299 template<class FaceList, class PointField>
301 {
302  if (debug)
303  {
304  Pout<< "PrimitivePatch<FaceList, PointField>::calcFaceNormals() : "
305  "calculating faceNormals in PrimitivePatch"
306  << endl;
307  }
308 
309  // It is considered an error to attempt to recalculate faceNormals
310  // if they have already been calculated.
311  if (faceNormalsPtr_)
312  {
314  << "faceNormalsPtr_already allocated"
315  << abort(FatalError);
316  }
317 
318  faceNormalsPtr_ = new Field<PointType>(this->size());
319 
320  Field<PointType>& n = *faceNormalsPtr_;
321 
322  forAll(n, facei)
323  {
324  n[facei] = this->operator[](facei).normal(points_);
325  }
326 
327  if (debug)
328  {
329  Pout<< "PrimitivePatch<FaceList, PointField>::calcFaceNormals() : "
330  "finished calculating faceNormals in PrimitivePatch"
331  << endl;
332  }
333 }
334 
335 
336 // ************************************************************************* //
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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:256
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 > &)