Dune Core Modules (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
9namespace 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
Type traits to determine the type of reals (when working with complex numbers)
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's VectDot function: dot(a,...
Definition: dotproduct.hh:43
Dune namespace.
Definition: alignment.hh:11
auto dotT(const A &a, const B &b) -> decltype(a *b)
Computes an indefinite vector dot product for fundamental data types according to Petsc's VectTDot fu...
Definition: dotproduct.hh:91
Traits for type conversions and type information.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 23, 23:29, 2024)