Dune Core Modules (2.8.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, class = void>
25 struct IsVector : std::false_type {};
26
27 template<class T>
28 struct IsVector<T, std::void_t<typename T::field_type> >
29 : std::true_type {};
30
38 template<class A, class B>
39 auto
40 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
41 {
42 return conj(a)*b;
43 }
44
54 // fundamental type with A being a real type
55 template<class A, class B>
56 auto
57 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
58 {
59 return a*b;
60 }
61
71 template<typename A, typename B>
72 auto
73 dot(const A & a, const B & b) -> typename std::enable_if<IsVector<A>::value, decltype(a.dot(b))>::type
74 {
75 return a.dot(b);
76 }
86 template<class A, class B>
87 auto
88 dotT(const A & a, const B & b) -> decltype(a*b)
89 {
90 return a*b;
91 }
92
94} // end namespace DUNE
95
96#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:40
typename Impl::voider< Types... >::type void_t
Is void for all valid input types. The workhorse for C++11 SFINAE-techniques.
Definition: typetraits.hh:38
Dune namespace.
Definition: alignedallocator.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:88
STL namespace.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)