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 "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 // Create a map for marking points. Estimated size is 4 times the
64 // number of faces in the patch
65 Map<label> markedPoints(4*this->size());
70 // In <= 1.5 the meshPoints would be in increasing order but this gives
71 // problems in processor point synchronisation where we have to find out
72 // how the opposite side would have allocated points.
75 //// if the point is used, set the mark to 1
76 //forAll(*this, facei)
78 // const Face& curPoints = this->operator[](facei);
80 // forAll(curPoints, pointi)
82 // markedPoints.insert(curPoints[pointi], -1);
86 //// Create the storage and store the meshPoints. Mesh points are
87 //// the ones marked by the usage loop above
88 //meshPointsPtr_ = new labelList(markedPoints.toc());
89 //labelList& pointPatch = *meshPointsPtr_;
91 //// Sort the list to preserve compatibility with the old ordering
94 //// For every point in map give it its label in mesh points
95 //forAll(pointPatch, pointi)
97 // markedPoints.find(pointPatch[pointi])() = pointi;
100 //- Unsorted version:
101 DynamicList<label> meshPoints(2*this->size());
104 const Face& curPoints = this->operator[](facei);
106 forAll(curPoints, pointi)
108 if (markedPoints.insert(curPoints[pointi], meshPoints.size()))
110 meshPoints.append(curPoints[pointi]);
114 // Transfer to straight list (reuses storage)
115 meshPointsPtr_ = new labelList(meshPoints, true);
118 // Create local faces. Note that we start off from copy of original face
119 // list (even though vertices are overwritten below). This is done so
120 // additional data gets copied (e.g. region number of labelledTri)
121 localFacesPtr_ = new List<Face>(*this);
122 List<Face>& lf = *localFacesPtr_;
126 const Face& curFace = this->operator[](facei);
127 lf[facei].setSize(curFace.size());
129 forAll(curFace, labelI)
131 lf[facei][labelI] = markedPoints.find(curFace[labelI])();
137 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
139 "finished calculating mesh data in PrimitivePatch"
148 template<class> class FaceList,
153 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
154 calcMeshPointMap() const
158 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
159 "calcMeshPointMap() : "
160 "calculating mesh point map in PrimitivePatch"
164 // It is considered an error to attempt to recalculate meshPoints
165 // if they have already been calculated.
166 if (meshPointMapPtr_)
170 "PrimitivePatch<Face, FaceList, PointField, PointType>::"
172 ) << "meshPointMapPtr_ already allocated"
173 << abort(FatalError);
176 const labelList& mp = meshPoints();
178 meshPointMapPtr_ = new Map<label>(2*mp.size());
179 Map<label>& mpMap = *meshPointMapPtr_;
183 mpMap.insert(mp[i], i);
188 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
189 "calcMeshPointMap() : "
190 "finished calculating mesh point map in PrimitivePatch"
199 template<class> class FaceList,
204 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
205 calcLocalPoints() const
209 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
210 "calcLocalPoints() : "
211 "calculating localPoints in PrimitivePatch"
215 // It is considered an error to attempt to recalculate localPoints
216 // if they have already been calculated.
221 "PrimitivePatch<Face, FaceList, PointField, PointType>::"
223 ) << "localPointsPtr_already allocated"
224 << abort(FatalError);
227 const labelList& meshPts = meshPoints();
229 localPointsPtr_ = new Field<PointType>(meshPts.size());
231 Field<PointType>& locPts = *localPointsPtr_;
233 forAll(meshPts, pointi)
235 locPts[pointi] = points_[meshPts[pointi]];
240 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
241 << "calcLocalPoints() : "
242 << "finished calculating localPoints in PrimitivePatch"
251 template<class> class FaceList,
256 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
257 calcPointNormals() const
261 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
262 "calcPointNormals() : "
263 "calculating pointNormals in PrimitivePatch"
267 // It is considered an error to attempt to recalculate pointNormals
268 // if they have already been calculated.
269 if (pointNormalsPtr_)
273 "PrimitivePatch<Face, FaceList, PointField, PointType>::"
275 ) << "pointNormalsPtr_already allocated"
276 << abort(FatalError);
279 const Field<PointType>& faceUnitNormals = faceNormals();
281 const labelListList& pf = pointFaces();
283 pointNormalsPtr_ = new Field<PointType>
289 Field<PointType>& n = *pointNormalsPtr_;
293 PointType& curNormal = n[pointi];
295 const labelList& curFaces = pf[pointi];
297 forAll(curFaces, facei)
299 curNormal += faceUnitNormals[curFaces[facei]];
302 curNormal /= mag(curNormal) + VSMALL;
307 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
308 "calcPointNormals() : "
309 "finished calculating pointNormals in PrimitivePatch"
318 template<class> class FaceList,
323 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
324 calcFaceCentres() const
328 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
329 "calcFaceCentres() : "
330 "calculating faceCentres in PrimitivePatch"
334 // It is considered an error to attempt to recalculate faceCentres
335 // if they have already been calculated.
340 "PrimitivePatch<Face, FaceList, PointField, PointType>::"
342 ) << "faceCentresPtr_already allocated"
343 << abort(FatalError);
346 faceCentresPtr_ = new Field<PointType>(this->size());
348 Field<PointType>& c = *faceCentresPtr_;
352 c[facei] = this->operator[](facei).centre(points_);
357 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
358 "calcFaceCentres() : "
359 "finished calculating faceCentres in PrimitivePatch"
368 template<class> class FaceList,
373 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
374 calcFaceNormals() const
378 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
379 "calcFaceNormals() : "
380 "calculating faceNormals in PrimitivePatch"
384 // It is considered an error to attempt to recalculate faceNormals
385 // if they have already been calculated.
390 "PrimitivePatch<Face, FaceList, PointField, PointType>::"
392 ) << "faceNormalsPtr_already allocated"
393 << abort(FatalError);
396 faceNormalsPtr_ = new Field<PointType>(this->size());
398 Field<PointType>& n = *faceNormalsPtr_;
402 n[facei] = this->operator[](facei).normal(points_);
403 n[facei] /= mag(n[facei]) + VSMALL;
408 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
409 "calcFaceNormals() : "
410 "finished calculating faceNormals in PrimitivePatch"
416 // ************************************************************************* //