1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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
43 const fvMesh& mesh = vMesh_.mesh();
44 const vtkTopo& topo = vMesh_.topo();
47 writeFuns::writeHeader(os_, binary_, mesh.time().caseName());
48 os_ << "DATASET UNSTRUCTURED_GRID" << std::endl;
51 //------------------------------------------------------------------
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)
69 writeFuns::insert(ctrs[addPointCellLabels[api]], ptField);
71 writeFuns::write(os_, binary_, ptField);
78 const labelListList& vtkVertLabels = topo.vertLabels();
80 // Count total number of vertices referenced.
83 forAll(vtkVertLabels, cellI)
85 nFaceVerts += vtkVertLabels[cellI].size() + 1;
88 os_ << "CELLS " << vtkVertLabels.size() << ' ' << nFaceVerts << std::endl;
90 DynamicList<label> vertLabels(nFaceVerts);
92 forAll(vtkVertLabels, cellI)
94 const labelList& vtkVerts = vtkVertLabels[cellI];
96 vertLabels.append(vtkVerts.size());
98 writeFuns::insert(vtkVerts, vertLabels);
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();
126 os_ << "cellID 1 " << vtkCellTypes.size() << " int" << std::endl;
128 labelList cellId(vtkCellTypes.size());
132 if (vMesh_.useSubMesh())
134 const labelList& cMap = vMesh_.subsetter().cellMap();
136 forAll(mesh.cells(), cellI)
138 cellId[labelI++] = cMap[cellI];
140 forAll(superCells, superCellI)
142 label origCellI = cMap[superCells[superCellI]];
144 cellId[labelI++] = origCellI;
149 forAll(mesh.cells(), cellI)
151 cellId[labelI++] = cellI;
153 forAll(superCells, superCellI)
155 label origCellI = superCells[superCellI];
157 cellId[labelI++] = origCellI;
161 writeFuns::write(os_, binary_, cellId);
165 // ************************************************************************* //