Merge branch 'upstream/OpenFOAM' into master
[freefoam.git] / src / conversion / ensight / part / ensightParts.C
blobb0600ef54d656dcc63f092750cf47dade2d84092
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 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 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 <conversion/ensightParts.H>
29 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
31 Foam::ensightParts::ensightParts(const polyMesh& pMesh)
33     partsList_()
35     recalculate(pMesh);
39 Foam::ensightParts::ensightParts(const IOobject& ioObj)
41     partsList_()
43     IOPtrList<ensightPart> ioList(ioObj);
44     partsList_.transfer(ioList);
48 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
50 Foam::ensightParts::~ensightParts()
54 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
56 void Foam::ensightParts::recalculate(const polyMesh& pMesh)
58     partsList_.clear();
60     // extra space for unzoned cells
61     label nPart =
62     (
63         pMesh.cellZones().size()
64       + pMesh.boundaryMesh().size()
65       + 1
66     );
68     partsList_.setSize(nPart);
69     nPart = 0;
71     label nZoneCells = 0;
73     // do cell zones
74     forAll(pMesh.cellZones(), zoneI)
75     {
76         const cellZone& cZone = pMesh.cellZones()[zoneI];
77         nZoneCells += cZone.size();
79         if (cZone.size())
80         {
81             partsList_.set
82             (
83                 nPart,
84                 new ensightPartCells
85                 (
86                     nPart,
87                     pMesh,
88                     cZone
89                 )
90             );
92             nPart++;
93         }
94     }
96     // collect unzoned cells
98     // special case: no zones at all - do entire mesh
99     if (nZoneCells == 0)
100     {
101         partsList_.set
102         (
103             nPart,
104             new ensightPartCells
105             (
106                 nPart,
107                 pMesh
108             )
109         );
111         nPart++;
112     }
113     else if (pMesh.nCells() > nZoneCells)
114     {
115         // determine which cells are not in a cellZone
116         labelList unzoned(pMesh.nCells(), -1);
118         forAll(pMesh.cellZones(), zoneI)
119         {
120             const labelList& idList = pMesh.cellZones()[zoneI];
122             forAll(idList, i)
123             {
124                 unzoned[idList[i]] = idList[i];
125             }
126         }
128         label nUnzoned = 0;
129         forAll(unzoned, i)
130         {
131             if (unzoned[i] < 0)
132             {
133                 unzoned[nUnzoned] = i;
134                 nUnzoned++;
135             }
136         }
137         unzoned.setSize(nUnzoned);
139         if (unzoned.size())
140         {
141             partsList_.set
142             (
143                 nPart,
144                 new ensightPartCells
145                 (
146                     nPart,
147                     pMesh,
148                     unzoned
149                 )
150             );
152             nPart++;
153         }
154     }
157     // do boundaries, skipping empty and processor patches
158     forAll(pMesh.boundaryMesh(), patchI)
159     {
160         const polyPatch& pPatch = pMesh.boundaryMesh()[patchI];
161         if
162         (
163             pPatch.size()
164          && typeid(pPatch) != typeid(processorPolyPatch)
165         )
166         {
167             partsList_.set
168             (
169                 nPart,
170                 new ensightPartFaces
171                 (
172                     nPart,
173                     pMesh,
174                     pPatch
175                 )
176             );
178             nPart++;
179         }
180     }
182     // truncate to correct size
183     partsList_.setSize(nPart);
187 void Foam::ensightParts::renumber
189     const labelList& origCellId,
190     const labelList& origFaceId
193     forAll(partsList_, partI)
194     {
195         if (partsList_[partI].isCellData())
196         {
197             partsList_[partI].renumber(origCellId);
198         }
199         else
200         {
201             partsList_[partI].renumber(origFaceId);
202         }
203     }
207 void Foam::ensightParts::writeGeometry( ensightGeoFile& os) const
209     // with some feedback
210     Info<< "write geometry part:" << nl << flush;
212     forAll(partsList_, partI)
213     {
214         Info<< " " << partI << flush;
215         partsList_[partI].writeGeometry(os);
216     }
220 bool Foam::ensightParts::writeSummary(Ostream& os) const
222     forAll(partsList_, partI)
223     {
224         partsList_[partI].writeSummary(os);
225     }
227     return true;
231 void Foam::ensightParts::writeData(Ostream& os) const
233     // Write size of list
234     os << nl << partsList_.size();
236     // Write beginning of contents
237     os << nl << token::BEGIN_LIST;
239     // Write list contents
240     forAll(partsList_, i)
241     {
242         os << nl << partsList_[i];
243     }
245     // Write end of contents
246     os << nl << token::END_LIST << nl;
248     // Check state of IOstream
249     os.check("Ostream& operator<<(Ostream&, const PtrList&)");
253 void Foam::ensightParts::writeScalarField
255     ensightFile& os,
256     const List<scalar>& field,
257     bool useFaceData
258 ) const
260     forAll(partsList_, partI)
261     {
262         if
263         (
264             useFaceData
265           ? partsList_[partI].isFaceData()
266           : partsList_[partI].isCellData()
267         )
268         {
269             partsList_[partI].writeScalarField(os,field);
270         }
271     }
275 void Foam::ensightParts::writeVectorField
277     ensightFile& os,
278     const List<scalar>& field0,
279     const List<scalar>& field1,
280     const List<scalar>& field2,
281     bool useFaceData
282 ) const
284     forAll(partsList_, partI)
285     {
286         if
287         (
288             useFaceData
289           ? partsList_[partI].isFaceData()
290           : partsList_[partI].isCellData()
291         )
292         {
293             partsList_[partI].writeVectorField(os, field0, field1, field2);
294         }
295     }
299 // * * * * * * * * * * * * * * * *  IOStream operators * * * * * * * * * * * //
301 Foam::ensightGeoFile& Foam::operator<<
303     ensightGeoFile& os,
304     const ensightParts& parts
307     parts.writeGeometry(os);
308     return os;
312 // ************************ vim: set sw=4 sts=4 et: ************************ //