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-2024 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.push_back(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& meshPts = meshPoints();
133 
134  meshPointMapPtr_.reset(new Map<label>(invertToMap(meshPts)));
135 
136  DebugInfo << "Calculated mesh point map" << endl;
137 }
138 
139 
140 template<class FaceList, class PointField>
141 void
143 {
144  DebugInFunction << "Calculating localPoints" << endl;
145 
146  if (localPointsPtr_)
147  {
148  // An error to recalculate if already allocated
150  << "localPointsPtr_ already allocated"
151  << abort(FatalError);
152  }
153 
154  const labelList& meshPts = meshPoints();
155 
156  localPointsPtr_.reset(new Field<point_type>(meshPts.size()));
157  auto& locPts = *localPointsPtr_;
158 
159  forAll(meshPts, pointi)
160  {
161  locPts[pointi] = points_[meshPts[pointi]];
162  }
163 
164  DebugInfo << "Calculated localPoints" << endl;
165 }
166 
167 
168 template<class FaceList, class PointField>
169 void
171 {
172  DebugInFunction << "Calculating pointNormals" << endl;
173 
174  if (pointNormalsPtr_)
175  {
176  // An error to recalculate if already allocated
178  << "pointNormalsPtr_ already allocated"
179  << abort(FatalError);
180  }
181 
182  const auto& faceUnitNormals = faceNormals();
183 
184  const labelListList& pf = pointFaces();
185 
186  pointNormalsPtr_.reset(new Field<point_type>(meshPoints().size(), Zero));
187  auto& n = *pointNormalsPtr_;
188 
189  forAll(pf, pointi)
190  {
191  point_type& curNormal = n[pointi];
192 
193  const labelList& curFaces = pf[pointi];
194 
195  for (const label facei : curFaces)
196  {
197  curNormal += faceUnitNormals[facei];
198  }
199 
200  curNormal.normalise();
201  }
202 
203  DebugInfo << "Calculated pointNormals" << endl;
204 }
205 
206 
207 template<class FaceList, class PointField>
208 void
210 {
211  DebugInFunction << "Calculating faceCentres" << endl;
212 
213  if (faceCentresPtr_)
214  {
215  // An error to recalculate if already allocated
217  << "faceCentresPtr_ already allocated"
218  << abort(FatalError);
219  }
220 
221  faceCentresPtr_.reset(new Field<point_type>(this->size()));
222  auto& c = *faceCentresPtr_;
223 
224  forAll(c, facei)
225  {
226  c[facei] = this->operator[](facei).centre(points_);
227  }
228 
229  DebugInfo << "Calculated faceCentres" << endl;
230 }
231 
232 
233 template<class FaceList, class PointField>
234 void
236 {
237  DebugInFunction << "Calculating magFaceAreas" << endl;
238 
239  if (magFaceAreasPtr_)
240  {
241  // An error to recalculate if already allocated
243  << "magFaceAreasPtr_ already allocated"
244  << abort(FatalError);
245  }
246 
247  magFaceAreasPtr_.reset(new Field<scalar>(this->size()));
248  auto& a = *magFaceAreasPtr_;
249 
250  forAll(a, facei)
251  {
252  a[facei] = this->operator[](facei).mag(points_);
253  }
254 
255  DebugInfo << "Calculated magFaceAreas" << endl;
256 }
257 
258 
259 template<class FaceList, class PointField>
260 void
262 {
263  DebugInFunction << "Calculating faceAreas" << endl;
264 
265  if (faceAreasPtr_)
266  {
267  // An error to recalculate if already allocated
269  << "faceAreasPtr_ already allocated"
270  << abort(FatalError);
271  }
272 
273  faceAreasPtr_.reset(new Field<point_type>(this->size()));
274  auto& n = *faceAreasPtr_;
275 
276  forAll(n, facei)
277  {
278  n[facei] = this->operator[](facei).areaNormal(points_);
279  }
280 
281  DebugInfo << "Calculated faceAreas" << endl;
282 }
283 
284 
285 template<class FaceList, class PointField>
286 void
288 {
289  DebugInFunction << "Calculating faceNormals" << endl;
290 
291  if (faceNormalsPtr_)
292  {
293  // An error to recalculate if already allocated
295  << "faceNormalsPtr_ already allocated"
296  << abort(FatalError);
297  }
298 
299  faceNormalsPtr_.reset(new Field<point_type>(this->size()));
300  auto& n = *faceNormalsPtr_;
301 
302  forAll(n, facei)
303  {
304  n[facei] = this->operator[](facei).unitNormal(points_);
305  }
306 
307  DebugInfo << "Calculated faceNormals" << endl;
308 }
309 
310 
311 // ************************************************************************* //
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:600
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:529
List< labelList > labelListList
List of labelList.
Definition: labelList.H:38
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:286
A list of faces which address into the list of points.
#define DebugInFunction
Report an information message using Foam::Info.
errorManip< error > abort(error &err)
Definition: errorManip.H:139
#define DebugInfo
Report an information message using Foam::Info.
labelList f(nPoints)
const dimensionedScalar c
Speed of light in a vacuum.
label n
List< label > labelList
A List of labels.
Definition: List.H:61
Map< label > invertToMap(const labelUList &values)
Create inverse mapping, which is a lookup table into the given list.
Definition: ListOps.C:105
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127