Dune Core Modules (2.9.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// SPDX-FileCopyrightInfo: Copyright (C) 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 }
88 template<class A, class B>
89 auto
90 dotT(const A & a, const B & b) -> decltype(a*b)
91 {
92 return a*b;
93 }
94
96} // end namespace DUNE
97
98#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< 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
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:90
STL namespace.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 21, 23:30, 2024)