1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 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
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 "PrimitivePatch.H"
29 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34 template<class> class FaceList,
39 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
44 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
46 "calculating mesh data in PrimitivePatch"
50 // It is considered an error to attempt to recalculate meshPoints
51 // if they have already been calculated.
52 if (meshPointsPtr_ || localFacesPtr_)
56 "PrimitivePatch<Face, FaceList, PointField, PointType>::"
58 ) << "meshPointsPtr_ or localFacesPtr_already allocated"
62 // Create a map for marking points. Estimated size is 4 times the
63 // number of faces in the patch
64 Map<label> markedPoints(4*this->size());
69 // In <= 1.5 the meshPoints would be in increasing order but this gives
70 // problems in processor point synchronisation where we have to find out
71 // how the opposite side would have allocated points.
74 //// if the point is used, set the mark to 1
75 //forAll(*this, facei)
77 // const Face& curPoints = this->operator[](facei);
79 // forAll(curPoints, pointi)
81 // markedPoints.insert(curPoints[pointi], -1);
85 //// Create the storage and store the meshPoints. Mesh points are
86 //// the ones marked by the usage loop above
87 //meshPointsPtr_ = new labelList(markedPoints.toc());
88 //labelList& pointPatch = *meshPointsPtr_;
90 //// Sort the list to preserve compatibility with the old ordering
93 //// For every point in map give it its label in mesh points
94 //forAll(pointPatch, pointi)
96 // markedPoints.find(pointPatch[pointi])() = pointi;
100 DynamicList<label> meshPoints(2*this->size());
103 const Face& curPoints = this->operator[](facei);
105 forAll(curPoints, pointi)
107 if (markedPoints.insert(curPoints[pointi], meshPoints.size()))
109 meshPoints.append(curPoints[pointi]);
113 // Transfer to straight list (reuses storage)
114 meshPointsPtr_ = new labelList(meshPoints, true);
117 // Create local faces. Note that we start off from copy of original face
118 // list (even though vertices are overwritten below). This is done so
119 // additional data gets copied (e.g. region number of labelledTri)
120 localFacesPtr_ = new List<Face>(*this);
121 List<Face>& lf = *localFacesPtr_;
125 const Face& curFace = this->operator[](facei);
126 lf[facei].setSize(curFace.size());
128 forAll(curFace, labelI)
130 lf[facei][labelI] = markedPoints.find(curFace[labelI])();
136 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
138 "finished calculating mesh data in PrimitivePatch"
147 template<class> class FaceList,
152 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
153 calcMeshPointMap() const
157 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
158 "calcMeshPointMap() : "
159 "calculating mesh point map in PrimitivePatch"
163 // It is considered an error to attempt to recalculate meshPoints
164 // if they have already been calculated.
165 if (meshPointMapPtr_)
169 "PrimitivePatch<Face, FaceList, PointField, PointType>::"
171 ) << "meshPointMapPtr_ already allocated"
172 << abort(FatalError);
175 const labelList& mp = meshPoints();
177 meshPointMapPtr_ = new Map<label>(2*mp.size());
178 Map<label>& mpMap = *meshPointMapPtr_;
182 mpMap.insert(mp[i], i);
187 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
188 "calcMeshPointMap() : "
189 "finished calculating mesh point map in PrimitivePatch"
198 template<class> class FaceList,
203 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
204 calcLocalPoints() const
208 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
209 "calcLocalPoints() : "
210 "calculating localPoints in PrimitivePatch"
214 // It is considered an error to attempt to recalculate localPoints
215 // if they have already been calculated.
220 "PrimitivePatch<Face, FaceList, PointField, PointType>::"
222 ) << "localPointsPtr_already allocated"
223 << abort(FatalError);
226 const labelList& meshPts = meshPoints();
228 localPointsPtr_ = new Field<PointType>(meshPts.size());
230 Field<PointType>& locPts = *localPointsPtr_;
232 forAll(meshPts, pointi)
234 locPts[pointi] = points_[meshPts[pointi]];
239 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
240 << "calcLocalPoints() : "
241 << "finished calculating localPoints in PrimitivePatch"
250 template<class> class FaceList,
255 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
256 calcPointNormals() const
260 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
261 "calcPointNormals() : "
262 "calculating pointNormals in PrimitivePatch"
266 // It is considered an error to attempt to recalculate pointNormals
267 // if they have already been calculated.
268 if (pointNormalsPtr_)
272 "PrimitivePatch<Face, FaceList, PointField, PointType>::"
274 ) << "pointNormalsPtr_already allocated"
275 << abort(FatalError);
278 const Field<PointType>& faceUnitNormals = faceNormals();
280 const labelListList& pf = pointFaces();
282 pointNormalsPtr_ = new Field<PointType>
288 Field<PointType>& n = *pointNormalsPtr_;
292 PointType& curNormal = n[pointi];
294 const labelList& curFaces = pf[pointi];
296 forAll(curFaces, facei)
298 curNormal += faceUnitNormals[curFaces[facei]];
301 curNormal /= mag(curNormal) + VSMALL;
306 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
307 "calcPointNormals() : "
308 "finished calculating pointNormals in PrimitivePatch"
317 template<class> class FaceList,
322 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
323 calcFaceCentres() const
327 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
328 "calcFaceCentres() : "
329 "calculating faceCentres in PrimitivePatch"
333 // It is considered an error to attempt to recalculate faceCentres
334 // if they have already been calculated.
339 "PrimitivePatch<Face, FaceList, PointField, PointType>::"
341 ) << "faceCentresPtr_already allocated"
342 << abort(FatalError);
345 faceCentresPtr_ = new Field<PointType>(this->size());
347 Field<PointType>& c = *faceCentresPtr_;
351 c[facei] = this->operator[](facei).centre(points_);
356 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
357 "calcFaceCentres() : "
358 "finished calculating faceCentres in PrimitivePatch"
367 template<class> class FaceList,
372 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
373 calcFaceNormals() const
377 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
378 "calcFaceNormals() : "
379 "calculating faceNormals in PrimitivePatch"
383 // It is considered an error to attempt to recalculate faceNormals
384 // if they have already been calculated.
389 "PrimitivePatch<Face, FaceList, PointField, PointType>::"
391 ) << "faceNormalsPtr_already allocated"
392 << abort(FatalError);
395 faceNormalsPtr_ = new Field<PointType>(this->size());
397 Field<PointType>& n = *faceNormalsPtr_;
401 n[facei] = this->operator[](facei).normal(points_);
402 n[facei] /= mag(n[facei]) + VSMALL;
407 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
408 "calcFaceNormals() : "
409 "finished calculating faceNormals in PrimitivePatch"
415 // ************************************************************************* //