primitiveMesh.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-2016 OpenFOAM Foundation
9  Copyright (C) 2021 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 "primitiveMesh.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
36 }
37 
38 
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 
42 :
43  nInternalPoints_(0), // note: points are considered ordered on empty mesh
44  nPoints_(0),
45  nInternal0Edges_(-1),
46  nInternal1Edges_(-1),
47  nInternalEdges_(-1),
48  nEdges_(-1),
49  nInternalFaces_(0),
50  nFaces_(0),
51  nCells_(0),
52 
53  cellShapesPtr_(nullptr),
54  edgesPtr_(nullptr),
55  ccPtr_(nullptr),
56  ecPtr_(nullptr),
57  pcPtr_(nullptr),
58 
59  cfPtr_(nullptr),
60  efPtr_(nullptr),
61  pfPtr_(nullptr),
62 
63  cePtr_(nullptr),
64  fePtr_(nullptr),
65  pePtr_(nullptr),
66  ppPtr_(nullptr),
67  cpPtr_(nullptr),
68 
69  labels_(0),
70 
71  cellCentresPtr_(nullptr),
72  faceCentresPtr_(nullptr),
73  cellVolumesPtr_(nullptr),
74  faceAreasPtr_(nullptr)
75 {}
76 
77 
79 (
80  const label nPoints,
81  const label nInternalFaces,
82  const label nFaces,
83  const label nCells
84 )
85 :
86  nInternalPoints_(-1),
87  nPoints_(nPoints),
88  nEdges_(-1),
89  nInternalFaces_(nInternalFaces),
90  nFaces_(nFaces),
91  nCells_(nCells),
92 
93  cellShapesPtr_(nullptr),
94  edgesPtr_(nullptr),
95  ccPtr_(nullptr),
96  ecPtr_(nullptr),
97  pcPtr_(nullptr),
98 
99  cfPtr_(nullptr),
100  efPtr_(nullptr),
101  pfPtr_(nullptr),
102 
103  cePtr_(nullptr),
104  fePtr_(nullptr),
105  pePtr_(nullptr),
106  ppPtr_(nullptr),
107  cpPtr_(nullptr),
108 
109  labels_(0),
110 
111  cellCentresPtr_(nullptr),
112  faceCentresPtr_(nullptr),
113  cellVolumesPtr_(nullptr),
114  faceAreasPtr_(nullptr)
115 {}
116 
117 
118 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
119 
121 {
123 }
124 
125 
126 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
127 
129 (
130  label& nInternalPoints,
131  labelList& oldToNew,
132  const faceList& faces,
133  const label nInternalFaces,
134  const label nPoints
135 )
136 {
137  // Internal points are points that are not used by a boundary face.
138 
139  // Map from old to new position
140  oldToNew.resize_nocopy(nPoints);
141  oldToNew = -1;
142 
143 
144  // 1. Create compact addressing for boundary points. Start off by indexing
145  // from 0 inside oldToNew. (shifted up later on)
146 
147  label nBoundaryPoints = 0;
148  for (label facei = nInternalFaces; facei < faces.size(); ++facei)
149  {
150  const face& f = faces[facei];
151 
152  for (label pointi : f)
153  {
154  if (oldToNew[pointi] == -1)
155  {
156  oldToNew[pointi] = nBoundaryPoints++;
157  }
158  }
159  }
160 
161  // Now we know the number of boundary and internal points
162 
163  nInternalPoints = nPoints - nBoundaryPoints;
164 
165  // Move the boundary addressing up
166  forAll(oldToNew, pointi)
167  {
168  if (oldToNew[pointi] != -1)
169  {
170  oldToNew[pointi] += nInternalPoints;
171  }
172  }
173 
174 
175  // 2. Compact the internal points. Detect whether internal and boundary
176  // points are mixed.
177 
178  label internalPointi = 0;
179 
180  bool ordered = true;
181 
182  for (label facei = 0; facei < nInternalFaces; facei++)
183  {
184  const face& f = faces[facei];
185 
186  for (label pointi : f)
187  {
188  if (oldToNew[pointi] == -1)
189  {
190  if (pointi >= nInternalPoints)
191  {
192  ordered = false;
193  }
194  oldToNew[pointi] = internalPointi++;
195  }
196  }
197  }
198 
199  return ordered;
200 }
201 
202 
204 (
205  const label nPoints,
206  const label nInternalFaces,
207  const label nFaces,
208  const label nCells
209 )
210 {
211  clearOut();
212 
213  nPoints_ = nPoints;
214  nEdges_ = -1;
215  nInternal0Edges_ = -1;
216  nInternal1Edges_ = -1;
217  nInternalEdges_ = -1;
218 
219  nInternalFaces_ = nInternalFaces;
220  nFaces_ = nFaces;
221  nCells_ = nCells;
222 
223  // Check if points are ordered
224  label nInternalPoints;
225  labelList pointMap;
226 
227  bool isOrdered = calcPointOrder
228  (
229  nInternalPoints,
230  pointMap,
231  faces(),
232  nInternalFaces_,
233  nPoints_
234  );
235 
236  if (isOrdered)
237  {
238  nInternalPoints_ = nInternalPoints;
239  }
240  else
241  {
242  nInternalPoints_ = -1;
243  }
244 
245  if (debug)
246  {
247  Pout<< "primitiveMesh::reset : mesh reset to"
248  << " nInternalPoints:" << nInternalPoints_
249  << " nPoints:" << nPoints_
250  << " nEdges:" << nEdges_
251  << " nInternalFaces:" << nInternalFaces_
252  << " nFaces:" << nFaces_
253  << " nCells:" << nCells_
254  << endl;
255  }
256 }
257 
258 
260 (
261  const label nPoints,
262  const label nInternalFaces,
263  const label nFaces,
264  const label nCells,
265  cellList& clst
266 )
267 {
268  reset
269  (
270  nPoints,
271  nInternalFaces,
272  nFaces,
273  nCells
274  );
275 
276  cfPtr_ = new cellList(clst, true);
277 }
278 
279 
281 (
282  pointField&& faceCentres,
283  pointField&& faceAreas,
284  pointField&& cellCentres,
285  scalarField&& cellVolumes
286 )
287 {
288  if
289  (
290  faceCentres.size() != nFaces_
291  || faceAreas.size() != nFaces_
292  || cellCentres.size() != nCells_
293  || cellVolumes.size() != nCells_
294  )
295  {
297  << "Wrong sizes of passed in face/cell data"
298  << abort(FatalError);
299  }
300 
301  // Remove old geometry
302  clearGeom();
303 
304  faceCentresPtr_ = new pointField(std::move(faceCentres));
305  faceAreasPtr_ = new pointField(std::move(faceAreas));
306  cellCentresPtr_ = new pointField(std::move(cellCentres));
307  cellVolumesPtr_ = new scalarField(std::move(cellVolumes));
308 
309  if (debug)
310  {
311  Pout<< "primitiveMesh::resetGeometry : geometry reset for"
312  << " nFaces:" << faceCentresPtr_->size()
313  << " nCells:" << cellCentresPtr_->size() << endl;
314  }
315 }
316 
317 
319 (
320  const pointField& newPoints,
321  const pointField& oldPoints
322 )
323 {
324  // Note: the following clearout is now handled by the fvGeometryScheme
325  // triggered by the call to updateGeom() in polyMesh::movePoints
326 
327  // Force recalculation of all geometric data with new points
328  //clearGeom();
329 }
330 
331 
333 {
334  if (!cellShapesPtr_)
335  {
336  calcCellShapes();
337  }
338 
339  return *cellShapesPtr_;
340 }
341 
342 
344 {
345  if (!faceCentresPtr_ || !faceAreasPtr_)
346  {
347  // These are always calculated in tandem, but only once
348  calcFaceCentresAndAreas();
349  }
350 
351  if (!cellCentresPtr_ || !cellVolumesPtr_)
352  {
353  // These are always calculated in tandem, but only once
354  calcCellCentresAndVols();
355  }
356 }
357 
358 
359 // ************************************************************************* //
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
List< cell > cellList
List of cell.
Definition: cellListFwd.H:39
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:68
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:598
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:75
const cellShapeList & cellShapes() const
Return cell shapes.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
primitiveMesh()
Construct null.
Definition: primitiveMesh.C:34
void resize_nocopy(const label len)
Adjust allocated size of list without necessarily.
Definition: ListI.H:175
void movePoints(const pointField &p, const pointField &oldP)
Move points.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
void resetGeometry(pointField &&faceCentres, pointField &&faceAreas, pointField &&cellCentres, scalarField &&cellVolumes)
Reset the local geometry.
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
void clearOut()
Clear all geometry and addressing unnecessary for CFD.
label nPoints
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
virtual void updateGeom()
Update all geometric data.
errorManip< error > abort(error &err)
Definition: errorManip.H:139
void reset(const label nPoints, const label nInternalFaces, const label nFaces, const label nCells)
Reset this primitiveMesh given the primitive array sizes.
int debug
Static debugging option.
defineTypeNameAndDebug(combustionModel, 0)
labelList f(nPoints)
virtual ~primitiveMesh()
Destructor.
List< label > labelList
A List of labels.
Definition: List.H:62
static bool calcPointOrder(label &nInternalPoints, labelList &pointMap, const faceList &, const label nInternalFaces, const label nPoints)
Helper function to calculate point ordering. Returns true.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
Namespace for OpenFOAM.