Dune Core Modules (2.3.1)

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 // //! Ouput is compressed and appended to the file.
52 // compressedappended
53 };
55
64 enum DataMode {
66
70 conforming,
72
78 nonconforming
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 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 quadrilateral = 9,
183 tetrahedron = 10,
184 hexahedron = 12,
185 prism = 13,
186 pyramid = 14
187 };
188
190
196 {
197 if (t.isVertex()) return vertex;
198 if (t.isLine()) return line;
199 if (t.isTriangle()) return triangle;
200 if (t.isQuadrilateral()) return quadrilateral;
201 if (t.isTetrahedron()) return tetrahedron;
202 if (t.isPyramid()) return pyramid;
203 if (t.isPrism()) return prism;
204 if (t.isHexahedron()) return hexahedron;
205
206 DUNE_THROW(IOError,"VTKWriter: unsupported GeometryType " << t);
207 }
208
210 //
211 // Functions for transforming the index of a corner inside an entity
212 // between Dune and VTK
213 //
214
216
224 inline int renumber(const Dune::GeometryType &t, int i)
225 {
226 static const int quadRenumbering[4] = {0,1,3,2};
227 static const int cubeRenumbering[8] = {0,1,3,2,4,5,7,6};
228 static const int prismRenumbering[6] = {0,2,1,3,5,4};
229 static const int pyramidRenumbering[5] = {0,1,3,2,4};
230
231 if (t.isQuadrilateral()) return quadRenumbering[i];
232 if (t.isPyramid()) return pyramidRenumbering[i];
233 if (t.isPrism()) return prismRenumbering[i];
234 if (t.isHexahedron()) return cubeRenumbering[i];
235
236 return i;
237 }
238
240
254 template<typename T>
255 int renumber(const T& t, int i)
256 {
257 return renumber(t.type(), i);
258 }
259
261 //
262 // Determine Endianness
263 //
264
266
270 inline std::string getEndiannessString()
271 {
272 short i = 1;
273 if (reinterpret_cast<char*>(&i)[1] == 1)
274 return "BigEndian";
275 else
276 return "LittleEndian";
277 }
278
280 //
281 // which type of vtkfile to write
282 //
283
285
290 enum FileType {
295 };
296
297 } // namespace VTK
298
300
301} // namespace Dune
302
303#endif // DUNE_GRID_IO_FILE_VTK_COMMON_HH
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:25
Default exception class for I/O errors.
Definition: exceptions.hh:257
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
OutputType
How the bulk data should be stored in the file.
Definition: common.hh:40
@ appendedraw
Ouput is to the file is appended raw binary.
Definition: common.hh:46
@ appendedbase64
Ouput 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:224
FileType
which type of VTK file to write
Definition: common.hh:290
@ polyData
for .vtp files (PolyData)
Definition: common.hh:292
@ unstructuredGrid
for .vtu files (UnstructuredGrid)
Definition: common.hh:294
DataMode
Whether to produce conforming or non-conforming output.
Definition: common.hh:64
GeometryType geometryType(const Dune::GeometryType &t)
mapping from GeometryType to VTKGeometryType
Definition: common.hh:195
std::string getEndiannessString()
determine endianness of this C++ implementation
Definition: common.hh:270
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:178
A few common exception classes.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:244
Dune namespace.
Definition: alignment.hh:14
@ ascii
store data in a human readable form
Definition: grapedataioformattypes.hh:15
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 (Jul 15, 22:36, 2024)