Commit c244e3cd authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

Explicit enums

parent 89c6ad62
......@@ -37,7 +37,7 @@ public:
```
where `Function` is either a `GridViewFunction`, i.e. supports `bind()`, `unbind()`, and `localFunction(Function)`, or is a legacy `VTKFunction` from Dune-Grid. The optional parameters `name`, `numComponents` and `format` may be given for a `GridViewFunction`.
The parameter `Vtk::FormatTypes` is one of `Vtk::FormatTypes::ASCII`, `Vtk::FormatTypes::BINARY`, or `Vtk::COMPRESSED` and `Vtk::DataTypes` is one of `Vtk::DataTypes::FLOAT32`, or `Vtk::DataTypes::FLOAT64`. The `[Type]` of a VtkWriter is one of `UnstructuredGrid`, `StructuredGrid`, `RectilinearGrid`, `ImageData`, or `Timeseries`, see below for details. A `DataCollector` may be specified to control how point and cell values are extracted from the `GridView` and the bound data. See `dune/vtk/datacollectors/` of a list of poissible types. The default datacollector extracts a connected grid with continuous data, where points are grid vertices.
The parameter `Vtk::FormatTypes` is one of `Vtk::FormatTypes::ASCII`, `Vtk::FormatTypes::BINARY`, or `Vtk::FormatTypes::COMPRESSED` and `Vtk::DataTypes` is one of `Vtk::DataTypes::FLOAT32`, or `Vtk::DataTypes::FLOAT64`. The `[Type]` of a VtkWriter is one of `UnstructuredGrid`, `StructuredGrid`, `RectilinearGrid`, `ImageData`, or `Timeseries`, see below for details. A `DataCollector` may be specified to control how point and cell values are extracted from the `GridView` and the bound data. See `dune/vtk/datacollectors/` of a list of poissible types. The default datacollector extracts a connected grid with continuous data, where points are grid vertices.
See also the `src/` directory for more examples.
......
......@@ -129,7 +129,7 @@ namespace Dune
std::int64_t old_o = 0;
for (auto const& element : elements(gridView_, partition)) {
auto refElem = referenceElement<double,dim>(element.type());
Vtk::CellType cellType(element.type(), Vtk::LAGRANGE);
Vtk::CellType cellType(element.type(), Vtk::CellType::LAGRANGE);
auto const& pointSet = pointSets_.at(element.type());
unsigned int vertexDOFs = refElem.size(dim);
......
......@@ -92,7 +92,7 @@ namespace Dune
std::int64_t old_o = 0;
auto const& indexSet = gridView_.indexSet();
for (auto const& c : elements(gridView_, partition)) {
Vtk::CellType cellType(c.type(), Vtk::QUADRATIC);
Vtk::CellType cellType(c.type(), Vtk::CellType::QUADRATIC);
for (unsigned int j = 0; j < c.subEntities(dim); ++j) {
int k = cellType.permutation(j);
std::int64_t point_idx = indexSet.subIndex(c,k,dim);
......@@ -118,7 +118,7 @@ namespace Dune
auto localFct = localFunction(fct);
for (auto const& e : elements(gridView_, partition)) {
localFct.bind(e);
Vtk::CellType cellType{e.type(), Vtk::QUADRATIC};
Vtk::CellType cellType{e.type(), Vtk::CellType::QUADRATIC};
auto refElem = referenceElement(e.geometry());
for (unsigned int j = 0; j < e.subEntities(dim); ++j) {
int k = cellType.permutation(j);
......
......@@ -86,7 +86,7 @@ void PvdWriter<W>
<< " type=\"Collection\""
<< " version=\"0.1\""
<< (format_ != Vtk::FormatTypes::ASCII ? " byte_order=\"" + vtkWriter_.getEndian() + "\"" : "")
<< (format_ == Vtk::COMPRESSED ? " compressor=\"vtkZLibDataCompressor\"" : "")
<< (format_ == Vtk::FormatTypes::COMPRESSED ? " compressor=\"vtkZLibDataCompressor\"" : "")
<< ">\n";
out << "<Collection>\n";
......
......@@ -71,7 +71,7 @@ int testGridView (std::string prefix, Dune::VTKChecker& vtkChecker, GridView con
// COMPRESSED files
{
vtk.setFormat(Dune::Vtk::COMPRESSED);
vtk.setFormat(Dune::Vtk::FormatTypes::COMPRESSED);
std::string name = vtk.write(prefix + "_compressed");
if (gridView.comm().rank() == 0) vtkChecker.push(name);
}
......
......@@ -130,12 +130,12 @@ Vtk::DataTypes dataTypeOf (std::string s)
}
std::string to_string (CompressorTypes type)
std::string to_string (Vtk::CompressorTypes type)
{
switch (type) {
case ZLIB: return "vtkZLibDataCompressor";
case LZ4: return "vtkLZ4DataCompressor";
case LZMA: return "vtkLZMADataCompressor";
case Vtk::CompressorTypes::ZLIB: return "vtkZLibDataCompressor";
case Vtk::CompressorTypes::LZ4: return "vtkLZ4DataCompressor";
case Vtk::CompressorTypes::LZMA: return "vtkLZMADataCompressor";
default:
DUNE_THROW(RangeError, "CompressorTypes not found.");
std::abort();
......@@ -146,29 +146,30 @@ std::string to_string (CompressorTypes type)
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;
case Vtk::CellType::VERTEX: return GeometryTypes::vertex;
case Vtk::CellType::LINE: return GeometryTypes::line;
case Vtk::CellType::TRIANGLE: return GeometryTypes::triangle;
case Vtk::CellType::QUAD: return GeometryTypes::quadrilateral;
case Vtk::CellType::TETRA: return GeometryTypes::tetrahedron;
case Vtk::CellType::HEXAHEDRON: return GeometryTypes::hexahedron;
case Vtk::CellType::WEDGE: return GeometryTypes::prism;
case Vtk::CellType::PYRAMID: return GeometryTypes::pyramid;
// 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;
case Vtk::CellType::QUADRATIC_EDGE: return GeometryTypes::line;
case Vtk::CellType::QUADRATIC_TRIANGLE: return GeometryTypes::triangle;
case Vtk::CellType::QUADRATIC_QUAD: return GeometryTypes::quadrilateral;
case Vtk::CellType::QUADRATIC_TETRA: return GeometryTypes::tetrahedron;
case Vtk::CellType::QUADRATIC_HEXAHEDRON: return GeometryTypes::hexahedron;
// 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;
case Vtk::CellType::LAGRANGE_CURVE: return GeometryTypes::line;
case Vtk::CellType::LAGRANGE_TRIANGLE: return GeometryTypes::triangle;
case Vtk::CellType::LAGRANGE_QUADRILATERAL:return GeometryTypes::quadrilateral;
case Vtk::CellType::LAGRANGE_TETRAHEDRON: return GeometryTypes::tetrahedron;
case Vtk::CellType::LAGRANGE_HEXAHEDRON: return GeometryTypes::hexahedron;
case Vtk::CellType::LAGRANGE_WEDGE: return GeometryTypes::prism;
default:
DUNE_THROW(RangeError, "CellType does not map to GeometryType.");
std::abort();
......@@ -176,7 +177,7 @@ GeometryType to_geometry (std::uint8_t cell)
}
CellType::CellType (GeometryType const& t, CellParametrization parametrization)
CellType::CellType (GeometryType const& t, Parametrization parametrization)
: noPermutation_(true)
{
if (parametrization == LINEAR) {
......
......@@ -18,7 +18,7 @@ namespace Dune
namespace Vtk
{
/// Type used for representing the output format
enum FormatTypes {
enum class FormatTypes {
ASCII = 1<<0,
BINARY = 1<<1,
COMPRESSED = 1<<2,
......@@ -40,7 +40,7 @@ namespace Dune
TENSOR //< Use exactly 9 components
};
std::string to_string (Vtk::RangeTypes);
inline auto rangeTypesList = { RangeTypes::UNSPECIFIED, RangeTypes::AUTO, RangeTypes::SCALAR, RangeTypes::VECTOR, RangeTypes::TENSOR };
inline auto rangeTypesList = {RangeTypes::UNSPECIFIED, RangeTypes::AUTO, RangeTypes::SCALAR, RangeTypes::VECTOR, RangeTypes::TENSOR};
// Map a dune-grid FieldInfo::Type to ValueTypes
Vtk::RangeTypes rangeTypeOf (Dune::VTK::FieldInfo::Type);
......@@ -49,7 +49,7 @@ namespace Dune
Vtk::RangeTypes rangeTypeOf (int ncomps);
enum DataTypes {
enum class DataTypes {
UNKNOWN = 0,
INT8, UINT8,
INT16, UINT16,
......@@ -100,16 +100,16 @@ namespace Dune
void mapDataTypes (Vtk::DataTypes t, Caller caller)
{
switch (t) {
case INT8: if constexpr(C<std::int8_t>::value) caller(MetaType<std::int8_t>{}); break;
case UINT8: if constexpr(C<std::uint8_t>::value) caller(MetaType<std::uint8_t>{}); break;
case INT16: if constexpr(C<std::int16_t>::value) caller(MetaType<std::int16_t>{}); break;
case UINT16: if constexpr(C<std::uint16_t>::value) caller(MetaType<std::uint16_t>{}); break;
case INT32: if constexpr(C<std::int32_t>::value) caller(MetaType<std::int32_t>{}); break;
case UINT32: if constexpr(C<std::uint32_t>::value) caller(MetaType<std::uint32_t>{}); break;
case INT64: if constexpr(C<std::int64_t>::value) caller(MetaType<std::int64_t>{}); break;
case UINT64: if constexpr(C<std::uint64_t>::value) caller(MetaType<std::uint64_t>{}); break;
case FLOAT32: if constexpr(C<float>::value) caller(MetaType<float>{}); break;
case FLOAT64: if constexpr(C<double>::value) caller(MetaType<double>{}); break;
case DataTypes::INT8: if constexpr(C<std::int8_t>::value) caller(MetaType<std::int8_t>{}); break;
case DataTypes::UINT8: if constexpr(C<std::uint8_t>::value) caller(MetaType<std::uint8_t>{}); break;
case DataTypes::INT16: if constexpr(C<std::int16_t>::value) caller(MetaType<std::int16_t>{}); break;
case DataTypes::UINT16: if constexpr(C<std::uint16_t>::value) caller(MetaType<std::uint16_t>{}); break;
case DataTypes::INT32: if constexpr(C<std::int32_t>::value) caller(MetaType<std::int32_t>{}); break;
case DataTypes::UINT32: if constexpr(C<std::uint32_t>::value) caller(MetaType<std::uint32_t>{}); break;
case DataTypes::INT64: if constexpr(C<std::int64_t>::value) caller(MetaType<std::int64_t>{}); break;
case DataTypes::UINT64: if constexpr(C<std::uint64_t>::value) caller(MetaType<std::uint64_t>{}); break;
case DataTypes::FLOAT32: if constexpr(C<float>::value) caller(MetaType<float>{}); break;
case DataTypes::FLOAT64: if constexpr(C<double>::value) caller(MetaType<double>{}); break;
default:
VTK_ASSERT_MSG(false, "Unsupported type " + to_string(t));
break;
......@@ -146,7 +146,7 @@ namespace Dune
}
enum CompressorTypes {
enum class CompressorTypes {
NONE = 0,
ZLIB,
LZ4,
......@@ -155,52 +155,49 @@ namespace Dune
std::string to_string (CompressorTypes);
enum CellParametrization {
LINEAR,
QUADRATIC,
LAGRANGE
};
enum CellTypes : std::uint8_t {
// Linear VTK cell types
VERTEX = 1,
/* POLY_VERTEX = 2, // not supported */
LINE = 3,
/* POLY_LINE = 4, // not supported */
TRIANGLE = 5,
/* TRIANGLE_STRIP = 6, // not supported */
POLYGON = 7,
/* PIXEL = 8, // not supported */
QUAD = 9,
TETRA = 10,
/* VOXEL = 11, // not supported */
HEXAHEDRON = 12,
WEDGE = 13,
PYRAMID = 14,
// Quadratic VTK cell types
QUADRATIC_EDGE = 21,
QUADRATIC_TRIANGLE = 22,
QUADRATIC_QUAD = 23,
QUADRATIC_TETRA = 24,
QUADRATIC_HEXAHEDRON = 25,
// Arbitrary order Lagrange elements
LAGRANGE_CURVE = 68,
LAGRANGE_TRIANGLE = 69,
LAGRANGE_QUADRILATERAL = 70,
LAGRANGE_TETRAHEDRON = 71,
LAGRANGE_HEXAHEDRON = 72,
LAGRANGE_WEDGE = 73,
LAGRANGE_PYRAMID = 74,
};
GeometryType to_geometry (std::uint8_t);
/// Mapping of Dune geometry types to VTK cell types
class CellType
struct CellType
{
enum Parametrization {
LINEAR = 1,
QUADRATIC = 2,
LAGRANGE = 3
};
enum Type : std::uint8_t {
// Linear VTK cell types
VERTEX = 1,
/* POLY_VERTEX = 2, // not supported */
LINE = 3,
/* POLY_LINE = 4, // not supported */
TRIANGLE = 5,
/* TRIANGLE_STRIP = 6, // not supported */
POLYGON = 7,
/* PIXEL = 8, // not supported */
QUAD = 9,
TETRA = 10,
/* VOXEL = 11, // not supported */
HEXAHEDRON = 12,
WEDGE = 13,
PYRAMID = 14,
// Quadratic VTK cell types
QUADRATIC_EDGE = 21,
QUADRATIC_TRIANGLE = 22,
QUADRATIC_QUAD = 23,
QUADRATIC_TETRA = 24,
QUADRATIC_HEXAHEDRON = 25,
// Arbitrary order Lagrange elements
LAGRANGE_CURVE = 68,
LAGRANGE_TRIANGLE = 69,
LAGRANGE_QUADRILATERAL= 70,
LAGRANGE_TETRAHEDRON = 71,
LAGRANGE_HEXAHEDRON = 72,
LAGRANGE_WEDGE = 73,
LAGRANGE_PYRAMID = 74,
};
public:
CellType (GeometryType const& t, CellParametrization = LINEAR);
CellType (GeometryType const& t, Parametrization = LINEAR);
/// Return VTK Cell type
std::uint8_t type () const
......@@ -224,6 +221,7 @@ namespace Dune
std::vector<int> permutation_;
bool noPermutation_ = true;
};
GeometryType to_geometry (std::uint8_t);
class FieldInfo
......
......@@ -516,9 +516,9 @@ void VtkReader<Grid,Creator,Field>::readCellsAppended (MetaType<HeaderType>, std
readAppended(input, vec_types, HeaderType(types_data.offset));
VTK_ASSERT(vec_types.size() == numberOfCells_);
if (offsets_data.type == Vtk::INT64)
if (offsets_data.type == Vtk::DataTypes::INT64)
readAppended(input, vec_offsets, HeaderType(offsets_data.offset));
else if (offsets_data.type == Vtk::INT32) {
else if (offsets_data.type == Vtk::DataTypes::INT32) {
std::vector<std::int32_t> offsets;
readAppended(input, offsets, HeaderType(offsets_data.offset));
vec_offsets.resize(offsets.size());
......@@ -527,9 +527,9 @@ void VtkReader<Grid,Creator,Field>::readCellsAppended (MetaType<HeaderType>, std
else { DUNE_THROW(Dune::NotImplemented, "Unsupported DataType in Cell offsets."); }
VTK_ASSERT(vec_offsets.size() == numberOfCells_);
if (connectivity_data.type == Vtk::INT64)
if (connectivity_data.type == Vtk::DataTypes::INT64)
readAppended(input, vec_connectivity, HeaderType(connectivity_data.offset));
else if (connectivity_data.type == Vtk::INT32) {
else if (connectivity_data.type == Vtk::DataTypes::INT32) {
std::vector<std::int32_t> connectivity;
readAppended(input, connectivity, HeaderType(connectivity_data.offset));
vec_connectivity.resize(connectivity.size());
......
......@@ -40,10 +40,10 @@ using TestCasesNew = std::set<std::tuple<std::string,Vtk::FormatTypes,Vtk::DataT
static TestCasesNew test_cases_new = {
{"ascii32", Vtk::FormatTypes::ASCII, Vtk::DataTypes::FLOAT32},
{"bin32", Vtk::FormatTypes::BINARY, Vtk::DataTypes::FLOAT32},
// {"zlib32", Vtk::COMPRESSED, Vtk::DataTypes::FLOAT32},
// {"zlib32", Vtk::FormatTypes::COMPRESSED, Vtk::DataTypes::FLOAT32},
// {"ascii64", Vtk::FormatTypes::ASCII, Vtk::DataTypes::FLOAT64},
// {"bin64", Vtk::FormatTypes::BINARY, Vtk::DataTypes::FLOAT64},
// {"zlib64", Vtk::COMPRESSED, Vtk::DataTypes::FLOAT64}
// {"zlib64", Vtk::FormatTypes::COMPRESSED, Vtk::DataTypes::FLOAT64}
};
template <class GridView>
......
......@@ -63,7 +63,7 @@ void run(std::string const& prefix)
vtkWriter2.addCellData(data, "g");
vtkWriter2.write(prefix + "_binary.vtu");
VtkUnstructuredGridWriter<GridView> vtkWriter3(gridView, Vtk::COMPRESSED, Vtk::DataTypes::FLOAT64);
VtkUnstructuredGridWriter<GridView> vtkWriter3(gridView, Vtk::FormatTypes::COMPRESSED, Vtk::DataTypes::FLOAT64);
vtkWriter3.addPointData(data, "f");
vtkWriter3.addCellData(data, "g");
vtkWriter3.write(prefix + "_compressed.vtu");
......
......@@ -63,10 +63,10 @@ using TestCases = std::set<std::tuple<std::string,Vtk::FormatTypes,Vtk::DataType
static TestCases test_cases = {
{"ascii32", Vtk::FormatTypes::ASCII, Vtk::DataTypes::FLOAT32},
{"bin32", Vtk::FormatTypes::BINARY, Vtk::DataTypes::FLOAT32},
{"zlib32", Vtk::COMPRESSED, Vtk::DataTypes::FLOAT32},
{"zlib32", Vtk::FormatTypes::COMPRESSED, Vtk::DataTypes::FLOAT32},
{"ascii64", Vtk::FormatTypes::ASCII, Vtk::DataTypes::FLOAT64},
{"bin64", Vtk::FormatTypes::BINARY, Vtk::DataTypes::FLOAT64},
{"zlib64", Vtk::COMPRESSED, Vtk::DataTypes::FLOAT64},
{"zlib64", Vtk::FormatTypes::COMPRESSED, Vtk::DataTypes::FLOAT64},
};
template <class GridView>
......
......@@ -73,10 +73,10 @@ using TestCases = std::set<std::tuple<std::string,Vtk::FormatTypes,Vtk::DataType
static TestCases test_cases = {
{"ascii32", Vtk::FormatTypes::ASCII, Vtk::DataTypes::FLOAT32},
{"bin32", Vtk::FormatTypes::BINARY, Vtk::DataTypes::FLOAT32},
{"zlib32", Vtk::COMPRESSED, Vtk::DataTypes::FLOAT32},
{"zlib32", Vtk::FormatTypes::COMPRESSED, Vtk::DataTypes::FLOAT32},
{"ascii64", Vtk::FormatTypes::ASCII, Vtk::DataTypes::FLOAT64},
{"bin64", Vtk::FormatTypes::BINARY, Vtk::DataTypes::FLOAT64},
{"zlib64", Vtk::COMPRESSED, Vtk::DataTypes::FLOAT64},
{"zlib64", Vtk::FormatTypes::COMPRESSED, Vtk::DataTypes::FLOAT64},
};
template <class Test>
......
......@@ -23,10 +23,10 @@ using TestCases = std::set<std::tuple<std::string,Vtk::FormatTypes,Vtk::DataType
static TestCases test_cases = {
{"ascii32", Vtk::FormatTypes::ASCII, Vtk::DataTypes::FLOAT32},
{"bin32", Vtk::FormatTypes::BINARY, Vtk::DataTypes::FLOAT32},
{"zlib32", Vtk::COMPRESSED, Vtk::DataTypes::FLOAT32},
{"zlib32", Vtk::FormatTypes::COMPRESSED, Vtk::DataTypes::FLOAT32},
{"ascii64", Vtk::FormatTypes::ASCII, Vtk::DataTypes::FLOAT64},
{"bin64", Vtk::FormatTypes::BINARY, Vtk::DataTypes::FLOAT64},
{"zlib64", Vtk::COMPRESSED, Vtk::DataTypes::FLOAT64},
{"zlib64", Vtk::FormatTypes::COMPRESSED, Vtk::DataTypes::FLOAT64},
};
template <class GridView>
......
......@@ -45,7 +45,7 @@ int main(int argc, char** argv)
VtkUnstructuredGridWriter<GridView> vtkWriter2(gridView, Vtk::FormatTypes::BINARY);
vtkWriter2.write("test_binary_float32.vtu");
VtkUnstructuredGridWriter<GridView> vtkWriter3(gridView, Vtk::COMPRESSED, Vtk::DataTypes::FLOAT64);
VtkUnstructuredGridWriter<GridView> vtkWriter3(gridView, Vtk::FormatTypes::COMPRESSED, Vtk::DataTypes::FLOAT64);
vtkWriter3.write("test_compressed_float64.vtu");
}
......
......@@ -31,10 +31,10 @@ using TestCases = std::set<std::tuple<std::string,Vtk::FormatTypes,Vtk::DataType
static TestCases test_cases = {
{"ascii32", Vtk::FormatTypes::ASCII, Vtk::DataTypes::FLOAT32},
{"bin32", Vtk::FormatTypes::BINARY, Vtk::DataTypes::FLOAT32},
{"zlib32", Vtk::COMPRESSED, Vtk::DataTypes::FLOAT32},
{"zlib32", Vtk::FormatTypes::COMPRESSED, Vtk::DataTypes::FLOAT32},
{"ascii64", Vtk::FormatTypes::ASCII, Vtk::DataTypes::FLOAT64},
{"bin64", Vtk::FormatTypes::BINARY, Vtk::DataTypes::FLOAT64},
{"zlib64", Vtk::COMPRESSED, Vtk::DataTypes::FLOAT64},
{"zlib64", Vtk::FormatTypes::COMPRESSED, Vtk::DataTypes::FLOAT64},
};
template <class GridView>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment