CoDiPack  2.2.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
expressionInterface.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 <iostream>
38
39#include "../config.h"
40#include "../misc/macros.hpp"
41#include "../traits/expressionTraits.hpp"
42#include "../traits/realTraits.hpp"
43#include "logic/nodeInterface.hpp"
44
46namespace codi {
47
58 template<typename T_Real, typename T_Impl>
59 struct ExpressionInterface : public NodeInterface<T_Impl> {
60 public:
61
62 using Real = CODI_DD(T_Real, double);
63 using Impl = CODI_DD(T_Impl, ExpressionInterface);
64
67
70
73
75 CODI_INLINE Impl const& cast() const {
76 return static_cast<Impl const&>(*this);
77 }
78
79#if CODI_ImplicitConversion
81 CODI_INLINE operator const Real() const {
82 Warning::implicitCast<Config::ImplicitConversionWarning>();
83
84 return cast().getValue();
85 }
86#endif
87
88 /*******************************************************************************/
91
93
95 CODI_INLINE Real const getValue() const;
96
100 template<size_t argNumber>
104
105 private:
106 ExpressionInterface& operator=(ExpressionInterface const&) = delete;
107 };
108
109#ifndef DOXYGEN_DISABLE
110 template<typename T_Type>
111 struct RealTraits::TraitsImplementation<T_Type, ExpressionTraits::EnableIfExpression<T_Type>> {
112 public:
113
115 using Real = typename Type::Real;
116
118
119 static int constexpr MaxDerivativeOrder = 1 + RealTraits::MaxDerivativeOrder<Real>();
120
121 static CODI_INLINE PassiveReal const& getPassiveValue(Type const& v) {
122 return RealTraits::getPassiveValue(v.getValue());
123 }
124 };
125#endif
126
128 template<typename Expr>
129 ExpressionTraits::EnableIfExpression<Expr, std::ostream>& operator<<(std::ostream& out, Expr const& v) {
130 out << v.getValue();
131
132 return out;
133 }
134}
#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_UNDEFINED
Used in interface declarations for types that have to be defined in the specializations.
Definition macros.hpp:114
#define CODI_T(...)
Abbreviation for CODI_TEMPLATE.
Definition macros.hpp:111
PassiveReal< Type > const & getPassiveValue(Type const &v)
Get the basic primal value of the type.
Definition realTraits.hpp:127
typename TraitsImplementation< Type >::PassiveReal PassiveReal
The original computation type, that was used in the application.
Definition realTraits.hpp:117
CoDiPack - Code Differentiation Package.
Definition codi.hpp:90
ExpressionTraits::EnableIfExpression< Expr, std::ostream > & operator<<(std::ostream &out, Expr const &v)
Write the primal value to the stream.
Definition expressionInterface.hpp:129
Represents a concrete lvalue in the CoDiPack expression tree.
Definition activeType.hpp:52
Base class for all CoDiPack expressions.
Definition expressionInterface.hpp:59
Real const getValue() const
Compute the primal value that is usually evaluated by the statement/expression.
T_Real Real
See ExpressionInterface.
Definition expressionInterface.hpp:62
Impl const & cast() const
Cast to the implementation.
Definition expressionInterface.hpp:75
ExpressionInterface(ExpressionInterface const &)=default
Constructor.
T_Impl Impl
See ExpressionInterface.
Definition expressionInterface.hpp:63
ExpressionInterface()=default
Constructor.
void ActiveResult
Type into which the expression can be converted. Usually also the type from which it is constructed.
Definition expressionInterface.hpp:66
Node side interface for the traversal of expressions.
Definition nodeInterface.hpp:56
Common traits for all types used as real values.
Definition realTraits.hpp:60
static PassiveReal const & getPassiveValue(Type const &v)
Get the basic primal value of the type.
Definition realTraits.hpp:71
static int constexpr MaxDerivativeOrder
CoDiPack derivative order of the type.
Definition realTraits.hpp:68
T_Type Type
See TraitsImplementation.
Definition realTraits.hpp:63
Type PassiveReal
The original computation type, that was used in the application.
Definition realTraits.hpp:66