1 /*---------------------------------------------------------------------------*\
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 -------------------------------------------------------------------------------
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
44 const fvMesh& mesh = vMesh_.mesh();
45 const vtkTopo& topo = vMesh_.topo();
48 writeFuns::writeHeader(os_, binary_, mesh.time().caseName());
49 os_ << "DATASET UNSTRUCTURED_GRID" << std::endl;
52 //------------------------------------------------------------------
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)
71 writeFuns::insert(ctrs[addPointCellLabels[api]], ptField);
73 writeFuns::write(os_, binary_, ptField);
80 const labelListList& vtkVertLabels = topo.vertLabels();
82 // Count total number of vertices referenced.
85 forAll(vtkVertLabels, cellI)
87 nFaceVerts += vtkVertLabels[cellI].size() + 1;
90 os_ << "CELLS " << vtkVertLabels.size() << ' ' << nFaceVerts
94 DynamicList<label> vertLabels(nFaceVerts);
96 forAll(vtkVertLabels, cellI)
98 const labelList& vtkVerts = vtkVertLabels[cellI];
100 vertLabels.append(vtkVerts.size());
102 writeFuns::insert(vtkVerts, vertLabels);
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();
131 os_ << "cellID 1 " << vtkCellTypes.size() << " int"
134 labelList cellId(vtkCellTypes.size());
138 if (vMesh_.useSubMesh())
140 const labelList& cMap = vMesh_.subsetMesh().cellMap();
142 forAll(mesh.cells(), cellI)
144 cellId[labelI++] = cMap[cellI];
146 forAll(superCells, superCellI)
148 label origCellI = cMap[superCells[superCellI]];
150 cellId[labelI++] = origCellI;
155 forAll(mesh.cells(), cellI)
157 cellId[labelI++] = cellI;
159 forAll(superCells, superCellI)
161 label origCellI = superCells[superCellI];
163 cellId[labelI++] = origCellI;
167 writeFuns::write(os_, binary_, cellId);
171 // ************************************************************************* //