1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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 "PrimitivePatch.H"
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
35 template<class> class FaceList,
40 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
45 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
47 "calculating mesh data in PrimitivePatch"
51 // It is considered an error to attempt to recalculate meshPoints
52 // if they have already been calculated.
53 if (meshPointsPtr_ || localFacesPtr_)
57 "PrimitivePatch<Face, FaceList, PointField, PointType>::"
59 ) << "meshPointsPtr_ or localFacesPtr_ already allocated"
63 // If there are no faces in the patch, set both lists to zero size
65 if (this->size() == 0)
67 meshPointsPtr_ = new labelList(0);
68 localFacesPtr_ = new List<Face>(0);
73 // Create a map for marking points. Estimated size is 4 times the
74 // number of faces in the patch
75 Map<label> markedPoints(4*this->size());
80 // In <= 1.5 the meshPoints would be in increasing order but this gives
81 // problems in processor point synchronisation where we have to find out
82 // how the opposite side would have allocated points.
86 // This is all garbage. All -ext versions will preserve strong ordering
90 // If the point is used, set the mark to 1
93 const Face& curPoints = this->operator[](facei);
95 forAll(curPoints, pointi)
97 markedPoints.insert(curPoints[pointi], -1);
101 // Create the storage and store the meshPoints. Mesh points are
102 // the ones marked by the usage loop above
103 meshPointsPtr_ = new labelList(markedPoints.toc());
104 labelList& pointPatch = *meshPointsPtr_;
106 // Sort the list to preserve compatibility with the old ordering
109 // For every point in map give it its label in mesh points
110 forAll(pointPatch, pointi)
112 markedPoints.find(pointPatch[pointi])() = pointi;
117 const Face& curPoints = this->operator[](faceI);
119 forAll (curPoints, pointI)
121 markedPoints.insert(curPoints[pointI], -1);
125 // Create local faces. Note that we start off from copy of original face
126 // list (even though vertices are overwritten below). This is done so
127 // additional data gets copied (e.g. region number of labelledTri)
128 localFacesPtr_ = new List<Face>(*this);
129 List<Face>& lf = *localFacesPtr_;
131 forAll (*this, faceI)
133 const Face& curFace = this->operator[](faceI);
134 lf[faceI].setSize(curFace.size());
136 forAll (curFace, labelI)
138 lf[faceI][labelI] = markedPoints.find(curFace[labelI])();
144 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
146 "finished calculating mesh data in PrimitivePatch"
155 template<class> class FaceList,
160 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
161 calcMeshPointMap() const
165 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
166 "calcMeshPointMap() : "
167 "calculating mesh point map in PrimitivePatch"
171 // It is considered an error to attempt to recalculate meshPoints
172 // if they have already been calculated.
173 if (meshPointMapPtr_)
177 "PrimitivePatch<Face, FaceList, PointField, PointType>::"
179 ) << "meshPointMapPtr_ already allocated"
180 << abort(FatalError);
183 const labelList& mp = meshPoints();
185 meshPointMapPtr_ = new Map<label>(2*mp.size());
186 Map<label>& mpMap = *meshPointMapPtr_;
190 mpMap.insert(mp[i], i);
195 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
196 "calcMeshPointMap() : "
197 "finished calculating mesh point map in PrimitivePatch"
206 template<class> class FaceList,
211 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
212 calcLocalPoints() const
216 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
217 "calcLocalPoints() : "
218 "calculating localPoints in PrimitivePatch"
222 // It is considered an error to attempt to recalculate localPoints
223 // if they have already been calculated.
228 "PrimitivePatch<Face, FaceList, PointField, PointType>::"
230 ) << "localPointsPtr_ already allocated"
231 << abort(FatalError);
234 const labelList& meshPts = meshPoints();
236 localPointsPtr_ = new Field<PointType>(meshPts.size());
238 Field<PointType>& locPts = *localPointsPtr_;
240 forAll (meshPts, pointI)
242 locPts[pointI] = points_[meshPts[pointI]];
247 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
248 << "calcLocalPoints() : "
249 << "finished calculating localPoints in PrimitivePatch"
258 template<class> class FaceList,
263 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
264 calcPointNormals() const
268 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
269 "calcPointNormals() : "
270 "calculating pointNormals in PrimitivePatch"
274 // It is considered an error to attempt to recalculate pointNormals
275 // if they have already been calculated.
276 if (pointNormalsPtr_)
280 "PrimitivePatch<Face, FaceList, PointField, PointType>::"
282 ) << "pointNormalsPtr_ already allocated"
283 << abort(FatalError);
286 const Field<PointType>& faceUnitNormals = faceNormals();
288 const labelListList& pf = pointFaces();
290 pointNormalsPtr_ = new Field<PointType>
296 Field<PointType>& n = *pointNormalsPtr_;
300 PointType& curNormal = n[pointI];
302 const labelList& curFaces = pf[pointI];
304 forAll (curFaces, faceI)
306 curNormal += faceUnitNormals[curFaces[faceI]];
309 curNormal /= mag(curNormal) + VSMALL;
314 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
315 "calcPointNormals() : "
316 "finished calculating pointNormals in PrimitivePatch"
324 template<class> class FaceList,
329 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
330 calcFaceCentres() const
334 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
335 "calcFaceCentres() : "
336 "calculating faceCentres in PrimitivePatch"
340 // It is considered an error to attempt to recalculate faceCentres
341 // if they have already been calculated.
346 "PrimitivePatch<Face, FaceList, PointField, PointType>::"
348 ) << "faceCentresPtr_already allocated"
349 << abort(FatalError);
352 faceCentresPtr_ = new Field<PointType>(this->size());
354 Field<PointType>& c = *faceCentresPtr_;
358 c[facei] = this->operator[](facei).centre(points_);
363 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
364 "calcFaceCentres() : "
365 "finished calculating faceCentres in PrimitivePatch"
374 template<class> class FaceList,
379 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
380 calcFaceNormals() const
384 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
385 "calcFaceNormals() : "
386 "calculating faceNormals in PrimitivePatch"
390 // It is considered an error to attempt to recalculate faceNormals
391 // if they have already been calculated.
396 "PrimitivePatch<Face, FaceList, PointField, PointType>::"
398 ) << "faceNormalsPtr_ already allocated"
399 << abort(FatalError);
402 faceNormalsPtr_ = new Field<PointType>(this->size());
404 Field<PointType>& n = *faceNormalsPtr_;
408 n[faceI] = this->operator[](faceI).normal(points_);
409 n[faceI] /= mag(n[faceI]) + VSMALL;
414 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
415 "calcFaceNormals() : "
416 "finished calculating faceNormals in PrimitivePatch"
422 // ************************************************************************* //