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  os_(fName.c_str())
42 {
43  const fvMesh& mesh = vMesh_.mesh();
44  const vtkTopo& topo = vMesh_.topo();
45 
46  // Write header
47  writeFuns::writeHeader(os_, binary_, mesh.time().caseName());
48  os_ << "DATASET UNSTRUCTURED_GRID" << std::endl;
49 
50 
51  //------------------------------------------------------------------
52  //
53  // Write topology
54  //
55  //------------------------------------------------------------------
56 
57  const labelList& addPointCellLabels = topo.addPointCellLabels();
58  const label nTotPoints = mesh.nPoints() + addPointCellLabels.size();
59 
60  os_ << "POINTS " << nTotPoints << " float" << std::endl;
61 
62  DynamicList<floatScalar> ptField(3*nTotPoints);
63 
64  writeFuns::insert(mesh.points(), ptField);
65 
66  const pointField& ctrs = mesh.cellCentres();
67  forAll(addPointCellLabels, api)
68  {
69  writeFuns::insert(ctrs[addPointCellLabels[api]], ptField);
70  }
71  writeFuns::write(os_, binary_, ptField);
72 
73 
74  //
75  // Write cells
76  //
77 
78  const labelListList& vtkVertLabels = topo.vertLabels();
79 
80  // Count total number of vertices referenced.
81  label nFaceVerts = 0;
82 
83  forAll(vtkVertLabels, cellI)
84  {
85  nFaceVerts += vtkVertLabels[cellI].size() + 1;
86  }
87 
88  os_ << "CELLS " << vtkVertLabels.size() << ' ' << nFaceVerts << std::endl;
89 
90  DynamicList<label> vertLabels(nFaceVerts);
91 
92  forAll(vtkVertLabels, cellI)
93  {
94  const labelList& vtkVerts = vtkVertLabels[cellI];
95 
96  vertLabels.append(vtkVerts.size());
97 
98  writeFuns::insert(vtkVerts, vertLabels);
99  }
100  writeFuns::write(os_, binary_, vertLabels);
101 
102 
103  const labelList& vtkCellTypes = topo.cellTypes();
104 
105  os_ << "CELL_TYPES " << vtkCellTypes.size() << std::endl;
106 
107  // Make copy since writing might swap stuff.
108  DynamicList<label> cellTypes(vtkCellTypes.size());
109 
110  writeFuns::insert(vtkCellTypes, cellTypes);
111 
112  writeFuns::write(os_, binary_, cellTypes);
113 }
114 
115 
116 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
117 
119 {
120  const fvMesh& mesh = vMesh_.mesh();
121  const vtkTopo& topo = vMesh_.topo();
122  const labelList& vtkCellTypes = topo.cellTypes();
123  const labelList& superCells = topo.superCells();
124 
125  // Cell ids first
126  os_ << "cellID 1 " << vtkCellTypes.size() << " int" << std::endl;
127 
128  labelList cellId(vtkCellTypes.size());
129  label labelI = 0;
130 
131 
132  if (vMesh_.useSubMesh())
133  {
134  const labelList& cMap = vMesh_.subsetter().cellMap();
135 
136  forAll(mesh.cells(), cellI)
137  {
138  cellId[labelI++] = cMap[cellI];
139  }
140  forAll(superCells, superCellI)
141  {
142  label origCellI = cMap[superCells[superCellI]];
143 
144  cellId[labelI++] = origCellI;
145  }
146  }
147  else
148  {
149  forAll(mesh.cells(), cellI)
150  {
151  cellId[labelI++] = cellI;
152  }
153  forAll(superCells, superCellI)
154  {
155  label origCellI = superCells[superCellI];
156 
157  cellId[labelI++] = origCellI;
158  }
159  }
160 
162 }
163 
164 
165 // ************************************************************************* //
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.