CoDiPack  2.2.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
activeTypeBase.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
60 template<typename T_Tape, typename T_Impl>
62 : public LhsExpressionInterface<typename T_Tape::Real, typename T_Tape::Gradient, T_Tape, T_Impl>,
63 public AssignmentOperators<T_Tape, T_Impl>,
64 public IncrementOperators<T_Tape, T_Impl> {
65 public:
66
71 using Tape = CODI_DD(T_Tape, CODI_DEFAULT_TAPE);
72
74 using Impl = CODI_DD(T_Impl, CODI_DEFAULT_LHS_EXPRESSION);
75
76 using Real = typename Tape::Real;
78 using Identifier = typename Tape::Identifier;
79 using Gradient = typename Tape::Gradient;
80
82
83 private:
84
85 Real primalValue;
86 Identifier identifier;
87
88 public:
89
92 return static_cast<Impl&>(*this);
93 }
94
96 CODI_INLINE ActiveTypeBase() : primalValue(), identifier() {
97 Base::init(Real(), EventHints::Statement::Passive);
98 }
99
101 template<typename U = Real, typename = RealTraits::EnableIfNotPassiveReal<U>>
102 CODI_INLINE ActiveTypeBase(PassiveReal const& value) : primalValue(value), identifier() {
103 Base::init(value, EventHints::Statement::Passive);
104 }
105
107 CODI_INLINE ActiveTypeBase(ActiveTypeBase const& v) : primalValue(), identifier() {
108 Base::init(v.getValue(), EventHints::Statement::Copy);
109 cast().getTape().store(*this, v);
110 }
111
113 CODI_INLINE ActiveTypeBase(Real const& value) : primalValue(value), identifier() {
114 Base::init(value, EventHints::Statement::Passive);
115 }
116
118 template<typename Rhs>
119 CODI_INLINE ActiveTypeBase(ExpressionInterface<Real, Rhs> const& rhs) : primalValue(), identifier() {
120 Base::init(rhs.cast().getValue(), EventHints::Statement::Expression);
121 cast().getTape().store(*this, rhs.cast());
122 }
123
125 template<typename Rhs, typename U = Real, typename = RealTraits::EnableIfNotPassiveReal<U>>
127 : primalValue(rhs.cast()), identifier() {
128 Base::init(rhs.cast().getValue(), EventHints::Statement::Passive);
129 }
130
135
139 return cast();
140 }
141 using Base::operator=;
142
143 /*******************************************************************************/
146
147 using StoreAs = Impl const&;
149
151 /*******************************************************************************/
154
157 return identifier;
158 }
159
162 return identifier;
163 }
164
167 return primalValue;
168 }
169
171 CODI_INLINE Real const& value() const {
172 return primalValue;
173 }
174
175 // getTape must be implemented in the derived type
176
178 };
179}
#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< 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 the base implementation concrete lvalue in the CoDiPack expression tree.
Definition activeTypeBase.hpp:64
ActiveTypeBase(PassiveReal const &value)
Constructor.
Definition activeTypeBase.hpp:102
Impl const & StoreAs
Defines how this expression is stored in an expression tree.
Definition activeTypeBase.hpp:147
RealTraits::PassiveReal< Real > PassiveReal
Basic computation type.
Definition activeTypeBase.hpp:77
typename Tape::Identifier Identifier
See LhsExpressionInterface.
Definition activeTypeBase.hpp:78
Impl & cast()
Cast to the implementation.
Definition activeTypeBase.hpp:91
T_Impl Impl
Abbreviation for the implementing class.
Definition activeTypeBase.hpp:74
Real const & value() const
Get a constant reference to the lvalue represented by the expression.
Definition activeTypeBase.hpp:171
Impl & operator=(ActiveTypeBase const &v)
See LhsExpressionInterface::operator=(LhsExpressionInterface const&).
Definition activeTypeBase.hpp:137
Impl ActiveResult
Type into which the expression can be converted. Usually also the type from which it is constructed.
Definition activeTypeBase.hpp:148
ActiveTypeBase(ExpressionInterface< typename U::Real, Rhs > const &rhs)
Constructor.
Definition activeTypeBase.hpp:126
Real & value()
Get a reference to the lvalue represented by the expression.
Definition activeTypeBase.hpp:166
Identifier const & getIdentifier() const
Definition activeTypeBase.hpp:161
~ActiveTypeBase()
Destructor.
Definition activeTypeBase.hpp:132
ActiveTypeBase(Real const &value)
Constructor.
Definition activeTypeBase.hpp:113
ActiveTypeBase(ActiveTypeBase const &v)
Constructor.
Definition activeTypeBase.hpp:107
ActiveTypeBase()
Constructor.
Definition activeTypeBase.hpp:96
Identifier & getIdentifier()
Definition activeTypeBase.hpp:156
typename Tape::Gradient Gradient
See LhsExpressionInterface.
Definition activeTypeBase.hpp:79
ActiveTypeBase(ExpressionInterface< Real, Rhs > const &rhs)
Constructor.
Definition activeTypeBase.hpp:119
typename Tape::Real Real
See LhsExpressionInterface.
Definition activeTypeBase.hpp:76
T_Tape Tape
Definition activeTypeBase.hpp:71
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 destroy()
Definition lhsExpressionInterface.hpp:219
void init(Real const &newValue, EventHints::Statement statementType)
Definition lhsExpressionInterface.hpp:210