CoDiPack  3.0.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-2025 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
75
76 private:
77
78 Real primalValue;
79 Identifier identifier;
80
81 public:
82
86
88 constexpr CODI_INLINE ActiveTypeStatelessTape(PassiveReal const& value) : primalValue(value), identifier() {}
89
91 CODI_INLINE ActiveTypeStatelessTape(ActiveTypeStatelessTape const& v) : primalValue(), identifier() {
92 Base::init(v.getValue(), EventHints::Statement::Copy);
93 getTape().store(*this, v);
94 }
95
97 template<typename Rhs>
98 CODI_INLINE ActiveTypeStatelessTape(ExpressionInterface<Real, Rhs> const& rhs) : primalValue(), identifier() {
99 Base::init(rhs.cast().getValue(), EventHints::Statement::Expression);
100 getTape().store(*this, rhs.cast());
101 }
102
103 /*******************************************************************************/
106
109 static_cast<Base&>(*this) = static_cast<Base const&>(v);
110 return *this;
111 }
112
113 using Base::operator=;
114
115 /*******************************************************************************/
118
120 using ADLogic = Tape;
121
123 /*******************************************************************************/
126
129 return identifier;
130 }
131
134 return identifier;
135 }
136
139 return primalValue;
140 }
141
143 CODI_INLINE Real const& value() const {
144 return primalValue;
145 }
146
149 return Tape();
150 }
151
153 };
154}
#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:96
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:94
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
static inlineTape getTape()
Get a reference to the tape which manages this expression.
Definition activeTypeStatelessTape.hpp:148
inlineIdentifier const & getIdentifier() const
Definition activeTypeStatelessTape.hpp:133
inlineActiveTypeStatelessTape & operator=(ActiveTypeStatelessTape const &v)
Definition activeTypeStatelessTape.hpp:108
typename Tape::Gradient Gradient
See LhsExpressionInterface.
Definition activeTypeStatelessTape.hpp:71
inlineReal const & value() const
Definition activeTypeStatelessTape.hpp:143
inlineIdentifier & getIdentifier()
Definition activeTypeStatelessTape.hpp:128
LhsExpressionInterface< Real, Gradient, T_Tape, ActiveTypeStatelessTape< T_Tape > > Base
Definition activeTypeStatelessTape.hpp:73
typename Tape::Identifier Identifier
See LhsExpressionInterface.
Definition activeTypeStatelessTape.hpp:70
inlineReal & value()
Definition activeTypeStatelessTape.hpp:138
constexpr ActiveTypeStatelessTape()=default
Constructor.
Tape ADLogic
AD logic that governs the expression. Needs to be the same for all inputs of the expression.
Definition activeTypeStatelessTape.hpp:120
ActiveTypeStatelessTape const & StoreAs
Defines how this expression is stored in an expression tree.
Definition activeTypeStatelessTape.hpp:119
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:198
inlineReal const & getValue() const
Get the primal value of this lvalue.
Definition lhsExpressionInterface.hpp:125