internalWriter.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 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 
161  writeFuns::write(os_, binary_, cellId);
162 }
163 
164 
165 // ************************************************************************* //
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
static void writeHeader(std::ostream &, const bool isBinary, const std::string &title)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
static void insert(const point &, DynamicList< floatScalar > &dest)
Append point to given DynamicList.
void writeCellIDs()
Write cellIDs.
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
void append(const T &)
Append an element at the end of the list.
Definition: ListI.H:177
List< label > labelList
A List of labels.
Definition: labelList.H:56
static void write(std::ostream &, const bool, DynamicList< floatScalar > &)
Write floats ascii or binary.
label cellId
internalWriter(const vtkMesh &, const bool binary, const fileName &)
Construct from components.