foamVtuCells.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2016-2021 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "polyMesh.H"
29 #include "foamVtuCells.H"
30 #include "foamVtkOutputOptions.H"
31 
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 
34 Foam::vtk::vtuCells::vtuCells
35 (
36  const contentType output,
37  const bool decompose
38 )
39 :
40  vtk::vtuSizing(),
41  output_(output),
42  decomposeRequest_(decompose),
43  cellTypes_(),
44  vertLabels_(),
45  vertOffset_(),
46  faceLabels_(),
47  faceOffset_(),
48  maps_()
49 {}
50 
51 
52 Foam::vtk::vtuCells::vtuCells
53 (
54  const polyMesh& mesh,
55  const contentType output,
56  const bool decompose
57 )
58 :
59  vtuCells(output, decompose)
60 {
61  reset(mesh);
62 }
63 
64 
65 Foam::vtk::vtuCells::vtuCells
66 (
67  const vtk::outputOptions opts,
68  const bool decompose
69 )
70 :
71  vtuCells
72  (
73  (opts.legacy() ? contentType::LEGACY : contentType::XML),
74  decompose
75  )
76 {}
77 
78 
79 Foam::vtk::vtuCells::vtuCells
80 (
81  const polyMesh& mesh,
82  const vtk::outputOptions opts,
83  const bool decompose
84 )
85 :
86  vtuCells(opts, decompose)
87 {
88  reset(mesh);
89 }
90 
91 
92 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
93 
94 void Foam::vtk::vtuCells::resize_all()
95 {
96  cellTypes_.resize(nFieldCells());
97  vertLabels_.resize(sizeOf(output_, slotType::CELLS));
98  vertOffset_.resize(sizeOf(output_, slotType::CELLS_OFFSETS));
99  faceLabels_.resize(sizeOf(output_, slotType::FACES));
100  faceOffset_.resize(sizeOf(output_, slotType::FACES_OFFSETS));
101 }
102 
103 
104 void Foam::vtk::vtuCells::populateOutput(const polyMesh& mesh)
105 {
106  // Already called
107  // - vtuSizing::reset
108  // - resize_all();
109 
110  switch (output_)
111  {
112  case contentType::LEGACY:
113  {
114  populateLegacy
115  (
116  mesh,
117  cellTypes_,
118  vertLabels_,
119  maps_
120  );
121  break;
122  }
123 
124  case contentType::XML:
125  {
126  populateXml
127  (
128  mesh,
129  cellTypes_,
130  vertLabels_,
131  vertOffset_,
132  faceLabels_,
133  faceOffset_,
134  maps_
135  );
136  break;
137  }
138 
139  case contentType::INTERNAL1:
140  case contentType::INTERNAL2:
141  {
142  populateInternal
143  (
144  mesh,
145  cellTypes_,
146  vertLabels_,
147  vertOffset_,
148  faceLabels_,
149  faceOffset_,
150  maps_,
151  output_
152  );
153  break;
154  }
155  }
156 }
157 
158 
159 void Foam::vtk::vtuCells::populateOutput(const UList<cellShape>& shapes)
160 {
161  if (output_ != contentType::LEGACY && output_ != contentType::XML)
162  {
164  << "Internal formats not supported for shape cells - using XML"
165  << nl << nl;
166 
167  output_ = contentType::XML;
168  }
169 
170  vtuSizing::resetShapes(shapes);
171 
172  maps_.clear();
173  resize_all();
174  // Done in populate routine:
176 
177  switch (output_)
178  {
179  case contentType::LEGACY:
180  {
181  populateShapesLegacy
182  (
183  shapes,
184  cellTypes_,
185  vertLabels_,
186  maps_
187  );
188  break;
189  }
190 
191  case contentType::XML:
192  {
193  populateShapesXml
194  (
195  shapes,
196  cellTypes_,
197  vertLabels_,
198  vertOffset_,
199  faceLabels_,
200  faceOffset_,
201  maps_
202  );
203  break;
204  }
205 
206  default:
207  {
209  << "Unhandled VTK format " << int(output_) << nl
210  << exit(FatalError);
211  break;
212  }
213  }
214 }
215 
216 
217 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
218 
220 {
222  cellTypes_.clear();
223  vertLabels_.clear();
224  vertOffset_.clear();
225  faceLabels_.clear();
226  faceOffset_.clear();
227 
228  maps_.clear();
229 }
230 
231 
233 {
234  vtuSizing::reset(mesh, decomposeRequest_);
235  resize_all();
236 
237  populateOutput(mesh);
238 }
239 
240 
242 (
243  const polyMesh& mesh,
244  const labelUList& subsetCellsIds
245 )
246 {
247  vtuSizing::reset(mesh, subsetCellsIds, decomposeRequest_);
248  resize_all();
249 
250  if (selectionMode() == selectionModeType::SUBSET_MESH)
251  {
252  maps_.cellMap() = subsetCellsIds;
253  }
254 
255  populateOutput(mesh);
256 }
257 
258 
260 (
261  const polyMesh& mesh,
262  const enum contentType output,
263  const bool decompose
264 )
265 {
266  output_ = output;
267  decomposeRequest_ = decompose;
268 
269  reset(mesh);
270 }
271 
272 
274 (
275  const UList<cellShape>& shapes
276 )
277 {
278  if (output_ != contentType::LEGACY && output_ != contentType::XML)
279  {
281  << "VTK internal format is not supported for shape cells"
282  << " switching to xml" << nl << nl;
283 
284  output_ = contentType::XML;
285  }
286 
287  decomposeRequest_ = false;
288 
289  vtuSizing::resetShapes(shapes);
290 
291  maps_.clear();
292  resize_all();
293  maps_.cellMap() = identity(vtuSizing::nCells());
294 
295  switch (output_)
296  {
297  case contentType::LEGACY:
298  {
299  populateShapesLegacy
300  (
301  shapes,
302  cellTypes_,
303  vertLabels_,
304  maps_
305  );
306  break;
307  }
308 
309  case contentType::XML:
310  {
311  populateShapesXml
312  (
313  shapes,
314  cellTypes_,
315  vertLabels_,
316  vertOffset_,
317  faceLabels_,
318  faceOffset_,
319  maps_
320  );
321  break;
322  }
323 
324  default:
325  {
327  << "Unhandled VTK format " << int(output_) << nl
328  << exit(FatalError);
329  break;
330  }
331  }
332 }
333 
334 
336 {
337  maps_.additionalIds() = cellIds;
338  setNumAddPoints(maps_.additionalIds().size());
339 }
340 
341 
343 {
344  maps_.renumberCells(mapping);
345 }
346 
347 
349 {
350  maps_.renumberPoints(mapping);
351 }
352 
353 
354 // ************************************************************************* //
Foam::vtk::outputOptions
Encapsulated combinations of output format options. This is primarily useful when defining the output...
Definition: foamVtkOutputOptions.H:59
Foam::vtk::vtuSizing::nCells
label nCells() const noexcept
Number of cells for the mesh.
Definition: foamVtuSizingI.H:45
Foam::output
static Ostream & output(Ostream &os, const IntRange< T > &range)
Definition: IntRanges.C:66
Foam::vtk::vtuSizing::resetShapes
void resetShapes(const UList< cellShape > &shapes)
Reset sizing using primitive shapes only (ADVANCED USAGE)
Definition: foamVtuSizing.C:404
Foam::vtk::vtuCells::reset
void reset(const polyMesh &mesh)
Definition: foamVtuCells.C:232
Foam::vtk::outputOptions::legacy
bool legacy() const
True if writer uses legacy file format.
Definition: foamVtkOutputOptionsI.H:88
Foam::vtk::dataArrayAttr::FACES
"faces"
polyMesh.H
foamVtuCells.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::vtk::fileTag::CELLS
"Cells"
Foam::vtk::vtuCells::resetShapes
void resetShapes(const UList< cellShape > &shapes)
Reset sizing using primitive shapes only (ADVANCED USAGE)
Definition: foamVtuCells.C:274
Foam::FatalError
error FatalError
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
foamVtkOutputOptions.H
Foam::vtk::vtuCells::renumberCells
void renumberCells(const labelUList &mapping)
Renumber cell ids to account for subset meshes.
Definition: foamVtuCells.C:342
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
reset
meshPtr reset(new Foam::fvMesh(Foam::IOobject(regionName, runTime.timeName(), runTime, Foam::IOobject::MUST_READ), false))
Foam::vtk::vtuSizing::clear
void clear() noexcept
Reset all sizes to zero.
Definition: foamVtuSizing.C:222
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
clear
patchWriters clear()
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::vtk::vtuCells::addPointCellLabels
const labelList & addPointCellLabels() const noexcept
Additional point addressing (from added point to original cell)
Definition: foamVtuCellsI.H:93
Foam::vtk::vtuCells::clear
void clear()
Reset all sizes to zero.
Definition: foamVtuCells.C:219
Foam::vtk::vtuCells::renumberPoints
void renumberPoints(const labelUList &mapping)
Renumber point ids to account for subset meshes.
Definition: foamVtuCells.C:348
Foam::UList< label >
Foam::vtk::vtuCells
A deep-copy description of an OpenFOAM volume mesh in data structures suitable for VTK UnstructuredGr...
Definition: foamVtuCells.H:70
Foam::identity
labelList identity(const label len, label start=0)
Create identity map of the given length with (map[i] == i)
Definition: labelList.C:38
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328
Foam::vtk::vtuSizing::reset
void reset(const polyMesh &mesh, const bool decompose=false)
Reset sizing by analyzing the mesh.
Definition: foamVtuSizing.C:241