3.2-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
vtkprecision.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3/*****************************************************************************
4 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
24#ifndef DUMUX_IO_VTK_PRECISION_HH
25#define DUMUX_IO_VTK_PRECISION_HH
26
27#include <array>
28#include <string_view>
29
30#include <dune/common/version.hh>
31#include <dune/grid/io/file/vtk/common.hh>
32
33namespace Dumux::Vtk {
34
35#if DUNE_VERSION_LT(DUNE_GRID, 2, 7)
37enum class Precision
38{
39 int32,
40 uint8,
41 uint32,
42 float32,
43 float64
44};
45#else
46using Dune::VTK::Precision;
47#endif
48
53inline Precision stringToPrecision(std::string_view precisionName)
54{
55 // this should really be constexpr but GCC <= 7.2 has a bug which
56 // doesn't allow string_view to be constexpr
57 static const std::array<std::pair<std::string_view, Precision>, 5> nameToPrecision
58 {{
59 { "Float32", Precision::float32 },
60 { "Float64", Precision::float64 },
61 { "UInt32", Precision::uint32 },
62 { "UInt8", Precision::uint8 },
63 { "Int32", Precision::int32 },
64 }};
65
66 for (const auto& [name, precision] : nameToPrecision)
67 if (name == precisionName)
68 return precision;
69
70 DUNE_THROW(Dune::InvalidStateException, "Unknown precision type " << precisionName);
71}
72
73} // end namespace Dumux::Vtk
74
75#endif
Precision stringToPrecision(std::string_view precisionName)
Maps a string (e.g. from input) to a Dune precision type.
Definition: vtkprecision.hh:53
Definition: vtkfunction.hh:37