CoDiPack  2.2.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
primalEvaluationTapeInterface.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 "../data/position.hpp"
40#include "positionalEvaluationTapeInterface.hpp"
41
43namespace codi {
44
69 template<typename T_Real, typename T_Identifier, typename T_Position>
71 public:
72
73 using Real = CODI_DD(T_Real, double);
74 using Identifier = CODI_DD(T_Identifier, int);
75 using Position = CODI_DD(T_Position, EmptyPosition);
76
77 /*******************************************************************************/
79
80 static bool constexpr HasPrimalValues = CODI_UNDEFINED_VALUE;
81 static bool constexpr RequiresPrimalRestore =
83
85 void evaluatePrimal(Position const& start, Position const& end);
86
89
90 void setPrimal(Identifier const& identifier, Real const& gradient);
91 Real const& getPrimal(Identifier const& identifier) const;
92
93 Real& primal(Identifier const& identifier);
94 Real const& primal(Identifier const& identifier) const;
95
97 void revertPrimals(Position const& pos);
98 };
99}
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:94
#define CODI_UNDEFINED_VALUE
Used in interface declarations for variables that have to be defined in the specializations.
Definition macros.hpp:117
CoDiPack - Code Differentiation Package.
Definition codi.hpp:90
Empty Position with no nested data.
Definition position.hpp:47
Reverse AD evaluation for parts of a recorded tape.
Definition positionalEvaluationTapeInterface.hpp:59
Perform a primal reevaluation of the tape.
Definition primalEvaluationTapeInterface.hpp:70
static bool constexpr RequiresPrimalRestore
True if the primal state changes during a reverse or forward evaluation.
Definition primalEvaluationTapeInterface.hpp:81
void setPrimal(Identifier const &identifier, Real const &gradient)
Set primal value.
T_Position Position
See PrimalEvaluationTapeInterface.
Definition primalEvaluationTapeInterface.hpp:75
Real & primal(Identifier const &identifier)
Writable reference to primal value.
void evaluatePrimal()
Perform a full (forward) reevaluation of the primals in the tape.
static bool constexpr HasPrimalValues
True if the tape has primal values.
Definition primalEvaluationTapeInterface.hpp:80
Real const & getPrimal(Identifier const &identifier) const
Get primal value.
T_Real Real
See PrimalEvaluationTapeInterface.
Definition primalEvaluationTapeInterface.hpp:73
void evaluatePrimal(Position const &start, Position const &end)
Perform a partly (forward) reevaluation of the primals in the tape. It has to hold start <= end.
T_Identifier Identifier
See PrimalEvaluationTapeInterface.
Definition primalEvaluationTapeInterface.hpp:74
Real const & primal(Identifier const &identifier) const
Read only reference to primal value.
void revertPrimals(Position const &pos)
Revert the primals to the state indicated by pos.