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-2012 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
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  (
315  "primitiveMesh::movePoints(const pointField& newPoints, "
316  "const pointField& oldPoints)"
317  ) << "Cannot move points: size of given point list smaller "
318  << "than the number of active points"
319  << abort(FatalError);
320  }
321 
322  // Create swept volumes
323  const faceList& f = faces();
324 
325  tmp<scalarField> tsweptVols(new scalarField(f.size()));
326  scalarField& sweptVols = tsweptVols();
327 
328  forAll(f, faceI)
329  {
330  sweptVols[faceI] = f[faceI].sweptVol(oldPoints, newPoints);
331  }
332 
333  // Force recalculation of all geometric data with new points
334  clearGeom();
335 
336  return tsweptVols;
337 }
338 
339 
341 {
342  if (!cellShapesPtr_)
343  {
344  calcCellShapes();
345  }
346 
347  return *cellShapesPtr_;
348 }
349 
350 
351 // ************************************************************************* //
label nFaces() const
labelList f(nPoints)
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
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
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
label nCells() const
const cellShapeList & cellShapes() const
Return cell shapes.
virtual const faceList & faces() const =0
Return faces.
Namespace for OpenFOAM.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
void setSize(const label)
Reset size of List.
Definition: List.C:318
List< cell > cellList
list of cells
Definition: cellList.H:42
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
primitiveMesh()
Construct null.
Definition: primitiveMesh.C:39
void reset(const label nPoints, const label nInternalFaces, const label nFaces, const label nCells)
Reset this primitiveMesh given the primitive array sizes.
#define forAll(list, i)
Definition: UList.H:421
void clearOut()
Clear all geometry and addressing unnecessary for CFD.
Template functions to aid in the implementation of demand driven data.
virtual ~primitiveMesh()
Destructor.
errorManip< error > abort(error &err)
Definition: errorManip.H:131
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
label nInternalFaces() const
error FatalError
tmp< scalarField > movePoints(const pointField &p, const pointField &oldP)
Move points, returns volumes swept by faces in motion.
void clearGeom()
Clear geometry.
static bool calcPointOrder(label &nInternalPoints, labelList &pointMap, const faceList &, const label nInternalFaces, const label nPoints)
Helper function to calculate point ordering. Returns true.
A class for managing temporary objects.
Definition: PtrList.H:118
label nInternalPoints() const
Points not on boundary.
label nPoints() const
defineTypeNameAndDebug(combustionModel, 0)
prefixOSstream Pout(cout,"Pout")
Definition: IOstreams.H:53