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 | Copyright (C) 2011-2015 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_(NULL),
52  edgesPtr_(NULL),
53  ccPtr_(NULL),
54  ecPtr_(NULL),
55  pcPtr_(NULL),
56 
57  cfPtr_(NULL),
58  efPtr_(NULL),
59  pfPtr_(NULL),
60 
61  cePtr_(NULL),
62  fePtr_(NULL),
63  pePtr_(NULL),
64  ppPtr_(NULL),
65  cpPtr_(NULL),
66 
67  labels_(0),
68 
69  cellCentresPtr_(NULL),
70  faceCentresPtr_(NULL),
71  cellVolumesPtr_(NULL),
72  faceAreasPtr_(NULL)
73 {}
74 
75 
76 // Construct from components
77 // WARNING: ASSUMES CORRECT ORDERING OF DATA.
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_(NULL),
94  edgesPtr_(NULL),
95  ccPtr_(NULL),
96  ecPtr_(NULL),
97  pcPtr_(NULL),
98 
99  cfPtr_(NULL),
100  efPtr_(NULL),
101  pfPtr_(NULL),
102 
103  cePtr_(NULL),
104  fePtr_(NULL),
105  pePtr_(NULL),
106  ppPtr_(NULL),
107  cpPtr_(NULL),
108 
109  labels_(0),
110 
111  cellCentresPtr_(NULL),
112  faceCentresPtr_(NULL),
113  cellVolumesPtr_(NULL),
114  faceAreasPtr_(NULL)
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  const label nPoints,
287  const label nInternalFaces,
288  const label nFaces,
289  const label nCells,
290  const Xfer<cellList>& clst
291 )
292 {
293  reset
294  (
295  nPoints,
296  nInternalFaces,
297  nFaces,
298  nCells
299  );
300 
301  cfPtr_ = new cellList(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();
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 // ************************************************************************* //
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:48
primitiveMesh.H
Foam::primitiveMesh::primitiveMesh
primitiveMesh()
Construct null.
Definition: primitiveMesh.C:36
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
Foam::primitiveMesh::~primitiveMesh
virtual ~primitiveMesh()
Definition: primitiveMesh.C:112
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
Foam::label
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
Foam::cellList
List< cell > cellList
list of cells
Definition: cellList.H:42
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: combustionModel.C:30
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::primitiveMesh::cellShapes
const cellShapeList & cellShapes() const
Return cell shapes.
Definition: primitiveMesh.C:230
Foam::List::setSize
void setSize(const label)
Reset size of List.
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::Pout
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
f
labelList f(nPoints)
Foam::faceList
List< face > faceList
Definition: faceListFwd.H:43
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::primitiveMesh::movePoints
tmp< scalarField > movePoints(const pointField &p, const pointField &oldP)
Move points, returns volumes swept by faces in motion.
Definition: primitiveMesh.C:193
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:121
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)