Sacado Package Browser (Single Doxygen Collection)  Version of the Day
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 
35 
36 namespace Sacado {
37 
38  namespace Fad {
39 
50  template <typename ValueT>
51  class SimpleFad : public GeneralFad<ValueT,DynamicStorage<ValueT> > {
52 
53  public:
54 
58 
61 
64 
67 
69  template <typename T>
70  struct apply {
71  typedef SimpleFad<T> type;
72  };
73 
78 
80 
84  GeneralFadType() {}
85 
87 
90  template <typename S>
92  GeneralFadType(x) {}
93 
95 
98  SimpleFad(const int sz, const ValueT& x, const DerivInit zero_out = InitDerivArray) :
99  GeneralFadType(sz,x,zero_out) {}
100 
102 
107  SimpleFad(const int sz, const int i, const ValueT & x) :
108  GeneralFadType(sz,i,x) {}
109 
111  SimpleFad(const SimpleFad& x) :
112  GeneralFadType(x) {}
113 
115  SimpleFad(const SimpleFad& x, const ValueT& v, const ValueT& partial) :
116  GeneralFadType(x.size(), v) {
117  for (int i=0; i<this->size(); i++)
118  this->fastAccessDx(i) = x.fastAccessDx(i)*partial;
119  }
120 
122 
125 
127  bool isEqualTo(const SimpleFad& x) const {
128  typedef IsEqual<value_type> IE;
129  if (x.size() != this->size()) return false;
130  bool eq = IE::eval(x.val(), this->val());
131  for (int i=0; i<this->size(); i++)
132  eq = eq && IE::eval(x.dx(i), this->dx(i));
133  return eq;
134  }
135 
137  template <typename S>
139  GeneralFadType::operator=(v);
140  return *this;
141  }
142 
144  SimpleFad& operator=(const SimpleFad& x) {
145  GeneralFadType::operator=(static_cast<const GeneralFadType&>(x));
146  return *this;
147  }
148 
150  template <typename S>
152  SACADO_ENABLE_VALUE_FUNC(SimpleFad&) operator += (const S& x) {
153  GeneralFadType::operator+=(x);
154  return *this;
155  }
156 
158  template <typename S>
160  SACADO_ENABLE_VALUE_FUNC(SimpleFad&) operator -= (const S& x) {
161  GeneralFadType::operator-=(x);
162  return *this;
163  }
164 
166  template <typename S>
168  SACADO_ENABLE_VALUE_FUNC(SimpleFad&) operator *= (const S& x) {
169  GeneralFadType::operator*=(x);
170  return *this;
171  }
172 
174  template <typename S>
176  SACADO_ENABLE_VALUE_FUNC(SimpleFad&) operator /= (const S& x) {
177  GeneralFadType::operator/=(x);
178  return *this;
179  }
180 
183  SimpleFad& operator += (const SimpleFad& x) {
184  GeneralFadType::operator+=(static_cast<const GeneralFadType&>(x));
185  return *this;
186  }
187 
190  SimpleFad& operator -= (const SimpleFad& x) {
191  GeneralFadType::operator-=(static_cast<const GeneralFadType&>(x));
192  return *this;
193  }
194 
197  SimpleFad& operator *= (const SimpleFad& x) {
198  GeneralFadType::operator*=(static_cast<const GeneralFadType&>(x));
199  return *this;
200  }
201 
204  SimpleFad& operator /= (const SimpleFad& x) {
205  GeneralFadType::operator/=(static_cast<const GeneralFadType&>(x));
206  return *this;
207  }
208 
209  }; // class SimpleFad<ValueT>
210 
211  } // namespace Fad
212 
213 } // namespace Sacado
214 
215 // Include elementary operation overloads
217 
218 #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.
KOKKOS_INLINE_FUNCTION const T & val() const
Returns value.
Forward-mode AD class using dynamic memory allocation but no expression templates.
KOKKOS_INLINE_FUNCTION int size() const
Returns number of derivative components.
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.
#define SACADO_ENABLE_VALUE_FUNC(RETURN_TYPE)
KOKKOS_INLINE_FUNCTION const U * dx() const
Returns derivative array.
Base template specification for testing equivalence.
Turn SimpleFad into a meta-function class usable with mpl::apply.
DerivInit
Enum use to signal whether the derivative array should be initialized in AD object constructors...
bool isEqualTo(const SimpleFad &x) const
Returns whether two Fad objects have the same values.
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.