Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Sacado_ELRFad_Expression.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Sacado Package
4 //
5 // Copyright 2006 NTESS and the Sacado contributors.
6 // SPDX-License-Identifier: LGPL-2.1-or-later
7 //
8 // ***********************************************************************
9 //
10 // The forward-mode AD classes in Sacado are a derivative work of the
11 // expression template classes in the Fad package by Nicolas Di Cesare.
12 // The following banner is included in the original Fad source code:
13 //
14 // ************ DO NOT REMOVE THIS BANNER ****************
15 //
16 // Nicolas Di Cesare <Nicolas.Dicesare@ann.jussieu.fr>
17 // http://www.ann.jussieu.fr/~dicesare
18 //
19 // CEMRACS 98 : C++ courses,
20 // templates : new C++ techniques
21 // for scientific computing
22 //
23 //********************************************************
24 //
25 // A short implementation ( not all operators and
26 // functions are overloaded ) of 1st order Automatic
27 // Differentiation in forward mode (FAD) using
28 // EXPRESSION TEMPLATES.
29 //
30 //********************************************************
31 // @HEADER
32 
33 #ifndef SACADO_ELRFAD_EXPRESSION_HPP
34 #define SACADO_ELRFAD_EXPRESSION_HPP
35 
36 #include "Sacado_Traits.hpp"
37 
38 namespace Sacado {
39 
40  namespace ELRFad {
41 
43 
50  template <typename> struct BaseExpr {};
51 
53 
57  template <typename ExprT>
58  class Expr {};
59 
61 
66  template <typename T>
67  struct ExprLevel {
68  static const unsigned value = 0;
69  };
70 
71  template <typename T>
72  struct ExprLevel< Expr<T> > {
73  static const unsigned value =
75  };
76 
78  template <typename T>
79  struct IsFadExpr {
80  static const bool value = false;
81  };
82 
83  template <typename T>
84  struct IsFadExpr< Expr<T> > {
85  static const bool value = true;
86  };
87 
89 
92  template <typename ConstT>
93  class ConstExpr {
94 
95  public:
96 
98  typedef ConstT value_type;
99 
102 
104  typedef ConstT base_expr_type;
105 
107  static const int num_args = 0;
108 
111  ConstExpr(const ConstT& constant) : constant_(constant) {}
112 
115  int size() const { return 0; }
116 
119  bool updateValue() const { return true; }
120 
123  value_type val() const { return constant_; }
124 
128  value_type partials[]) const {}
129 
132  void getTangents(int i, value_type dots[]) const {}
133 
135  template <int Arg>
137  value_type getTangent(int i) const { return 0.0; }
138 
140  template <int Arg>
142  bool isActive() const { return false; }
143 
146  bool isLinear() const { return true; }
147 
148  protected:
149 
151  const ConstT& constant_;
152 
153  }; // class ConstExpr
154 
155  template <typename T> struct ExprConstRef {
156  typedef const T& type;
157  };
158  template <typename T> struct ExprConstRef< ConstExpr<T> > {
159  typedef const ConstExpr<T> type;
160  };
161 
162  } // namespace ELRFad
163 
164  template <typename T>
165  struct IsExpr< ELRFad::Expr<T> > {
166  static const bool value = true;
167  };
168 
169  template <typename T>
170  struct BaseExprType< ELRFad::Expr<T> > {
172  };
173 
174 } // namespace Sacado
175 
176 #include "Sacado_SFINAE_Macros.hpp"
177 
178 #endif // SACADO_ELRFAD_EXPRESSION_HPP
SACADO_INLINE_FUNCTION int size() const
Return size of the derivative array of the operation.
const ConstT & constant_
The constant.
SACADO_INLINE_FUNCTION void computePartials(const value_type &bar, value_type partials[]) const
Return partials w.r.t. arguments.
expr bar
static const bool value
ScalarType< value_type >::type scalar_type
Typename of scalar&#39;s (which may be different from ConstT)
ConstT base_expr_type
Typename of base-expressions.
Is a type an expression.
static const int num_args
Number of arguments.
#define T
Definition: Sacado_rad.hpp:553
SACADO_INLINE_FUNCTION bool isActive() const
Return whether argument is active.
Get the base Fad type from a view/expression.
Determine whether a given type is an expression.
ConstT value_type
Typename of argument values.
Constant expression template.
Meta-function for determining nesting with an expression.
SACADO_INLINE_FUNCTION value_type getTangent(int i) const
Return tangent component i of argument Arg.
SACADO_INLINE_FUNCTION void getTangents(int i, value_type dots[]) const
Rturn tangent component i of arguments.
SACADO_INLINE_FUNCTION ConstExpr(const ConstT &constant)
Constructor.
Wrapper for a generic expression template.
Meta-function for determining concrete base expression.
SACADO_INLINE_FUNCTION value_type val() const
Return value of operation.
#define SACADO_INLINE_FUNCTION
SACADO_INLINE_FUNCTION bool updateValue() const
Return whether value should be updated.
SACADO_INLINE_FUNCTION bool isLinear() const
Return whether expression is linear.