dune-common  2.3.1
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 #include "promotiontraits.hh"
9 
10 namespace Dune {
25  template<class T>
26  struct AlwaysVoid { typedef void type; };
27 
28  template<class T, class = void>
29  struct IsVector : false_type {};
30 
31  template<class T>
32  struct IsVector<T, typename AlwaysVoid<typename T::field_type>::type>
33  : true_type {};
34 
42  template<class A, class B>
43  inline typename enable_if<!IsVector<A>::value && !is_same<typename FieldTraits<A>::field_type,typename FieldTraits<A>::real_type> ::value, typename PromotionTraits<A,B>::PromotedType>::type
44  dot(const A & a, const B & b) {
45  return conj(a)*b;
46  }
47 
57  // fundamental type with A being a real type
58  template<class A, class B>
59  inline typename enable_if<!IsVector<A>::value && is_same<typename FieldTraits<A>::field_type,typename FieldTraits<A>::real_type>::value, typename PromotionTraits<A,B>::PromotedType>::type
60  dot(const A & a, const B & b) {
61  return a*b;
62  }
63 
73  // vectors
74  template<typename A, typename B>
75  // inline typename enable_if<IsVector<A>::value, typename PromotionTraits<typename FieldTraits<A>::field_type, typename FieldTraits<B>::field_type >::PromotedType>::type
76  inline typename enable_if<IsVector<A>::value, typename PromotionTraits<typename A::field_type, typename B::field_type >::PromotedType>::type
77  dot(const A & a, const B & b) {
78  return a.dot(b);
79  }
89  template<class A, class B>
90  inline typename enable_if<!IsVector<A>::value && !is_same<typename FieldTraits<A>::field_type,typename FieldTraits<A>::real_type> ::value, typename PromotionTraits<A,B>::PromotedType>::type
91  dotT(const A & a, const B & b) {
92  return a*b;
93  }
94 
102  template<class A, class B>
103  inline typename enable_if<IsVector<A>::value, typename PromotionTraits<typename A::field_type, typename B::field_type >::PromotedType>::type
104  dotT(const A & a, const B & b) {
105  return a*b;
106  }
107 
109 } // end namespace DUNE
110 
111 #endif // DUNE_DOTPRODUCT_HH
Definition: dotproduct.hh:29
Compile time test for testing whether two types are the same.
Definition: typetraits.hh:359
enable_if<!IsVector< A >::value &&!is_same< typename FieldTraits< A >::field_type, typename FieldTraits< A >::real_type >::value, typename PromotionTraits< A, B >::PromotedType >::type dot(const A &a, const B &b)
computes the dot product for fundamental data types according to Petsc's VectDot function: dot(a...
Definition: dotproduct.hh:44
void type
Definition: dotproduct.hh:26
Enable typedef if condition is met.
Definition: typetraits.hh:328
Traits for type conversions and type information.
Type traits to determine the type of reals (when working with complex numbers)
T real_type
export the type representing the real type of the field
Definition: ftraits.hh:28
enable_if<!IsVector< A >::value &&!is_same< typename FieldTraits< A >::field_type, typename FieldTraits< A >::real_type >::value, typename PromotionTraits< A, B >::PromotedType >::type dotT(const A &a, const B &b)
Computes an indefinite vector dot product for fundamental data types according to Petsc's VectTDot fu...
Definition: dotproduct.hh:91
Definition: dotproduct.hh:26
Provides some promotion traits.
Generate a type for a given integral constant.
Definition: typetraits.hh:457