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_SimpleFad.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 // @HEADER
9 
10 #ifndef SACADO_FAD_SIMPLEFAD_HPP
11 #define SACADO_FAD_SIMPLEFAD_HPP
12 
16 
17 namespace Sacado {
18 
19  namespace Fad {
20 
31  template <typename ValueT>
32  class SimpleFad : public GeneralFad<ValueT,DynamicStorage<ValueT> > {
33 
34  public:
35 
39 
42 
45 
48 
50  template <typename T>
51  struct apply {
52  typedef SimpleFad<T> type;
53  };
54 
59 
61 
65  GeneralFadType() {}
66 
68 
71  template <typename S>
73  GeneralFadType(x) {}
74 
76 
79  SimpleFad(const int sz, const ValueT& x, const DerivInit zero_out = InitDerivArray) :
80  GeneralFadType(sz,x,zero_out) {}
81 
83 
88  SimpleFad(const int sz, const int i, const ValueT & x) :
89  GeneralFadType(sz,i,x) {}
90 
92  SimpleFad(const SimpleFad& x) :
93  GeneralFadType(x) {}
94 
96  SimpleFad(const SimpleFad& x, const ValueT& v, const ValueT& partial) :
97  GeneralFadType(x.size(), v) {
98  for (int i=0; i<this->size(); i++)
99  this->fastAccessDx(i) = x.fastAccessDx(i)*partial;
100  }
101 
103 
106 
108  bool isEqualTo(const SimpleFad& x) const {
109  typedef IsEqual<value_type> IE;
110  if (x.size() != this->size()) return false;
111  bool eq = IE::eval(x.val(), this->val());
112  for (int i=0; i<this->size(); i++)
113  eq = eq && IE::eval(x.dx(i), this->dx(i));
114  return eq;
115  }
116 
118  template <typename S>
119  SACADO_ENABLE_VALUE_FUNC(SimpleFad&) operator=(const S& v) {
120  GeneralFadType::operator=(v);
121  return *this;
122  }
123 
125  SimpleFad& operator=(const SimpleFad& x) {
126  GeneralFadType::operator=(static_cast<const GeneralFadType&>(x));
127  return *this;
128  }
129 
131  template <typename S>
133  SACADO_ENABLE_VALUE_FUNC(SimpleFad&) operator += (const S& x) {
134  GeneralFadType::operator+=(x);
135  return *this;
136  }
137 
139  template <typename S>
141  SACADO_ENABLE_VALUE_FUNC(SimpleFad&) operator -= (const S& x) {
142  GeneralFadType::operator-=(x);
143  return *this;
144  }
145 
147  template <typename S>
149  SACADO_ENABLE_VALUE_FUNC(SimpleFad&) operator *= (const S& x) {
150  GeneralFadType::operator*=(x);
151  return *this;
152  }
153 
155  template <typename S>
157  SACADO_ENABLE_VALUE_FUNC(SimpleFad&) operator /= (const S& x) {
158  GeneralFadType::operator/=(x);
159  return *this;
160  }
161 
164  SimpleFad& operator += (const SimpleFad& x) {
165  GeneralFadType::operator+=(static_cast<const GeneralFadType&>(x));
166  return *this;
167  }
168 
171  SimpleFad& operator -= (const SimpleFad& x) {
172  GeneralFadType::operator-=(static_cast<const GeneralFadType&>(x));
173  return *this;
174  }
175 
178  SimpleFad& operator *= (const SimpleFad& x) {
179  GeneralFadType::operator*=(static_cast<const GeneralFadType&>(x));
180  return *this;
181  }
182 
185  SimpleFad& operator /= (const SimpleFad& x) {
186  GeneralFadType::operator/=(static_cast<const GeneralFadType&>(x));
187  return *this;
188  }
189 
190  }; // class SimpleFad<ValueT>
191 
192  } // namespace Fad
193 
194 } // namespace Sacado
195 
196 // Include elementary operation overloads
198 
199 #endif // SACADO_FAD_SIMPLEFAD_HPP
SimpleFad(const SimpleFad &x, const ValueT &v, const ValueT &partial)
Tangent copy constructor.
ScalarType< value_type >::type scalar_type
Typename of scalar&#39;s (which may be different from T)
#define SACADO_ENABLE_VALUE_CTOR_DECL
GeneralFadType::scalar_type scalar_type
Typename of scalar&#39;s (which may be different from value_type)
RemoveConst< T >::type value_type
Typename of values.
GeneralFad< ValueT, StorageType > GeneralFadType
ScalarType< ValueT >::type ScalarT
Typename of scalar&#39;s (which may be different from ValueT)
SimpleFad(const SimpleFad &x)
Copy constructor.
Forward-mode AD class using dynamic memory allocation but no expression templates.
SimpleFad()
Default constructor.
SACADO_INLINE_FUNCTION DynamicStorage & operator=(const DynamicStorage &x)
Assignment.
SimpleFad(const int sz, const ValueT &x, const DerivInit zero_out=InitDerivArray)
Constructor with size sz and value x.
#define SACADO_ENABLE_VALUE_FUNC(RETURN_TYPE)
Base template specification for testing equivalence.
SACADO_INLINE_FUNCTION ValueT & fastAccessDx(int i)
Returns derivative component i without bounds checking.
Turn SimpleFad into a meta-function class usable with mpl::apply.
bool isEqualTo(const SimpleFad &x) const
Returns whether two Fad objects have the same values.
SACADO_INLINE_FUNCTION const T & val() const
Returns value.
DerivInit
Enum use to signal whether the derivative array should be initialized in AD object constructors...
GeneralFadType::value_type value_type
Typename of values.
SACADO_INLINE_FUNCTION int size() const
Returns number of derivative components.
Initialize the derivative array.
SimpleFad(const int sz, const int i, const ValueT &x)
Constructor with size sz, index i, and value x.
DynamicStorage< ValueT > StorageType
Base classes.
#define SACADO_INLINE_FUNCTION
SimpleFad(const S &x, SACADO_ENABLE_VALUE_CTOR_DECL)
Constructor with supplied value x convertible to ValueT.
SACADO_INLINE_FUNCTION const U * dx() const
Returns derivative array.
Forward-mode AD class templated on the storage for the derivative array.