CoDiPack  3.0.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
directStatementEvaluator.hpp
1/*
2 * CoDiPack, a Code Differentiation Package
3 *
4 * Copyright (C) 2015-2025 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 <algorithm>
38#include <functional>
39#include <type_traits>
40
41#include "../../expressions/activeType.hpp"
42#include "../../misc/macros.hpp"
43#include "../misc/assignStatement.hpp"
44#include "statementEvaluatorInterface.hpp"
45
47namespace codi {
48
53 public:
54
55 using Handle = void*;
56
57 std::array<Handle, (size_t)StatementCall::N_Elements> funcs;
58
60 template<typename... Args>
61 PrimalTapeStatementFunctions(Args... args) : funcs{args...} {}
62 };
63
66 template<typename Generator, typename Stmt>
68 public:
69
73
75 template<StatementCall... types>
77 using Handle = typename PrimalTapeStatementFunctions::Handle;
78
80 reinterpret_cast<Handle>(Generator::template StatementCallGenerator<types, Stmt>::evaluate)...);
81 }
82 };
83
84 template<typename Generator, typename Stmt>
87
97 public:
98
99 /*******************************************************************************/
102
104
106 template<StatementCall type, typename Tape, typename... Args>
107 static void call(Handle const& h, Args&&... args) {
109 using CallGen = typename Tape::template StatementCallGenerator<type, Stmt>;
110
111 using Function = decltype(&CallGen::evaluate);
112
113 ((Function)h->funcs[(size_t)type])(std::forward<Args>(args)...);
114 }
115
117 template<typename Tape, typename Generator, typename Stmt>
121
123 };
124}
CoDiPack - Code Differentiation Package.
Definition codi.hpp:94
StatementCall
Defines all the operations which can be evaluated on a statement by a tape.
Definition statementEvaluatorTapeInterface.hpp:45
@ N_Elements
Number of elements.
Definition statementEvaluatorTapeInterface.hpp:52
Represents a concrete lvalue in the CoDiPack expression tree.
Definition activeType.hpp:52
Definition assignStatement.hpp:50
Definition directStatementEvaluator.hpp:67
static PrimalTapeStatementFunctions gen()
Generates the data for the static store.
Definition directStatementEvaluator.hpp:76
static PrimalTapeStatementFunctions const staticStore
Definition directStatementEvaluator.hpp:72
Full evaluation of the expression in the function handle. Storing in static context.
Definition directStatementEvaluator.hpp:96
PrimalTapeStatementFunctions const * Handle
Pointer to static storage location.
Definition directStatementEvaluator.hpp:103
static void call(Handle const &h, Args &&... args)
Definition directStatementEvaluator.hpp:107
static Handle createHandle()
Definition directStatementEvaluator.hpp:118
Data required for all possible handle calls.
Definition directStatementEvaluator.hpp:52
PrimalTapeStatementFunctions(Args... args)
Constructor.
Definition directStatementEvaluator.hpp:61
void * Handle
Function pointer.
Definition directStatementEvaluator.hpp:55
std::array< Handle,(size_t) StatementCall::N_Elements > funcs
Array for the function handles.
Definition directStatementEvaluator.hpp:57
Creation of handles for the evaluation of expressions in a context where the expression type is not a...
Definition statementEvaluatorInterface.hpp:103