Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / applications / utilities / postProcessing / dataConversion / foamToVTK / internalWriter.C
blob8489663c598d562ff59117cc060934055e0ad8ef
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 "internalWriter.H"
27 #include "writeFuns.H"
29 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
31 Foam::internalWriter::internalWriter
33     const vtkMesh& vMesh,
34     const bool binary,
35     const fileName& fName
38     vMesh_(vMesh),
39     binary_(binary),
40     fName_(fName),
41     os_(fName.c_str())
43     const fvMesh& mesh = vMesh_.mesh();
44     const vtkTopo& topo = vMesh_.topo();
46     // Write header
47     writeFuns::writeHeader(os_, binary_, mesh.time().caseName());
48     os_ << "DATASET UNSTRUCTURED_GRID" << std::endl;
51     //------------------------------------------------------------------
52     //
53     // Write topology
54     //
55     //------------------------------------------------------------------
57     const labelList& addPointCellLabels = topo.addPointCellLabels();
58     const label nTotPoints = mesh.nPoints() + addPointCellLabels.size();
60     os_ << "POINTS " << nTotPoints << " float" << std::endl;
62     DynamicList<floatScalar> ptField(3*nTotPoints);
64     writeFuns::insert(mesh.points(), ptField);
66     const pointField& ctrs = mesh.cellCentres();
67     forAll(addPointCellLabels, api)
68     {
69         writeFuns::insert(ctrs[addPointCellLabels[api]], ptField);
70     }
71     writeFuns::write(os_, binary_, ptField);
74     //
75     // Write cells
76     //
78     const labelListList& vtkVertLabels = topo.vertLabels();
80     // Count total number of vertices referenced.
81     label nFaceVerts = 0;
83     forAll(vtkVertLabels, cellI)
84     {
85         nFaceVerts += vtkVertLabels[cellI].size() + 1;
86     }
88     os_ << "CELLS " << vtkVertLabels.size() << ' ' << nFaceVerts << std::endl;
90     DynamicList<label> vertLabels(nFaceVerts);
92     forAll(vtkVertLabels, cellI)
93     {
94         const labelList& vtkVerts = vtkVertLabels[cellI];
96         vertLabels.append(vtkVerts.size());
98         writeFuns::insert(vtkVerts, vertLabels);
99     }
100     writeFuns::write(os_, binary_, vertLabels);
103     const labelList& vtkCellTypes = topo.cellTypes();
105     os_ << "CELL_TYPES " << vtkCellTypes.size() << std::endl;
107     // Make copy since writing might swap stuff.
108     DynamicList<label> cellTypes(vtkCellTypes.size());
110     writeFuns::insert(vtkCellTypes, cellTypes);
112     writeFuns::write(os_, binary_, cellTypes);
116 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
118 void Foam::internalWriter::writeCellIDs()
120     const fvMesh& mesh = vMesh_.mesh();
121     const vtkTopo& topo = vMesh_.topo();
122     const labelList& vtkCellTypes = topo.cellTypes();
123     const labelList& superCells = topo.superCells();
125     // Cell ids first
126     os_ << "cellID 1 " << vtkCellTypes.size() << " int" << std::endl;
128     labelList cellId(vtkCellTypes.size());
129     label labelI = 0;
132     if (vMesh_.useSubMesh())
133     {
134         const labelList& cMap = vMesh_.subsetter().cellMap();
136         forAll(mesh.cells(), cellI)
137         {
138             cellId[labelI++] = cMap[cellI];
139         }
140         forAll(superCells, superCellI)
141         {
142             label origCellI = cMap[superCells[superCellI]];
144             cellId[labelI++] = origCellI;
145         }
146     }
147     else
148     {
149         forAll(mesh.cells(), cellI)
150         {
151             cellId[labelI++] = cellI;
152         }
153         forAll(superCells, superCellI)
154         {
155             label origCellI = superCells[superCellI];
157             cellId[labelI++] = origCellI;
158         }
159     }
161     writeFuns::write(os_, binary_, cellId);
165 // ************************************************************************* //