AMDiS  0.3
The Adaptive Multi-Dimensional Simulation Toolbox
ValueCategory.hpp
1 #pragma once
2 
3 #include <functional>
4 #include <type_traits>
5 
6 #include <dune/common/fmatrix.hh>
7 #include <dune/common/fvector.hh>
8 
9 #include <amdis/common/Tags.hpp>
10 
11 namespace AMDiS
12 {
14  template <class T, class = void>
16  {
17  using type = tag::unknown;
18  };
19 
20  template <class T>
21  using ValueCategory_t = typename ValueCategory<remove_cvref_t<T>>::type;
22 
23  template <class T>
24  struct ValueCategory<T, std::enable_if_t< std::is_arithmetic_v<T> >>
25  {
26  using type = tag::scalar;
27  };
28 
29  template <class K, int SIZE>
30  struct ValueCategory< Dune::FieldVector<K, SIZE> >
31  {
32  using type = tag::vector;
33  };
34 
35  template <class K>
36  struct ValueCategory< Dune::FieldVector<K, 1> >
37  {
38  using type = tag::scalar;
39  };
40 
41  template <class K, int ROWS, int COLS>
42  struct ValueCategory< Dune::FieldMatrix<K, ROWS, COLS> >
43  {
44  using type = tag::matrix;
45  };
46 
47  template <class K>
48  struct ValueCategory< Dune::FieldMatrix<K, 1, 1> >
49  {
50  using type = tag::scalar;
51  };
52 
53  template <class T>
54  struct ValueCategory< std::reference_wrapper<T> >
55  {
56  using type = typename ValueCategory<T>::type;
57  };
58 
59 
60  namespace Category
61  {
62  template <class T>
63  constexpr bool Scalar = std::is_same_v<ValueCategory_t<T>, tag::scalar>;
64 
65  template <class T>
66  constexpr bool Vector = std::is_same_v<ValueCategory_t<T>, tag::vector>;
67 
68  template <class T>
69  constexpr bool Matrix = std::is_same_v<ValueCategory_t<T>, tag::matrix>;
70 
71  } // end namespace Category
72 
73  template <class V>
74  constexpr bool isVector(V const&)
75  {
76  static_assert(Category::Vector<V>,"");
77  return Category::Vector<V>;
78  }
79 
80  template <class V>
81  constexpr bool isNotVector(V const&)
82  {
83  static_assert(!Category::Vector<V>,"");
84  return !Category::Vector<V>;
85  }
86 } // end namespace AMDiS
Definition: Tags.hpp:11
Definition: Tags.hpp:10
Definition: FieldMatVec.hpp:12
Contains all classes needed for solving linear and non linear equation systems.
Definition: AdaptBase.hpp:6
Definition: Tags.hpp:9
Category of type T, e.g. scalar, vector matrix, specified by a tag.
Definition: ValueCategory.hpp:15
Definition: Tags.hpp:12