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 //
4 // Sacado Package
5 // Copyright (2006) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // This library is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as
12 // published by the Free Software Foundation; either version 2.1 of the
13 // License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23 // USA
24 // Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
25 // (etphipp@sandia.gov).
26 //
27 // ***********************************************************************
28 // @HEADER
29 
30 #ifndef SACADO_FAD_SIMPLEFAD_HPP
31 #define SACADO_FAD_SIMPLEFAD_HPP
32 
36 
37 namespace Sacado {
38 
39  namespace Fad {
40 
51  template <typename ValueT>
52  class SimpleFad : public GeneralFad<ValueT,DynamicStorage<ValueT> > {
53 
54  public:
55 
59 
62 
65 
68 
70  template <typename T>
71  struct apply {
72  typedef SimpleFad<T> type;
73  };
74 
79 
81 
85  GeneralFadType() {}
86 
88 
91  template <typename S>
93  GeneralFadType(x) {}
94 
96 
99  SimpleFad(const int sz, const ValueT& x, const DerivInit zero_out = InitDerivArray) :
100  GeneralFadType(sz,x,zero_out) {}
101 
103 
108  SimpleFad(const int sz, const int i, const ValueT & x) :
109  GeneralFadType(sz,i,x) {}
110 
112  SimpleFad(const SimpleFad& x) :
113  GeneralFadType(x) {}
114 
116  SimpleFad(const SimpleFad& x, const ValueT& v, const ValueT& partial) :
117  GeneralFadType(x.size(), v) {
118  for (int i=0; i<this->size(); i++)
119  this->fastAccessDx(i) = x.fastAccessDx(i)*partial;
120  }
121 
123 
126 
128  bool isEqualTo(const SimpleFad& x) const {
129  typedef IsEqual<value_type> IE;
130  if (x.size() != this->size()) return false;
131  bool eq = IE::eval(x.val(), this->val());
132  for (int i=0; i<this->size(); i++)
133  eq = eq && IE::eval(x.dx(i), this->dx(i));
134  return eq;
135  }
136 
138  template <typename S>
139  SACADO_ENABLE_VALUE_FUNC(SimpleFad&) operator=(const S& v) {
140  GeneralFadType::operator=(v);
141  return *this;
142  }
143 
145  SimpleFad& operator=(const SimpleFad& x) {
146  GeneralFadType::operator=(static_cast<const GeneralFadType&>(x));
147  return *this;
148  }
149 
151  template <typename S>
153  SACADO_ENABLE_VALUE_FUNC(SimpleFad&) operator += (const S& x) {
154  GeneralFadType::operator+=(x);
155  return *this;
156  }
157 
159  template <typename S>
161  SACADO_ENABLE_VALUE_FUNC(SimpleFad&) operator -= (const S& x) {
162  GeneralFadType::operator-=(x);
163  return *this;
164  }
165 
167  template <typename S>
169  SACADO_ENABLE_VALUE_FUNC(SimpleFad&) operator *= (const S& x) {
170  GeneralFadType::operator*=(x);
171  return *this;
172  }
173 
175  template <typename S>
177  SACADO_ENABLE_VALUE_FUNC(SimpleFad&) operator /= (const S& x) {
178  GeneralFadType::operator/=(x);
179  return *this;
180  }
181 
184  SimpleFad& operator += (const SimpleFad& x) {
185  GeneralFadType::operator+=(static_cast<const GeneralFadType&>(x));
186  return *this;
187  }
188 
191  SimpleFad& operator -= (const SimpleFad& x) {
192  GeneralFadType::operator-=(static_cast<const GeneralFadType&>(x));
193  return *this;
194  }
195 
198  SimpleFad& operator *= (const SimpleFad& x) {
199  GeneralFadType::operator*=(static_cast<const GeneralFadType&>(x));
200  return *this;
201  }
202 
205  SimpleFad& operator /= (const SimpleFad& x) {
206  GeneralFadType::operator/=(static_cast<const GeneralFadType&>(x));
207  return *this;
208  }
209 
210  }; // class SimpleFad<ValueT>
211 
212  } // namespace Fad
213 
214 } // namespace Sacado
215 
216 // Include elementary operation overloads
218 
219 #endif // SACADO_FAD_SIMPLEFAD_HPP
KOKKOS_INLINE_FUNCTION int size() const
Returns number of derivative components.
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
KOKKOS_INLINE_FUNCTION const T & val() const
Returns value.
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.
#define KOKKOS_INLINE_FUNCTION
SimpleFad(const int sz, const ValueT &x, const DerivInit zero_out=InitDerivArray)
Constructor with size sz and value x.
KOKKOS_INLINE_FUNCTION const U * dx() const
Returns derivative array.
#define SACADO_ENABLE_VALUE_FUNC(RETURN_TYPE)
Base template specification for testing equivalence.
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.
DerivInit
Enum use to signal whether the derivative array should be initialized in AD object constructors...
GeneralFadType::value_type value_type
Typename of values.
KOKKOS_INLINE_FUNCTION DynamicStorage & operator=(const DynamicStorage &x)
Assignment.
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.
KOKKOS_INLINE_FUNCTION ValueT & fastAccessDx(int i)
Returns derivative component i without bounds checking.
SimpleFad(const S &x, SACADO_ENABLE_VALUE_CTOR_DECL)
Constructor with supplied value x convertible to ValueT.
Forward-mode AD class templated on the storage for the derivative array.