Dune Core Modules (2.6.0)

common.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3
4#ifndef DUNE_GRID_IO_FILE_VTK_COMMON_HH
5#define DUNE_GRID_IO_FILE_VTK_COMMON_HH
6
7#include <limits>
8#include <sstream>
9#include <string>
10
12#include <dune/geometry/type.hh>
14
22namespace Dune
23{
26
27 namespace VTK {
28
30 //
31 // VTKOptions
32 //
33
35
49 // //! Output to the file is compressed inline binary.
50 // binarycompressed,
51 // //! Output is compressed and appended to the file.
52 // compressedappended
53 };
55
64 enum DataMode {
66
72
79 };
80
82 //
83 // PrintType
84 //
85
87
91 template<typename T>
92 struct PrintType {
94 typedef T Type;
95 };
96
97 template<>
98 struct PrintType<unsigned char> {
99 typedef unsigned Type;
100 };
101
102 template<>
103 struct PrintType<signed char> {
104 typedef int Type;
105 };
106
107 template<>
108 struct PrintType<char> {
109 typedef std::conditional<std::numeric_limits<char>::is_signed,
110 int, unsigned>::type
111 Type;
112 };
113
115 //
116 // TypeName
117 //
118
120
123 template<typename T>
124 class TypeName {
125 static std::string getString() {
126 static const unsigned int_sizes[] = { 8, 16, 32, 64, 0 };
127 static const unsigned float_sizes[] = { 32, 64, 0 };
128 const unsigned* sizes;
129
130 std::ostringstream s;
131 if(std::numeric_limits<T>::is_integer) {
132 if(std::numeric_limits<T>::is_signed)
133 s << "Int";
134 else
135 s << "UInt";
136 sizes = int_sizes;
137 }
138 else {
139 // assume float
140 s << "Float";
141 sizes = float_sizes;
142 }
143
144 static const unsigned size = 8*sizeof(T);
145 while(*sizes != 0 && *sizes <= size) ++sizes;
146 --sizes;
147 s << *sizes;
148
149 return s.str();
150 }
151
152 public:
154
157 const std::string& operator()() const {
158 static const std::string s = getString();
159 return s;
160 }
161 };
162
164 //
165 // VTK::GeometryType related stuff
166 //
167
169
179 vertex = 1,
180 line = 3,
181 triangle = 5,
182 polygon = 7,
183 quadrilateral = 9,
184 tetrahedron = 10,
185 hexahedron = 12,
186 prism = 13,
187 pyramid = 14,
188 polyhedron = 42
189 };
190
192
198 {
199 if (t.isVertex()) return vertex;
200 if (t.isLine()) return line;
201 if (t.isTriangle()) return triangle;
202 if (t.isQuadrilateral()) return quadrilateral;
203 if (t.isTetrahedron()) return tetrahedron;
204 if (t.isPyramid()) return pyramid;
205 if (t.isPrism()) return prism;
206 if (t.isHexahedron()) return hexahedron;
207
208 if (t.isNone() )
209 {
210 if( t.dim() == 2 ) return polygon;
211 if( t.dim() == 3 ) return polyhedron;
212 }
213
214 DUNE_THROW(IOError,"VTKWriter: unsupported GeometryType " << t);
215 }
216
218 //
219 // Functions for transforming the index of a corner inside an entity
220 // between Dune and VTK
221 //
222
224
232 inline int renumber(const Dune::GeometryType &t, int i)
233 {
234 static const int quadRenumbering[4] = {0,1,3,2};
235 static const int cubeRenumbering[8] = {0,1,3,2,4,5,7,6};
236 static const int prismRenumbering[6] = {0,2,1,3,5,4};
237 static const int pyramidRenumbering[5] = {0,1,3,2,4};
238
239 if (t.isQuadrilateral()) return quadRenumbering[i];
240 if (t.isPyramid()) return pyramidRenumbering[i];
241 if (t.isPrism()) return prismRenumbering[i];
242 if (t.isHexahedron()) return cubeRenumbering[i];
243
244 return i;
245 }
246
248
262 template<typename T>
263 int renumber(const T& t, int i)
264 {
265 return renumber(t.type(), i);
266 }
267
269 //
270 // Determine Endianness
271 //
272
274
278 inline std::string getEndiannessString()
279 {
280 short i = 1;
281 if (reinterpret_cast<char*>(&i)[1] == 1)
282 return "BigEndian";
283 else
284 return "LittleEndian";
285 }
286
288 //
289 // which type of vtkfile to write
290 //
291
293
298 enum FileType {
303 };
304
305
307
315 {
316
317 public:
318
320 enum class Type {
323 scalar,
325 vector,
327 tensor
328 };
329
331 FieldInfo(std::string name, Type type, std::size_t size)
332 : _name(name)
333 , _type(type)
334 , _size(size)
335 {}
336
338 std::string name() const
339 {
340 return _name;
341 }
342
344 Type type() const
345 {
346 return _type;
347 }
348
350 std::size_t size() const
351 {
352 return _size;
353 }
354
355 private:
356
357 std::string _name;
358 Type _type;
359 std::size_t _size;
360
361 };
362
363
364 } // namespace VTK
365
367
368} // namespace Dune
369
370#endif // DUNE_GRID_IO_FILE_VTK_COMMON_HH
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:277
constexpr bool isPyramid() const
Return true if entity is a pyramid.
Definition: type.hh:542
constexpr bool isTetrahedron() const
Return true if entity is a tetrahedron.
Definition: type.hh:537
constexpr bool isPrism() const
Return true if entity is a prism.
Definition: type.hh:547
constexpr bool isVertex() const
Return true if entity is a vertex.
Definition: type.hh:517
constexpr unsigned int dim() const
Return dimension of the type.
Definition: type.hh:572
constexpr bool isTriangle() const
Return true if entity is a triangle.
Definition: type.hh:527
constexpr bool isLine() const
Return true if entity is a line segment.
Definition: type.hh:522
constexpr bool isQuadrilateral() const
Return true if entity is a quadrilateral.
Definition: type.hh:532
constexpr bool isNone() const
Return true if entity is a singular of any dimension.
Definition: type.hh:567
constexpr bool isHexahedron() const
Return true if entity is a hexahedron.
Definition: type.hh:552
Default exception class for I/O errors.
Definition: exceptions.hh:229
Descriptor struct for VTK fields.
Definition: common.hh:315
std::size_t size() const
The number of components in the data field.
Definition: common.hh:350
FieldInfo(std::string name, Type type, std::size_t size)
Create a FieldInfo instance with the given name, type and size.
Definition: common.hh:331
Type
VTK data type.
Definition: common.hh:320
Type type() const
The type of the data field.
Definition: common.hh:344
std::string name() const
The name of the data field.
Definition: common.hh:338
map type to its VTK name in data array
Definition: common.hh:124
const std::string & operator()() const
return VTK name of the type
Definition: common.hh:157
A few common exception classes.
OutputType
How the bulk data should be stored in the file.
Definition: common.hh:40
@ ascii
Output to the file is in ascii.
Definition: common.hh:42
@ appendedraw
Output is to the file is appended raw binary.
Definition: common.hh:46
@ appendedbase64
Output is to the file is appended base64 binary.
Definition: common.hh:48
@ base64
Output to the file is inline base64 binary.
Definition: common.hh:44
int renumber(const Dune::GeometryType &t, int i)
renumber VTK <-> Dune
Definition: common.hh:232
FileType
which type of VTK file to write
Definition: common.hh:298
@ polyData
for .vtp files (PolyData)
Definition: common.hh:300
@ unstructuredGrid
for .vtu files (UnstructuredGrid)
Definition: common.hh:302
DataMode
Whether to produce conforming or non-conforming output.
Definition: common.hh:64
@ conforming
Output conforming data.
Definition: common.hh:70
@ nonconforming
Output non-conforming data.
Definition: common.hh:78
GeometryType geometryType(const Dune::GeometryType &t)
mapping from GeometryType to VTKGeometryType
Definition: common.hh:197
std::string getEndiannessString()
determine endianness of this C++ implementation
Definition: common.hh:278
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:178
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
Dune namespace.
Definition: alignedallocator.hh:10
determine a type to safely put another type into a stream
Definition: common.hh:92
T Type
type to convert T to before putting it into a stream with <<
Definition: common.hh:94
A unique label for each type of element that can occur in a grid.
Traits for type conversions and type information.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 24, 23:30, 2024)