38#include "../misc/eventSystem.hpp"
40#include "../misc/toConst.hpp"
41#include "../tapes/interfaces/fullTapeInterface.hpp"
42#include "../traits/expressionTraits.hpp"
43#include "../traits/realTraits.hpp"
44#include "expressionInterface.hpp"
62 template<
typename T_Real,
typename T_Gradient,
typename T_Tape,
typename T_Impl>
74 using TapeData =
typename Tape::ActiveTypeTapeData;
104 return static_cast<Impl&
>(*this);
120 return cast().gradient();
125 cast().gradient() = g;
130 return cast().value();
141 rhs, EventHints::Statement::Passive);
147 template<
typename U = Real,
typename = RealTraits::EnableIfNotPassiveReal<U>>
150 rhs, EventHints::Statement::Passive);
151 Impl::getTape().store(
cast(), rhs);
156 template<
typename Rhs>
159 rhs.
cast().getValue(), EventHints::Statement::Expression);
160 Impl::getTape().store(
cast(), rhs.
cast());
165 template<
typename Rhs,
typename U = Real,
typename = RealTraits::EnableIfNotPassiveReal<U>>
168 rhs.
cast().getValue(), EventHints::Statement::Passive);
169 Impl::getTape().store(
cast(),
Real(rhs));
176 rhs.
cast().getValue(), EventHints::Statement::Copy);
177 Impl::getTape().store(
cast(), rhs);
182 template<
typename Rhs>
185 rhs.
cast().getValue(), EventHints::Statement::Copy);
186 Impl::getTape().store(
cast(), rhs);
219 template<
typename Expr>
221 typename Expr::Real temp;
229#ifndef DOXYGEN_DISABLE
232 template<
typename T_Type>
233 struct RealTraits::DataExtraction<T_Type, ExpressionTraits::EnableIfLhsExpression<T_Type>> {
235 using Type =
CODI_DD(T_Type, CODI_DEFAULT_LHS_EXPRESSION);
237 using Real =
typename Type::Real;
238 using Identifier =
typename Type::Identifier;
239 using TapeData =
typename Type::TapeData;
248 return v.getIdentifier();
253 return v.getTapeData();
263 v.getIdentifier() = identifier;
268 v.getTapeData() = data;
273 template<
typename T_Type>
275 using Type =
CODI_DD(T_Type, CODI_DEFAULT_LHS_EXPRESSION);
281 Type::getTape().registerInput(v);
286 Type::getTape().registerOutput(v);
291 return Type::getTape().registerExternalFunctionOutput(v);
296 template<
typename T_Type>
#define CODI_INLINE
See codi::Config::ForcedInlines.
Definition config.h:469
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:97
Statement
Classify statements.
Definition eventSystem.hpp:65
Traits for everything that can be an expression e.g. codi::RealReverse, a + b, etc....
Definition expressionTraits.hpp:71
typename std::enable_if< IsLhsExpression< Expr >::value, T >::type EnableIfLhsExpression
Enable if wrapper for IsLhsExpression.
Definition expressionTraits.hpp:198
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
ExpressionTraits::EnableIfLhsExpression< Expr, std::istream > & operator>>(std::istream &stream, Expr &v)
Read the primal value from a stream.
Definition lhsExpressionInterface.hpp:220
inlineT const toConst(T &&v)
Constant cast function that works with CUDA.
Definition toConst.hpp:47
static inlineTape & getTape()
Get a reference to the tape which manages this expression.
Definition activeType.hpp:99
static inlinevoid notifyStatementPrimalListeners(Tape &tape, Real const &lhsValue, Identifier const &lhsIdentifier, Real const &newValue, EventHints::Statement statement)
Invoke callbacks for StatementPrimal events.
Definition eventSystem.hpp:264
ExpressionInterface()=default
Constructor.
inlineImpl const & cast() const
Cast to the implementation.
Definition expressionInterface.hpp:76
Identifier & getIdentifier()
Real & value()
Get a reference to the lvalue represented by the expression.
inlineImpl & operator=(Real const &rhs)
Assignment operator for passive values. Calls store on the InternalStatementRecordingTapeInterface.
Definition lhsExpressionInterface.hpp:139
LhsExpressionInterface(LhsExpressionInterface const &other)=default
Constructor.
inlineGradient & gradient()
Get the gradient of this lvalue from the tape.
Definition lhsExpressionInterface.hpp:109
inlinevoid setGradient(Gradient const &g)
Set the gradient of this lvalue in the tape.
Definition lhsExpressionInterface.hpp:124
Real const & value() const
Get a constant reference to the lvalue represented by the expression.
inlineImpl & operator=(LhsExpressionInterface< Real, Gradient, Tape, Rhs > const &rhs)
Assignment operator for lhs expressions. Calls store on the InternalStatementRecordingTapeInterface.
Definition lhsExpressionInterface.hpp:183
TapeData & getTapeData()
Get the data of the tape stored in this lhs expression.
static size_t constexpr LinkCount
Definition lhsExpressionInterface.hpp:195
RealTraits::PassiveReal< Real > PassiveReal
Definition lhsExpressionInterface.hpp:75
TapeData const & getTapeData() const
Get the data of the tape stored in this lhs expression.
typename Tape::Identifier Identifier
Definition lhsExpressionInterface.hpp:73
inlineImpl & operator=(LhsExpressionInterface const &rhs)
Assignment operator for lhs expressions. Calls store on the InternalStatementRecordingTapeInterface.
Definition lhsExpressionInterface.hpp:174
Real Real
Definition lhsExpressionInterface.hpp:66
LhsExpressionInterface()=default
Constructor.
T_Tape Tape
Definition lhsExpressionInterface.hpp:68
inlineImpl & operator=(ExpressionInterface< Real, Rhs > const &rhs)
Assignment operator for expressions. Calls store on the InternalStatementRecordingTapeInterface.
Definition lhsExpressionInterface.hpp:157
ExpressionInterface< Real, T_Impl > Base
Definition lhsExpressionInterface.hpp:71
inlineGradient const & gradient() const
Get the gradient of this lvalue from the tape.
Definition lhsExpressionInterface.hpp:114
inlinevoid init(Real const &newValue, EventHints::Statement statementType)
Definition lhsExpressionInterface.hpp:202
typename Tape::ActiveTypeTapeData TapeData
Definition lhsExpressionInterface.hpp:74
Identifier const & getIdentifier() const
inlineImpl & operator=(PassiveReal const &rhs)
Assignment operator for passive values. Calls store on the InternalStatementRecordingTapeInterface.
Definition lhsExpressionInterface.hpp:148
inlineGradient getGradient() const
Get the gradient of this lvalue from the tape.
Definition lhsExpressionInterface.hpp:119
Gradient Gradient
Definition lhsExpressionInterface.hpp:67
static Tape & getTape()
Get a reference to the tape which manages this expression.
inlinevoid setValue(Real const &v)
Set the primal value of this lvalue.
Definition lhsExpressionInterface.hpp:134
inlineReal const & getValue() const
Get the primal value of this lvalue.
Definition lhsExpressionInterface.hpp:129
T_Impl Impl
Definition lhsExpressionInterface.hpp:69
inlineImpl & cast()
Cast to the implementation.
Definition lhsExpressionInterface.hpp:103
inlineImpl & operator=(ExpressionInterface< typename U::Real, Rhs > const &rhs)
Assignment operator for expressions. Calls store on the InternalStatementRecordingTapeInterface.
Definition lhsExpressionInterface.hpp:166
inlinevoid destroy()
Definition lhsExpressionInterface.hpp:211
Methods that access inner values of aggregated types that contain CoDiPack active types.
Definition realTraits.hpp:233
static inlinestd::string getMathRep()
Get the math symbol of the operation. E.g. + for operators and pow() for functions.
Definition realTraits.hpp:298
Base implementation of AggregatedTypeTraits for aggregated types that can be defined as an array.
Definition realTraits.hpp:308
Tape registration methods for aggregated types that contain CoDiPack active types.
Definition realTraits.hpp:204
T_Type Type
See TapeRegistration.
Definition realTraits.hpp:209
inlinestatic void registerInput(Type &v)
Register all active types of an aggregated type as tape inputs.
inlinestatic void registerOutput(Type &v)
Register all active types of an aggregated type as tape outputs.
typename DataExtraction< Type >::Real Real
See DataExtraction::Real.
Definition realTraits.hpp:211
inlinestatic Real registerExternalFunctionOutput(Type &v)
Register all active types of an aggregated type as external function outputs.