Forward compatibility: flex
[foam-extend-3.2.git] / src / conversion / ensight / part / ensightParts.C
blob4af5003a033455ae582d11b73d704efffeaedee5
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 \*----------------------------------------------------------------------------*/
26 #include "ensightParts.H"
28 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
30 Foam::ensightParts::ensightParts(const polyMesh& pMesh)
32     partsList_()
34     recalculate(pMesh);
38 Foam::ensightParts::ensightParts(const IOobject& ioObj)
40     partsList_()
42     IOPtrList<ensightPart> ioList(ioObj);
43     partsList_.transfer(ioList);
47 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
49 Foam::ensightParts::~ensightParts()
53 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
55 void Foam::ensightParts::recalculate(const polyMesh& pMesh)
57     partsList_.clear();
59     // extra space for unzoned cells
60     label nPart =
61     (
62         pMesh.cellZones().size()
63       + pMesh.boundaryMesh().size()
64       + 1
65     );
67     partsList_.setSize(nPart);
68     nPart = 0;
70     label nZoneCells = 0;
72     // do cell zones
73     forAll(pMesh.cellZones(), zoneI)
74     {
75         const cellZone& cZone = pMesh.cellZones()[zoneI];
76         nZoneCells += cZone.size();
78         if (cZone.size())
79         {
80             partsList_.set
81             (
82                 nPart,
83                 new ensightPartCells
84                 (
85                     nPart,
86                     pMesh,
87                     cZone
88                 )
89             );
91             nPart++;
92         }
93     }
95     // collect unzoned cells
97     // special case: no zones at all - do entire mesh
98     if (nZoneCells == 0)
99     {
100         partsList_.set
101         (
102             nPart,
103             new ensightPartCells
104             (
105                 nPart,
106                 pMesh
107             )
108         );
110         nPart++;
111     }
112     else if (pMesh.nCells() > nZoneCells)
113     {
114         // determine which cells are not in a cellZone
115         labelList unzoned(pMesh.nCells(), -1);
117         forAll(pMesh.cellZones(), zoneI)
118         {
119             const labelList& idList = pMesh.cellZones()[zoneI];
121             forAll(idList, i)
122             {
123                 unzoned[idList[i]] = idList[i];
124             }
125         }
127         label nUnzoned = 0;
128         forAll(unzoned, i)
129         {
130             if (unzoned[i] < 0)
131             {
132                 unzoned[nUnzoned] = i;
133                 nUnzoned++;
134             }
135         }
136         unzoned.setSize(nUnzoned);
138         if (unzoned.size())
139         {
140             partsList_.set
141             (
142                 nPart,
143                 new ensightPartCells
144                 (
145                     nPart,
146                     pMesh,
147                     unzoned
148                 )
149             );
151             nPart++;
152         }
153     }
156     // do boundaries, skipping empty and processor patches
157     forAll(pMesh.boundaryMesh(), patchI)
158     {
159         const polyPatch& pPatch = pMesh.boundaryMesh()[patchI];
160         if (pPatch.size() && !isA<processorPolyPatch>(pPatch))
161         {
162             partsList_.set
163             (
164                 nPart,
165                 new ensightPartFaces
166                 (
167                     nPart,
168                     pMesh,
169                     pPatch
170                 )
171             );
173             nPart++;
174         }
175     }
177     // truncate to correct size
178     partsList_.setSize(nPart);
182 void Foam::ensightParts::renumber
184     const labelList& origCellId,
185     const labelList& origFaceId
188     forAll(partsList_, partI)
189     {
190         if (partsList_[partI].isCellData())
191         {
192             partsList_[partI].renumber(origCellId);
193         }
194         else
195         {
196             partsList_[partI].renumber(origFaceId);
197         }
198     }
202 void Foam::ensightParts::writeGeometry( ensightGeoFile& os) const
204     // with some feedback
205     Info<< "write geometry part:" << nl << flush;
207     forAll(partsList_, partI)
208     {
209         Info<< " " << partI << flush;
210         partsList_[partI].writeGeometry(os);
211     }
215 bool Foam::ensightParts::writeSummary(Ostream& os) const
217     forAll(partsList_, partI)
218     {
219         partsList_[partI].writeSummary(os);
220     }
222     return true;
226 void Foam::ensightParts::writeData(Ostream& os) const
228     // Write size of list
229     os << nl << partsList_.size();
231     // Write beginning of contents
232     os << nl << token::BEGIN_LIST;
234     // Write list contents
235     forAll(partsList_, i)
236     {
237         os << nl << partsList_[i];
238     }
240     // Write end of contents
241     os << nl << token::END_LIST << nl;
243     // Check state of IOstream
244     os.check("Ostream& operator<<(Ostream&, const PtrList&)");
248 void Foam::ensightParts::writeScalarField
250     ensightFile& os,
251     const List<scalar>& field,
252     bool useFaceData
253 ) const
255     forAll(partsList_, partI)
256     {
257         if
258         (
259             useFaceData
260           ? partsList_[partI].isFaceData()
261           : partsList_[partI].isCellData()
262         )
263         {
264             partsList_[partI].writeScalarField(os,field);
265         }
266     }
270 void Foam::ensightParts::writeVectorField
272     ensightFile& os,
273     const List<scalar>& field0,
274     const List<scalar>& field1,
275     const List<scalar>& field2,
276     bool useFaceData
277 ) const
279     forAll(partsList_, partI)
280     {
281         if
282         (
283             useFaceData
284           ? partsList_[partI].isFaceData()
285           : partsList_[partI].isCellData()
286         )
287         {
288             partsList_[partI].writeVectorField(os, field0, field1, field2);
289         }
290     }
294 // * * * * * * * * * * * * * * * *  IOStream operators * * * * * * * * * * * //
296 Foam::ensightGeoFile& Foam::operator<<
298     ensightGeoFile& os,
299     const ensightParts& parts
302     parts.writeGeometry(os);
303     return os;
307 // ************************************************************************* //