Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Sacado_CacheFad_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_CACHEFAD_EXPRESSION_HPP
34 #define SACADO_CACHEFAD_EXPRESSION_HPP
35 
36 #include "Sacado_Traits.hpp"
37 
38 namespace Sacado {
39 
40  namespace CacheFad {
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 
108  ConstExpr(const ConstT& constant) : constant_(constant) {}
109 
112  int size() const { return 0; }
113 
116  bool hasFastAccess() const { return 1; }
117 
120  void cache() const {}
121 
124  value_type val() const { return constant_; }
125 
128  value_type dx(int i) const { return value_type(0); }
129 
132  value_type fastAccessDx(int i) const { return value_type(0); }
133 
134  protected:
135 
137  const ConstT& constant_;
138 
139  }; // class ConstExpr
140 
141  } // namespace CacheFad
142 
143  template <typename T>
144  struct IsExpr< CacheFad::Expr<T> > {
145  static const bool value = true;
146  };
147 
148  template <typename T>
149  struct BaseExprType< CacheFad::Expr<T> > {
151  };
152 
153 } // namespace Sacado
154 
155 #include "Sacado_SFINAE_Macros.hpp"
156 
157 #endif // SACADO_CACHEFAD_EXPRESSION_HPP
Determine whether a given type is an expression.
const ConstT & constant_
The constant.
ConstT base_expr_type
Typename of base-expressions.
static const bool value
SACADO_INLINE_FUNCTION value_type dx(int i) const
Return derivative component i of operation.
Is a type an expression.
Constant expression template.
Meta-function for determining concrete base expression.
#define T
Definition: Sacado_rad.hpp:553
ConstT value_type
Typename of argument values.
Get the base Fad type from a view/expression.
SACADO_INLINE_FUNCTION value_type val() const
Return value of operation.
SACADO_INLINE_FUNCTION bool hasFastAccess() const
Return if operation has fast access.
SACADO_INLINE_FUNCTION value_type fastAccessDx(int i) const
Return derivative component i of operation.
SACADO_INLINE_FUNCTION int size() const
Return size of the derivative array of the operation.
ScalarType< value_type >::type scalar_type
Typename of scalar&#39;s (which may be different from ConstT)
#define SACADO_INLINE_FUNCTION
SACADO_INLINE_FUNCTION ConstExpr(const ConstT &constant)
Constructor.
SACADO_INLINE_FUNCTION void cache() const
Cache values.
Wrapper for a generic expression template.
Meta-function for determining nesting with an expression.