AMDiS  0.3
The Adaptive Multi-Dimensional Simulation Toolbox
QuadMath.hpp
1 #pragma once
2 
3 #if HAVE_QUADMATH
4 #include <functional>
5 #include <type_traits>
6 
7 #include <dune/common/hash.hh>
8 #include <dune/common/quadmath.hh>
9 
10 #include <amdis/common/DerivativeTraits.hpp>
11 #include <amdis/common/StaticSize.hpp>
12 #include <amdis/common/ValueCategory.hpp>
13 #include <amdis/gridfunctions/ConstantGridFunction.hpp>
14 
15 namespace std
16 {
17  template <class T>
18  struct common_type<Dune::Float128, T>
19  {
20  using type = Dune::Float128;
21  };
22 
23  template <class T>
24  struct common_type<T, Dune::Float128>
25  {
26  using type = Dune::Float128;
27  };
28 
29  template <>
30  struct common_type<Dune::Float128, Dune::Float128>
31  {
32  using type = Dune::Float128;
33  };
34 
35  template <>
36  struct hash<Dune::Float128>
37  {
38  typedef Dune::Float128 argument_type;
39  typedef std::size_t result_type;
40 
41  std::size_t operator()(const Dune::Float128& arg) const
42  {
43  hash<long double> hasher_ld;
44  return hasher_ld((long double)(arg));
45  }
46  };
47 
48  template <>
49  struct hash<const Dune::Float128>
50  : public hash<Dune::Float128>
51  {};
52 
53 } // end namespace std
54 
55 
56 namespace Dune
57 {
58  namespace Impl
59  {
60  // specialization for float arguments due to ambiguity
61  template <class T,
62  std::enable_if_t<not std::is_integral_v<T> && std::is_arithmetic_v<T>, int> = 0>
63  inline Float128 pow(const Float128& x, const T& p)
64  {
65  return powq(float128_t(x), float128_t(p));
66  }
67 
68  } // end namespace Impl
69 } // end namespace Dune
70 
71 
72 namespace AMDiS
73 {
74  namespace Concepts
75  {
76  namespace Definition
77  {
78  template <>
79  struct ConstantToGridFunction<Dune::Float128>
80  : std::true_type {};
81 
82  } // end namespace Definition
83  } // end namespace Concepts
84 
85  namespace Impl
86  {
87  template <>
88  struct SizeImpl<Dune::Float128>
89  {
90  static constexpr auto eval(Dune::Float128)
91  -> std::integral_constant<std::size_t, 1> { return {}; }
92  };
93 
94  template <>
95  struct NumRowsImpl<Dune::Float128>
96  {
97  static constexpr auto eval(Dune::Float128)
98  -> std::integral_constant<std::size_t, 1> { return {}; }
99  };
100 
101  template <>
102  struct NumColsImpl<Dune::Float128>
103  {
104  static constexpr auto eval(Dune::Float128)
105  -> std::integral_constant<std::size_t, 1> { return {}; }
106  };
107 
108  } // end namespace Impl
109 
110  template <class K, int N>
111  struct DerivativeTraits<Dune::Float128(Dune::FieldVector<K,N>), tag::gradient>
112  {
113  using Range = Dune::FieldVector<Dune::Float128,N>;
114  };
115 
116  template <>
117  struct ValueCategory<Dune::Float128>
118  {
119  using type = tag::scalar;
120  };
121 
122 } // end namespace AMDiS
123 
124 #endif // HAVE_QUADMATH
Definition: AdaptiveGrid.hpp:373
Definition: FieldMatVec.hpp:12
Contains all classes needed for solving linear and non linear equation systems.
Definition: AdaptBase.hpp:6
constexpr bool ConstantToGridFunction
Concepts that is true for all &#39;&#39;simple&#39;&#39; types that can be converted automatically to a GridFunction...
Definition: ConstantGridFunction.hpp:165