CoDiPack  3.0.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
realToComplexCast.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 <complex>
38
39#include "../../config.h"
40#include "../../misc/macros.hpp"
41#include "../../traits/expressionTraits.hpp"
42#include "../computeExpression.hpp"
43
45namespace codi {
46
47 struct ReduceToReal {};
48
58 template<typename T_ComplexReal>
59 struct OperationRealToComplexCast : public UnaryOperation<T_ComplexReal, OperationRealToComplexCast<T_ComplexReal>> {
60 public:
61
62 using ComplexReal = CODI_DD(T_ComplexReal, std::complex<double>);
64
65 using Real = typename ComplexReal::value_type;
66
68 template<typename Arg>
69 static CODI_INLINE ComplexReal primal(Arg const& arg) {
70 return arg;
71 }
72
74 template<typename Tangent, typename Arg>
75 static CODI_INLINE ComplexReal applyTangentArg(Tangent const& tangent, ComplexReal const& result,
76 Arg const& arg) {
77 CODI_UNUSED(result, arg);
78 return tangent;
79 }
80
82 template<typename Adjoint, typename Arg>
83 static CODI_INLINE Real applyAdjointArg(Adjoint const& adjoint, ComplexReal const& result, Arg const& arg) {
84 CODI_UNUSED(result, arg);
85
86 return adjoint.real();
87 }
88
90 static CODI_INLINE std::string getMathRep() {
91 return "()";
92 }
93 };
94
97 template<typename T_Real, typename T_Arg>
99}
#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
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
inlineauto arg(ExpressionInterface< std::complex< Real >, Arg > const &arg)
Function overload for FUNCTION.
Definition allOperators.hpp:75
ComputeExpression< std::complex< T_Real >, OperationRealToComplexCast, T_Arg > RealToComplexCast
Definition realToComplexCast.hpp:98
Represents an operator or function with an arbitrary number of arguments in the expression tree.
Definition computeExpression.hpp:371
Returns a proxy object for the gradient that implements the operation in the multiplication of the pr...
Definition realToComplexCast.hpp:59
static inlineReal applyAdjointArg(Adjoint const &adjoint, ComplexReal const &result, Arg const &arg)
Definition realToComplexCast.hpp:83
static inlineComplexReal applyTangentArg(Tangent const &tangent, ComplexReal const &result, Arg const &arg)
Definition realToComplexCast.hpp:75
T_ComplexReal ComplexReal
See OperationRealToComplexCast.
Definition realToComplexCast.hpp:62
static inlineComplexReal primal(Arg const &arg)
Definition realToComplexCast.hpp:69
ReduceToReal Jacobian
See OperationRealToComplexCast.
Definition realToComplexCast.hpp:63
typename ComplexReal::value_type Real
Inner type of the complex value.
Definition realToComplexCast.hpp:65
static inlinestd::string getMathRep()
Get the math symbol of the operation. E.g. + for operators and pow() for functions.
Definition realToComplexCast.hpp:90
Placeholder to identify the operation on the Jacobian.
Definition realToComplexCast.hpp:47
Implements ComputeOperation for one argument.
Definition computeExpression.hpp:98