primitiveMesh.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 "primitiveMesh.H"
27 #include "demandDrivenData.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33 defineTypeNameAndDebug(primitiveMesh, 0);
34 }
35 
36 
37 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
38 
40 :
41  nInternalPoints_(0), // note: points are considered ordered on empty mesh
42  nPoints_(0),
43  nInternal0Edges_(-1),
44  nInternal1Edges_(-1),
45  nInternalEdges_(-1),
46  nEdges_(-1),
47  nInternalFaces_(0),
48  nFaces_(0),
49  nCells_(0),
50 
51  cellShapesPtr_(nullptr),
52  edgesPtr_(nullptr),
53  ccPtr_(nullptr),
54  ecPtr_(nullptr),
55  pcPtr_(nullptr),
56 
57  cfPtr_(nullptr),
58  efPtr_(nullptr),
59  pfPtr_(nullptr),
60 
61  cePtr_(nullptr),
62  fePtr_(nullptr),
63  pePtr_(nullptr),
64  ppPtr_(nullptr),
65  cpPtr_(nullptr),
66 
67  labels_(0),
68 
69  cellCentresPtr_(nullptr),
70  faceCentresPtr_(nullptr),
71  cellVolumesPtr_(nullptr),
72  faceAreasPtr_(nullptr)
73 {}
74 
75 
77 (
78  const label nPoints,
79  const label nInternalFaces,
80  const label nFaces,
81  const label nCells
82 )
83 :
84  nInternalPoints_(-1),
85  nPoints_(nPoints),
86  nEdges_(-1),
87  nInternalFaces_(nInternalFaces),
88  nFaces_(nFaces),
89  nCells_(nCells),
90 
91  cellShapesPtr_(nullptr),
92  edgesPtr_(nullptr),
93  ccPtr_(nullptr),
94  ecPtr_(nullptr),
95  pcPtr_(nullptr),
96 
97  cfPtr_(nullptr),
98  efPtr_(nullptr),
99  pfPtr_(nullptr),
100 
101  cePtr_(nullptr),
102  fePtr_(nullptr),
103  pePtr_(nullptr),
104  ppPtr_(nullptr),
105  cpPtr_(nullptr),
106 
107  labels_(0),
108 
109  cellCentresPtr_(nullptr),
110  faceCentresPtr_(nullptr),
111  cellVolumesPtr_(nullptr),
112  faceAreasPtr_(nullptr)
113 {}
114 
115 
116 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
117 
119 {
120  clearOut();
121 }
122 
123 
124 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
125 
127 (
128  label& nInternalPoints,
129  labelList& oldToNew,
130  const faceList& faces,
131  const label nInternalFaces,
132  const label nPoints
133 )
134 {
135  // Internal points are points that are not used by a boundary face.
136 
137  // Map from old to new position
138  oldToNew.setSize(nPoints);
139  oldToNew = -1;
140 
141 
142  // 1. Create compact addressing for boundary points. Start off by indexing
143  // from 0 inside oldToNew. (shifted up later on)
144 
145  label nBoundaryPoints = 0;
146  for (label facei = nInternalFaces; facei < faces.size(); facei++)
147  {
148  const face& f = faces[facei];
149 
150  forAll(f, fp)
151  {
152  label pointi = f[fp];
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  forAll(f, fp)
187  {
188  label pointi = f[fp];
189 
190  if (oldToNew[pointi] == -1)
191  {
192  if (pointi >= nInternalPoints)
193  {
194  ordered = false;
195  }
196  oldToNew[pointi] = internalPointi++;
197  }
198  }
199  }
200 
201  return ordered;
202 }
203 
204 
206 (
207  const label nPoints,
208  const label nInternalFaces,
209  const label nFaces,
210  const label nCells
211 )
212 {
213  clearOut();
214 
215  nPoints_ = nPoints;
216  nEdges_ = -1;
217  nInternal0Edges_ = -1;
218  nInternal1Edges_ = -1;
219  nInternalEdges_ = -1;
220 
221  nInternalFaces_ = nInternalFaces;
222  nFaces_ = nFaces;
223  nCells_ = nCells;
224 
225  // Check if points are ordered
227  labelList pointMap;
228 
229  bool isOrdered = calcPointOrder
230  (
231  nInternalPoints,
232  pointMap,
233  faces(),
234  nInternalFaces_,
235  nPoints_
236  );
237 
238  if (isOrdered)
239  {
240  nInternalPoints_ = nInternalPoints;
241  }
242  else
243  {
244  nInternalPoints_ = -1;
245  }
246 
247  if (debug)
248  {
249  Pout<< "primitiveMesh::reset : mesh reset to"
250  << " nInternalPoints:" << nInternalPoints_
251  << " nPoints:" << nPoints_
252  << " nEdges:" << nEdges_
253  << " nInternalFaces:" << nInternalFaces_
254  << " nFaces:" << nFaces_
255  << " nCells:" << nCells_
256  << endl;
257  }
258 }
259 
260 
262 (
263  const label nPoints,
264  const label nInternalFaces,
265  const label nFaces,
266  const label nCells,
267  cellList& clst
268 )
269 {
270  reset
271  (
272  nPoints,
273  nInternalFaces,
274  nFaces,
275  nCells
276  );
277 
278  cfPtr_ = new cellList(clst, true);
279 }
280 
281 
283 (
284  const label nPoints,
285  const label nInternalFaces,
286  const label nFaces,
287  const label nCells,
288  cellList&& clst
289 )
290 {
291  reset
292  (
293  nPoints,
294  nInternalFaces,
295  nFaces,
296  nCells
297  );
298 
299  cfPtr_ = new cellList(move(clst));
300 }
301 
302 
304 (
305  const pointField& newPoints,
306  const pointField& oldPoints
307 )
308 {
309  if (newPoints.size() < nPoints() || oldPoints.size() < nPoints())
310  {
312  << "Cannot move points: size of given point list smaller "
313  << "than the number of active points"
314  << abort(FatalError);
315  }
316 
317  // Create swept volumes
318  const faceList& f = faces();
319 
320  tmp<scalarField> tsweptVols(new scalarField(f.size()));
321  scalarField& sweptVols = tsweptVols.ref();
322 
323  forAll(f, facei)
324  {
325  sweptVols[facei] = f[facei].sweptVol(oldPoints, newPoints);
326  }
327 
328  // Force recalculation of all geometric data with new points
329  clearGeom();
330 
331  return tsweptVols;
332 }
333 
334 
336 {
337  if (!cellShapesPtr_)
338  {
339  calcCellShapes();
340  }
341 
342  return *cellShapesPtr_;
343 }
344 
345 
346 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
label nInternalFaces() const
label nFaces() const
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:174
label nInternalPoints() const
Points not on boundary.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
const cellShapeList & cellShapes() const
Return cell shapes.
label nCells() const
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
primitiveMesh()
Construct null.
Definition: primitiveMesh.C:39
void clearGeom()
Clear geometry.
tmp< scalarField > movePoints(const pointField &p, const pointField &oldP)
Move points, returns volumes swept by faces in motion.
void clearOut()
Clear all geometry and addressing unnecessary for CFD.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
errorManip< error > abort(error &err)
Definition: errorManip.H:131
void reset(const label nPoints, const label nInternalFaces, const label nFaces, const label nCells)
Reset this primitiveMesh given the primitive array sizes.
defineTypeNameAndDebug(combustionModel, 0)
labelList f(nPoints)
virtual ~primitiveMesh()
Destructor.
void setSize(const label)
Reset size of List.
Definition: List.C:281
Template functions to aid in the implementation of demand driven data.
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
virtual const faceList & faces() const =0
Return faces.
label nPoints() const
A class for managing temporary objects.
Definition: PtrList.H:53
static bool calcPointOrder(label &nInternalPoints, labelList &pointMap, const faceList &, const label nInternalFaces, const label nPoints)
Helper function to calculate point ordering. Returns true.
List< cell > cellList
list of cells
Definition: cellList.H:42
Namespace for OpenFOAM.