Dune Core Modules (unstable)

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// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
4// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5#ifndef DUNE_DOTPRODUCT_HH
6#define DUNE_DOTPRODUCT_HH
7
8#include "ftraits.hh"
9#include "typetraits.hh"
10
11namespace Dune {
26 template<class T, class = void>
27 struct IsVector : std::false_type {};
28
29 template<class T>
30 struct IsVector<T, std::void_t<typename T::field_type> >
31 : std::true_type {};
32
40 template<class A, class B>
41 auto
42 dot(const A & a, const B & b) -> typename std::enable_if<IsNumber<A>::value && !IsVector<A>::value && !std::is_same<typename FieldTraits<A>::field_type,typename FieldTraits<A>::real_type> ::value, decltype(conj(a)*b)>::type
43 {
44 return conj(a)*b;
45 }
46
56 // fundamental type with A being a real type
57 template<class A, class B>
58 auto
59 dot(const A & a, const B & b) -> typename std::enable_if<IsNumber<A>::value && !IsVector<A>::value && std::is_same<typename FieldTraits<A>::field_type,typename FieldTraits<A>::real_type>::value, decltype(a*b)>::type
60 {
61 return a*b;
62 }
63
73 template<typename A, typename B>
74 auto
75 dot(const A & a, const B & b) -> typename std::enable_if<IsVector<A>::value, decltype(a.dot(b))>::type
76 {
77 return a.dot(b);
78 }
79
87 template<class A, class B>
88 auto
89 dotT(const A & a, const B & b) -> decltype(a*b)
90 {
91 return a*b;
92 }
93
95} // end namespace DUNE
96
97#endif // DUNE_DOTPRODUCT_HH
Type traits to determine the type of reals (when working with complex numbers)
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:89
auto dot(const A &a, const B &b) -> typename std::enable_if< IsNumber< A >::value &&!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:42
typename Impl::voider< Types... >::type void_t
Is void for all valid input types. The workhorse for C++11 SFINAE-techniques.
Definition: typetraits.hh:40
Dune namespace.
Definition: alignedallocator.hh:13
STL namespace.
Traits for type conversions and type information.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 21, 23:30, 2024)