dune-vtk 2.12
Loading...
Searching...
No Matches
types.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file AUTHORS.md
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
3#pragma once
4
5#include <cstdint>
6#include <map>
7#include <string>
8#include <vector>
9
13#include <dune/geometry/type.hh>
17
18namespace Dune::Vtk
19{
21 enum class FormatTypes {
22 UNKNOWN = 0,
23 ASCII = 1<<0,
24 BINARY = 1<<1,
25 COMPRESSED = 1<<2,
27 };
30
33
34
36 enum class RangeTypes {
37 UNSPECIFIED, //< The output components are not restricted
38 AUTO, //< Detect the category automatically from number of components
39 SCALAR, //< Use exactly 1 component
40 VECTOR, //< Use exactly 3 components
41 TENSOR //< Use exactly 9 components
42 };
45
46 // Map a dune-grid FieldInfo::Type to ValueTypes
48
49 // Map a number of components to a corresponding value type
50 Vtk::RangeTypes rangeTypeOf (int ncomps);
51
52
53 enum class DataTypes {
54 UNKNOWN = 0,
55 INT8, UINT8,
59 FLOAT32 = 32,
60 FLOAT64 = 64
61 };
71
72 // Map a dune-grid Precision type to DataTypes
74
75 // Map a string to DataTypes
77
78 // Map the field_type of T to DataTypes
79 template <class T>
81 {
82 using F = typename FieldTraits<T>::field_type;
83 if constexpr (std::is_same_v<F, std::int8_t>) { return Vtk::DataTypes::INT8; }
84 if constexpr (std::is_same_v<F, std::uint8_t>) { return Vtk::DataTypes::UINT8; }
85 if constexpr (std::is_same_v<F, std::int16_t>) { return Vtk::DataTypes::INT16; }
86 if constexpr (std::is_same_v<F, std::uint16_t>) { return Vtk::DataTypes::UINT16; }
87 if constexpr (std::is_same_v<F, std::int32_t>) { return Vtk::DataTypes::INT32; }
88 if constexpr (std::is_same_v<F, std::uint32_t>) { return Vtk::DataTypes::UINT32; }
89 if constexpr (std::is_same_v<F, std::int64_t>) { return Vtk::DataTypes::INT64; }
90 if constexpr (std::is_same_v<F, std::uint64_t>) { return Vtk::DataTypes::UINT64; }
91 if constexpr (std::is_same_v<F, float>) { return Vtk::DataTypes::FLOAT32; }
92 if constexpr (std::is_same_v<F, double>) { return Vtk::DataTypes::FLOAT64; }
93 if constexpr (std::is_same_v<F, long double>) { return Vtk::DataTypes::FLOAT64; }
95 }
96
97 template <class> struct NoConstraint : std::true_type {};
98
100 template <template <class> class C = NoConstraint, class Caller>
102 {
103 switch (t) {
112 case DataTypes::FLOAT32: if constexpr(C<float>::value) caller(MetaType<float>{}); break;
113 case DataTypes::FLOAT64: if constexpr(C<double>::value) caller(MetaType<double>{}); break;
114 default:
115 VTK_ASSERT_MSG(false, "Unsupported type " + to_string(t));
116 break;
117 }
118 }
119
121 template <template <class> class Constraint1 = NoConstraint,
122 template <class> class Constraint2 = NoConstraint,
123 class Caller>
125 {
129 });
130 });
131 }
132
134 template <template <class> class Constraint1 = NoConstraint,
135 template <class> class Constraint2 = NoConstraint,
136 template <class> class Constraint3 = NoConstraint,
137 class Caller>
148
149
150 enum class CompressorTypes {
151 NONE = 0,
152 ZLIB,
153 LZ4,
154 LZMA
155 };
157
158
160 struct CellType
161 {
168
171 // Linear VTK cell types
173 /* POLY_VERTEX = 2, // not supported */
174 LINE = 3,
175 /* POLY_LINE = 4, // not supported */
177 /* TRIANGLE_STRIP = 6, // not supported */
179 /* PIXEL = 8, // not supported */
180 QUAD = 9,
181 TETRA = 10,
182 /* VOXEL = 11, // not supported */
184 WEDGE = 13,
186 // Quadratic VTK cell types
194 // Multi-quadratic cell types
199 // Arbitrary order Lagrange elements
207 };
208
209 public:
211
214 {
215 return type_;
216 }
217
218 int layout (int dim) const
219 {
220 return layout_[dim];
221 }
222
224 int permutation (int idx) const
225 {
226 return permutation_[idx];
227 }
228
230 int size () const
231 {
232 return permutation_.size();
233 }
234
235 bool noPermutation () const
236 {
237 return noPermutation_;
238 }
239
240 private:
241 std::uint8_t type_;
242 std::vector<int> layout_; // number of nodes for each dimension
243 std::vector<int> permutation_;
244 bool noPermutation_ = true;
245 };
247
248
250 {
251 public:
252 template <class... Args>
254 : name_(std::move(name))
255 , ncomps_(getArg<int,unsigned int,long,unsigned long>(args..., 1))
256 , rangeType_(getArg<Vtk::RangeTypes>(args..., Vtk::RangeTypes::AUTO))
257 , dataType_(getArg<Vtk::DataTypes>(args..., Vtk::DataTypes::FLOAT32))
258 {
259 if (rangeType_ == Vtk::RangeTypes::AUTO)
260 rangeType_ = rangeTypeOf(ncomps_);
261 }
262
263 // Construct from dune-grid FieldInfo
265 : FieldInfo(info.name(), info.size(), rangeTypeOf(info.type()), dataTypeOf(info.precision()))
266 {}
267
269 std::string const& name () const
270 {
271 return name_;
272 }
273
275 int size () const
276 {
277 return ncomps_;
278 }
279
282 {
283 return rangeType_;
284 }
285
288 {
289 return dataType_;
290 }
291
292 private:
293 std::string name_;
294 int ncomps_;
295 Vtk::RangeTypes rangeType_;
296 Vtk::DataTypes dataType_;
297 };
298
299} // end namespace Dune::Vtk
Macro for wrapping error checks and throwing exceptions.
#define VTK_ASSERT_MSG(cond, text)
check if condition cond holds; otherwise, throw a VtkError with a message.
Definition errors.hh:21
STL namespace.
Definition datacollector.hh:19
const auto dataTypesLists
Definition types.hh:63
FormatTypes
Type used for representing the output format.
Definition types.hh:21
void mapDataTypes(Vtk::DataTypes t, Caller caller)
Map a given enum DataType to a type passed to Caller as MetaType.
Definition types.hh:101
CompressorTypes
Definition types.hh:150
Vtk::FormatTypes formatTypeOf(Dune::VTK::OutputType o)
Map the dune-grid OutputType to FormatTypes.
Definition types.cc:26
Vtk::DataTypes dataTypeOf()
Definition types.hh:80
RangeTypes
Type used to determine whether to limit output components to e.g. 3 (vector), or 9 (tensor)
Definition types.hh:36
const auto formatTypesList
Definition types.hh:29
DataTypes
Definition types.hh:53
std::string to_string(Vtk::FormatTypes)
Definition types.cc:13
decltype(auto) getArg(Arg0 &&arg0, Args &&... args)
Definition arguments.hh:29
GeometryType to_geometry(std::uint8_t cell)
Definition types.cc:147
Vtk::RangeTypes rangeTypeOf(Dune::VTK::FieldInfo::Type t)
Definition types.cc:57
const auto rangeTypesList
Definition types.hh:44
size_type dim() const
Implementation of DataCollector for cells, with continuous data.
Definition celltypedatacollector.hh:20
Definition types.hh:97
Mapping of Dune geometry types to VTK cell types.
Definition types.hh:161
int layout(int dim) const
Definition types.hh:218
int size() const
Number of nodes.
Definition types.hh:230
bool noPermutation() const
Definition types.hh:235
Parametrization
Definition types.hh:162
@ MULTI_QUADRATIC
Definition types.hh:165
@ LINEAR
Definition types.hh:163
@ QUADRATIC
Definition types.hh:164
@ LAGRANGE
Definition types.hh:166
std::uint8_t type() const
Return VTK Cell type.
Definition types.hh:213
int permutation(int idx) const
Return a permutation of Dune element vertices to conform to VTK element numbering.
Definition types.hh:224
Type
Definition types.hh:169
@ QUADRATIC_EDGE
Definition types.hh:187
@ POLYGON
Definition types.hh:178
@ QUADRATIC_HEXAHEDRON
Definition types.hh:191
@ LAGRANGE_WEDGE
Definition types.hh:205
@ BIQUADRATIC_QUAD
Definition types.hh:195
@ HEXAHEDRON
Definition types.hh:183
@ VERTEX
Definition types.hh:172
@ TRIQUADRATIC_PYRAMID
Definition types.hh:198
@ LINE
Definition types.hh:174
@ BIQUADRATIC_TRIANGLE
Definition types.hh:197
@ LAGRANGE_PYRAMID
Definition types.hh:206
@ QUAD
Definition types.hh:180
@ QUADRATIC_QUAD
Definition types.hh:189
@ PYRAMID
Definition types.hh:185
@ TETRA
Definition types.hh:181
@ LAGRANGE_HEXAHEDRON
Definition types.hh:204
@ QUADRATIC_PYRAMID
Definition types.hh:193
@ TRIQUADRATIC_HEXAHEDRON
Definition types.hh:196
@ LAGRANGE_CURVE
Definition types.hh:200
@ UNKNOWN
Definition types.hh:170
@ LAGRANGE_TRIANGLE
Definition types.hh:201
@ WEDGE
Definition types.hh:184
@ QUADRATIC_WEDGE
Definition types.hh:192
@ QUADRATIC_TRIANGLE
Definition types.hh:188
@ QUADRATIC_TETRA
Definition types.hh:190
@ LAGRANGE_TETRAHEDRON
Definition types.hh:203
@ LAGRANGE_QUADRILATERAL
Definition types.hh:202
@ TRIANGLE
Definition types.hh:176
Definition types.hh:250
int size() const
The number of components in the data field.
Definition types.hh:275
FieldInfo(Dune::VTK::FieldInfo info)
Definition types.hh:264
std::string const & name() const
The name of the data field.
Definition types.hh:269
Vtk::RangeTypes rangeType() const
Return the category of the stored range.
Definition types.hh:281
Vtk::DataTypes dataType() const
Return the data tpe of the data field.
Definition types.hh:287
FieldInfo(std::string name, Args... args)
Definition types.hh:253
T size(T... args)