CoDiPack  3.1.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
activeTypeStatelessTape.hpp
1/*
2 * CoDiPack, a Code Differentiation Package
3 *
4 * Copyright (C) 2015-2026 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 "../config.h"
38#include "../misc/macros.hpp"
39#include "../tapes/interfaces/fullTapeInterface.hpp"
40#include "../traits/realTraits.hpp"
41#include "assignmentOperators.hpp"
42#include "incrementOperators.hpp"
43#include "lhsExpressionInterface.hpp"
44
46namespace codi {
47
58 template<typename T_Tape>
59 struct ActiveTypeStatelessTape : public LhsExpressionInterface<typename T_Tape::Real, typename T_Tape::Gradient,
60 T_Tape, ActiveTypeStatelessTape<T_Tape>>,
61 public AssignmentOperators<typename T_Tape::Real, T_Tape::AllowJacobianOptimization,
62 ActiveTypeStatelessTape<T_Tape>>,
63 public IncrementOperators<T_Tape, ActiveTypeStatelessTape<T_Tape>> {
64 public:
65
66 using Tape = CODI_DD(T_Tape, CODI_DEFAULT_TAPE);
67
68 using Real = typename Tape::Real;
70 using Identifier = typename Tape::Identifier;
71 using Gradient = typename Tape::Gradient;
72 using TapeData = typename Tape::ActiveTypeTapeData;
73
76
77 private:
78
79 Real primalValue;
80 TapeData tapeData;
81
82 public:
83
87
89 constexpr CODI_INLINE ActiveTypeStatelessTape(PassiveReal const& value) : primalValue(value), tapeData() {}
90
92 CODI_INLINE ActiveTypeStatelessTape(ActiveTypeStatelessTape const& v) : primalValue(), tapeData() {
93 Base::init(v.getValue(), EventHints::Statement::Copy);
94 getTape().store(*this, v);
95 }
96
98 template<typename Rhs>
99 CODI_INLINE ActiveTypeStatelessTape(ExpressionInterface<Real, Rhs> const& rhs) : primalValue(), tapeData() {
100 Base::init(rhs.cast().getValue(), EventHints::Statement::Expression);
101 getTape().store(*this, rhs.cast());
102 }
103
104 /*******************************************************************************/
107
110 static_cast<Base&>(*this) = static_cast<Base const&>(v);
111 return *this;
112 }
113
114 using Base::operator=;
115
116 /*******************************************************************************/
119
121 using ADLogic = Tape;
122
124 /*******************************************************************************/
127
130 return getTape().getIdentifier(tapeData);
131 }
132
135 return getTape().getIdentifier(tapeData);
136 }
137
140 return tapeData;
141 }
142
145 return tapeData;
146 }
147
150 return primalValue;
151 }
152
154 CODI_INLINE Real const& value() const {
155 return primalValue;
156 }
157
160 return Tape();
161 }
162
164 };
165}
#define CODI_INLINE
See codi::Config::ForcedInlines.
Definition config.h:469
#define CODI_INLINE_NO_FA
See codi::Config::ForcedInlines.
Definition config.h:471
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:97
typename TraitsImplementation< Type >::PassiveReal PassiveReal
The original computation type that was used in the application.
Definition realTraits.hpp:123
CoDiPack - Code Differentiation Package.
Definition codi.hpp:97
RealTraits::PassiveReal< Real > PassiveReal
Basic computation type.
Definition activeTypeStatelessTape.hpp:69
typename Tape::Real Real
See LhsExpressionInterface.
Definition activeTypeStatelessTape.hpp:68
T_Tape Tape
See ActiveTypeStatelessTape.
Definition activeTypeStatelessTape.hpp:66
inlineTapeData & getTapeData()
Definition activeTypeStatelessTape.hpp:139
static inlineTape getTape()
Get a reference to the tape which manages this expression.
Definition activeTypeStatelessTape.hpp:159
inlineIdentifier const & getIdentifier() const
Definition activeTypeStatelessTape.hpp:134
inlineActiveTypeStatelessTape & operator=(ActiveTypeStatelessTape const &v)
Definition activeTypeStatelessTape.hpp:109
typename Tape::Gradient Gradient
See LhsExpressionInterface.
Definition activeTypeStatelessTape.hpp:71
inlineTapeData const & getTapeData() const
Definition activeTypeStatelessTape.hpp:144
inlineReal const & value() const
Definition activeTypeStatelessTape.hpp:154
inlineIdentifier & getIdentifier()
Definition activeTypeStatelessTape.hpp:129
LhsExpressionInterface< Real, Gradient, T_Tape, ActiveTypeStatelessTape< T_Tape > > Base
Definition activeTypeStatelessTape.hpp:74
typename Tape::Identifier Identifier
See LhsExpressionInterface.
Definition activeTypeStatelessTape.hpp:70
inlineReal & value()
Definition activeTypeStatelessTape.hpp:149
constexpr ActiveTypeStatelessTape()=default
Constructor.
typename Tape::ActiveTypeTapeData TapeData
See IdentifierInformationTapeInterface.
Definition activeTypeStatelessTape.hpp:72
Tape ADLogic
AD logic that governs the expression. Needs to be the same for all inputs of the expression.
Definition activeTypeStatelessTape.hpp:121
ActiveTypeStatelessTape const & StoreAs
Defines how this expression is stored in an expression tree.
Definition activeTypeStatelessTape.hpp:120
Provides assignment operators for LhsExpressionInterface implementations.
Definition assignmentOperators.hpp:120
Base class for all CoDiPack expressions.
Definition expressionInterface.hpp:60
inlineImpl const & cast() const
Cast to the implementation.
Definition expressionInterface.hpp:76
Implementation of increment operators for LhsExpressionInterface implementations.
Definition incrementOperators.hpp:54
inlinevoid init(Real const &newValue, EventHints::Statement statementType)
Definition lhsExpressionInterface.hpp:202
inlineReal const & getValue() const
Get the primal value of this lvalue.
Definition lhsExpressionInterface.hpp:129