Forward compatibility: flex
[foam-extend-3.2.git] / applications / utilities / postProcessing / dataConversion / foamToVTK / internalWriter.C
blob498ebccbd145bdb55bbc22b015784652118baf6b
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 "internalWriter.H"
27 #include "writeFuns.H"
29 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
31 // Construct from components
32 Foam::internalWriter::internalWriter
34     const vtkMesh& vMesh,
35     const bool binary,
36     const fileName& fName
39     vMesh_(vMesh),
40     binary_(binary),
41     fName_(fName),
42     os_(fName.c_str())
44     const fvMesh& mesh = vMesh_.mesh();
45     const vtkTopo& topo = vMesh_.topo();
47     // Write header
48     writeFuns::writeHeader(os_, binary_, mesh.time().caseName());
49     os_ << "DATASET UNSTRUCTURED_GRID" << std::endl;
52     //------------------------------------------------------------------
53     //
54     // Write topology
55     //
56     //------------------------------------------------------------------
58     const labelList& addPointCellLabels = topo.addPointCellLabels();
59     const label nTotPoints = mesh.nPoints() + addPointCellLabels.size();
61     os_ << "POINTS " << nTotPoints
62         << " float" << std::endl;
64     DynamicList<floatScalar> ptField(3*nTotPoints);
66     writeFuns::insert(mesh.points(), ptField);
68     const pointField& ctrs = mesh.cellCentres();
69     forAll(addPointCellLabels, api)
70     {
71         writeFuns::insert(ctrs[addPointCellLabels[api]], ptField);
72     }
73     writeFuns::write(os_, binary_, ptField);
76     //
77     // Write cells
78     //
80     const labelListList& vtkVertLabels = topo.vertLabels();
82     // Count total number of vertices referenced.
83     label nFaceVerts = 0;
85     forAll(vtkVertLabels, cellI)
86     {
87         nFaceVerts += vtkVertLabels[cellI].size() + 1;
88     }
90     os_ << "CELLS " << vtkVertLabels.size() << ' ' << nFaceVerts
91         << std::endl;
94     DynamicList<label> vertLabels(nFaceVerts);
96     forAll(vtkVertLabels, cellI)
97     {
98         const labelList& vtkVerts = vtkVertLabels[cellI];
100         vertLabels.append(vtkVerts.size());
102         writeFuns::insert(vtkVerts, vertLabels);
103     }
104     writeFuns::write(os_, binary_, vertLabels);
108     const labelList& vtkCellTypes = topo.cellTypes();
110     os_ << "CELL_TYPES " << vtkCellTypes.size() << std::endl;
112     // Make copy since writing might swap stuff.
113     DynamicList<label> cellTypes(vtkCellTypes.size());
115     writeFuns::insert(vtkCellTypes, cellTypes);
117     writeFuns::write(os_, binary_, cellTypes);
121 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
123 void Foam::internalWriter::writeCellIDs()
125     const fvMesh& mesh = vMesh_.mesh();
126     const vtkTopo& topo = vMesh_.topo();
127     const labelList& vtkCellTypes = topo.cellTypes();
128     const labelList& superCells = topo.superCells();
130     // Cell ids first
131     os_ << "cellID 1 " << vtkCellTypes.size() << " int"
132         << std::endl;
134     labelList cellId(vtkCellTypes.size());
135     label labelI = 0;
138     if (vMesh_.useSubMesh())
139     {
140         const labelList& cMap = vMesh_.subsetMesh().cellMap();
142         forAll(mesh.cells(), cellI)
143         {
144             cellId[labelI++] = cMap[cellI];
145         }
146         forAll(superCells, superCellI)
147         {
148             label origCellI = cMap[superCells[superCellI]];
150             cellId[labelI++] = origCellI;
151         }
152     }
153     else
154     {
155         forAll(mesh.cells(), cellI)
156         {
157             cellId[labelI++] = cellI;
158         }
159         forAll(superCells, superCellI)
160         {
161             label origCellI = superCells[superCellI];
163             cellId[labelI++] = origCellI;
164         }
165     }
167     writeFuns::write(os_, binary_, cellId);
171 // ************************************************************************* //