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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "primitiveMesh.H"
29 #include "demandDrivenData.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 defineTypeNameAndDebug(primitiveMesh, 0);
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 {
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
228  label nInternalPoints;
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  pointField&& faceCentres,
287  pointField&& faceAreas,
288  pointField&& cellCentres,
289  scalarField&& cellVolumes
290 )
291 {
292  if
293  (
294  faceCentres.size() != nFaces_
295  || faceAreas.size() != nFaces_
296  || cellCentres.size() != nCells_
297  || cellVolumes.size() != nCells_
298  )
299  {
301  << "Wrong sizes of passed in face/cell data"
302  << abort(FatalError);
303  }
304 
305  // Remove old geometry
306  clearGeom();
307 
308  faceCentresPtr_ = new pointField(std::move(faceCentres));
309  faceAreasPtr_ = new pointField(std::move(faceAreas));
310  cellCentresPtr_ = new pointField(std::move(cellCentres));
311  cellVolumesPtr_ = new scalarField(std::move(cellVolumes));
312 
313  if (debug)
314  {
315  Pout<< "primitiveMesh::resetGeometry : geometry reset for"
316  << " nFaces:" << faceCentresPtr_->size()
317  << " nCells:" << cellCentresPtr_->size() << endl;
318  }
319 }
320 
321 
323 (
324  const pointField& newPoints,
325  const pointField& oldPoints
326 )
327 {
328  if (newPoints.size() < nPoints() || oldPoints.size() < nPoints())
329  {
331  << "Cannot move points: size of given point list smaller "
332  << "than the number of active points"
333  << abort(FatalError);
334  }
335 
336  // Create swept volumes
337  const faceList& f = faces();
338 
339  tmp<scalarField> tsweptVols(new scalarField(f.size()));
340  scalarField& sweptVols = tsweptVols.ref();
341 
342  forAll(f, facei)
343  {
344  sweptVols[facei] = f[facei].sweptVol(oldPoints, newPoints);
345  }
346 
347  // Force recalculation of all geometric data with new points
348  clearGeom();
349 
350  return tsweptVols;
351 }
352 
353 
355 {
356  if (!cellShapesPtr_)
357  {
358  calcCellShapes();
359  }
360 
361  return *cellShapesPtr_;
362 }
363 
364 
365 
367 {
368  if (!faceCentresPtr_)
369  {
370  calcFaceCentresAndAreas();
371  }
372  if (!faceAreasPtr_)
373  {
374  calcFaceCentresAndAreas();
375  }
376  if (!cellCentresPtr_)
377  {
378  calcCellCentresAndVols();
379  }
380  if (!cellVolumesPtr_)
381  {
382  calcCellCentresAndVols();
383  }
384 }
385 
386 
387 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:52
Foam::primitiveMesh::primitiveMesh
primitiveMesh()
Construct null.
Definition: primitiveMesh.C:41
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::primitiveMesh::~primitiveMesh
virtual ~primitiveMesh()
Destructor.
Definition: primitiveMesh.C:120
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
primitiveMesh.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::Pout
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
Foam::tmp::ref
T & ref() const
Definition: tmpI.H:228
Foam::Field< vector >
Foam::cellList
List< cell > cellList
A List of cells.
Definition: cellListFwd.H:47
Foam::primitiveMesh::calcPointOrder
static bool calcPointOrder(label &nInternalPoints, labelList &pointMap, const faceList &, const label nInternalFaces, const label nPoints)
Helper function to calculate point ordering. Returns true.
Definition: primitiveMesh.C:129
Foam::FatalError
error FatalError
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::primitiveMesh::cellShapes
const cellShapeList & cellShapes() const
Return cell shapes.
Definition: primitiveMesh.C:354
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
f
labelList f(nPoints)
Foam::List< label >
Foam::primitiveMesh::resetGeometry
void resetGeometry(pointField &&faceCentres, pointField &&faceAreas, pointField &&cellCentres, scalarField &&cellVolumes)
Reset the local geometry.
Definition: primitiveMesh.C:285
Foam::primitiveMesh::movePoints
tmp< scalarField > movePoints(const pointField &p, const pointField &oldP)
Move points, returns volumes swept by faces in motion.
Definition: primitiveMesh.C:323
Foam::primitiveMesh::reset
void reset(const label nPoints, const label nInternalFaces, const label nFaces, const label nCells)
Reset this primitiveMesh given the primitive array sizes.
Definition: primitiveMesh.C:208
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:72
Foam::primitiveMesh::updateGeom
virtual void updateGeom()
Update all geometric data.
Definition: primitiveMesh.C:366
Foam::List::setSize
void setSize(const label newSize)
Alias for resize(const label)
Definition: ListI.H:146
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)