initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / applications / utilities / postProcessing / dataConversion / foamToVTK / internalWriter.C
blobadf9acaf016a3968b9aa444b189c854078dac969
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 "internalWriter.H"
28 #include "writeFuns.H"
30 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
32 // Construct from components
33 Foam::internalWriter::internalWriter
35     const vtkMesh& vMesh,
36     const bool binary,
37     const fileName& fName
40     vMesh_(vMesh),
41     binary_(binary),
42     fName_(fName),
43     os_(fName.c_str())
45     const fvMesh& mesh = vMesh_.mesh();
46     const vtkTopo& topo = vMesh_.topo();
48     // Write header
49     writeFuns::writeHeader(os_, binary_, mesh.time().caseName());
50     os_ << "DATASET UNSTRUCTURED_GRID" << std::endl;
53     //------------------------------------------------------------------
54     //
55     // Write topology
56     // 
57     //------------------------------------------------------------------
59     const labelList& addPointCellLabels = topo.addPointCellLabels();
60     const label nTotPoints = mesh.nPoints() + addPointCellLabels.size();
62     os_ << "POINTS " << nTotPoints
63         << " float" << std::endl;
65     DynamicList<floatScalar> ptField(3*nTotPoints);
67     writeFuns::insert(mesh.points(), ptField);
69     const pointField& ctrs = mesh.cellCentres();
70     forAll(addPointCellLabels, api)
71     {
72         writeFuns::insert(ctrs[addPointCellLabels[api]], ptField);
73     }
74     writeFuns::write(os_, binary_, ptField);
77     //
78     // Write cells
79     //
81     const labelListList& vtkVertLabels = topo.vertLabels();
83     // Count total number of vertices referenced.
84     label nFaceVerts = 0;
86     forAll(vtkVertLabels, cellI)
87     {
88         nFaceVerts += vtkVertLabels[cellI].size() + 1;
89     }
91     os_ << "CELLS " << vtkVertLabels.size() << ' ' << nFaceVerts
92         << std::endl;
95     DynamicList<label> vertLabels(nFaceVerts);
97     forAll(vtkVertLabels, cellI)
98     {
99         const labelList& vtkVerts = vtkVertLabels[cellI];
101         vertLabels.append(vtkVerts.size());
103         writeFuns::insert(vtkVerts, vertLabels);
104     }
105     writeFuns::write(os_, binary_, vertLabels);
109     const labelList& vtkCellTypes = topo.cellTypes();
111     os_ << "CELL_TYPES " << vtkCellTypes.size() << std::endl;
113     // Make copy since writing might swap stuff.
114     DynamicList<label> cellTypes(vtkCellTypes.size());
116     writeFuns::insert(vtkCellTypes, cellTypes);
118     writeFuns::write(os_, binary_, cellTypes);
122 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
124 void Foam::internalWriter::writeCellIDs()
126     const fvMesh& mesh = vMesh_.mesh();
127     const vtkTopo& topo = vMesh_.topo();
128     const labelList& vtkCellTypes = topo.cellTypes();
129     const labelList& superCells = topo.superCells();
131     // Cell ids first
132     os_ << "cellID 1 " << vtkCellTypes.size() << " int"
133         << std::endl;
135     labelList cellId(vtkCellTypes.size());
136     label labelI = 0;
139     if (vMesh_.useSubMesh())
140     {
141         const labelList& cMap = vMesh_.subsetter().cellMap();
143         forAll(mesh.cells(), cellI)
144         {
145             cellId[labelI++] = cMap[cellI];
146         }
147         forAll(superCells, superCellI)
148         {
149             label origCellI = cMap[superCells[superCellI]];
151             cellId[labelI++] = origCellI;
152         }
153     }
154     else
155     {
156         forAll(mesh.cells(), cellI)
157         {
158             cellId[labelI++] = cellI;
159         }
160         forAll(superCells, superCellI)
161         {
162             label origCellI = superCells[superCellI];
164             cellId[labelI++] = origCellI;
165         }
166     }
168     writeFuns::write(os_, binary_, cellId);
172 // ************************************************************************* //