CoDiPack  3.0.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
jacobianComputationLogic.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 <type_traits>
38#include <utility>
39
40#include "../../../config.h"
42#include "../../../traits/expressionTraits.hpp"
43#include "../../constantExpression.hpp"
44#include "../traversalLogic.hpp"
45
47namespace codi {
48
53 template<typename T_Impl>
54 struct JacobianComputationLogic : public TraversalLogic<T_Impl> {
55 public:
56
58
59 /*******************************************************************************/
62
64 template<typename Node, typename Jacobian, typename... Args>
65 void handleJacobianOnActive(Node const& node, Jacobian jacobian, Args&&... args);
66
68 /*******************************************************************************/
71
73 template<typename Node, typename Jacobian, typename... Args>
75 Args&&... args) {
76 cast().handleJacobianOnActive(node, jacobian, std::forward<Args>(args)...);
77 }
78
80
84 template<size_t ChildNumber, typename Child, typename Root, typename Jacobian, typename... Args>
85 CODI_INLINE void link(Child const& child, Root const& root, Jacobian const& jacobian, Args&&... args) {
86 auto curJacobian = root.template applyAdjoint<ChildNumber>(jacobian);
87 cast().toNode(child, curJacobian, std::forward<Args>(args)...);
88 }
89
91 template<size_t ChildNumber, typename Real, template<typename> class ConvOp, typename Root, typename Jacobian,
92 typename... Args>
93 CODI_INLINE void link(ConstantExpression<Real, ConvOp> const& child, Root const& root, Jacobian const& jacobian,
94 Args&&... args) {
95 CODI_UNUSED(child, root, jacobian, args...);
96
97 // Do not compute Jacobian for constant arguments.
98 }
99
101
102 private:
103
104 CODI_INLINE Impl& cast() {
105 return static_cast<Impl&>(*this);
106 }
107 };
108}
#define CODI_INLINE
See codi::Config::ForcedInlines.
Definition config.h:469
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:96
#define CODI_T(...)
Abbreviation for CODI_TEMPLATE.
Definition macros.hpp:116
typename std::enable_if< IsLhsExpression< Expr >::value, T >::type EnableIfLhsExpression
Enable if wrapper for IsLhsExpression.
Definition expressionTraits.hpp:183
CoDiPack - Code Differentiation Package.
Definition codi.hpp:94
inlinevoid CODI_UNUSED(Args const &...)
Disable unused warnings for an arbitrary number of arguments.
Definition macros.hpp:54
Represents constant values in the expression tree.
Definition constantExpression.hpp:78
Definition jacobianComputationLogic.hpp:54
inlinevoid link(ConstantExpression< Real, ConvOp > const &child, Root const &root, Jacobian const &jacobian, Args &&... args)
Specialization for ConstantExpressions. Will not compute Jacobians for these links.
Definition jacobianComputationLogic.hpp:93
void handleJacobianOnActive(Node const &node, Jacobian jacobian, Args &&... args)
Called for leaf nodes which implement LhsExpressionInterface.
inlinevoid link(Child const &child, Root const &root, Jacobian const &jacobian, Args &&... args)
Definition jacobianComputationLogic.hpp:85
T_Impl Impl
See JacobianComputationLogic.
Definition jacobianComputationLogic.hpp:57
inlineExpressionTraits::EnableIfLhsExpression< Node > leaf(Node const &node, Jacobian jacobian, Args &&... args)
Called for all leaf nodes in the expression.
Definition jacobianComputationLogic.hpp:74
Default implementation of the Jacobian interface.
Definition jacobian.hpp:60
Traversal of CoDiPack expressions.
Definition traversalLogic.hpp:57
inlinevoid node(Node const &node, Args &&... args)
Called for each node in the expression.
Definition traversalLogic.hpp:87