vtktypes.cc 4 KB
Newer Older
Praetorius, Simon's avatar
Praetorius, Simon committed
1
2
3
4
#include "vtktypes.hh"

#include <iostream>

5
namespace Dune { namespace experimental {
Praetorius, Simon's avatar
Praetorius, Simon committed
6
7
namespace Vtk {

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

std::string to_string (DataTypes type)
{
  switch (type) {
24
25
26
27
28
29
30
31
    case INT8:    return "Int8";
    case UINT8:   return "UInt8";
    case INT16:   return "Int16";
    case UINT16:  return "UInt16";
    case INT32:   return "Int32";
    case UINT32:  return "UInt32";
    case INT64:   return "Int64";
    case UINT64:  return "UInt64";
Praetorius, Simon's avatar
Praetorius, Simon committed
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
    case FLOAT32: return "Float32";
    case FLOAT64: return "Float64";
    default:
      DUNE_THROW(RangeError, "DataType not found.");
      std::abort();
  }
}

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;
    default:
      DUNE_THROW(RangeError, "CellType does not map to GeometryType.");
      std::abort();
  }
}

Praetorius, Simon's avatar
Praetorius, Simon committed
57

58
std::map<std::string, DataTypes> Map::to_datatype = {
Praetorius, Simon's avatar
Praetorius, Simon committed
59
60
61
62
63
64
65
66
67
68
69
70
  {"Int8",    INT8},
  {"UInt8",   UINT8},
  {"Int16",   INT16},
  {"UInt16",  UINT16},
  {"Int32",   INT32},
  {"UInt32",  UINT32},
  {"Int64",   INT64},
  {"UInt64",  UINT64},
  {"Float32", FLOAT32},
  {"Float64", FLOAT64}
};

Praetorius, Simon's avatar
Praetorius, Simon committed
71

Praetorius, Simon's avatar
Praetorius, Simon committed
72

73
CellType::CellType (GeometryType const& t, CellParametrization parametrization)
74
  : noPermutation_(true)
Praetorius, Simon's avatar
Praetorius, Simon committed
75
{
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
  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;
    }
113
114
115
116
117
118
119
120
    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};
    }
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
    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, 3,1,0,2}; // maybe need inverse permutation as well
      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}; // maybe need inverse permutation as well
      noPermutation_ = false;
    }
    else {
      std::cerr << "Geometry Type not supported by VTK!\n";
      std::abort();
    }
Praetorius, Simon's avatar
Praetorius, Simon committed
154
155
156
  }
}

157
}}} // end namespace Dune::experimental::Vtk