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  DebugInFunction << "Calculating mesh data" << endl;
39 
40  if (meshPointsPtr_ || localFacesPtr_)
41  {
42  // An error to recalculate if already allocated
44  << "meshPointsPtr_ or localFacesPtr_ already allocated"
45  << abort(FatalError);
46  }
47 
48  // Create a map for marking points. Estimated size is 4 times the
49  // number of faces in the patch
50  Map<label> markedPoints(4*this->size());
51 
52 
53  // Important:
54  // ~~~~~~~~~~
55  // In <= 1.5 the meshPoints would be in increasing order but this gives
56  // problems in processor point synchronisation where we have to find out
57  // how the opposite side would have allocated points.
58 
61  //forAll(*this, facei)
62  //{
63  // const face_type& curPoints = this->operator[](facei);
64  //
65  // forAll(curPoints, pointi)
66  // {
67  // markedPoints.insert(curPoints[pointi], -1);
68  // }
69  //}
70  //
73  //meshPointsPtr_.reset(new labelList(markedPoints.toc()));
74  //auto& pointPatch = *meshPointsPtr_;
75  //
77  //sort(pointPatch);
78  //
80  //forAll(pointPatch, pointi)
81  //{
82  // markedPoints.find(pointPatch[pointi])() = pointi;
83  //}
84 
85  //- Unsorted version:
86  DynamicList<label> meshPoints(2*this->size());
87  for (const face_type& f : *this)
88  {
89  for (const label pointi : f)
90  {
91  if (markedPoints.insert(pointi, meshPoints.size()))
92  {
93  meshPoints.append(pointi);
94  }
95  }
96  }
97  // Transfer to straight list (reuses storage)
98  meshPointsPtr_.reset(new labelList(meshPoints, true));
99 
100  // Create local faces. Deep-copy original faces to retain additional
101  // data (e.g. region number of labelledTri)
102  // The vertices will be overwritten later
103  localFacesPtr_.reset(new List<face_type>(*this));
104  auto& locFaces = *localFacesPtr_;
105 
106  for (face_type& f : locFaces)
107  {
108  for (label& pointi : f)
109  {
110  pointi = *(markedPoints.cfind(pointi));
111  }
112  }
113 
114  DebugInfo << "Calculated mesh data" << endl;
115 }
116 
117 
118 template<class FaceList, class PointField>
119 void
121 {
122  DebugInFunction << "Calculating mesh point map" << endl;
123 
124  if (meshPointMapPtr_)
125  {
126  // An error to recalculate if already allocated
128  << "meshPointMapPtr_ already allocated"
129  << abort(FatalError);
130  }
131 
132  const labelList& mp = meshPoints();
133 
134  meshPointMapPtr_.reset(new Map<label>(2*mp.size()));
135  auto& mpMap = *meshPointMapPtr_;
136 
137  forAll(mp, i)
138  {
139  mpMap.insert(mp[i], i);
140  }
141 
142  DebugInfo << "Calculated mesh point map" << endl;
143 }
144 
145 
146 template<class FaceList, class PointField>
147 void
149 {
150  DebugInFunction << "Calculating localPoints" << endl;
151 
152  if (localPointsPtr_)
153  {
154  // An error to recalculate if already allocated
156  << "localPointsPtr_ already allocated"
157  << abort(FatalError);
158  }
159 
160  const labelList& meshPts = meshPoints();
161 
162  localPointsPtr_.reset(new Field<point_type>(meshPts.size()));
163  auto& locPts = *localPointsPtr_;
164 
165  forAll(meshPts, pointi)
166  {
167  locPts[pointi] = points_[meshPts[pointi]];
168  }
169 
170  DebugInfo << "Calculated localPoints" << endl;
171 }
172 
173 
174 template<class FaceList, class PointField>
175 void
177 {
178  DebugInFunction << "Calculating pointNormals" << endl;
179 
180  if (pointNormalsPtr_)
181  {
182  // An error to recalculate if already allocated
184  << "pointNormalsPtr_ already allocated"
185  << abort(FatalError);
186  }
187 
188  const auto& faceUnitNormals = faceNormals();
189 
190  const labelListList& pf = pointFaces();
191 
192  pointNormalsPtr_.reset(new Field<point_type>(meshPoints().size(), Zero));
193  auto& n = *pointNormalsPtr_;
194 
195  forAll(pf, pointi)
196  {
197  point_type& curNormal = n[pointi];
198 
199  const labelList& curFaces = pf[pointi];
200 
201  for (const label facei : curFaces)
202  {
203  curNormal += faceUnitNormals[facei];
204  }
205 
206  curNormal.normalise();
207  }
208 
209  DebugInfo << "Calculated pointNormals" << endl;
210 }
211 
212 
213 template<class FaceList, class PointField>
214 void
216 {
217  DebugInFunction << "Calculating faceCentres" << endl;
218 
219  if (faceCentresPtr_)
220  {
221  // An error to recalculate if already allocated
223  << "faceCentresPtr_ already allocated"
224  << abort(FatalError);
225  }
226 
227  faceCentresPtr_.reset(new Field<point_type>(this->size()));
228  auto& c = *faceCentresPtr_;
229 
230  forAll(c, facei)
231  {
232  c[facei] = this->operator[](facei).centre(points_);
233  }
234 
235  DebugInfo << "Calculated faceCentres" << endl;
236 }
237 
238 
239 template<class FaceList, class PointField>
240 void
242 {
243  DebugInFunction << "Calculating magFaceAreas" << endl;
244 
245  if (magFaceAreasPtr_)
246  {
247  // An error to recalculate if already allocated
249  << "magFaceAreasPtr_ already allocated"
250  << abort(FatalError);
251  }
252 
253  magFaceAreasPtr_.reset(new Field<scalar>(this->size()));
254  auto& a = *magFaceAreasPtr_;
255 
256  forAll(a, facei)
257  {
258  a[facei] = this->operator[](facei).mag(points_);
259  }
260 
261  DebugInfo << "Calculated magFaceAreas" << endl;
262 }
263 
264 
265 template<class FaceList, class PointField>
266 void
268 {
269  DebugInFunction << "Calculating faceAreas" << endl;
270 
271  if (faceAreasPtr_)
272  {
273  // An error to recalculate if already allocated
275  << "faceAreasPtr_ already allocated"
276  << abort(FatalError);
277  }
278 
279  faceAreasPtr_.reset(new Field<point_type>(this->size()));
280  auto& n = *faceAreasPtr_;
281 
282  forAll(n, facei)
283  {
284  n[facei] = this->operator[](facei).areaNormal(points_);
285  }
286 
287  DebugInfo << "Calculated faceAreas" << endl;
288 }
289 
290 
291 template<class FaceList, class PointField>
292 void
294 {
295  DebugInFunction << "Calculating faceNormals" << endl;
296 
297  if (faceNormalsPtr_)
298  {
299  // An error to recalculate if already allocated
301  << "faceNormalsPtr_ already allocated"
302  << abort(FatalError);
303  }
304 
305  faceNormalsPtr_.reset(new Field<point_type>(this->size()));
306  auto& n = *faceNormalsPtr_;
307 
308  forAll(n, facei)
309  {
310  n[facei] = this->operator[](facei).unitNormal(points_);
311  }
312 
313  DebugInfo << "Calculated faceNormals" << endl;
314 }
315 
316 
317 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
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:369
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
DebugInFunction
#define DebugInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:388
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:453
DebugInfo
#define DebugInfo
Report an information message using Foam::Info.
Definition: messageStream.H:382
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:79