CoDiPack  2.2.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
tagTapeForward.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 "../../expressions/lhsExpressionInterface.hpp"
39#include "../../misc/macros.hpp"
40#include "../../traits/realTraits.hpp"
41#include "../interfaces/gradientAccessTapeInterface.hpp"
42#include "../interfaces/internalStatementRecordingTapeInterface.hpp"
43#include "tagData.hpp"
44#include "tagTapeBase.hpp"
45
47namespace codi {
48
59 template<typename T_Real, typename T_Tag>
61 public GradientAccessTapeInterface<T_Tag, T_Tag>,
62 public TagTapeBase<T_Real, T_Tag, TagData<T_Tag>, TagTapeForward<T_Real, T_Tag>> {
63 public:
64
65 using Real = CODI_DD(T_Real, double);
66 using Tag = CODI_DD(T_Tag, double);
67
69 struct TapeTypes {
71 struct IndexManager {
73 using Index = int;
74 };
75 };
76
80
82
84
85 private:
86
88 Gradient tempGradient;
89
90 public:
91
93 TagTapeForward() : Base(), tempGradient() {}
94
95 /*******************************************************************************/
98
99 static bool constexpr AllowJacobianOptimization = false;
100
102 template<typename Real>
103 void initIdentifier(Real& value, Identifier& identifier) {
104 CODI_UNUSED(value);
105 identifier = Identifier();
106 }
107
109 template<typename Real>
110 void destroyIdentifier(Real& value, Identifier& identifier) {
111 CODI_UNUSED(value, identifier);
112 }
113
115 template<typename Lhs, typename Rhs>
118 typename Base::ValidateTags validate;
120
121 validate.eval(rhs, vi, *this);
122
123 Base::checkLhsError(lhs, rhs.cast().getValue());
124
126
127 if (vi.isActive) {
128 Base::setTag(lhs.cast().getIdentifier().tag);
129 } else {
130 Base::resetTag(lhs.cast().getIdentifier().tag);
131 }
132
133 lhs.cast().value() = rhs.cast().getValue();
134 }
135
137 template<typename Lhs, typename Rhs>
142
144 template<typename Lhs>
146 Base::checkLhsError(lhs, rhs);
147
148 Base::resetTag(lhs.cast().getIdentifier().tag);
149
150 lhs.cast().value() = rhs;
151 }
152
154 /*******************************************************************************/
157
159 void setGradient(Identifier& identifier, Gradient const& gradient) {
161
162 Base::verifyTagAndProperties(identifier.tag, 0.0, identifier.properties);
163 }
164
166 Gradient const& getGradient(Identifier const& identifier) const {
167 Base::verifyTagAndProperties(identifier.tag, 0.0, identifier.properties);
168
169 return tempGradient;
170 }
171
174 Base::verifyTagAndProperties(identifier.tag, 0.0, identifier.properties);
175
176 return tempGradient;
177 }
178
180 Gradient const& gradient(Identifier const& identifier) const {
181 Base::verifyTagAndProperties(identifier.tag, 0.0, identifier.properties);
182
183 return tempGradient;
184 }
185
187 void setGradient(Identifier const& identifier, Gradient const& gradient) = delete;
188
190 Gradient& gradient(Identifier const& identifier) = delete;
191
193 };
194}
#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
void CODI_UNUSED(Args const &...)
Disable unused warnings for an arbitrary number of arguments.
Definition macros.hpp:46
Empty Position with no nested data.
Definition position.hpp:47
Base class for all CoDiPack expressions.
Definition expressionInterface.hpp:59
Impl const & cast() const
Cast to the implementation.
Definition expressionInterface.hpp:75
Allow for a direct access to the gradient information computed by the tape.
Definition gradientAccessTapeInterface.hpp:67
Internal tape interface that is used by active types to trigger the storing of an expression.
Definition internalStatementRecordingTapeInterface.hpp:65
Base class for all CoDiPack lvalue expression.
Definition lhsExpressionInterface.hpp:63
Impl & cast()
Cast to the implementation.
Definition lhsExpressionInterface.hpp:99
EnumBitset< TagFlags > properties
Current properties of the value.
Definition tagData.hpp:62
Tag tag
Current tag of the value.
Definition tagData.hpp:61
Looks at the tags for the expression.
Definition tagTapeBase.hpp:117
Base implementation for tagging tapes.
Definition tagTapeBase.hpp:73
void resetTag(Tag &tag) const
Reset tag on value.
Definition tagTapeBase.hpp:336
void handleError(ValidationIndicator< Real, Tag > &vi) const
Call tag error callback.
Definition tagTapeBase.hpp:306
void setTag(Tag &tag) const
Set tag on value.
Definition tagTapeBase.hpp:331
void verifyTagAndProperties(Tag const &tag, Real const &value, const EnumBitset< TagFlags > &properties) const
Checks if the tag and the properties are correct.
Definition tagTapeBase.hpp:256
void checkLhsError(Real &lhsValue, Identifier &lhsIdentifier, const Real &rhs) const
Check if a property for the lhs value is triggered.
Definition tagTapeBase.hpp:289
Required definition for event system.
Definition tagTapeForward.hpp:71
int Index
Required definition for event system.
Definition tagTapeForward.hpp:73
Required definition for event system.
Definition tagTapeForward.hpp:69
Tape for tagging variables and find errors in the AD workflow.
Definition tagTapeForward.hpp:62
T_Real Real
See TagTapeForward.
Definition tagTapeForward.hpp:65
Gradient & gradient(Identifier const &identifier)=delete
Do not allow.
Gradient const & getGradient(Identifier const &identifier) const
Verify tag.
Definition tagTapeForward.hpp:166
void destroyIdentifier(Real &value, Identifier &identifier)
Do nothing.
Definition tagTapeForward.hpp:110
TagTapeForward()
Constructor.
Definition tagTapeForward.hpp:93
void setGradient(Identifier const &identifier, Gradient const &gradient)=delete
Do not allow.
Gradient & gradient(Identifier &identifier)
Verify tag.
Definition tagTapeForward.hpp:173
void store(LhsExpressionInterface< Real, Gradient, TagTapeForward, Lhs > &lhs, LhsExpressionInterface< Real, Gradient, TagTapeForward, Rhs > const &rhs)
Verify all tags of the rhs and the lhs properties.
Definition tagTapeForward.hpp:138
T_Tag Tag
See TagTapeForward.
Definition tagTapeForward.hpp:66
TagData< Tag > Gradient
See TapeTypesInterface.
Definition tagTapeForward.hpp:77
void setGradient(Identifier &identifier, Gradient const &gradient)
Verify tag.
Definition tagTapeForward.hpp:159
void initIdentifier(Real &value, Identifier &identifier)
Do nothing.
Definition tagTapeForward.hpp:103
void store(LhsExpressionInterface< Real, Gradient, TagTapeForward, Lhs > &lhs, ExpressionInterface< Real, Rhs > const &rhs)
Verify all tags of the rhs and the lhs properties.
Definition tagTapeForward.hpp:116
Gradient const & gradient(Identifier const &identifier) const
Verify tag.
Definition tagTapeForward.hpp:180
void store(LhsExpressionInterface< Real, Gradient, TagTapeForward, Lhs > &lhs, Real const &rhs)
Verify the lhs properties.
Definition tagTapeForward.hpp:145
static bool constexpr AllowJacobianOptimization
Do not allow Jacobian optimization.
Definition tagTapeForward.hpp:99
Gradient Identifier
Same as the gradient type. Tangent data is stored in the active types.
Definition tagTapeForward.hpp:78
RealTraits::PassiveReal< Real > PassiveReal
Basic computation type.
Definition tagTapeForward.hpp:81
void eval(NodeInterface< Node > const &node, Args &&... args)
Start the evaluation of the logic on the given expression.
Definition traversalLogic.hpp:70
Helper class for statement validation.
Definition tagTapeBase.hpp:49
bool isActive
true if an active rhs is detected. tag != 0
Definition tagTapeBase.hpp:50