internalWriter.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "internalWriter.H"
27 #include "writeFuns.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
32 (
33  const vtkMesh& vMesh,
34  const bool binary,
35  const fileName& fName
36 )
37 :
38  vMesh_(vMesh),
39  binary_(binary),
40  fName_(fName),
41  // Use binary mode in case we write binary.
42  // Causes windows reading to fail if we don't
43  os_(fName.c_str(),
44  ios_base::out|ios_base::binary)
45 {
46 
47 Info << "header of " << endl;
48  const fvMesh& mesh = vMesh_.mesh();
49  const vtkTopo& topo = vMesh_.topo();
50 Info << "header of " << endl;
51  // Write header
52  writeFuns::writeHeader(os_, binary_, mesh.time().caseName());
53  os_ << "DATASET UNSTRUCTURED_GRID" << std::endl;
54 
55 
56 Info << "begin POINTS " << endl;
57 
58  //------------------------------------------------------------------
59  //
60  // Write topology
61  //
62  //------------------------------------------------------------------
63 
64  const labelList& addPointCellLabels = topo.addPointCellLabels();
65  const label nTotPoints = mesh.nPoints() + addPointCellLabels.size();
66 
67  os_ << "POINTS " << nTotPoints << " double" << std::endl;
68 
69  DynamicList<doubleScalar> ptField(3*nTotPoints);
70 
71  writeFuns::insert(mesh.points(), ptField);
72 
73  const pointField& ctrs = mesh.cellCentres();
74  forAll(addPointCellLabels, api)
75  {
76  writeFuns::insert(ctrs[addPointCellLabels[api]], ptField);
77  }
78  writeFuns::write(os_, binary_, ptField);
79 
80 
81  //
82  // Write cells
83  //
84 
85  const labelListList& vtkVertLabels = topo.vertLabels();
86 
87  // Count total number of vertices referenced.
88  label nFaceVerts = 0;
89 
90  forAll(vtkVertLabels, cellI)
91  {
92  nFaceVerts += vtkVertLabels[cellI].size() + 1;
93  }
94 
95 Info << "begin CELLS " << endl;
96  os_ << "CELLS " << vtkVertLabels.size() << ' ' << nFaceVerts << std::endl;
97 
98  DynamicList<label> vertLabels(nFaceVerts);
99 
100  forAll(vtkVertLabels, cellI)
101  {
102  const labelList& vtkVerts = vtkVertLabels[cellI];
103 
104  vertLabels.append(vtkVerts.size());
105 
106  writeFuns::insert(vtkVerts, vertLabels);
107  }
108  writeFuns::write(os_, binary_, vertLabels);
109 
110 
111  const labelList& vtkCellTypes = topo.cellTypes();
112 
113  os_ << "CELL_TYPES " << vtkCellTypes.size() << std::endl;
114 
115  // Make copy since writing might swap stuff.
116  DynamicList<label> cellTypes(vtkCellTypes.size());
117 
118  writeFuns::insert(vtkCellTypes, cellTypes);
119 
120  writeFuns::write(os_, binary_, cellTypes);
121 }
122 
123 
124 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
125 
127 {
128  const fvMesh& mesh = vMesh_.mesh();
129  const vtkTopo& topo = vMesh_.topo();
130  const labelList& vtkCellTypes = topo.cellTypes();
131  const labelList& superCells = topo.superCells();
132 
133  // Cell ids first
134  os_ << "cellID 1 " << vtkCellTypes.size() << " int" << std::endl;
135 
136  labelList cellId(vtkCellTypes.size());
137  label labelI = 0;
138 
139 
140  if (vMesh_.useSubMesh())
141  {
142  const labelList& cMap = vMesh_.subsetter().cellMap();
143 
144  forAll(mesh.cells(), cellI)
145  {
146  cellId[labelI++] = cMap[cellI];
147  }
148  forAll(superCells, superCellI)
149  {
150  label origCellI = cMap[superCells[superCellI]];
151 
152  cellId[labelI++] = origCellI;
153  }
154  }
155  else
156  {
157  forAll(mesh.cells(), cellI)
158  {
159  cellId[labelI++] = cellI;
160  }
161  forAll(superCells, superCellI)
162  {
163  label origCellI = superCells[superCellI];
164 
165  cellId[labelI++] = origCellI;
166  }
167  }
168 
170 }
171 
172 
173 // ************************************************************************* //
Foam::polyMesh::points
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:979
Foam::internalWriter::binary_
const bool binary_
Definition: internalWriter.H:60
writeFuns.H
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::Time::caseName
const fileName & caseName() const
Return case name.
Definition: Time.H:275
Foam::vtkTopo::vertLabels
const labelListList & vertLabels() const
Definition: vtkTopo.H:108
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:56
Foam::internalWriter::vMesh_
const vtkMesh & vMesh_
Definition: internalWriter.H:58
Foam::primitiveMesh::cells
const cellList & cells() const
Definition: primitiveMeshCells.C:136
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::vtkMesh
Encapsulation of VTK mesh data. Holds mesh or meshsubset and polyhedral-cell decomposition on it.
Definition: vtkMesh.H:52
Foam::internalWriter::internalWriter
internalWriter(const vtkMesh &, const bool binary, const fileName &)
Construct from components.
Definition: internalWriter.C:32
Foam::vtkMesh::topo
const vtkTopo & topo() const
topology
Definition: vtkMesh.H:110
Foam::fvMeshSubset::cellMap
const labelList & cellMap() const
Return cell map.
Definition: fvMeshSubset.C:1542
Foam::primitiveMesh::nPoints
label nPoints() const
Definition: primitiveMeshI.H:35
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::vtkTopo::superCells
const labelList & superCells() const
Definition: vtkTopo.H:123
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::Info
messageStream Info
Foam::vtkMesh::subsetter
const fvMeshSubset & subsetter() const
Definition: vtkMesh.H:97
Foam::writeFuns::write
static void write(std::ostream &, const bool, DynamicList< floatScalar > &)
Write floats ascii or binary.
Definition: writeFuns.C:107
Foam::vtkTopo::cellTypes
const labelList & cellTypes() const
Definition: vtkTopo.H:113
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Foam::vtkTopo
Polyhedral cell decomposition for VTK.
Definition: vtkTopo.H:51
cellId
label cellId
Definition: interrogateWallPatches.H:67
Foam::DynamicList::append
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Foam::vtkMesh::mesh
const fvMesh & mesh() const
Access either mesh or submesh.
Definition: vtkMesh.H:119
Foam::internalWriter::writeCellIDs
void writeCellIDs()
Write cellIDs.
Foam::primitiveMesh::cellCentres
const vectorField & cellCentres() const
Definition: primitiveMeshCellCentresAndVols.C:211
Foam::vtkTopo::addPointCellLabels
const labelList & addPointCellLabels() const
Definition: vtkTopo.H:118
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::vtkMesh::useSubMesh
bool useSubMesh() const
Check if running subMesh.
Definition: vtkMesh.H:103
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:243
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::internalWriter::os_
std::ofstream os_
Definition: internalWriter.H:64
write
Tcoeff write()
insert
timeIndices insert(timeIndex, timeDirs[timeI].value())
internalWriter.H
Foam::labelI
static const labelSphericalTensor labelI(1)
Identity labelTensor.