dune-common  2.5.0
dotproduct.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_DOTPRODUCT_HH
4 #define DUNE_DOTPRODUCT_HH
5 
6 #include "ftraits.hh"
7 #include "typetraits.hh"
8 
9 namespace Dune {
24  template<class T>
25  struct AlwaysVoid { typedef void type; };
26 
27  template<class T, class = void>
28  struct IsVector : std::false_type {};
29 
30  template<class T>
31  struct IsVector<T, typename AlwaysVoid<typename T::field_type>::type>
32  : std::true_type {};
33 
41  template<class A, class B>
42  auto
43  dot(const A & a, const B & b) -> typename std::enable_if<!IsVector<A>::value && !std::is_same<typename FieldTraits<A>::field_type,typename FieldTraits<A>::real_type> ::value, decltype(conj(a)*b)>::type
44  {
45  return conj(a)*b;
46  }
47 
57  // fundamental type with A being a real type
58  template<class A, class B>
59  auto
60  dot(const A & a, const B & b) -> typename std::enable_if<!IsVector<A>::value && std::is_same<typename FieldTraits<A>::field_type,typename FieldTraits<A>::real_type>::value, decltype(a*b)>::type
61  {
62  return a*b;
63  }
64 
74  template<typename A, typename B>
75  auto
76  dot(const A & a, const B & b) -> typename std::enable_if<IsVector<A>::value, decltype(a.dot(b))>::type
77  {
78  return a.dot(b);
79  }
89  template<class A, class B>
90  auto
91  dotT(const A & a, const B & b) -> decltype(a*b)
92  {
93  return a*b;
94  }
95 
97 } // end namespace DUNE
98 
99 #endif // DUNE_DOTPRODUCT_HH
auto dot(const A &a, const B &b) -> typename std::enable_if<!IsVector< A >::value &&!std::is_same< typename FieldTraits< A >::field_type, typename FieldTraits< A >::real_type > ::value, decltype(conj(a) *b)>::type
computes the dot product for fundamental data types according to Petsc&#39;s VectDot function: dot(a...
Definition: dotproduct.hh:43
auto dotT(const A &a, const B &b) -> decltype(a *b)
Computes an indefinite vector dot product for fundamental data types according to Petsc&#39;s VectTDot fu...
Definition: dotproduct.hh:91
Definition: dotproduct.hh:25
Dune namespace.
Definition: alignment.hh:10
Traits for type conversions and type information.
T real_type
export the type representing the real type of the field
Definition: ftraits.hh:28
void type
Definition: dotproduct.hh:25
Definition: dotproduct.hh:28
Type traits to determine the type of reals (when working with complex numbers)