1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "primitiveMesh.H"
27 #include "demandDrivenData.H"
28 #include "indexedOctree.H"
29 #include "treeDataCell.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 defineTypeNameAndDebug(Foam::primitiveMesh, 0);
36 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
38 Foam::primitiveMesh::primitiveMesh()
40 nInternalPoints_(0), // note: points are considered ordered on empty mesh
70 cellCentresPtr_(NULL),
71 faceCentresPtr_(NULL),
72 cellVolumesPtr_(NULL),
77 // Construct from components
78 // WARNING: ASSUMES CORRECT ORDERING OF DATA.
79 Foam::primitiveMesh::primitiveMesh
82 const label nInternalFaces,
90 nInternalFaces_(nInternalFaces),
114 cellCentresPtr_(NULL),
115 faceCentresPtr_(NULL),
116 cellVolumesPtr_(NULL),
121 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
123 Foam::primitiveMesh::~primitiveMesh()
129 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
131 bool Foam::primitiveMesh::calcPointOrder
133 label& nInternalPoints,
135 const faceList& faces,
136 const label nInternalFaces,
140 // Internal points are points that are not used by a boundary face.
142 // Map from old to new position
143 oldToNew.setSize(nPoints);
147 // 1. Create compact addressing for boundary points. Start off by indexing
148 // from 0 inside oldToNew. (shifted up later on)
150 label nBoundaryPoints = 0;
151 for (label faceI = nInternalFaces; faceI < faces.size(); faceI++)
153 const face& f = faces[faceI];
157 label pointI = f[fp];
159 if (oldToNew[pointI] == -1)
161 oldToNew[pointI] = nBoundaryPoints++;
166 // Now we know the number of boundary and internal points
168 nInternalPoints = nPoints - nBoundaryPoints;
170 // Move the boundary addressing up
171 forAll(oldToNew, pointI)
173 if (oldToNew[pointI] != -1)
175 oldToNew[pointI] += nInternalPoints;
180 // 2. Compact the internal points. Detect whether internal and boundary
183 label internalPointI = 0;
187 for (label faceI = 0; faceI < nInternalFaces; faceI++)
189 const face& f = faces[faceI];
193 label pointI = f[fp];
195 if (oldToNew[pointI] == -1)
197 if (pointI >= nInternalPoints)
201 oldToNew[pointI] = internalPointI++;
210 void Foam::primitiveMesh::reset
213 const label nInternalFaces,
222 nInternal0Edges_ = -1;
223 nInternal1Edges_ = -1;
224 nInternalEdges_ = -1;
226 nInternalFaces_ = nInternalFaces;
230 // Check if points are ordered
231 label nInternalPoints;
234 bool isOrdered = calcPointOrder
245 nInternalPoints_ = nInternalPoints;
249 nInternalPoints_ = -1;
254 Pout<< "primitiveMesh::reset : mesh reset to"
255 << " nInternalPoints:" << nInternalPoints_
256 << " nPoints:" << nPoints_
257 << " nEdges:" << nEdges_
258 << " nInternalFaces:" << nInternalFaces_
259 << " nFaces:" << nFaces_
260 << " nCells:" << nCells_
266 void Foam::primitiveMesh::reset
269 const label nInternalFaces,
283 cfPtr_ = new cellList(clst, true);
287 void Foam::primitiveMesh::reset
290 const label nInternalFaces,
293 const Xfer<cellList>& clst
304 cfPtr_ = new cellList(clst);
308 Foam::tmp<Foam::scalarField> Foam::primitiveMesh::movePoints
310 const pointField& newPoints,
311 const pointField& oldPoints
314 if (newPoints.size() < nPoints() || oldPoints.size() < nPoints())
318 "primitiveMesh::movePoints(const pointField& newPoints, "
319 "const pointField& oldPoints)"
320 ) << "Cannot move points: size of given point list smaller "
321 << "than the number of active points"
322 << abort(FatalError);
325 // Create swept volumes
326 const faceList& f = faces();
328 tmp<scalarField> tsweptVols(new scalarField(f.size()));
329 scalarField& sweptVols = tsweptVols();
333 sweptVols[faceI] = f[faceI].sweptVol(oldPoints, newPoints);
336 // Force recalculation of all geometric data with new points
343 const Foam::cellShapeList& Foam::primitiveMesh::cellShapes() const
350 return *cellShapesPtr_;
354 const Foam::indexedOctree<Foam::treeDataCell>&
355 Foam::primitiveMesh::cellTree() const
359 treeBoundBox overallBb(points());
361 Random rndGen(261782);
363 overallBb = overallBb.extend(rndGen, 1E-4);
364 overallBb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
365 overallBb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
368 new indexedOctree<treeDataCell>
372 false, // not cache bb
382 return *cellTreePtr_;
386 // ************************************************************************* //