CoDiPack  2.2.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-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 "../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<T_Tape, ActiveTypeStatelessTape<T_Tape>>,
62 public IncrementOperators<T_Tape, ActiveTypeStatelessTape<T_Tape>> {
63 public:
64
65 using Tape = CODI_DD(T_Tape, CODI_DEFAULT_TAPE);
66
67 using Real = typename Tape::Real;
69 using Identifier = typename Tape::Identifier;
70 using Gradient = typename Tape::Gradient;
71
74
75 private:
76
77 Real primalValue;
78 Identifier identifier;
79
80 public:
81
85
87 constexpr CODI_INLINE ActiveTypeStatelessTape(PassiveReal const& value) : primalValue(value), identifier() {}
88
90 CODI_INLINE ActiveTypeStatelessTape(ActiveTypeStatelessTape const& v) : primalValue(), identifier() {
91 Base::init(v.getValue(), EventHints::Statement::Copy);
92 getTape().store(*this, v);
93 }
94
96 template<typename Rhs>
97 CODI_INLINE ActiveTypeStatelessTape(ExpressionInterface<Real, Rhs> const& rhs) : primalValue(), identifier() {
98 Base::init(rhs.cast().getValue(), EventHints::Statement::Expression);
99 getTape().store(*this, rhs.cast());
100 }
101
102 /*******************************************************************************/
105
108 static_cast<Base&>(*this) = static_cast<Base const&>(v);
109 return *this;
110 }
111
112 using Base::operator=;
113
114 /*******************************************************************************/
117
120
122 /*******************************************************************************/
125
128 return identifier;
129 }
130
133 return identifier;
134 }
135
138 return primalValue;
139 }
140
142 CODI_INLINE Real const& value() const {
143 return primalValue;
144 }
145
148 return Tape();
149 }
150
152 };
153}
#define CODI_INLINE
See codi::Config::ForcedInlines.
Definition config.h:457
#define CODI_INLINE_NO_FA
See codi::Config::ForcedInlines.
Definition config.h:459
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:94
typename TraitsImplementation< Type >::PassiveReal PassiveReal
The original computation type, that was used in the application.
Definition realTraits.hpp:117
CoDiPack - Code Differentiation Package.
Definition codi.hpp:90
Represents a concrete lvalue in the CoDiPack expression tree.
Definition activeTypeStatelessTape.hpp:62
Real & value()
Get a reference to the lvalue represented by the expression.
Definition activeTypeStatelessTape.hpp:137
RealTraits::PassiveReal< Real > PassiveReal
Basic computation type.
Definition activeTypeStatelessTape.hpp:68
ActiveTypeStatelessTape(ExpressionInterface< Real, Rhs > const &rhs)
Constructor.
Definition activeTypeStatelessTape.hpp:97
typename Tape::Real Real
See LhsExpressionInterface.
Definition activeTypeStatelessTape.hpp:67
T_Tape Tape
See ActiveTypeStatelessTape.
Definition activeTypeStatelessTape.hpp:65
ActiveTypeStatelessTape & operator=(ActiveTypeStatelessTape const &v)
See ActiveTypeStatelessTape::operator=(ActiveTypeStatelessTape const&).
Definition activeTypeStatelessTape.hpp:107
static Tape getTape()
Get a reference to the tape which manages this expression.
Definition activeTypeStatelessTape.hpp:147
typename Tape::Gradient Gradient
See LhsExpressionInterface.
Definition activeTypeStatelessTape.hpp:70
constexpr ActiveTypeStatelessTape(PassiveReal const &value)
Constructor.
Definition activeTypeStatelessTape.hpp:87
Real const & value() const
Get a constant reference to the lvalue represented by the expression.
Definition activeTypeStatelessTape.hpp:142
ActiveTypeStatelessTape(ActiveTypeStatelessTape const &v)
Constructor.
Definition activeTypeStatelessTape.hpp:90
Identifier const & getIdentifier() const
Definition activeTypeStatelessTape.hpp:132
typename Tape::Identifier Identifier
See LhsExpressionInterface.
Definition activeTypeStatelessTape.hpp:69
constexpr ActiveTypeStatelessTape()=default
Constructor.
Identifier & getIdentifier()
Definition activeTypeStatelessTape.hpp:127
ActiveTypeStatelessTape const & StoreAs
Defines how this expression is stored in an expression tree.
Definition activeTypeStatelessTape.hpp:118
Implementation of assignment operators for LhsExpressionInterface implementations.
Definition assignmentOperators.hpp:54
Base class for all CoDiPack expressions.
Definition expressionInterface.hpp:59
Impl const & cast() const
Cast to the implementation.
Definition expressionInterface.hpp:75
Implementation of increment operators for LhsExpressionInterface implementations.
Definition incrementOperators.hpp:54
Base class for all CoDiPack lvalue expression.
Definition lhsExpressionInterface.hpp:63
Real const & getValue() const
Get the primal value of this lvalue.
Definition lhsExpressionInterface.hpp:125
void init(Real const &newValue, EventHints::Statement statementType)
Definition lhsExpressionInterface.hpp:210