Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Sacado_ELRCacheFad_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_ELRCACHEFAD_EXPRESSION_HPP
34 #define SACADO_ELRCACHEFAD_EXPRESSION_HPP
35 
36 #include "Sacado_Traits.hpp"
37 
38 namespace Sacado {
39 
40  namespace ELRCacheFad {
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  void cache() const {}
124 
127  value_type val() const { return constant_; }
128 
132  value_type partials[]) const {}
133 
136  void getTangents(int i, value_type dots[]) const {}
137 
139  template <int Arg>
141  value_type getTangent(int i) const { return 0.0; }
142 
144  template <int Arg>
146  bool isActive() const { return false; }
147 
150  bool isLinear() const { return true; }
151 
152  protected:
153 
155  const ConstT& constant_;
156 
157  }; // class ConstExpr
158 
159  template <typename T> struct ExprConstRef {
160  typedef const T& type;
161  };
162  template <typename T> struct ExprConstRef< ConstExpr<T> > {
163  typedef const ConstExpr<T> type;
164  };
165 
166  } // namespace ELRCacheFad
167 
168  template <typename T>
169  struct IsExpr< ELRCacheFad::Expr<T> > {
170  static const bool value = true;
171  };
172 
173  template <typename T>
174  struct BaseExprType< ELRCacheFad::Expr<T> > {
176  };
177 
178 } // namespace Sacado
179 
180 #include "Sacado_SFINAE_Macros.hpp"
181 
182 #endif // SACADO_ELRCACHEFAD_EXPRESSION_HPP
ConstT base_expr_type
Typename of base-expressions.
SACADO_INLINE_FUNCTION ConstExpr(const ConstT &constant)
Constructor.
expr bar
static const bool value
SACADO_INLINE_FUNCTION value_type val() const
Return value of operation.
ScalarType< value_type >::type scalar_type
Typename of scalar&#39;s (which may be different from ConstT)
Is a type an expression.
Meta-function for determining concrete base expression.
SACADO_INLINE_FUNCTION value_type getTangent(int i) const
Return tangent component i of argument Arg.
#define T
Definition: Sacado_rad.hpp:553
Get the base Fad type from a view/expression.
Wrapper for a generic expression template.
Meta-function for determining nesting with an expression.
static const int num_args
Number of arguments.
SACADO_INLINE_FUNCTION int size() const
Return size of the derivative array of the operation.
SACADO_INLINE_FUNCTION void getTangents(int i, value_type dots[]) const
Rturn tangent component i of arguments.
SACADO_INLINE_FUNCTION void computePartials(const value_type &bar, value_type partials[]) const
Return partials w.r.t. arguments.
Determine whether a given type is an expression.
SACADO_INLINE_FUNCTION void cache() const
Cache values.
SACADO_INLINE_FUNCTION bool isLinear() const
Return whether expression is linear.
SACADO_INLINE_FUNCTION bool isActive() const
Return whether argument is active.
#define SACADO_INLINE_FUNCTION
ConstT value_type
Typename of argument values.
SACADO_INLINE_FUNCTION bool updateValue() const
Return whether value should be updated.