Sacado Package Browser (Single Doxygen Collection)  Version of the Day
Sacado_Fad_SFadTraits.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 //
29 // The forward-mode AD classes in Sacado are a derivative work of the
30 // expression template classes in the Fad package by Nicolas Di Cesare.
31 // The following banner is included in the original Fad source code:
32 //
33 // ************ DO NOT REMOVE THIS BANNER ****************
34 //
35 // Nicolas Di Cesare <Nicolas.Dicesare@ann.jussieu.fr>
36 // http://www.ann.jussieu.fr/~dicesare
37 //
38 // CEMRACS 98 : C++ courses,
39 // templates : new C++ techniques
40 // for scientific computing
41 //
42 //********************************************************
43 //
44 // NumericalTraits class to illustrate TRAITS
45 //
46 //********************************************************
47 // @HEADER
48 
49 #ifndef SACADO_FAD_SFADTRAITS_HPP
50 #define SACADO_FAD_SFADTRAITS_HPP
51 
52 #include "Sacado_Traits.hpp"
53 #include <sstream>
54 
55 // Forward declarations
56 namespace Sacado {
57  namespace Fad {
58  template <typename T, int Num> class SFad;
59  }
60 }
61 
62 namespace Sacado {
63 
65  SACADO_SFAD_PROMOTE_SPEC( Fad, SFad )
66 
67 
68  template <typename ValueT, int Num>
69  struct ScalarType< Fad::SFad<ValueT,Num> > {
71  };
72 
74  template <typename ValueT, int Num>
75  struct ValueType< Fad::SFad<ValueT,Num> > {
76  typedef ValueT type;
77  };
78 
80  template <typename ValueT, int Num>
81  struct IsADType< Fad::SFad<ValueT,Num> > {
82  static const bool value = true;
83  };
84 
86  template <typename ValueT, int Num>
87  struct IsScalarType< Fad::SFad<ValueT,Num> > {
88  static const bool value = false;
89  };
90 
92  template <typename ValueT, int Num>
93  struct Value< Fad::SFad<ValueT,Num> > {
94  typedef typename ValueType< Fad::SFad<ValueT,Num> >::type value_type;
96  static const value_type& eval(const Fad::SFad<ValueT,Num>& x) {
97  return x.val(); }
98  };
99 
101  template <typename ValueT, int Num>
102  struct ScalarValue< Fad::SFad<ValueT,Num> > {
106  static const scalar_type& eval(const Fad::SFad<ValueT,Num>& x) {
107  return ScalarValue<value_type>::eval(x.val()); }
108  };
109 
111  template <typename ValueT, int Num>
112  struct StringName< Fad::SFad<ValueT,Num> > {
113  static std::string eval() {
114  std::stringstream ss;
115  ss << "Sacado::Fad::SFad< "
116  << StringName<ValueT>::eval() << ", " << Num << " >";
117  return ss.str();
118  }
119  };
120 
122  template <typename ValueT, int Num>
123  struct IsEqual< Fad::SFad<ValueT,Num> > {
125  static bool eval(const Fad::SFad<ValueT,Num>& x,
126  const Fad::SFad<ValueT,Num>& y) {
127  return x.isEqualTo(y);
128  }
129  };
130 
132  template <typename ValueT, int Num>
133  struct IsStaticallySized< Fad::SFad<ValueT,Num> > {
134  static const bool value = true;
135  };
136 
138  template <typename ValueT, int Num>
139  struct IsStaticallySized< const Fad::SFad<ValueT,Num> > {
140  static const bool value = true;
141  };
142 
144  template <typename ValueT, int Num>
145  struct StaticSize< Fad::SFad<ValueT,Num> > {
146  static const unsigned value = Num;
147  };
148 
150  template <typename ValueT, int Num>
151  struct StaticSize< const Fad::SFad<ValueT,Num> > {
152  static const unsigned value = Num;
153  };
154 
155 } // namespace Sacado
156 
157 // Define Teuchos traits classes
158 #ifdef HAVE_SACADO_TEUCHOS
159 #include "Teuchos_PromotionTraits.hpp"
160 #include "Teuchos_ScalarTraits.hpp"
162 
163 namespace Teuchos {
164 
166  template <typename ValueT, int Num>
167  struct PromotionTraits< Sacado::Fad::SFad<ValueT,Num>,
168  Sacado::Fad::SFad<ValueT,Num> > {
171  promote;
172  };
173 
175  template <typename ValueT, int Num, typename R>
176  struct PromotionTraits< Sacado::Fad::SFad<ValueT,Num>, R > {
177  typedef typename Sacado::Promote< Sacado::Fad::SFad<ValueT,Num>, R >::type
178  promote;
179  };
180 
182  template <typename L, typename ValueT, int Num>
183  struct PromotionTraits< L, Sacado::Fad::SFad<ValueT,Num> > {
184  public:
186  promote;
187  };
188 
190  template <typename ValueT, int Num>
191  struct ScalarTraits< Sacado::Fad::SFad<ValueT,Num> > :
192  public Sacado::Fad::ScalarTraitsImp< Sacado::Fad::SFad<ValueT,Num> >
193  {};
194 
196  template <typename Ordinal, typename ValueT, int Num>
197  struct SerializationTraits<Ordinal, Sacado::Fad::SFad<ValueT,Num> > :
198  public Sacado::Fad::StaticSerializationTraitsImp< Ordinal,
199  Sacado::Fad::SFad<ValueT,Num> >
200  {};
201 
203  template <typename Ordinal, typename ValueT, int Num>
204  struct ValueTypeSerializer<Ordinal, Sacado::Fad::SFad<ValueT,Num> > :
205  public Sacado::Fad::SerializerImp< Ordinal,
206  Sacado::Fad::SFad<ValueT,Num>,
207  ValueTypeSerializer<Ordinal,ValueT> >
208  {
210  typedef ValueTypeSerializer<Ordinal,ValueT> ValueSerializer;
211  typedef Sacado::Fad::SerializerImp< Ordinal,FadType,ValueSerializer> Base;
212  ValueTypeSerializer(const Teuchos::RCP<const ValueSerializer>& vs,
213  Ordinal sz = 0) :
214  Base(vs, sz) {}
215  };
216 }
217 #endif // HAVE_SACADO_TEUCHOS
218 
219 #endif // SACADO_FAD_SFADTRAITS_HPP
static std::string eval()
Base template specification for ScalarValue.
Base template specification for ScalarType.
static KOKKOS_INLINE_FUNCTION bool eval(const Fad::SFad< ValueT, Num > &x, const Fad::SFad< ValueT, Num > &y)
Base template specification for string names of types.
ValueType< Fad::SFad< ValueT, Num > >::type value_type
Base template specification for IsADType.
Sacado::Fad::DFad< double > FadType
Base template specification for static size.
Base template specification for Value.
#define KOKKOS_INLINE_FUNCTION
static const bool value
ValueType< Fad::SFad< ValueT, Num > >::type value_type
Base template specification for testing equivalence.
static KOKKOS_INLINE_FUNCTION const value_type & eval(const Fad::SFad< ValueT, Num > &x)
static KOKKOS_INLINE_FUNCTION const scalar_type & eval(const Fad::SFad< ValueT, Num > &x)
ScalarType< Fad::SFad< ValueT, Num > >::type scalar_type
int Ordinal
static const bool value
Base template specification for IsScalarType.
#define SACADO_SFAD_PROMOTE_SPEC(NS, FAD)
static const unsigned value
Base template specification for ValueType.
Base template specification for Promote.
static KOKKOS_INLINE_FUNCTION const T & eval(const T &x)
Base template specification for testing whether type is statically sized.