CoDiPack  2.2.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
gradientTraits.hpp
1/*
2 * CoDiPack, a Code Differentiation Package
3 *
4 * Copyright (C) 2015-2024 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau
5 * Homepage: http://scicomp.rptu.de
6 * Contact: Prof. Nicolas R. Gauger (codi@scicomp.uni-kl.de)
7 *
8 * Lead developers: Max Sagebaum, Johannes Blühdorn (SciComp, University of Kaiserslautern-Landau)
9 *
10 * This file is part of CoDiPack (http://scicomp.rptu.de/software/codi).
11 *
12 * CoDiPack is free software: you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, either version 3 of the
15 * License, or (at your option) any later version.
16 *
17 * CoDiPack is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty
19 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 *
21 * See the GNU General Public License for more details.
22 * You should have received a copy of the GNU
23 * General Public License along with CoDiPack.
24 * If not, see <http://www.gnu.org/licenses/>.
25 *
26 * For other licensing options please contact us.
27 *
28 * Authors:
29 * - SciComp, University of Kaiserslautern-Landau:
30 * - Max Sagebaum
31 * - Johannes Blühdorn
32 * - Former members:
33 * - Tim Albring
34 */
35#pragma once
36
37#include <array>
38#include <type_traits>
39
40#include "../misc/macros.hpp"
41#include "atomicTraits.hpp"
42#include "misc/enableIfHelpers.hpp"
43
45namespace codi {
46
47 template<typename Real, size_t dim>
48 struct Direction;
49
52 namespace GradientTraits {
53
54 /*******************************************************************************/
57
63 template<typename T_Gradient, typename = void>
65 public:
66
67 using Gradient = CODI_DD(T_Gradient, double);
68 using Real = Gradient;
69
70 static size_t constexpr dim = 1;
71
73 CODI_INLINE static Real& at(Gradient& gradient, size_t dim) {
75 return gradient;
76 }
77
79 CODI_INLINE static Real const& at(Gradient const& gradient, size_t dim) {
81 return gradient;
82 }
83
85 CODI_INLINE static std::array<AtomicTraits::RemoveAtomic<Real>, dim> toArray(Gradient const& gradient) {
86 return std::array<AtomicTraits::RemoveAtomic<Real>, dim>{at(gradient, 0)};
87 }
88 };
89
91 template<typename Gradient>
93
95 template<typename Gradient>
96 CODI_INLINE size_t constexpr dim() {
98 }
99
101 template<typename Gradient>
102 CODI_INLINE typename TraitsImplementation<Gradient>::Real& at(Gradient& gradient, size_t dim) {
103 return TraitsImplementation<Gradient>::at(gradient, dim);
104 }
105
107 template<typename Gradient>
108 CODI_INLINE typename TraitsImplementation<Gradient>::Real const& at(Gradient const& gradient, size_t dim) {
109 return TraitsImplementation<Gradient>::at(gradient, dim);
110 }
111
113 template<typename Gradient>
114 CODI_INLINE std::array<AtomicTraits::RemoveAtomic<typename TraitsImplementation<Gradient>::Real>,
116 toArray(Gradient const& gradient) {
118 }
119
121 /*******************************************************************************/
124
126 template<typename Gradient, typename = void>
127 struct IsDirection : std::false_type {};
128
129#ifndef DOXYGEN_DISABLE
130 template<typename Gradient>
131 struct IsDirection<Gradient,
132 typename enable_if_same<Gradient, Direction<typename Gradient::Real, Gradient::dim> >::type>
133 : std::true_type {};
134#endif
135
136#if CODI_IS_CPP14
138 template<typename Gradient>
139 bool constexpr isDirection = IsDirection<Gradient>::value;
140#endif
141
143 template<typename Gradient>
144 using EnableIfDirection = typename std::enable_if<IsDirection<Gradient>::value>::type;
145
147 }
148}
#define CODI_INLINE
See codi::Config::ForcedInlines.
Definition config.h:457
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:94
typename TraitsImplementation< Gradient >::Real Real
The base value used in the gradient entries.
Definition gradientTraits.hpp:92
typename std::enable_if< IsDirection< Gradient >::value >::type EnableIfDirection
Enable if wrapper for EnableIfDirection.
Definition gradientTraits.hpp:144
std::array< AtomicTraits::RemoveAtomic< typename TraitsImplementation< Gradient >::Real >, TraitsImplementation< Gradient >::dim > toArray(Gradient const &gradient)
Converts the (possibly multi-component) gradient to an array of Reals.
Definition gradientTraits.hpp:116
size_t constexpr dim()
Number of dimensions this gradient value has.
Definition gradientTraits.hpp:96
TraitsImplementation< Gradient >::Real & at(Gradient &gradient, size_t dim)
Get the entry at the given index.
Definition gradientTraits.hpp:102
CoDiPack - Code Differentiation Package.
Definition codi.hpp:90
void CODI_UNUSED(Args const &...)
Disable unused warnings for an arbitrary number of arguments.
Definition macros.hpp:46
std::enable_if< std::is_same< T1, T2 >::value, R > enable_if_same
Enable if abbreviation for "std::is_same".
Definition enableIfHelpers.hpp:51
Fixed size vector mode implementation.
Definition direction.hpp:57
If the expression inherits from Direction. Is either std::false_type or std::true_type.
Definition gradientTraits.hpp:127
Common traits for all types used as gradients.
Definition gradientTraits.hpp:64
static size_t constexpr dim
Number of dimensions this gradient value has.
Definition gradientTraits.hpp:70
static Real & at(Gradient &gradient, size_t dim)
Get the entry at the given index.
Definition gradientTraits.hpp:73
static std::array< AtomicTraits::RemoveAtomic< Real >, dim > toArray(Gradient const &gradient)
Converts the (possibly multi-component) gradient to an array of Reals.
Definition gradientTraits.hpp:85
T_Gradient Gradient
See TraitsImplementation.
Definition gradientTraits.hpp:67
Gradient Real
The base value used in the gradient entries.
Definition gradientTraits.hpp:68
static Real const & at(Gradient const &gradient, size_t dim)
Get the entry at the given index.
Definition gradientTraits.hpp:79