DUNE-ACFEM (unstable)

fieldpromotion.hh
Go to the documentation of this file.
1 #ifndef __DUNE_ACFEM_EXPRESSIONS_FIELDPROMOTION_HH__
2 #define __DUNE_ACFEM_EXPRESSIONS_FIELDPROMOTION_HH__
3 
9 #include <limits>
10 #include <complex>
11 
12 #include "../common/types.hh"
13 
14 #include "policy.hh"
15 #include "typetraits.hh"
16 
17 namespace Dune
18 {
19 
20  namespace ACFem
21  {
22 
32  namespace {
33 
35  template<class F, class SFINAE = void>
36  struct FloatingPointClosureHelper
37  {
38  using Type = Expressions::Policy::FloatingPointDefault;
39  };
40 
45  template<class F>
46  struct FloatingPointClosureHelper<F, std::enable_if_t<!IsDecay<F>::value> >
47  {
48  using Type = copy_cv_reference_t<F, typename FloatingPointClosureHelper<std::decay_t<F> >::Type>;
49  };
50 
53  template<class F>
54  struct FloatingPointClosureHelper<
55  F,
56  std::enable_if_t<IsDecay<F>::value
57  &&
58  std::numeric_limits<typename FieldTraits<F>::real_type>::is_iec559>
59  >
60  {
61  using Type = typename FieldTraits<F>::real_type;
62  };
63 
64  template<class T>
65  struct FloatingPointClosureHelper<std::complex<T> >
66  {
67  using Type = std::complex<typename FloatingPointClosureHelper<T>::Type>;
68  };
69 
70  } // NS anonymous
71 
73  template<class T>
74  using FloatingPointClosure = typename FloatingPointClosureHelper<T>::Type;
75 
79  template<class T, std::enable_if_t<!std::is_same<FloatingPointClosure<std::decay_t<T> >, std::decay_t<T> >::value, int> = 0>
80  constexpr auto floatingPointClosure(T&& t)
81  {
83  }
84 
86  template<class T, std::enable_if_t<std::is_same<FloatingPointClosure<std::decay_t<T> >, std::decay_t<T> >::value, int> = 0>
87  constexpr decltype(auto) floatingPointClosure(T&& t)
88  {
89  return std::forward<T>(t);
90  }
91 
95  template<class T1, class T2, class SFINAE = void>
97  {
98  using Type = std::decay_t<decltype(std::declval<typename FieldTraits<std::decay_t<T1> >::field_type>()
99  *
100  std::declval<typename FieldTraits<std::decay_t<T2> >::field_type>())>;
101  };
102 
103  template<class T1, class T2>
104  using FieldPromotionType = typename FieldPromotion<T1, T2>::Type;
105 
107 
108  } // ACFem
109 
110 } // Dune
111 
112 #endif // __DUNE_ACFEM_EXPRESSIONS_FIELDPROMOTION_HH__
Various traits for expressions.
typename FloatingPointClosureHelper< T >::Type FloatingPointClosure
Template alias.
Definition: fieldpromotion.hh:74
constexpr auto floatingPointClosure(T &&t)
Convert in particular integer types to a decent floating point type.
Definition: fieldpromotion.hh:80
Promote potentially different numeric field types to a "closure" type.
Definition: fieldpromotion.hh:97
Helper class for specializing Dune::FieldTraits.
Definition: typetraits.hh:96
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (Apr 26, 22:29, 2024)