types.cc 8.5 KB
Newer Older
1
#include <config.h>
Stenger, Florian's avatar
Stenger, Florian committed
2
3

#include <iostream>
4
#include <map>
Stenger, Florian's avatar
Stenger, Florian committed
5
6

#include <dune/common/exceptions.hh>
7
#include <dune/vtk/types.hh>
Stenger, Florian's avatar
Stenger, Florian committed
8

9
10
namespace Dune {
namespace Vtk {
Stenger, Florian's avatar
Stenger, Florian committed
11

12
std::string to_string (Vtk::FormatTypes type)
13
14
{
  switch (type) {
15
16
17
18
    case Vtk::FormatTypes::ASCII:      return "ascii";
    case Vtk::FormatTypes::BINARY:     return "binary";
    case Vtk::FormatTypes::COMPRESSED: return "compressed";
    case Vtk::FormatTypes::APPENDED:   return "appended";
19
20
21
22
23
    default:
      DUNE_THROW(RangeError, "FormatType not found.");
      std::abort();
  }
}
Stenger, Florian's avatar
Stenger, Florian committed
24

25
Vtk::FormatTypes formatTypeOf (Dune::VTK::OutputType o)
26
27
{
  switch (o) {
28
29
30
31
32
33
    case Dune::VTK::ascii:          return Vtk::FormatTypes::ASCII;
 // case Dune::VTK::base64:         return Vtk::FormatTypes::BASE64;
    case Dune::VTK::appendedraw:    return Vtk::FormatTypes::BINARY;
 // case Dune::VTK::appendedbase64: return Vtk::FormatTypes::BASE64;
 // case Dune::VTK::binarycompressed:   return Vtk::FormatTypes::COMPRESSED;
 // case Dune::VTK::compressedappended: return Vtk::FormatTypes::COMPRESSED;
34
35
36
37
38
39
    default:
      DUNE_THROW(RangeError, "OutputType not supported.");
      std::abort();
  }
}

40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

std::string to_string (Vtk::RangeTypes type)
{
  switch (type) {
    case Vtk::RangeTypes::UNSPECIFIED:  return "unspecified";
    case Vtk::RangeTypes::AUTO:         return "auto";
    case Vtk::RangeTypes::SCALAR:       return "scalar";
    case Vtk::RangeTypes::VECTOR:       return "vector";
    case Vtk::RangeTypes::TENSOR:       return "tensor";
    default:
      DUNE_THROW(RangeError, "RangeType not found.");
      std::abort();
  }
}

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Map a dune-grid FieldInfo::Type to ValueTypes
Vtk::RangeTypes rangeTypeOf (Dune::VTK::FieldInfo::Type t)
{
  switch (t) {
    case Dune::VTK::FieldInfo::Type::scalar: return Vtk::RangeTypes::UNSPECIFIED;
    case Dune::VTK::FieldInfo::Type::vector: return Vtk::RangeTypes::VECTOR;
    case Dune::VTK::FieldInfo::Type::tensor: return Vtk::RangeTypes::TENSOR;
    default:
      DUNE_THROW(RangeError, "FieldInfo::Type not supported.");
      std::abort();
  }
}

// Map a number of components to a corresponding value type
Vtk::RangeTypes rangeTypeOf (int ncomps)
{
  return ncomps > 9 ? Vtk::RangeTypes::UNSPECIFIED :
         ncomps > 3 ? Vtk::RangeTypes::TENSOR :
         ncomps > 1 ? Vtk::RangeTypes::VECTOR :
                      Vtk::RangeTypes::SCALAR;
}

77

78
std::string to_string (Vtk::DataTypes type)
79
80
{
  switch (type) {
81
82
83
84
85
86
87
88
89
90
    case Vtk::DataTypes::INT8:    return "Int8";
    case Vtk::DataTypes::UINT8:   return "UInt8";
    case Vtk::DataTypes::INT16:   return "Int16";
    case Vtk::DataTypes::UINT16:  return "UInt16";
    case Vtk::DataTypes::INT32:   return "Int32";
    case Vtk::DataTypes::UINT32:  return "UInt32";
    case Vtk::DataTypes::INT64:   return "Int64";
    case Vtk::DataTypes::UINT64:  return "UInt64";
    case Vtk::DataTypes::FLOAT32: return "Float32";
    case Vtk::DataTypes::FLOAT64: return "Float64";
91
92
93
94
95
    default:
      DUNE_THROW(RangeError, "DataType not found.");
      std::abort();
  }
}
Stenger, Florian's avatar
Stenger, Florian committed
96

97

98
99
100
Vtk::DataTypes dataTypeOf (Dune::VTK::Precision p)
{
  switch (p) {
101
102
103
104
105
    case Dune::VTK::Precision::int32:    return Vtk::DataTypes::INT32;
    case Dune::VTK::Precision::uint8:    return Vtk::DataTypes::UINT8;
    case Dune::VTK::Precision::uint32:   return Vtk::DataTypes::UINT32;
    case Dune::VTK::Precision::float32:  return Vtk::DataTypes::FLOAT32;
    case Dune::VTK::Precision::float64:  return Vtk::DataTypes::FLOAT64;
106
107
108
109
110
    default:
      DUNE_THROW(RangeError, "Precision not supported.");
      std::abort();
  }
}
111

112
113
114
115

Vtk::DataTypes dataTypeOf (std::string s)
{
  static const std::map<std::string, Vtk::DataTypes> to_datatype{
116
117
118
119
120
121
122
123
124
125
    {"Int8",    Vtk::DataTypes::INT8},
    {"UInt8",   Vtk::DataTypes::UINT8},
    {"Int16",   Vtk::DataTypes::INT16},
    {"UInt16",  Vtk::DataTypes::UINT16},
    {"Int32",   Vtk::DataTypes::INT32},
    {"UInt32",  Vtk::DataTypes::UINT32},
    {"Int64",   Vtk::DataTypes::INT64},
    {"UInt64",  Vtk::DataTypes::UINT64},
    {"Float32", Vtk::DataTypes::FLOAT32},
    {"Float64", Vtk::DataTypes::FLOAT64}
126
127
  };
  auto it = to_datatype.find(s);
128
  return it != to_datatype.end() ? it->second : Vtk::DataTypes::UNKNOWN;
129
130
131
}


132
133
134
135
136
137
138
139
140
141
142
143
std::string to_string (CompressorTypes type)
{
  switch (type) {
    case ZLIB: return "vtkZLibDataCompressor";
    case LZ4:  return "vtkLZ4DataCompressor";
    case LZMA: return "vtkLZMADataCompressor";
    default:
      DUNE_THROW(RangeError, "CompressorTypes not found.");
      std::abort();
  }
}

144

145
146
147
148
149
150
151
152
153
154
155
GeometryType to_geometry (std::uint8_t cell)
{
  switch (cell) {
    case VERTEX:     return GeometryTypes::vertex;
    case LINE:       return GeometryTypes::line;
    case TRIANGLE:   return GeometryTypes::triangle;
    case QUAD:       return GeometryTypes::quadrilateral;
    case TETRA:      return GeometryTypes::tetrahedron;
    case HEXAHEDRON: return GeometryTypes::hexahedron;
    case WEDGE:      return GeometryTypes::prism;
    case PYRAMID:    return GeometryTypes::pyramid;
Stenger, Florian's avatar
Stenger, Florian committed
156

157
158
159
160
161
162
    // Quadratic VTK cell types
    case QUADRATIC_EDGE:        return GeometryTypes::line;
    case QUADRATIC_TRIANGLE:    return GeometryTypes::triangle;
    case QUADRATIC_QUAD:        return GeometryTypes::quadrilateral;
    case QUADRATIC_TETRA:       return GeometryTypes::tetrahedron;
    case QUADRATIC_HEXAHEDRON:  return GeometryTypes::hexahedron;
Stenger, Florian's avatar
Stenger, Florian committed
163

164
165
166
167
168
169
170
171
172
173
174
175
    // Arbitrary order Lagrange elements
    case LAGRANGE_CURVE:        return GeometryTypes::line;
    case LAGRANGE_TRIANGLE:     return GeometryTypes::triangle;
    case LAGRANGE_QUADRILATERAL:return GeometryTypes::quadrilateral;
    case LAGRANGE_TETRAHEDRON:  return GeometryTypes::tetrahedron;
    case LAGRANGE_HEXAHEDRON:   return GeometryTypes::hexahedron;
    case LAGRANGE_WEDGE:        return GeometryTypes::prism;
    default:
      DUNE_THROW(RangeError, "CellType does not map to GeometryType.");
      std::abort();
  }
}
Stenger, Florian's avatar
Stenger, Florian committed
176
177


178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
CellType::CellType (GeometryType const& t, CellParametrization parametrization)
  : noPermutation_(true)
{
  if (parametrization == LINEAR) {
    if (t.isVertex()) {
      type_ = VERTEX;
      permutation_ = {0};
    }
    else if (t.isLine()) {
      type_ = LINE;
      permutation_ = {0,1};
    }
    else if (t.isTriangle()) {
      type_ = TRIANGLE;
      permutation_ = {0,1,2};
    }
    else if (t.isQuadrilateral()) {
      type_ = QUAD;
      permutation_ = {0,1,3,2};
      noPermutation_ = false;
    }
    else if (t.isTetrahedron()) {
      type_ = TETRA;
      permutation_ = {0,1,2,3};
    }
    else if (t.isHexahedron()) {
      type_ = HEXAHEDRON;
      permutation_ = {0,1,3,2,4,5,7,6};
      noPermutation_ = false;
    }
    else if (t.isPrism()) {
      type_ = WEDGE;
      permutation_ = {0,2,1,3,5,4};
      noPermutation_ = false;
    }
    else if (t.isPyramid()) {
      type_ = PYRAMID;
      permutation_ = {0,1,3,2,4};
      noPermutation_ = false;
    }
    else if (t.isNone() && t.dim() == 1) {
      type_ = LINE;
      permutation_ = {0,1};
    }
    else if (t.isNone() && t.dim() == 2) {
      type_ = POLYGON;
      permutation_ = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
    }
    else {
      std::cerr << "Geometry Type not supported by VTK!\n";
      std::abort();
    }
  } else if (parametrization == QUADRATIC) {
    if (t.isLine()) {
      type_ = QUADRATIC_EDGE;
      permutation_ = {0,1, 0};
    }
    else if (t.isTriangle()) {
      type_ = QUADRATIC_TRIANGLE;
      permutation_ = {0,1,2, 0,2,1};
      noPermutation_ = false;
    }
    else if (t.isQuadrilateral()) {
      type_ = QUADRATIC_QUAD;
      permutation_ = {0,1,3,2, 2,1,3,0};
      noPermutation_ = false;
    }
    else if (t.isTetrahedron()) {
      type_ = QUADRATIC_TETRA;
      permutation_ = {0,1,2,3, 0,2,1,3,4,5};
      noPermutation_ = false;
    }
    else if (t.isHexahedron()) {
      type_ = QUADRATIC_HEXAHEDRON;
      permutation_ = {0,1,3,2,4,5,7,6, 6,5,7,4,10,9,11,8,0,1,3,2};
      noPermutation_ = false;
    }
    else {
      std::cerr << "Geometry Type not supported by VTK!\n";
      std::abort();
    }
  } else if (parametrization == LAGRANGE) {
    if (t.isLine()) {
      type_ = LAGRANGE_CURVE;
    }
    else if (t.isTriangle()) {
      type_ = LAGRANGE_TRIANGLE;
    }
    else if (t.isQuadrilateral()) {
      type_ = LAGRANGE_QUADRILATERAL;
    }
    else if (t.isTetrahedron()) {
      type_ = LAGRANGE_TETRAHEDRON;
    }
    else if (t.isHexahedron()) {
      type_ = LAGRANGE_HEXAHEDRON;
    }
    else if (t.isPrism()) {
      type_ = LAGRANGE_WEDGE;
    }
    else if (t.isPyramid()) {
      type_ = LAGRANGE_PYRAMID;
    }
    else {
      std::cerr << "Geometry Type not supported by VTK!\n";
      std::abort();
Stenger, Florian's avatar
Stenger, Florian committed
284
    }
285
286
  }
}
Stenger, Florian's avatar
Stenger, Florian committed
287

288
} } // end namespace Dune::Vtk