CoDiPack  3.0.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
assignmentOperators.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 "../config.h"
38#include "../misc/macros.hpp"
39#include "lhsExpressionInterface.hpp"
40
42namespace codi {
43
45 template<typename T_Real, bool T_JacobianOptimization, typename T_Impl>
47 public:
48
49 using Real = CODI_DD(T_Real, double);
50 static bool constexpr JacobianOptimization =
51 CODI_DD(T_JacobianOptimization, false);
52 using Impl = CODI_DD(T_Impl,
54
56
59 cast() = (cast() + rhs);
60 return cast();
61 }
62
65 cast() = (cast() - rhs);
66 return cast();
67 }
68
69 private:
70
72 CODI_INLINE Impl& cast() {
73 return static_cast<Impl&>(*this);
74 }
75 };
76
78 template<typename T_Real, typename T_Impl>
80 public:
81
82 using Real = CODI_DD(T_Real, double);
83 static bool constexpr JacobianOptimization = true;
84 using Impl = CODI_DD(T_Impl,
86
88
91 cast().value() += rhs;
92 return cast();
93 }
94
97 cast().value() -= rhs;
98 return cast();
99 }
100
101 private:
102
104 CODI_INLINE Impl& cast() {
105 return static_cast<Impl&>(*this);
106 }
107 };
108
118 template<typename T_Real, bool T_JacobianOptimization, typename T_Impl>
120 : public AssignmentOperatorsPassiveJacobianOptimization<T_Real, T_JacobianOptimization, T_Impl> {
121 public:
122
123 using Real = CODI_DD(T_Real, double);
124 static bool constexpr JacobianOptimization = CODI_DD(T_JacobianOptimization, true);
125 using Impl = CODI_DD(T_Impl,
127
128 using Base =
133 /// Operator += for expressions.
134 template<typename Rhs>
136 return cast() = (cast() + rhs);
140 template<typename Rhs>
142 return cast() = (cast() - rhs);
143 }
144
146 template<typename Rhs>
148 return cast() = (cast() * rhs);
149 }
150
152 template<typename Rhs>
154 return cast() = (cast() / rhs);
155 }
156
157 using Base::operator+=;
158 using Base::operator-=;
159
162 return cast() = (cast() * rhs);
163 }
164
167 return cast() = (cast() / rhs);
168 }
169
170 private:
171
173 CODI_INLINE Impl& cast() {
174 return static_cast<Impl&>(*this);
175 }
176 };
177}
#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 TraitsImplementation< Type >::PassiveReal PassiveReal
The original computation type that was used in the application.
Definition realTraits.hpp:123
CoDiPack - Code Differentiation Package.
Definition codi.hpp:94
ResolveSelf< complex< codi::ActiveType< T_Tape > >, ActiveComplex > Impl
Definition stdComplex.hpp:111
RealTraits::PassiveReal< Real > PassiveReal
Passive value type of the real.
Definition aggregatedActiveType.hpp:173
T_Real Real
See AssignmentOperators.
Definition assignmentOperators.hpp:82
T_Impl Impl
See AssignmentOperators.
Definition assignmentOperators.hpp:84
inlineImpl & operator+=(PassiveReal const &rhs)
Operator += for passive values.
Definition assignmentOperators.hpp:90
RealTraits::PassiveReal< Real > PassiveReal
Basic computation type.
Definition assignmentOperators.hpp:87
inlineImpl & operator-=(PassiveReal const &rhs)
Operator -= for passive values.
Definition assignmentOperators.hpp:96
static bool constexpr JacobianOptimization
See AssignmentOperators.
Definition assignmentOperators.hpp:83
Default implementations for the passive += and -= operators.
Definition assignmentOperators.hpp:46
inlineImpl & operator-=(PassiveReal const &rhs)
Operator -= for passive values.
Definition assignmentOperators.hpp:64
T_Real Real
See AssignmentOperators.
Definition assignmentOperators.hpp:49
T_Impl Impl
See AssignmentOperators.
Definition assignmentOperators.hpp:52
RealTraits::PassiveReal< Real > PassiveReal
Basic computation type.
Definition assignmentOperators.hpp:55
static bool constexpr JacobianOptimization
See AssignmentOperators.
Definition assignmentOperators.hpp:50
inlineImpl & operator+=(PassiveReal const &rhs)
Operator += for passive values.
Definition assignmentOperators.hpp:58
Provides assignment operators for LhsExpressionInterface implementations.
Definition assignmentOperators.hpp:120
RealTraits::PassiveReal< Real > PassiveReal
Definition assignmentOperators.hpp:131
inlineImpl & operator/=(PassiveReal const &rhs)
Operator /= for passive values.
Definition assignmentOperators.hpp:166
T_Real Real
See AssignmentOperators.
Definition assignmentOperators.hpp:123
inlineImpl & operator*=(PassiveReal const &rhs)
Operator *= for passive values.
Definition assignmentOperators.hpp:161
inlineImpl & operator+=(ExpressionInterface< Real, Rhs > const &rhs)
Operator += for expressions.
Definition assignmentOperators.hpp:135
inlineImpl & operator-=(ExpressionInterface< Real, Rhs > const &rhs)
Operator -= for expressions.
Definition assignmentOperators.hpp:141
T_Impl Impl
See AssignmentOperators.
Definition assignmentOperators.hpp:125
static bool constexpr JacobianOptimization
Definition assignmentOperators.hpp:124
inlineImpl & operator/=(ExpressionInterface< Real, Rhs > const &rhs)
Operator /= for expressions.
Definition assignmentOperators.hpp:153
inlineImpl & operator*=(ExpressionInterface< Real, Rhs > const &rhs)
Operator *= for expressions.
Definition assignmentOperators.hpp:147
AssignmentOperatorsPassiveJacobianOptimization< T_Real, T_JacobianOptimization, T_Impl > Base
Definition assignmentOperators.hpp:128
Base class for all CoDiPack expressions.
Definition expressionInterface.hpp:60
Base class for all CoDiPack lvalue expression.
Definition lhsExpressionInterface.hpp:63