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 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 defineTypeNameAndDebug(primitiveMesh, 0);
35 }
36 
37 
38 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
39 
41 :
42  nInternalPoints_(0), // note: points are considered ordered on empty mesh
43  nPoints_(0),
44  nInternal0Edges_(-1),
45  nInternal1Edges_(-1),
46  nInternalEdges_(-1),
47  nEdges_(-1),
48  nInternalFaces_(0),
49  nFaces_(0),
50  nCells_(0),
51 
52  cellShapesPtr_(nullptr),
53  edgesPtr_(nullptr),
54  ccPtr_(nullptr),
55  ecPtr_(nullptr),
56  pcPtr_(nullptr),
57 
58  cfPtr_(nullptr),
59  efPtr_(nullptr),
60  pfPtr_(nullptr),
61 
62  cePtr_(nullptr),
63  fePtr_(nullptr),
64  pePtr_(nullptr),
65  ppPtr_(nullptr),
66  cpPtr_(nullptr),
67 
68  labels_(0),
69 
70  cellCentresPtr_(nullptr),
71  faceCentresPtr_(nullptr),
72  cellVolumesPtr_(nullptr),
73  faceAreasPtr_(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 {}
115 
116 
117 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
118 
120 {
121  clearOut();
122 }
123 
124 
125 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
126 
128 (
129  label& nInternalPoints,
130  labelList& oldToNew,
131  const faceList& faces,
132  const label nInternalFaces,
133  const label nPoints
134 )
135 {
136  // Internal points are points that are not used by a boundary face.
137 
138  // Map from old to new position
139  oldToNew.setSize(nPoints);
140  oldToNew = -1;
141 
142 
143  // 1. Create compact addressing for boundary points. Start off by indexing
144  // from 0 inside oldToNew. (shifted up later on)
145 
146  label nBoundaryPoints = 0;
147  for (label facei = nInternalFaces; facei < faces.size(); facei++)
148  {
149  const face& f = faces[facei];
150 
151  forAll(f, fp)
152  {
153  label pointi = f[fp];
154 
155  if (oldToNew[pointi] == -1)
156  {
157  oldToNew[pointi] = nBoundaryPoints++;
158  }
159  }
160  }
161 
162  // Now we know the number of boundary and internal points
163 
164  nInternalPoints = nPoints - nBoundaryPoints;
165 
166  // Move the boundary addressing up
167  forAll(oldToNew, pointi)
168  {
169  if (oldToNew[pointi] != -1)
170  {
171  oldToNew[pointi] += nInternalPoints;
172  }
173  }
174 
175 
176  // 2. Compact the internal points. Detect whether internal and boundary
177  // points are mixed.
178 
179  label internalPointi = 0;
180 
181  bool ordered = true;
182 
183  for (label facei = 0; facei < nInternalFaces; facei++)
184  {
185  const face& f = faces[facei];
186 
187  forAll(f, fp)
188  {
189  label pointi = f[fp];
190 
191  if (oldToNew[pointi] == -1)
192  {
193  if (pointi >= nInternalPoints)
194  {
195  ordered = false;
196  }
197  oldToNew[pointi] = internalPointi++;
198  }
199  }
200  }
201 
202  return ordered;
203 }
204 
205 
207 (
208  const label nPoints,
209  const label nInternalFaces,
210  const label nFaces,
211  const label nCells
212 )
213 {
214  clearOut();
215 
216  nPoints_ = nPoints;
217  nEdges_ = -1;
218  nInternal0Edges_ = -1;
219  nInternal1Edges_ = -1;
220  nInternalEdges_ = -1;
221 
222  nInternalFaces_ = nInternalFaces;
223  nFaces_ = nFaces;
224  nCells_ = nCells;
225 
226  // Check if points are ordered
227  label nInternalPoints;
228  labelList pointMap;
229 
230  bool isOrdered = calcPointOrder
231  (
232  nInternalPoints,
233  pointMap,
234  faces(),
235  nInternalFaces_,
236  nPoints_
237  );
238 
239  if (isOrdered)
240  {
241  nInternalPoints_ = nInternalPoints;
242  }
243  else
244  {
245  nInternalPoints_ = -1;
246  }
247 
248  if (debug)
249  {
250  Pout<< "primitiveMesh::reset : mesh reset to"
251  << " nInternalPoints:" << nInternalPoints_
252  << " nPoints:" << nPoints_
253  << " nEdges:" << nEdges_
254  << " nInternalFaces:" << nInternalFaces_
255  << " nFaces:" << nFaces_
256  << " nCells:" << nCells_
257  << endl;
258  }
259 }
260 
261 
263 (
264  const label nPoints,
265  const label nInternalFaces,
266  const label nFaces,
267  const label nCells,
268  cellList& clst
269 )
270 {
271  reset
272  (
273  nPoints,
274  nInternalFaces,
275  nFaces,
276  nCells
277  );
278 
279  cfPtr_ = new cellList(clst, true);
280 }
281 
282 
284 (
285  pointField&& faceCentres,
286  pointField&& faceAreas,
287  pointField&& cellCentres,
288  scalarField&& cellVolumes
289 )
290 {
291  if
292  (
293  faceCentres.size() != nFaces_
294  || faceAreas.size() != nFaces_
295  || cellCentres.size() != nCells_
296  || cellVolumes.size() != nCells_
297  )
298  {
300  << "Wrong sizes of passed in face/cell data"
301  << abort(FatalError);
302  }
303 
304  // Remove old geometry
305  clearGeom();
306 
307  faceCentresPtr_ = new pointField(std::move(faceCentres));
308  faceAreasPtr_ = new pointField(std::move(faceAreas));
309  cellCentresPtr_ = new pointField(std::move(cellCentres));
310  cellVolumesPtr_ = new scalarField(std::move(cellVolumes));
311 
312  if (debug)
313  {
314  Pout<< "primitiveMesh::resetGeometry : geometry reset for"
315  << " nFaces:" << faceCentresPtr_->size()
316  << " nCells:" << cellCentresPtr_->size() << endl;
317  }
318 }
319 
320 
322 (
323  const pointField& newPoints,
324  const pointField& oldPoints
325 )
326 {
327  if (newPoints.size() < nPoints() || oldPoints.size() < nPoints())
328  {
330  << "Cannot move points: size of given point list smaller "
331  << "than the number of active points"
332  << abort(FatalError);
333  }
334 
335  // Create swept volumes
336  const faceList& f = faces();
337 
338  tmp<scalarField> tsweptVols(new scalarField(f.size()));
339  scalarField& sweptVols = tsweptVols.ref();
340 
341  forAll(f, facei)
342  {
343  sweptVols[facei] = f[facei].sweptVol(oldPoints, newPoints);
344  }
345 
346  // Force recalculation of all geometric data with new points
347  clearGeom();
348 
349  return tsweptVols;
350 }
351 
352 
354 {
355  if (!cellShapesPtr_)
356  {
357  calcCellShapes();
358  }
359 
360  return *cellShapesPtr_;
361 }
362 
363 
364 
366 {
367  if (!faceCentresPtr_)
368  {
369  calcFaceCentresAndAreas();
370  }
371  if (!faceAreasPtr_)
372  {
373  calcFaceCentresAndAreas();
374  }
375  if (!cellCentresPtr_)
376  {
377  calcCellCentresAndVols();
378  }
379  if (!cellVolumesPtr_)
380  {
381  calcCellCentresAndVols();
382  }
383 }
384 
385 
386 // ************************************************************************* //
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:40
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::primitiveMesh::~primitiveMesh
virtual ~primitiveMesh()
Destructor.
Definition: primitiveMesh.C:119
primitiveMesh.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
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:227
Foam::Field< vector >
Foam::List::setSize
void setSize(const label n)
Alias for resize()
Definition: List.H:222
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:128
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:353
reset
meshPtr reset(new Foam::fvMesh(Foam::IOobject(regionName, runTime.timeName(), runTime, Foam::IOobject::MUST_READ), false))
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
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:284
Foam::primitiveMesh::movePoints
tmp< scalarField > movePoints(const pointField &p, const pointField &oldP)
Move points, returns volumes swept by faces in motion.
Definition: primitiveMesh.C:322
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:207
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:365
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)