fixed writing out entries in advective bc
[OpenFOAM-1.6-ext.git] / src / OpenFOAM / meshes / primitiveMesh / PrimitivePatch / PrimitivePatchMeshData.C
blob16a5383e5dce7ad9db7aa0db7064178711a402d7
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
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 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
19     for more details.
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"
28 #include "Map.H"
30 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
32 template
34     class Face,
35     template<class> class FaceList,
36     class PointField,
37     class PointType
39 void
40 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
41 calcMeshData() const
43     if (debug)
44     {
45         Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
46                "calcMeshData() : "
47                "calculating mesh data in PrimitivePatch"
48             << endl;
49     }
51     // It is considered an error to attempt to recalculate meshPoints
52     // if they have already been calculated.
53     if (meshPointsPtr_ || localFacesPtr_)
54     {
55         FatalErrorIn
56         (
57             "PrimitivePatch<Face, FaceList, PointField, PointType>::"
58             "calcMeshData()"
59         )   << "meshPointsPtr_ or localFacesPtr_ already allocated"
60             << abort(FatalError);
61     }
63     // If there are no faces in the patch, set both lists to zero size
64     // HJ, 22/Nov/2006
65     if (this->size() == 0)
66     {
67         meshPointsPtr_ = new labelList(0);
68         localFacesPtr_ = new List<Face>(0);
70         return;
71     }
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());
78     // Important:
79     // ~~~~~~~~~~
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.
84     // Note:
85     // ~~~~~
86     // This is all garbage.  All -ext versions will preserve strong ordering
87     // HJ, 17/Aug/2010
89     //- 1.5 code:
90     // If the point is used, set the mark to 1
91     forAll(*this, facei)
92     {
93         const Face& curPoints = this->operator[](facei);
95         forAll(curPoints, pointi)
96         {
97             markedPoints.insert(curPoints[pointi], -1);
98         }
99     }
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
107     sort(pointPatch);
109     // For every point in map give it its label in mesh points
110     forAll(pointPatch, pointi)
111     {
112         markedPoints.find(pointPatch[pointi])() = pointi;
113     }
115     forAll(*this, faceI)
116     {
117         const Face& curPoints = this->operator[](faceI);
119         forAll (curPoints, pointI)
120         {
121             markedPoints.insert(curPoints[pointI], -1);
122         }
123     }
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)
132     {
133         const Face& curFace = this->operator[](faceI);
134         lf[faceI].setSize(curFace.size());
136         forAll (curFace, labelI)
137         {
138             lf[faceI][labelI] = markedPoints.find(curFace[labelI])();
139         }
140     }
142     if (debug)
143     {
144         Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
145                "calcMeshData() : "
146                "finished calculating mesh data in PrimitivePatch"
147             << endl;
148     }
152 template
154     class Face,
155     template<class> class FaceList,
156     class PointField,
157     class PointType
159 void
160 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
161 calcMeshPointMap() const
163     if (debug)
164     {
165         Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
166                "calcMeshPointMap() : "
167                "calculating mesh point map in PrimitivePatch"
168             << endl;
169     }
171     // It is considered an error to attempt to recalculate meshPoints
172     // if they have already been calculated.
173     if (meshPointMapPtr_)
174     {
175         FatalErrorIn
176         (
177             "PrimitivePatch<Face, FaceList, PointField, PointType>::"
178             "calcMeshPointMap()"
179         )   << "meshPointMapPtr_ already allocated"
180             << abort(FatalError);
181     }
183     const labelList& mp = meshPoints();
185     meshPointMapPtr_ = new Map<label>(2*mp.size());
186     Map<label>& mpMap = *meshPointMapPtr_;
188     forAll (mp, i)
189     {
190         mpMap.insert(mp[i], i);
191     }
193     if (debug)
194     {
195         Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
196                "calcMeshPointMap() : "
197                "finished calculating mesh point map in PrimitivePatch"
198             << endl;
199     }
203 template
205     class Face,
206     template<class> class FaceList,
207     class PointField,
208     class PointType
210 void
211 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
212 calcLocalPoints() const
214     if (debug)
215     {
216         Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
217                "calcLocalPoints() : "
218                "calculating localPoints in PrimitivePatch"
219             << endl;
220     }
222     // It is considered an error to attempt to recalculate localPoints
223     // if they have already been calculated.
224     if (localPointsPtr_)
225     {
226         FatalErrorIn
227         (
228             "PrimitivePatch<Face, FaceList, PointField, PointType>::"
229             "calcLocalPoints()"
230         )   << "localPointsPtr_ already allocated"
231             << abort(FatalError);
232     }
234     const labelList& meshPts = meshPoints();
236     localPointsPtr_ = new Field<PointType>(meshPts.size());
238     Field<PointType>& locPts = *localPointsPtr_;
240     forAll (meshPts, pointI)
241     {
242         locPts[pointI] = points_[meshPts[pointI]];
243     }
245     if (debug)
246     {
247         Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
248             << "calcLocalPoints() : "
249             << "finished calculating localPoints in PrimitivePatch"
250             << endl;
251     }
255 template
257     class Face,
258     template<class> class FaceList,
259     class PointField,
260     class PointType
262 void
263 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
264 calcPointNormals() const
266     if (debug)
267     {
268         Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
269                "calcPointNormals() : "
270                "calculating pointNormals in PrimitivePatch"
271             << endl;
272     }
274     // It is considered an error to attempt to recalculate pointNormals
275     // if they have already been calculated.
276     if (pointNormalsPtr_)
277     {
278         FatalErrorIn
279         (
280             "PrimitivePatch<Face, FaceList, PointField, PointType>::"
281             "calcPointNormals()"
282         )   << "pointNormalsPtr_ already allocated"
283             << abort(FatalError);
284     }
286     const Field<PointType>& faceUnitNormals = faceNormals();
288     const labelListList& pf = pointFaces();
290     pointNormalsPtr_ = new Field<PointType>
291     (
292         meshPoints().size(),
293         PointType::zero
294     );
296     Field<PointType>& n = *pointNormalsPtr_;
298     forAll (pf, pointI)
299     {
300         PointType& curNormal = n[pointI];
302         const labelList& curFaces = pf[pointI];
304         forAll (curFaces, faceI)
305         {
306             curNormal += faceUnitNormals[curFaces[faceI]];
307         }
309         curNormal /= mag(curNormal) + VSMALL;
310     }
312     if (debug)
313     {
314         Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
315                "calcPointNormals() : "
316                "finished calculating pointNormals in PrimitivePatch"
317             << endl;
318     }
321 template
323     class Face,
324     template<class> class FaceList,
325     class PointField,
326     class PointType
328 void
329 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
330 calcFaceCentres() const
332     if (debug)
333     {
334         Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
335                "calcFaceCentres() : "
336                "calculating faceCentres in PrimitivePatch"
337             << endl;
338     }
340     // It is considered an error to attempt to recalculate faceCentres
341     // if they have already been calculated.
342     if (faceCentresPtr_)
343     {
344         FatalErrorIn
345         (
346             "PrimitivePatch<Face, FaceList, PointField, PointType>::"
347             "calcFaceCentres()"
348         )   << "faceCentresPtr_already allocated"
349             << abort(FatalError);
350     }
352     faceCentresPtr_ = new Field<PointType>(this->size());
354     Field<PointType>& c = *faceCentresPtr_;
356     forAll(c, facei)
357     {
358         c[facei] = this->operator[](facei).centre(points_);
359     }
361     if (debug)
362     {
363         Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
364                "calcFaceCentres() : "
365                "finished calculating faceCentres in PrimitivePatch"
366             << endl;
367     }
371 template
373     class Face,
374     template<class> class FaceList,
375     class PointField,
376     class PointType
378 void
379 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
380 calcFaceNormals() const
382     if (debug)
383     {
384         Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
385                "calcFaceNormals() : "
386                "calculating faceNormals in PrimitivePatch"
387             << endl;
388     }
390     // It is considered an error to attempt to recalculate faceNormals
391     // if they have already been calculated.
392     if (faceNormalsPtr_)
393     {
394         FatalErrorIn
395         (
396             "PrimitivePatch<Face, FaceList, PointField, PointType>::"
397             "calcFaceNormals()"
398         )   << "faceNormalsPtr_ already allocated"
399             << abort(FatalError);
400     }
402     faceNormalsPtr_ = new Field<PointType>(this->size());
404     Field<PointType>& n = *faceNormalsPtr_;
406     forAll (n, faceI)
407     {
408         n[faceI] = this->operator[](faceI).normal(points_);
409         n[faceI] /= mag(n[faceI]) + VSMALL;
410     }
412     if (debug)
413     {
414         Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
415                "calcFaceNormals() : "
416                "finished calculating faceNormals in PrimitivePatch"
417             << endl;
418     }
422 // ************************************************************************* //