Dune Core Modules (2.4.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
10namespace 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
Type traits to determine the type of reals (when working with complex numbers)
enable_if<!IsVector< A >::value &&!is_same< typenameFieldTraits< A >::field_type, typenameFieldTraits< A >::real_type >::value, typenamePromotionTraits< 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
Dune namespace.
Definition: alignment.hh:10
enable_if<!IsVector< A >::value &&!is_same< typenameFieldTraits< A >::field_type, typenameFieldTraits< A >::real_type >::value, typenamePromotionTraits< 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
Provides some promotion traits.
Traits for type conversions and type information.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)