CoDiPack  2.3.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
jacobianBaseReaderWriter.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 "commonReaderWriterBase.hpp"
39
41namespace codi {
47 template<typename T_Type>
49 using Type = CODI_DD(T_Type, CODI_DEFAULT_LHS_EXPRESSION);
50 using Tape = typename Type::Tape;
51 using Identifier = typename Type::Identifier;
52 using Real = typename Type::Real;
53
55
57 void registerStatement(Identifier const& lhsIdentifier, Config::ArgumentSize const& nArgs,
58 std::vector<Identifier> const& rhsIdentifiers, std::vector<Real> const& rhsJacobians,
59 Identifier& lowestIndex, bool& isFirstIdentifier) {
60 // Update the lowest identifier for the Linear case. The lowest identifier will be the first identifier.
61 if (isFirstIdentifier && Tape::TapeTypes::IsLinearIndexHandler) {
62 lowestIndex = lhsIdentifier - 1;
63 isFirstIdentifier = false;
64 }
65
66 // Record the lhsIdentifier and the number of arguments of the current statement on the tape.
67 Identifier lhsIdentifierWithOffset = lhsIdentifier - lowestIndex;
68
69 // Store the rhsIdentifiers and rhsJacobians for the current statement.
70 std::vector<Identifier> rhsIdentifierWithOffset;
71
73 // TODO.
74 } else if (nArgs == Config::StatementInputTag) CODI_Unlikely {
75 // Do nothing.
76 } else CODI_Likely {
77 for (size_t rhsCount = 0; rhsCount < nArgs; rhsCount++) {
78 rhsIdentifierWithOffset.push_back(rhsIdentifiers[rhsCount] - lowestIndex);
79 }
80 }
81
82 this->tape.createStatementManual(0, lhsIdentifierWithOffset, nArgs, rhsJacobians.data(),
83 rhsIdentifierWithOffset.data());
84 }
85 };
86}
#define CODI_Unlikely
Declare unlikely evaluation of an execution path.
Definition config.h:399
#define CODI_Likely
Declare likely evaluation of an execution path.
Definition config.h:397
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:94
size_t constexpr StatementLowLevelFunctionTag
Statement tag for low level functions.
Definition config.h:126
uint8_t ArgumentSize
Type for the number of arguments in statements.
Definition config.h:117
size_t constexpr StatementInputTag
Tag for statements that are inputs. Used in linear index management context.
Definition config.h:123
CoDiPack - Code Differentiation Package.
Definition codi.hpp:91
Used to restore the IO from the "filename"IO.dat or "filename"IO.txt files. Also provides the get met...
Definition commonReaderWriterBase.hpp:143
Tape tape
The newly resorted tape.
Definition commonReaderWriterBase.hpp:153
Used to register a statement for a Jacobian tape.
Definition jacobianBaseReaderWriter.hpp:48
typename Type::Identifier Identifier
See TapeReaderInterface.
Definition jacobianBaseReaderWriter.hpp:51
void registerStatement(Identifier const &lhsIdentifier, Config::ArgumentSize const &nArgs, std::vector< Identifier > const &rhsIdentifiers, std::vector< Real > const &rhsJacobians, Identifier &lowestIndex, bool &isFirstIdentifier)
Constructor.
Definition jacobianBaseReaderWriter.hpp:57
typename Type::Real Real
See TapeReaderInterface.
Definition jacobianBaseReaderWriter.hpp:52
T_Type Type
See TapeReaderInterface.
Definition jacobianBaseReaderWriter.hpp:49
typename Type::Tape Tape
See TapeReaderInterface.
Definition jacobianBaseReaderWriter.hpp:50