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-2020 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  magFaceAreasPtr_(nullptr)
74 {}
75 
76 
78 (
79  const label nPoints,
80  const label nInternalFaces,
81  const label nFaces,
82  const label nCells
83 )
84 :
85  nInternalPoints_(-1),
86  nPoints_(nPoints),
87  nEdges_(-1),
88  nInternalFaces_(nInternalFaces),
89  nFaces_(nFaces),
90  nCells_(nCells),
91 
92  cellShapesPtr_(nullptr),
93  edgesPtr_(nullptr),
94  ccPtr_(nullptr),
95  ecPtr_(nullptr),
96  pcPtr_(nullptr),
97 
98  cfPtr_(nullptr),
99  efPtr_(nullptr),
100  pfPtr_(nullptr),
101 
102  cePtr_(nullptr),
103  fePtr_(nullptr),
104  pePtr_(nullptr),
105  ppPtr_(nullptr),
106  cpPtr_(nullptr),
107 
108  labels_(0),
109 
110  cellCentresPtr_(nullptr),
111  faceCentresPtr_(nullptr),
112  cellVolumesPtr_(nullptr),
113  faceAreasPtr_(nullptr),
114  magFaceAreasPtr_(nullptr)
115 {}
116 
117 
118 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
119 
121 {
122  clearOut();
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.setSize(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  forAll(f, fp)
153  {
154  label pointi = f[fp];
155 
156  if (oldToNew[pointi] == -1)
157  {
158  oldToNew[pointi] = nBoundaryPoints++;
159  }
160  }
161  }
162 
163  // Now we know the number of boundary and internal points
164 
165  nInternalPoints = nPoints - nBoundaryPoints;
166 
167  // Move the boundary addressing up
168  forAll(oldToNew, pointi)
169  {
170  if (oldToNew[pointi] != -1)
171  {
172  oldToNew[pointi] += nInternalPoints;
173  }
174  }
175 
176 
177  // 2. Compact the internal points. Detect whether internal and boundary
178  // points are mixed.
179 
180  label internalPointi = 0;
181 
182  bool ordered = true;
183 
184  for (label facei = 0; facei < nInternalFaces; facei++)
185  {
186  const face& f = faces[facei];
187 
188  forAll(f, fp)
189  {
190  label pointi = f[fp];
191 
192  if (oldToNew[pointi] == -1)
193  {
194  if (pointi >= nInternalPoints)
195  {
196  ordered = false;
197  }
198  oldToNew[pointi] = internalPointi++;
199  }
200  }
201  }
202 
203  return ordered;
204 }
205 
206 
208 (
209  const label nPoints,
210  const label nInternalFaces,
211  const label nFaces,
212  const label nCells
213 )
214 {
215  clearOut();
216 
217  nPoints_ = nPoints;
218  nEdges_ = -1;
219  nInternal0Edges_ = -1;
220  nInternal1Edges_ = -1;
221  nInternalEdges_ = -1;
222 
223  nInternalFaces_ = nInternalFaces;
224  nFaces_ = nFaces;
225  nCells_ = nCells;
226 
227  // Check if points are ordered
229  labelList pointMap;
230 
231  bool isOrdered = calcPointOrder
232  (
233  nInternalPoints,
234  pointMap,
235  faces(),
236  nInternalFaces_,
237  nPoints_
238  );
239 
240  if (isOrdered)
241  {
242  nInternalPoints_ = nInternalPoints;
243  }
244  else
245  {
246  nInternalPoints_ = -1;
247  }
248 
249  if (debug)
250  {
251  Pout<< "primitiveMesh::reset : mesh reset to"
252  << " nInternalPoints:" << nInternalPoints_
253  << " nPoints:" << nPoints_
254  << " nEdges:" << nEdges_
255  << " nInternalFaces:" << nInternalFaces_
256  << " nFaces:" << nFaces_
257  << " nCells:" << nCells_
258  << endl;
259  }
260 }
261 
262 
264 (
265  const label nPoints,
266  const label nInternalFaces,
267  const label nFaces,
268  const label nCells,
269  cellList& clst
270 )
271 {
272  reset
273  (
274  nPoints,
275  nInternalFaces,
276  nFaces,
277  nCells
278  );
279 
280  cfPtr_ = new cellList(clst, true);
281 }
282 
283 
285 (
286  const label nPoints,
287  const label nInternalFaces,
288  const label nFaces,
289  const label nCells,
290  cellList&& clst
291 )
292 {
293  reset
294  (
295  nPoints,
296  nInternalFaces,
297  nFaces,
298  nCells
299  );
300 
301  cfPtr_ = new cellList(move(clst));
302 }
303 
304 
306 (
307  const pointField& newPoints,
308  const pointField& oldPoints
309 )
310 {
311  if (newPoints.size() < nPoints() || oldPoints.size() < nPoints())
312  {
314  << "Cannot move points: size of given point list smaller "
315  << "than the number of active points"
316  << abort(FatalError);
317  }
318 
319  // Create swept volumes
320  const faceList& f = faces();
321 
322  tmp<scalarField> tsweptVols(new scalarField(f.size()));
323  scalarField& sweptVols = tsweptVols.ref();
324 
325  forAll(f, facei)
326  {
327  sweptVols[facei] = f[facei].sweptVol(oldPoints, newPoints);
328  }
329 
330  // Force recalculation of all geometric data with new points
331  clearGeom();
332 
333  return tsweptVols;
334 }
335 
336 
338 {
339  if (!cellShapesPtr_)
340  {
341  calcCellShapes();
342  }
343 
344  return *cellShapesPtr_;
345 }
346 
347 
348 // ************************************************************************* //
#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:164
const cellShapeList & cellShapes() const
Return cell shapes.
label nCells() const
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
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.