FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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"
28 
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
34 
35 
36 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
37 
39 :
40  nInternalPoints_(0), // note: points are considered ordered on empty mesh
41  nPoints_(0),
42  nInternal0Edges_(-1),
43  nInternal1Edges_(-1),
44  nInternalEdges_(-1),
45  nEdges_(-1),
46  nInternalFaces_(0),
47  nFaces_(0),
48  nCells_(0),
49 
50  cellShapesPtr_(NULL),
51  edgesPtr_(NULL),
52  ccPtr_(NULL),
53  ecPtr_(NULL),
54  pcPtr_(NULL),
55 
56  cfPtr_(NULL),
57  efPtr_(NULL),
58  pfPtr_(NULL),
59 
60  cePtr_(NULL),
61  fePtr_(NULL),
62  pePtr_(NULL),
63  ppPtr_(NULL),
64  cpPtr_(NULL),
65 
66  labels_(0),
67 
68  cellCentresPtr_(NULL),
69  faceCentresPtr_(NULL),
70  cellVolumesPtr_(NULL),
71  faceAreasPtr_(NULL)
72 {}
73 
74 
75 // Construct from components
76 // WARNING: ASSUMES CORRECT ORDERING OF DATA.
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_(NULL),
93  edgesPtr_(NULL),
94  ccPtr_(NULL),
95  ecPtr_(NULL),
96  pcPtr_(NULL),
97 
98  cfPtr_(NULL),
99  efPtr_(NULL),
100  pfPtr_(NULL),
101 
102  cePtr_(NULL),
103  fePtr_(NULL),
104  pePtr_(NULL),
105  ppPtr_(NULL),
106  cpPtr_(NULL),
107 
108  labels_(0),
109 
110  cellCentresPtr_(NULL),
111  faceCentresPtr_(NULL),
112  cellVolumesPtr_(NULL),
113  faceAreasPtr_(NULL)
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  const label nPoints,
286  const label nInternalFaces,
287  const label nFaces,
288  const label nCells,
289  const Xfer<cellList>& clst
290 )
291 {
292  reset
293  (
294  nPoints,
295  nInternalFaces,
296  nFaces,
297  nCells
298  );
299 
300  cfPtr_ = new cellList(clst);
301 }
302 
303 
305 (
306  const pointField& newPoints,
307  const pointField& oldPoints
308 )
309 {
310  if (newPoints.size() < nPoints() || oldPoints.size() < nPoints())
311  {
313  (
314  "primitiveMesh::movePoints(const pointField& newPoints, "
315  "const pointField& oldPoints)"
316  ) << "Cannot move points: size of given point list smaller "
317  << "than the number of active points"
318  << abort(FatalError);
319  }
320 
321  // Create swept volumes
322  const faceList& f = faces();
323 
324  tmp<scalarField> tsweptVols(new scalarField(f.size()));
325  scalarField& sweptVols = tsweptVols();
326 
327  forAll(f, faceI)
328  {
329  sweptVols[faceI] = f[faceI].sweptVol(oldPoints, newPoints);
330  }
331 
332  // Force recalculation of all geometric data with new points
333  clearGeom();
334 
335  return tsweptVols;
336 }
337 
338 
340 {
341  if (!cellShapesPtr_)
342  {
343  calcCellShapes();
344  }
345 
346  return *cellShapesPtr_;
347 }
348 
349 
350 // ************************ vim: set sw=4 sts=4 et: ************************ //