1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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
69 cellCentresPtr_(NULL),
70 faceCentresPtr_(NULL),
71 cellVolumesPtr_(NULL),
76 // Construct from components
77 // WARNING: ASSUMES CORRECT ORDERING OF DATA.
78 Foam::primitiveMesh::primitiveMesh
81 const label nInternalFaces,
89 nInternalFaces_(nInternalFaces),
111 cellCentresPtr_(NULL),
112 faceCentresPtr_(NULL),
113 cellVolumesPtr_(NULL),
118 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
120 Foam::primitiveMesh::~primitiveMesh()
126 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
128 bool Foam::primitiveMesh::calcPointOrder
130 label& nInternalPoints,
132 const faceList& faces,
133 const label nInternalFaces,
137 // Internal points are points that are not used by a boundary face.
139 // Map from old to new position
140 oldToNew.setSize(nPoints);
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++)
150 const face& f = faces[faceI];
154 label pointI = f[fp];
156 if (oldToNew[pointI] == -1)
158 oldToNew[pointI] = nBoundaryPoints++;
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)
170 if (oldToNew[pointI] != -1)
172 oldToNew[pointI] += nInternalPoints;
177 // 2. Compact the internal points. Detect whether internal and boundary
180 label internalPointI = 0;
184 for (label faceI = 0; faceI < nInternalFaces; faceI++)
186 const face& f = faces[faceI];
190 label pointI = f[fp];
192 if (oldToNew[pointI] == -1)
194 if (pointI >= nInternalPoints)
198 oldToNew[pointI] = internalPointI++;
207 void Foam::primitiveMesh::reset
210 const label nInternalFaces,
219 nInternal0Edges_ = -1;
220 nInternal1Edges_ = -1;
221 nInternalEdges_ = -1;
223 nInternalFaces_ = nInternalFaces;
227 // Check if points are ordered
228 label nInternalPoints;
231 bool isOrdered = calcPointOrder
242 nInternalPoints_ = nInternalPoints;
246 nInternalPoints_ = -1;
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_
263 void Foam::primitiveMesh::reset
266 const label nInternalFaces,
280 cfPtr_ = new cellList(clst, true);
284 void Foam::primitiveMesh::reset
287 const label nInternalFaces,
290 const Xfer<cellList>& clst
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())
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);
322 // Create swept volumes
323 const faceList& f = faces();
325 tmp<scalarField> tsweptVols(new scalarField(f.size()));
326 scalarField& sweptVols = tsweptVols();
330 sweptVols[faceI] = f[faceI].sweptVol(oldPoints, newPoints);
333 // Force recalculation of all geometric data with new points
340 const Foam::cellShapeList& Foam::primitiveMesh::cellShapes() const
347 return *cellShapesPtr_;
351 // ************************************************************************* //