CoDiPack  2.2.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
unaryExpression.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 "expressionInterface.hpp"
40#include "logic/compileTimeTraversalLogic.hpp"
41#include "logic/nodeInterface.hpp"
42#include "logic/traversalLogic.hpp"
43
45namespace codi {
46
54 template<typename T_Real>
56 public:
57
58 using Real = CODI_DD(T_Real, double);
59
63 template<typename Arg>
64 static CODI_INLINE Real primal(Arg const& arg);
65
69 template<typename Arg>
70 static CODI_INLINE Real gradient(Arg const& arg, Real const& result);
71 };
72
82 template<typename T_Real, typename T_Arg, template<typename> class T_Operation>
83 struct UnaryExpression : public ExpressionInterface<T_Real, UnaryExpression<T_Real, T_Arg, T_Operation> > {
84 public:
85
86 using Real = CODI_DD(T_Real, double);
88 using Operation = CODI_DD(CODI_T(T_Operation<Real>), CODI_T(UnaryOperation<Real>));
89
90 using ActiveResult = typename Arg::ActiveResult;
91
92 typename Arg::StoreAs arg;
94
96 template<typename RealArg>
99
100 /*******************************************************************************/
103
105
107 CODI_INLINE Real const& getValue() const {
108 return result;
109 }
110
112 template<size_t argNumber>
114 return Operation::gradient(arg.getValue(), result);
115 }
116
118 /*******************************************************************************/
121
122 static bool constexpr EndPoint = false;
123
125 template<typename Logic, typename... Args>
126 CODI_INLINE void forEachLink(TraversalLogic<Logic>& logic, Args&&... args) const {
127 logic.cast().template link<0>(arg, *this, std::forward<Args>(args)...);
128 }
129
131 template<typename CompileTimeLogic, typename... Args>
132 CODI_INLINE static typename CompileTimeLogic::ResultType constexpr forEachLinkConstExpr(Args&&... args) {
133 return CompileTimeLogic::template link<0, Arg, UnaryExpression>(std::forward<Args>(args)...);
134 }
135
137 };
138}
#define CODI_INLINE
See codi::Config::ForcedInlines.
Definition config.h:457
#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
CoDiPack - Code Differentiation Package.
Definition codi.hpp:90
Base class for all CoDiPack expressions.
Definition expressionInterface.hpp:59
Impl const & cast() const
Cast to the implementation.
Definition expressionInterface.hpp:75
Traversal of CoDiPack expressions.
Definition traversalLogic.hpp:56
Impl & cast()
Cast to the implementation.
Definition traversalLogic.hpp:62
Represents an operator with one argument in the expression tree.
Definition unaryExpression.hpp:83
void forEachLink(TraversalLogic< Logic > &logic, Args &&... args) const
Definition unaryExpression.hpp:126
T_Arg Arg
See UnaryExpression.
Definition unaryExpression.hpp:87
Real getJacobian() const
Definition unaryExpression.hpp:113
T_Operation< Real > Operation
See UnaryExpression.
Definition unaryExpression.hpp:88
UnaryExpression(ExpressionInterface< RealArg, Arg > const &arg)
Constructor.
Definition unaryExpression.hpp:97
static CompileTimeLogic::ResultType constexpr forEachLinkConstExpr(Args &&... args)
Definition unaryExpression.hpp:132
static bool constexpr EndPoint
If this expression is handled as a leaf in the tree.
Definition unaryExpression.hpp:122
typename Arg::ActiveResult ActiveResult
See ExpressionInterface.
Definition unaryExpression.hpp:90
Arg::StoreAs arg
Argument of the expression.
Definition unaryExpression.hpp:92
Real result
Precomputed result.
Definition unaryExpression.hpp:93
Real const & getValue() const
Compute the primal value that is usually evaluated by the statement/expression.
Definition unaryExpression.hpp:107
T_Real Real
See UnaryExpression.
Definition unaryExpression.hpp:86
Interface for implementing the logic for a UnaryExpression.
Definition unaryExpression.hpp:55
static Real primal(Arg const &arg)
T_Real Real
See UnaryOperation.
Definition unaryExpression.hpp:58
static Real gradient(Arg const &arg, Real const &result)