dune-vtk 2.12
Loading...
Searching...
No Matches
types.hh
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <map>
5#include <string>
6#include <vector>
7
11#include <dune/geometry/type.hh>
15
16namespace Dune::Vtk
17{
19 enum class FormatTypes {
20 UNKNOWN = 0,
21 ASCII = 1<<0,
22 BINARY = 1<<1,
23 COMPRESSED = 1<<2,
25 };
28
31
32
34 enum class RangeTypes {
35 UNSPECIFIED, //< The output components are not restricted
36 AUTO, //< Detect the category automatically from number of components
37 SCALAR, //< Use exactly 1 component
38 VECTOR, //< Use exactly 3 components
39 TENSOR //< Use exactly 9 components
40 };
43
44 // Map a dune-grid FieldInfo::Type to ValueTypes
46
47 // Map a number of components to a corresponding value type
48 Vtk::RangeTypes rangeTypeOf (int ncomps);
49
50
51 enum class DataTypes {
52 UNKNOWN = 0,
53 INT8, UINT8,
57 FLOAT32 = 32,
58 FLOAT64 = 64
59 };
69
70 // Map a dune-grid Precision type to DataTypes
72
73 // Map a string to DataTypes
75
76 // Map the field_type of T to DataTypes
77 template <class T>
79 {
80 using F = typename FieldTraits<T>::field_type;
81 if constexpr (std::is_same_v<F, std::int8_t>) { return Vtk::DataTypes::INT8; }
82 if constexpr (std::is_same_v<F, std::uint8_t>) { return Vtk::DataTypes::UINT8; }
83 if constexpr (std::is_same_v<F, std::int16_t>) { return Vtk::DataTypes::INT16; }
84 if constexpr (std::is_same_v<F, std::uint16_t>) { return Vtk::DataTypes::UINT16; }
85 if constexpr (std::is_same_v<F, std::int32_t>) { return Vtk::DataTypes::INT32; }
86 if constexpr (std::is_same_v<F, std::uint32_t>) { return Vtk::DataTypes::UINT32; }
87 if constexpr (std::is_same_v<F, std::int64_t>) { return Vtk::DataTypes::INT64; }
88 if constexpr (std::is_same_v<F, std::uint64_t>) { return Vtk::DataTypes::UINT64; }
89 if constexpr (std::is_same_v<F, float>) { return Vtk::DataTypes::FLOAT32; }
90 if constexpr (std::is_same_v<F, double>) { return Vtk::DataTypes::FLOAT64; }
91 if constexpr (std::is_same_v<F, long double>) { return Vtk::DataTypes::FLOAT64; }
93 }
94
95 template <class> struct NoConstraint : std::true_type {};
96
98 template <template <class> class C = NoConstraint, class Caller>
99 void mapDataTypes (Vtk::DataTypes t, Caller caller)
100 {
101 switch (t) {
102 case DataTypes::INT8: if constexpr(C<std::int8_t>::value) caller(MetaType<std::int8_t>{}); break;
103 case DataTypes::UINT8: if constexpr(C<std::uint8_t>::value) caller(MetaType<std::uint8_t>{}); break;
104 case DataTypes::INT16: if constexpr(C<std::int16_t>::value) caller(MetaType<std::int16_t>{}); break;
105 case DataTypes::UINT16: if constexpr(C<std::uint16_t>::value) caller(MetaType<std::uint16_t>{}); break;
106 case DataTypes::INT32: if constexpr(C<std::int32_t>::value) caller(MetaType<std::int32_t>{}); break;
107 case DataTypes::UINT32: if constexpr(C<std::uint32_t>::value) caller(MetaType<std::uint32_t>{}); break;
108 case DataTypes::INT64: if constexpr(C<std::int64_t>::value) caller(MetaType<std::int64_t>{}); break;
109 case DataTypes::UINT64: if constexpr(C<std::uint64_t>::value) caller(MetaType<std::uint64_t>{}); break;
110 case DataTypes::FLOAT32: if constexpr(C<float>::value) caller(MetaType<float>{}); break;
111 case DataTypes::FLOAT64: if constexpr(C<double>::value) caller(MetaType<double>{}); break;
112 default:
113 VTK_ASSERT_MSG(false, "Unsupported type " + to_string(t));
114 break;
115 }
116 }
117
119 template <template <class> class Constraint1 = NoConstraint,
120 template <class> class Constraint2 = NoConstraint,
121 class Caller>
122 void mapDataTypes (Vtk::DataTypes t1, Vtk::DataTypes t2, Caller caller)
123 {
124 mapDataTypes<Constraint1>(t1, [&](auto type1) {
125 mapDataTypes<Constraint2>(t2, [&](auto type2) {
126 caller(type1, type2);
127 });
128 });
129 }
130
132 template <template <class> class Constraint1 = NoConstraint,
133 template <class> class Constraint2 = NoConstraint,
134 template <class> class Constraint3 = NoConstraint,
135 class Caller>
137 {
138 mapDataTypes<Constraint1>(t1, [&](auto type1) {
139 mapDataTypes<Constraint2>(t2, [&](auto type2) {
140 mapDataTypes<Constraint3>(t3, [&](auto type3) {
141 caller(type1, type2, type3);
142 });
143 });
144 });
145 }
146
147
148 enum class CompressorTypes {
149 NONE = 0,
150 ZLIB,
151 LZ4,
152 LZMA
153 };
155
156
158 struct CellType
159 {
166
169 // Linear VTK cell types
171 /* POLY_VERTEX = 2, // not supported */
172 LINE = 3,
173 /* POLY_LINE = 4, // not supported */
175 /* TRIANGLE_STRIP = 6, // not supported */
177 /* PIXEL = 8, // not supported */
178 QUAD = 9,
179 TETRA = 10,
180 /* VOXEL = 11, // not supported */
182 WEDGE = 13,
184 // Quadratic VTK cell types
192 // Multi-quadratic cell types
197 // Arbitrary order Lagrange elements
205 };
206
207 public:
209
212 {
213 return type_;
214 }
215
216 int layout (int dim) const
217 {
218 return layout_[dim];
219 }
220
222 int permutation (int idx) const
223 {
224 return permutation_[idx];
225 }
226
228 int size () const
229 {
230 return permutation_.size();
231 }
232
233 bool noPermutation () const
234 {
235 return noPermutation_;
236 }
237
238 private:
239 std::uint8_t type_;
240 std::vector<int> layout_; // number of nodes for each dimension
241 std::vector<int> permutation_;
242 bool noPermutation_ = true;
243 };
245
246
248 {
249 public:
250 template <class... Args>
251 explicit FieldInfo (std::string name, Args... args)
252 : name_(std::move(name))
253 , ncomps_(getArg<int,unsigned int,long,unsigned long>(args..., 1))
254 , rangeType_(getArg<Vtk::RangeTypes>(args..., Vtk::RangeTypes::AUTO))
255 , dataType_(getArg<Vtk::DataTypes>(args..., Vtk::DataTypes::FLOAT32))
256 {
257 if (rangeType_ == Vtk::RangeTypes::AUTO)
258 rangeType_ = rangeTypeOf(ncomps_);
259 }
260
261 // Construct from dune-grid FieldInfo
263 : FieldInfo(info.name(), info.size(), rangeTypeOf(info.type()), dataTypeOf(info.precision()))
264 {}
265
267 std::string const& name () const
268 {
269 return name_;
270 }
271
273 int size () const
274 {
275 return ncomps_;
276 }
277
280 {
281 return rangeType_;
282 }
283
286 {
287 return dataType_;
288 }
289
290 private:
291 std::string name_;
292 int ncomps_;
293 Vtk::RangeTypes rangeType_;
294 Vtk::DataTypes dataType_;
295 };
296
297} // 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:19
STL namespace.
Definition writer.hh:16
const auto dataTypesLists
Definition types.hh:61
FormatTypes
Type used for representing the output format.
Definition types.hh:19
void mapDataTypes(Vtk::DataTypes t, Caller caller)
Map a given enum DataType to a type passed to Caller as MetaType.
Definition types.hh:99
CompressorTypes
Definition types.hh:148
Vtk::FormatTypes formatTypeOf(Dune::VTK::OutputType o)
Map the dune-grid OutputType to FormatTypes.
Definition types.cc:24
Vtk::DataTypes dataTypeOf()
Definition types.hh:78
RangeTypes
Type used to determine whether to limit output components to e.g. 3 (vector), or 9 (tensor)
Definition types.hh:34
const auto formatTypesList
Definition types.hh:27
DataTypes
Definition types.hh:51
std::string to_string(Vtk::FormatTypes)
Definition types.cc:11
decltype(auto) getArg(Arg0 &&arg0, Args &&... args)
Definition arguments.hh:27
GeometryType to_geometry(std::uint8_t cell)
Definition types.cc:145
Vtk::RangeTypes rangeTypeOf(Dune::VTK::FieldInfo::Type t)
Definition types.cc:55
const auto rangeTypesList
Definition types.hh:42
size_type dim() const
Definition types.hh:95
Mapping of Dune geometry types to VTK cell types.
Definition types.hh:159
int layout(int dim) const
Definition types.hh:216
int size() const
Number of nodes.
Definition types.hh:228
bool noPermutation() const
Definition types.hh:233
Parametrization
Definition types.hh:160
@ MULTI_QUADRATIC
Definition types.hh:163
@ LINEAR
Definition types.hh:161
@ QUADRATIC
Definition types.hh:162
@ LAGRANGE
Definition types.hh:164
std::uint8_t type() const
Return VTK Cell type.
Definition types.hh:211
int permutation(int idx) const
Return a permutation of Dune element vertices to conform to VTK element numbering.
Definition types.hh:222
Type
Definition types.hh:167
@ QUADRATIC_EDGE
Definition types.hh:185
@ POLYGON
Definition types.hh:176
@ QUADRATIC_HEXAHEDRON
Definition types.hh:189
@ LAGRANGE_WEDGE
Definition types.hh:203
@ BIQUADRATIC_QUAD
Definition types.hh:193
@ HEXAHEDRON
Definition types.hh:181
@ VERTEX
Definition types.hh:170
@ TRIQUADRATIC_PYRAMID
Definition types.hh:196
@ LINE
Definition types.hh:172
@ BIQUADRATIC_TRIANGLE
Definition types.hh:195
@ LAGRANGE_PYRAMID
Definition types.hh:204
@ QUAD
Definition types.hh:178
@ QUADRATIC_QUAD
Definition types.hh:187
@ PYRAMID
Definition types.hh:183
@ TETRA
Definition types.hh:179
@ LAGRANGE_HEXAHEDRON
Definition types.hh:202
@ QUADRATIC_PYRAMID
Definition types.hh:191
@ TRIQUADRATIC_HEXAHEDRON
Definition types.hh:194
@ LAGRANGE_CURVE
Definition types.hh:198
@ UNKNOWN
Definition types.hh:168
@ LAGRANGE_TRIANGLE
Definition types.hh:199
@ WEDGE
Definition types.hh:182
@ QUADRATIC_WEDGE
Definition types.hh:190
@ QUADRATIC_TRIANGLE
Definition types.hh:186
@ QUADRATIC_TETRA
Definition types.hh:188
@ LAGRANGE_TETRAHEDRON
Definition types.hh:201
@ LAGRANGE_QUADRILATERAL
Definition types.hh:200
@ TRIANGLE
Definition types.hh:174
Definition types.hh:248
int size() const
The number of components in the data field.
Definition types.hh:273
FieldInfo(Dune::VTK::FieldInfo info)
Definition types.hh:262
std::string const & name() const
The name of the data field.
Definition types.hh:267
Vtk::RangeTypes rangeType() const
Return the category of the stored range.
Definition types.hh:279
Vtk::DataTypes dataType() const
Return the data tpe of the data field.
Definition types.hh:285
FieldInfo(std::string name, Args... args)
Definition types.hh:251
T size(T... args)