Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / OpenFOAM / meshes / primitiveMesh / PrimitivePatch / PrimitivePatchMeshData.C
blobf0e7e539dcfb57f0769c25c64b0b6931ffbe81a3
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-2010 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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"
27 #include "Map.H"
29 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
31 template
33     class Face,
34     template<class> class FaceList,
35     class PointField,
36     class PointType
38 void
39 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
40 calcMeshData() const
42     if (debug)
43     {
44         Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
45                "calcMeshData() : "
46                "calculating mesh data in PrimitivePatch"
47             << endl;
48     }
50     // It is considered an error to attempt to recalculate meshPoints
51     // if they have already been calculated.
52     if (meshPointsPtr_ || localFacesPtr_)
53     {
54         FatalErrorIn
55         (
56             "PrimitivePatch<Face, FaceList, PointField, PointType>::"
57             "calcMeshData()"
58         )   << "meshPointsPtr_ or localFacesPtr_already allocated"
59             << abort(FatalError);
60     }
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());
67     // Important:
68     // ~~~~~~~~~~
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.
73     ////- 1.5 code:
74     //// if the point is used, set the mark to 1
75     //forAll(*this, facei)
76     //{
77     //    const Face& curPoints = this->operator[](facei);
78     //
79     //    forAll(curPoints, pointi)
80     //    {
81     //        markedPoints.insert(curPoints[pointi], -1);
82     //    }
83     //}
84     //
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_;
89     //
90     //// Sort the list to preserve compatibility with the old ordering
91     //sort(pointPatch);
92     //
93     //// For every point in map give it its label in mesh points
94     //forAll(pointPatch, pointi)
95     //{
96     //    markedPoints.find(pointPatch[pointi])() = pointi;
97     //}
99     //- Unsorted version:
100     DynamicList<label> meshPoints(2*this->size());
101     forAll(*this, facei)
102     {
103         const Face& curPoints = this->operator[](facei);
105         forAll(curPoints, pointi)
106         {
107             if (markedPoints.insert(curPoints[pointi], meshPoints.size()))
108             {
109                 meshPoints.append(curPoints[pointi]);
110             }
111         }
112     }
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_;
123     forAll(*this, facei)
124     {
125         const Face& curFace = this->operator[](facei);
126         lf[facei].setSize(curFace.size());
128         forAll(curFace, labelI)
129         {
130             lf[facei][labelI] = markedPoints.find(curFace[labelI])();
131         }
132     }
134     if (debug)
135     {
136         Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
137                "calcMeshData() : "
138                "finished calculating mesh data in PrimitivePatch"
139             << endl;
140     }
144 template
146     class Face,
147     template<class> class FaceList,
148     class PointField,
149     class PointType
151 void
152 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
153 calcMeshPointMap() const
155     if (debug)
156     {
157         Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
158                "calcMeshPointMap() : "
159                "calculating mesh point map in PrimitivePatch"
160             << endl;
161     }
163     // It is considered an error to attempt to recalculate meshPoints
164     // if they have already been calculated.
165     if (meshPointMapPtr_)
166     {
167         FatalErrorIn
168         (
169             "PrimitivePatch<Face, FaceList, PointField, PointType>::"
170             "calcMeshPointMap()"
171         )   << "meshPointMapPtr_ already allocated"
172             << abort(FatalError);
173     }
175     const labelList& mp = meshPoints();
177     meshPointMapPtr_ = new Map<label>(2*mp.size());
178     Map<label>& mpMap = *meshPointMapPtr_;
180     forAll(mp, i)
181     {
182         mpMap.insert(mp[i], i);
183     }
185     if (debug)
186     {
187         Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
188                "calcMeshPointMap() : "
189                "finished calculating mesh point map in PrimitivePatch"
190             << endl;
191     }
195 template
197     class Face,
198     template<class> class FaceList,
199     class PointField,
200     class PointType
202 void
203 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
204 calcLocalPoints() const
206     if (debug)
207     {
208         Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
209                "calcLocalPoints() : "
210                "calculating localPoints in PrimitivePatch"
211             << endl;
212     }
214     // It is considered an error to attempt to recalculate localPoints
215     // if they have already been calculated.
216     if (localPointsPtr_)
217     {
218         FatalErrorIn
219         (
220             "PrimitivePatch<Face, FaceList, PointField, PointType>::"
221             "calcLocalPoints()"
222         )   << "localPointsPtr_already allocated"
223             << abort(FatalError);
224     }
226     const labelList& meshPts = meshPoints();
228     localPointsPtr_ = new Field<PointType>(meshPts.size());
230     Field<PointType>& locPts = *localPointsPtr_;
232     forAll(meshPts, pointi)
233     {
234         locPts[pointi] = points_[meshPts[pointi]];
235     }
237     if (debug)
238     {
239         Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
240             << "calcLocalPoints() : "
241             << "finished calculating localPoints in PrimitivePatch"
242             << endl;
243     }
247 template
249     class Face,
250     template<class> class FaceList,
251     class PointField,
252     class PointType
254 void
255 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
256 calcPointNormals() const
258     if (debug)
259     {
260         Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
261                "calcPointNormals() : "
262                "calculating pointNormals in PrimitivePatch"
263             << endl;
264     }
266     // It is considered an error to attempt to recalculate pointNormals
267     // if they have already been calculated.
268     if (pointNormalsPtr_)
269     {
270         FatalErrorIn
271         (
272             "PrimitivePatch<Face, FaceList, PointField, PointType>::"
273             "calcPointNormals()"
274         )   << "pointNormalsPtr_already allocated"
275             << abort(FatalError);
276     }
278     const Field<PointType>& faceUnitNormals = faceNormals();
280     const labelListList& pf = pointFaces();
282     pointNormalsPtr_ = new Field<PointType>
283     (
284         meshPoints().size(),
285         PointType::zero
286     );
288     Field<PointType>& n = *pointNormalsPtr_;
290     forAll(pf, pointi)
291     {
292         PointType& curNormal = n[pointi];
294         const labelList& curFaces = pf[pointi];
296         forAll(curFaces, facei)
297         {
298             curNormal += faceUnitNormals[curFaces[facei]];
299         }
301         curNormal /= mag(curNormal) + VSMALL;
302     }
304     if (debug)
305     {
306         Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
307                "calcPointNormals() : "
308                "finished calculating pointNormals in PrimitivePatch"
309             << endl;
310     }
314 template
316     class Face,
317     template<class> class FaceList,
318     class PointField,
319     class PointType
321 void
322 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
323 calcFaceCentres() const
325     if (debug)
326     {
327         Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
328                "calcFaceCentres() : "
329                "calculating faceCentres in PrimitivePatch"
330             << endl;
331     }
333     // It is considered an error to attempt to recalculate faceCentres
334     // if they have already been calculated.
335     if (faceCentresPtr_)
336     {
337         FatalErrorIn
338         (
339             "PrimitivePatch<Face, FaceList, PointField, PointType>::"
340             "calcFaceCentres()"
341         )   << "faceCentresPtr_already allocated"
342             << abort(FatalError);
343     }
345     faceCentresPtr_ = new Field<PointType>(this->size());
347     Field<PointType>& c = *faceCentresPtr_;
349     forAll(c, facei)
350     {
351         c[facei] = this->operator[](facei).centre(points_);
352     }
354     if (debug)
355     {
356         Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
357                "calcFaceCentres() : "
358                "finished calculating faceCentres in PrimitivePatch"
359             << endl;
360     }
364 template
366     class Face,
367     template<class> class FaceList,
368     class PointField,
369     class PointType
371 void
372 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
373 calcFaceNormals() const
375     if (debug)
376     {
377         Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
378                "calcFaceNormals() : "
379                "calculating faceNormals in PrimitivePatch"
380             << endl;
381     }
383     // It is considered an error to attempt to recalculate faceNormals
384     // if they have already been calculated.
385     if (faceNormalsPtr_)
386     {
387         FatalErrorIn
388         (
389             "PrimitivePatch<Face, FaceList, PointField, PointType>::"
390             "calcFaceNormals()"
391         )   << "faceNormalsPtr_already allocated"
392             << abort(FatalError);
393     }
395     faceNormalsPtr_ = new Field<PointType>(this->size());
397     Field<PointType>& n = *faceNormalsPtr_;
399     forAll(n, facei)
400     {
401         n[facei] = this->operator[](facei).normal(points_);
402         n[facei] /= mag(n[facei]) + VSMALL;
403     }
405     if (debug)
406     {
407         Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
408                "calcFaceNormals() : "
409                "finished calculating faceNormals in PrimitivePatch"
410             << endl;
411     }
415 // ************************************************************************* //