Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Sacado_Fad_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_FAD_EXPRESSION_HPP
34 #define SACADO_FAD_EXPRESSION_HPP
35 
36 #include "Sacado_Traits.hpp"
38 
39 namespace Sacado {
40 
41  namespace Fad {
42 
44 
51  template <typename> struct BaseExpr {};
52 
53  struct ExprSpecDefault {};
54  template <typename ExprT> struct ExprSpec {
56  };
57 
59 
63  template <typename ExprT, typename Spec>
64  class Expr {
65  public:
66  typedef ExprT value_type;
67  };
68 
69  template <typename ExprT, typename Spec>
70  struct ExprSpec< Expr<ExprT,Spec> > {
71  typedef Spec type;
72  };
73 
75 
80  template <typename T>
81  struct ExprLevel {
82  static const unsigned value = 0;
83  };
84 
85  template <typename T>
86  struct ExprLevel< Expr<T> > {
87  static const unsigned value =
89  };
90 
92  template <typename T>
93  struct IsFadExpr {
94  static const bool value = false;
95  };
96 
97  template <typename T>
98  struct IsFadExpr< Expr<T> > {
99  static const bool value = true;
100  };
101 
103 
106  template <typename ConstT>
107  class ConstExpr {
108 
109  public:
110 
112  typedef ConstT value_type;
113 
116 
118  typedef ConstT base_expr_type;
119 
122  ConstExpr(const ConstT& constant) : constant_(constant) {}
123 
126  const ConstT& val() const { return constant_; }
127 
130  const ConstT& val(int j) const { return constant_; }
131 
132  protected:
133 
135  const ConstT& constant_;
136 
137  }; // class ConstExpr
138 
139  } // namespace Fad
140 
141  template <typename T>
142  struct IsExpr< Fad::Expr<T> > {
143  static const bool value = true;
144  };
145 
146  template <typename T>
147  struct BaseExprType< Fad::Expr<T> > {
149  };
150 
151  template <typename T>
152  struct ValueType< Fad::ConstExpr<T> > {
154  };
155 
156 } // namespace Sacado
157 
158 #include "Sacado_SFINAE_Macros.hpp"
159 
160 #endif // SACADO_FAD_EXPRESSION_HPP
Wrapper for a generic expression template.
SACADO_INLINE_FUNCTION ConstExpr(const ConstT &constant)
Constructor.
ScalarType< value_type >::type scalar_type
Typename of scalar&#39;s (which may be different from ConstT)
Constant expression template.
SACADO_INLINE_FUNCTION const ConstT & val() const
Return value of operation.
const ConstT & constant_
The constant.
static const bool value
Is a type an expression.
#define T
Definition: Sacado_rad.hpp:553
Determine whether a given type is an expression.
SACADO_INLINE_FUNCTION const ConstT & val(int j) const
Return value of operation.
Meta-function for determining concrete base expression.
Get the base Fad type from a view/expression.
ConstT base_expr_type
Typename of base-expressions.
Meta-function for determining nesting with an expression.
static const unsigned value
ConstT value_type
Typename of argument values.
#define SACADO_INLINE_FUNCTION
Base template specification for ValueType.