1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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 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
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
45 const fvMesh& mesh = vMesh_.mesh();
46 const vtkTopo& topo = vMesh_.topo();
49 writeFuns::writeHeader(os_, binary_, mesh.time().caseName());
50 os_ << "DATASET UNSTRUCTURED_GRID" << std::endl;
53 //------------------------------------------------------------------
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)
72 writeFuns::insert(ctrs[addPointCellLabels[api]], ptField);
74 writeFuns::write(os_, binary_, ptField);
81 const labelListList& vtkVertLabels = topo.vertLabels();
83 // Count total number of vertices referenced.
86 forAll(vtkVertLabels, cellI)
88 nFaceVerts += vtkVertLabels[cellI].size() + 1;
91 os_ << "CELLS " << vtkVertLabels.size() << ' ' << nFaceVerts
95 DynamicList<label> vertLabels(nFaceVerts);
97 forAll(vtkVertLabels, cellI)
99 const labelList& vtkVerts = vtkVertLabels[cellI];
101 vertLabels.append(vtkVerts.size());
103 writeFuns::insert(vtkVerts, vertLabels);
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();
132 os_ << "cellID 1 " << vtkCellTypes.size() << " int"
135 labelList cellId(vtkCellTypes.size());
139 if (vMesh_.useSubMesh())
141 const labelList& cMap = vMesh_.subsetMesh().cellMap();
143 forAll(mesh.cells(), cellI)
145 cellId[labelI++] = cMap[cellI];
147 forAll(superCells, superCellI)
149 label origCellI = cMap[superCells[superCellI]];
151 cellId[labelI++] = origCellI;
156 forAll(mesh.cells(), cellI)
158 cellId[labelI++] = cellI;
160 forAll(superCells, superCellI)
162 label origCellI = superCells[superCellI];
164 cellId[labelI++] = origCellI;
168 writeFuns::write(os_, binary_, cellId);
172 // ************************************************************************* //