CoDiPack  2.2.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
constructStaticContext.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/reverseTapeInterface.hpp"
40#include "../../traits/expressionTraits.hpp"
41#include "../binaryExpression.hpp"
42#include "../constantExpression.hpp"
43#include "../expressionInterface.hpp"
44#include "../static/staticContextActiveType.hpp"
45#include "../unaryExpression.hpp"
46#include "nodeInterface.hpp"
47
49namespace codi {
50
69 template<typename T_Rhs, typename T_Tape, size_t T_primalValueOffset, size_t T_constantValueOffset, typename = void>
71 public:
72
74 using Tape = CODI_DD(
76 static constexpr size_t primalValueOffset =
77 CODI_DD(T_primalValueOffset, 0);
78 static constexpr size_t constantValueOffset =
79 CODI_DD(T_constantValueOffset, 0);
80
81 using Real = typename Tape::Real;
82 using Identifier = typename Tape::Identifier;
83 using PassiveReal = typename Tape::PassiveReal;
84
87
93 static ResultType construct(Real* primalVector, Identifier const* const identifiers,
94 PassiveReal const* const constantData);
95 };
96
97#ifndef DOXYGEN_DISABLE
98
99 template<typename T_Rhs, typename T_Tape, size_t T_primalValueOffset, size_t T_constantValueOffset>
100 struct ConstructStaticContextLogic<T_Rhs, T_Tape, T_primalValueOffset, T_constantValueOffset,
101 ExpressionTraits::EnableIfLhsExpression<T_Rhs>> {
102 public:
103
104 using Rhs = T_Rhs;
105 using Tape = T_Tape;
106 static constexpr size_t primalValueOffset = T_primalValueOffset;
107 static constexpr size_t constantValueOffset = T_constantValueOffset;
108
109 using Real = typename Tape::Real;
110 using Identifier = typename Tape::Identifier;
111 using PassiveReal = typename Tape::PassiveReal;
112
115
117 static ResultType construct(Real* primalVector, Identifier const* const identifiers,
118 PassiveReal const* const constantData) {
119 CODI_UNUSED(constantData);
120
121 Identifier const identifier = identifiers[primalValueOffset];
122 Real const primal = primalVector[identifier];
123
124 return ResultType(primal, identifier);
125 }
126 };
127
128 template<typename T_Rhs, typename T_Tape, size_t T_primalValueOffset, size_t T_constantValueOffset>
129 struct ConstructStaticContextLogic<T_Rhs, T_Tape, T_primalValueOffset, T_constantValueOffset,
130 ExpressionTraits::EnableIfConstantExpression<T_Rhs>> {
131 public:
132
133 using Rhs = T_Rhs;
134 using Tape = T_Tape;
135 static constexpr size_t primalValueOffset = T_primalValueOffset;
136 static constexpr size_t constantValueOffset = T_constantValueOffset;
137
138 using Real = typename Tape::Real;
139 using Identifier = typename Tape::Identifier;
140 using PassiveReal = typename Tape::PassiveReal;
141
143 using ResultType = ConstantExpression<typename Rhs::Real>;
144
146 static ResultType construct(Real* primalVector, Identifier const* const identifiers,
147 PassiveReal const* const constantData) {
148 CODI_UNUSED(primalVector, identifiers);
149
150 using ConversionOperator = typename Rhs::template ConversionOperator<PassiveReal>;
151
152 return ResultType(ConversionOperator::fromDataStore(constantData[constantValueOffset]));
153 }
154 };
155
156 template<typename T_Real, typename T_ArgA, typename T_ArgB, template<typename> class T_Operation, typename T_Tape,
157 size_t T_primalValueOffset, size_t T_constantValueOffset>
158 struct ConstructStaticContextLogic<BinaryExpression<T_Real, T_ArgA, T_ArgB, T_Operation>, T_Tape, T_primalValueOffset,
159 T_constantValueOffset> {
160 public:
161
162 using OpReal = T_Real;
163 using ArgA = T_ArgA;
164 using ArgB = T_ArgB;
165 template<typename T>
166 using Operation = T_Operation<T>;
167 using Tape = T_Tape;
168 static constexpr size_t primalValueOffset = T_primalValueOffset;
169 static constexpr size_t constantValueOffset = T_constantValueOffset;
170
171 using Real = typename Tape::Real;
172 using Identifier = typename Tape::Identifier;
173 using PassiveReal = typename Tape::PassiveReal;
174
176 using ArgAConstructor = ConstructStaticContextLogic<ArgA, Tape, primalValueOffset, constantValueOffset>;
177 using ArgAMod = typename ArgAConstructor::ResultType;
178
180 static size_t constexpr primalValueOffsetArgB =
182 static size_t constexpr constantValueOffsetArgB =
184 using ArgBConstructor = ConstructStaticContextLogic<ArgB, Tape, primalValueOffsetArgB, constantValueOffsetArgB>;
185 using ArgBMod = typename ArgBConstructor::ResultType;
186
187 using ResultType = BinaryExpression<OpReal, ArgAMod, ArgBMod, Operation>;
188
189 static ResultType construct(Real* primalVector, Identifier const* const identifiers,
190 PassiveReal const* const constantData) {
191 return ResultType(ArgAConstructor::construct(primalVector, identifiers, constantData),
192 ArgBConstructor::construct(primalVector, identifiers, constantData));
193 }
194 };
195
196 template<typename T_Real, typename T_Arg, template<typename> class T_Operation, typename T_Tape,
197 size_t T_primalValueOffset, size_t T_constantValueOffset>
198 struct ConstructStaticContextLogic<UnaryExpression<T_Real, T_Arg, T_Operation>, T_Tape, T_primalValueOffset,
199 T_constantValueOffset> {
200 public:
201
202 using OpReal = T_Real;
203 using Arg = T_Arg;
204 template<typename T>
205 using Operation = T_Operation<T>;
206 using Tape = T_Tape;
207 static constexpr size_t primalValueOffset = T_primalValueOffset;
208 static constexpr size_t constantValueOffset = T_constantValueOffset;
209
210 using Real = typename Tape::Real;
211 using Identifier = typename Tape::Identifier;
212 using PassiveReal = typename Tape::PassiveReal;
213
215 using ArgConstructor = ConstructStaticContextLogic<Arg, Tape, primalValueOffset, constantValueOffset>;
216 using ArgMod = typename ArgConstructor::ResultType;
217
218 using ResultType = UnaryExpression<OpReal, ArgMod, Operation>;
219
220 static ResultType construct(Real* primalVector, Identifier const* const identifiers,
221 PassiveReal const* const constantData) {
222 return ResultType(ArgConstructor::construct(primalVector, identifiers, constantData));
223 }
224 };
225#endif
226}
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:94
#define CODI_T(...)
Abbreviation for CODI_TEMPLATE.
Definition macros.hpp:111
typename std::enable_if< IsConstantExpression< Expr >::value, T >::type EnableIfConstantExpression
Enable if wrapper for IsConstantExpression.
Definition expressionTraits.hpp:156
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
Represents a concrete lvalue in the CoDiPack expression tree.
Definition activeType.hpp:52
Helper class for the construction of an expression in a different context.
Definition constructStaticContext.hpp:70
T_Rhs ResultType
The resulting expression type after all nodes are replaced.
Definition constructStaticContext.hpp:86
static ResultType construct(Real *primalVector, Identifier const *const identifiers, PassiveReal const *const constantData)
Perform the construction.
typename Tape::PassiveReal PassiveReal
Basic computation type.
Definition constructStaticContext.hpp:83
T_Rhs Rhs
See ConstructStaticContextLogic.
Definition constructStaticContext.hpp:73
typename Tape::Real Real
See TapeTypesInterface.
Definition constructStaticContext.hpp:81
static constexpr size_t constantValueOffset
See ConstructStaticContextLogic.
Definition constructStaticContext.hpp:78
typename Tape::Identifier Identifier
See TapeTypesInterface.
Definition constructStaticContext.hpp:82
static constexpr size_t primalValueOffset
See ConstructStaticContextLogic.
Definition constructStaticContext.hpp:76
T_Tape Tape
See ConstructStaticContextLogic.
Definition constructStaticContext.hpp:74
Base class for all CoDiPack expressions.
Definition expressionInterface.hpp:59
static size_t constexpr value
See NumberOfActiveTypeArguments.
Definition expressionTraits.hpp:198
static size_t constexpr value
See NumberOfConstantTypeArguments.
Definition expressionTraits.hpp:224
Minimum tape interface for a working reverse tape implementation.
Definition reverseTapeInterface.hpp:78
Replacement type of LhsExpressionInterface types in ConstructStaticContext.
Definition staticContextActiveType.hpp:56