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  const fvMesh& mesh = vMesh_.mesh();
47  const vtkTopo& topo = vMesh_.topo();
48 
49  // Write header
50  writeFuns::writeHeader(os_, binary_, mesh.time().caseName());
51  os_ << "DATASET UNSTRUCTURED_GRID" << std::endl;
52 
53 
54  //------------------------------------------------------------------
55  //
56  // Write topology
57  //
58  //------------------------------------------------------------------
59 
60  const labelList& addPointCellLabels = topo.addPointCellLabels();
61  const label nTotPoints = mesh.nPoints() + addPointCellLabels.size();
62 
63  os_ << "POINTS " << nTotPoints << " double" << std::endl;
64 
65  DynamicList<doubleScalar> ptField(3*nTotPoints);
66 
67  writeFuns::insert(mesh.points(), ptField);
68 
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);
75 
76 
77  //
78  // Write cells
79  //
80 
81  const labelListList& vtkVertLabels = topo.vertLabels();
82 
83  // Count total number of vertices referenced.
84  label nFaceVerts = 0;
85 
86  forAll(vtkVertLabels, cellI)
87  {
88  nFaceVerts += vtkVertLabels[cellI].size() + 1;
89  }
90 
91  os_ << "CELLS " << vtkVertLabels.size() << ' ' << nFaceVerts << std::endl;
92 
93  DynamicList<label> vertLabels(nFaceVerts);
94 
95  forAll(vtkVertLabels, cellI)
96  {
97  const labelList& vtkVerts = vtkVertLabels[cellI];
98 
99  vertLabels.append(vtkVerts.size());
100 
101  writeFuns::insert(vtkVerts, vertLabels);
102  }
103  writeFuns::write(os_, binary_, vertLabels);
104 
105 
106  const labelList& vtkCellTypes = topo.cellTypes();
107 
108  os_ << "CELL_TYPES " << vtkCellTypes.size() << std::endl;
109 
110  // Make copy since writing might swap stuff.
111  DynamicList<label> cellTypes(vtkCellTypes.size());
112 
113  writeFuns::insert(vtkCellTypes, cellTypes);
114 
115  writeFuns::write(os_, binary_, cellTypes);
116 }
117 
118 
119 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
120 
122 {
123  const fvMesh& mesh = vMesh_.mesh();
124  const vtkTopo& topo = vMesh_.topo();
125  const labelList& vtkCellTypes = topo.cellTypes();
126  const labelList& superCells = topo.superCells();
127 
128  // Cell ids first
129  os_ << "cellID 1 " << vtkCellTypes.size() << " int" << std::endl;
130 
131  labelList cellId(vtkCellTypes.size());
132  label labelI = 0;
133 
134 
135  if (vMesh_.useSubMesh())
136  {
137  const labelList& cMap = vMesh_.subsetter().cellMap();
138 
139  forAll(mesh.cells(), cellI)
140  {
141  cellId[labelI++] = cMap[cellI];
142  }
143  forAll(superCells, superCellI)
144  {
145  label origCellI = cMap[superCells[superCellI]];
146 
147  cellId[labelI++] = origCellI;
148  }
149  }
150  else
151  {
152  forAll(mesh.cells(), cellI)
153  {
154  cellId[labelI++] = cellI;
155  }
156  forAll(superCells, superCellI)
157  {
158  label origCellI = superCells[superCellI];
159 
160  cellId[labelI++] = origCellI;
161  }
162  }
163 
165 }
166 
167 
168 // ************************************************************************* //
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
Foam::internalWriter::binary_
const bool binary_
Definition: internalWriter.H:60
Foam::labelList
List< label > labelList
A List of labels.
Definition: labelList.H:56
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::internalWriter::vMesh_
const vtkMesh & vMesh_
Definition: internalWriter.H:58
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
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::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::List::append
void append(const T &)
Append an element at the end of the list.
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
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
cellId
label cellId
Definition: interrogateWallPatches.H:67
Foam::vtkMesh::mesh
const fvMesh & mesh() const
Access either mesh or submesh.
Definition: vtkMesh.H:119
Foam::internalWriter::writeCellIDs
void writeCellIDs()
Write cellIDs.
Foam::labelListList
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
Foam::vtkMesh::useSubMesh
bool useSubMesh() const
Check if running subMesh.
Definition: vtkMesh.H:103
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())
Foam::labelI
static const labelSphericalTensor labelI(1)
Identity labelTensor.