initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / meshes / primitiveMesh / primitiveMesh.C
blob079a5b6c611c93aa5c434f5f77b2cee53a8a3a8a
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "primitiveMesh.H"
28 #include "demandDrivenData.H"
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 defineTypeNameAndDebug(Foam::primitiveMesh, 0);
37 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
39 Foam::primitiveMesh::primitiveMesh()
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),
51     cellShapesPtr_(NULL),
52     edgesPtr_(NULL),
53     ccPtr_(NULL),
54     ecPtr_(NULL),
55     pcPtr_(NULL),
57     cfPtr_(NULL),
58     efPtr_(NULL),
59     pfPtr_(NULL),
61     cePtr_(NULL),
62     fePtr_(NULL),
63     pePtr_(NULL),
64     ppPtr_(NULL),
65     cpPtr_(NULL),
67     labels_(0),
69     cellCentresPtr_(NULL),
70     faceCentresPtr_(NULL),
71     cellVolumesPtr_(NULL),
72     faceAreasPtr_(NULL)
76 // Construct from components
77 // WARNING: ASSUMES CORRECT ORDERING OF DATA.
78 Foam::primitiveMesh::primitiveMesh
80     const label nPoints,
81     const label nInternalFaces,
82     const label nFaces,
83     const label nCells
86     nInternalPoints_(-1),
87     nPoints_(nPoints),
88     nEdges_(-1),
89     nInternalFaces_(nInternalFaces),
90     nFaces_(nFaces),
91     nCells_(nCells),
93     cellShapesPtr_(NULL),
94     edgesPtr_(NULL),
95     ccPtr_(NULL),
96     ecPtr_(NULL),
97     pcPtr_(NULL),
99     cfPtr_(NULL),
100     efPtr_(NULL),
101     pfPtr_(NULL),
103     cePtr_(NULL),
104     fePtr_(NULL),
105     pePtr_(NULL),
106     ppPtr_(NULL),
107     cpPtr_(NULL),
109     labels_(0),
111     cellCentresPtr_(NULL),
112     faceCentresPtr_(NULL),
113     cellVolumesPtr_(NULL),
114     faceAreasPtr_(NULL)
118 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
120 Foam::primitiveMesh::~primitiveMesh()
122     clearOut();
126 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
128 bool Foam::primitiveMesh::calcPointOrder
130     label& nInternalPoints,
131     labelList& oldToNew,
132     const faceList& faces,
133     const label nInternalFaces,
134     const label nPoints
137     // Internal points are points that are not used by a boundary face.
139     // Map from old to new position
140     oldToNew.setSize(nPoints);
141     oldToNew = -1;
144     // 1. Create compact addressing for boundary points. Start off by indexing
145     // from 0 inside oldToNew. (shifted up later on)
147     label nBoundaryPoints = 0;
148     for (label faceI = nInternalFaces; faceI < faces.size(); faceI++)
149     {
150         const face& f = faces[faceI];
152         forAll(f, fp)
153         {
154             label pointI = f[fp];
156             if (oldToNew[pointI] == -1)
157             {
158                 oldToNew[pointI] = nBoundaryPoints++;
159             }
160         }
161     }
163     // Now we know the number of boundary and internal points
165     nInternalPoints = nPoints - nBoundaryPoints;
167     // Move the boundary addressing up
168     forAll(oldToNew, pointI)
169     {
170         if (oldToNew[pointI] != -1)
171         {
172             oldToNew[pointI] += nInternalPoints;
173         }
174     }
177     // 2. Compact the internal points. Detect whether internal and boundary
178     // points are mixed.
180     label internalPointI = 0;
182     bool ordered = true;
184     for (label faceI = 0; faceI < nInternalFaces; faceI++)
185     {
186         const face& f = faces[faceI];
188         forAll(f, fp)
189         {
190             label pointI = f[fp];
192             if (oldToNew[pointI] == -1)
193             {
194                 if (pointI >= nInternalPoints)
195                 {
196                     ordered = false;
197                 }
198                 oldToNew[pointI] = internalPointI++;
199             }
200         }
201     }
203     return ordered;
207 void Foam::primitiveMesh::reset
209     const label nPoints,
210     const label nInternalFaces,
211     const label nFaces,
212     const label nCells
215     clearOut();
217     nPoints_ = nPoints;
218     nEdges_ = -1;
219     nInternal0Edges_ = -1;
220     nInternal1Edges_ = -1;
221     nInternalEdges_ = -1;
223     nInternalFaces_ = nInternalFaces;
224     nFaces_ = nFaces;
225     nCells_ = nCells;
227     // Check if points are ordered
228     label nInternalPoints;
229     labelList pointMap;
231     bool isOrdered = calcPointOrder
232     (
233         nInternalPoints,
234         pointMap,
235         faces(),
236         nInternalFaces_,
237         nPoints_
238     );
240     if (isOrdered)
241     {
242         nInternalPoints_ = nInternalPoints;
243     }
244     else
245     {
246         nInternalPoints_ = -1;
247     }
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     }
263 void Foam::primitiveMesh::reset
265     const label nPoints,
266     const label nInternalFaces,
267     const label nFaces,
268     const label nCells,
269     cellList& clst
272     reset
273     (
274         nPoints,
275         nInternalFaces,
276         nFaces,
277         nCells
278     );
280     cfPtr_ = new cellList(clst, true);
284 void Foam::primitiveMesh::reset
286     const label nPoints,
287     const label nInternalFaces,
288     const label nFaces,
289     const label nCells,
290     const Xfer<cellList>& clst
293     reset
294     (
295         nPoints,
296         nInternalFaces,
297         nFaces,
298         nCells
299     );
301     cfPtr_ = new cellList(clst);
305 Foam::tmp<Foam::scalarField> Foam::primitiveMesh::movePoints
307     const pointField& newPoints,
308     const pointField& oldPoints
311     if (newPoints.size() <  nPoints() || oldPoints.size() < nPoints())
312     {
313         FatalErrorIn
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     }
322     // Create swept volumes
323     const faceList& f = faces();
325     tmp<scalarField> tsweptVols(new scalarField(f.size()));
326     scalarField& sweptVols = tsweptVols();
328     forAll(f, faceI)
329     {
330         sweptVols[faceI] = f[faceI].sweptVol(oldPoints, newPoints);
331     }
333     // Force recalculation of all geometric data with new points
334     clearGeom();
336     return tsweptVols;
340 const Foam::cellShapeList& Foam::primitiveMesh::cellShapes() const
342     if (!cellShapesPtr_)
343     {
344         calcCellShapes();
345     }
347     return *cellShapesPtr_;
351 // ************************************************************************* //