CoDiPack  2.3.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
73 static CODI_INLINE std::string getMathRep();
74 };
75
85 template<typename T_Real, typename T_Arg, template<typename> class T_Operation>
86 struct UnaryExpression : public ExpressionInterface<T_Real, UnaryExpression<T_Real, T_Arg, T_Operation> > {
87 public:
88
89 using Real = CODI_DD(T_Real, double);
91 using Operation = CODI_DD(CODI_T(T_Operation<Real>), CODI_T(UnaryOperation<Real>));
92
93 using ActiveResult = typename Arg::ActiveResult;
94
95 typename Arg::StoreAs arg;
97
99 template<typename RealArg>
102
103 /*******************************************************************************/
106
108
110 CODI_INLINE Real const& getValue() const {
111 return result;
112 }
113
115 template<size_t argNumber>
117 return Operation::gradient(arg.getValue(), result);
118 }
119
121 /*******************************************************************************/
124
125 static bool constexpr EndPoint = false;
126
128 template<typename Logic, typename... Args>
129 CODI_INLINE void forEachLink(TraversalLogic<Logic>& logic, Args&&... args) const {
130 logic.cast().template link<0>(arg, *this, std::forward<Args>(args)...);
131 }
132
134 CODI_INLINE std::string getMathRep() const {
135 return Operation::getMathRep();
136 }
137
139 template<typename CompileTimeLogic, typename... Args>
140 CODI_INLINE static typename CompileTimeLogic::ResultType constexpr forEachLinkConstExpr(Args&&... args) {
141 return CompileTimeLogic::template link<0, Arg, UnaryExpression>(std::forward<Args>(args)...);
142 }
143
145 };
146}
#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:91
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:86
std::string getMathRep() const
Get the math symbol of the unary operation. E.g. sin() for functions.
Definition unaryExpression.hpp:134
void forEachLink(TraversalLogic< Logic > &logic, Args &&... args) const
Definition unaryExpression.hpp:129
T_Arg Arg
See UnaryExpression.
Definition unaryExpression.hpp:90
Real getJacobian() const
Definition unaryExpression.hpp:116
T_Operation< Real > Operation
See UnaryExpression.
Definition unaryExpression.hpp:91
UnaryExpression(ExpressionInterface< RealArg, Arg > const &arg)
Constructor.
Definition unaryExpression.hpp:100
static CompileTimeLogic::ResultType constexpr forEachLinkConstExpr(Args &&... args)
Definition unaryExpression.hpp:140
static bool constexpr EndPoint
If this expression is handled as a leaf in the tree.
Definition unaryExpression.hpp:125
typename Arg::ActiveResult ActiveResult
See ExpressionInterface.
Definition unaryExpression.hpp:93
Arg::StoreAs arg
Argument of the expression.
Definition unaryExpression.hpp:95
Real result
Precomputed result.
Definition unaryExpression.hpp:96
Real const & getValue() const
Compute the primal value that is usually evaluated by the statement/expression.
Definition unaryExpression.hpp:110
T_Real Real
See UnaryExpression.
Definition unaryExpression.hpp:89
Interface for implementing the logic for a UnaryExpression.
Definition unaryExpression.hpp:55
static Real primal(Arg const &arg)
static std::string getMathRep()
Get the math symbol of the unary operation. E.g. sin() for functions.
T_Real Real
See UnaryOperation.
Definition unaryExpression.hpp:58
static Real gradient(Arg const &arg, Real const &result)