Sacado Package Browser (Single Doxygen Collection)  Version of the Day
Sacado_ELRCacheFad_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_ELRCACHEFAD_SFADTRAITS_HPP
50 #define SACADO_ELRCACHEFAD_SFADTRAITS_HPP
51 
52 #include "Sacado_Traits.hpp"
53 #include <sstream>
54 
55 // Forward declarations
56 namespace Sacado {
57  namespace ELRCacheFad {
58  template <typename T, int Num> class SFad;
59  }
60 }
61 
62 namespace Sacado {
63 
65  SACADO_SFAD_PROMOTE_SPEC( ELRCacheFad, SFad )
66 
67 
68  template <typename ValueT, int Num>
69  struct ScalarType< ELRCacheFad::SFad<ValueT,Num> > {
71  };
72 
74  template <typename ValueT, int Num>
75  struct ValueType< ELRCacheFad::SFad<ValueT,Num> > {
76  typedef ValueT type;
77  };
78 
80  template <typename ValueT, int Num>
81  struct IsADType< ELRCacheFad::SFad<ValueT,Num> > {
82  static const bool value = true;
83  };
84 
86  template <typename ValueT, int Num>
87  struct IsScalarType< ELRCacheFad::SFad<ValueT,Num> > {
88  static const bool value = false;
89  };
90 
92  template <typename ValueT, int Num>
93  struct Value< ELRCacheFad::SFad<ValueT,Num> > {
96  static const value_type& eval(const ELRCacheFad::SFad<ValueT,Num>& x) {
97  return x.val(); }
98  };
99 
101  template <typename ValueT, int Num>
102  struct ScalarValue< ELRCacheFad::SFad<ValueT,Num> > {
107  return ScalarValue<value_type>::eval(x.val()); }
108  };
109 
111  template <typename ValueT, int Num>
112  struct StringName< ELRCacheFad::SFad<ValueT,Num> > {
113  static std::string eval() {
114  std::stringstream ss;
115  ss << "Sacado::ELRCacheFad::SFad< "
116  << StringName<ValueT>::eval() << ", " << Num << " >";
117  return ss.str();
118  }
119  };
120 
122  template <typename ValueT, int Num>
123  struct IsEqual< ELRCacheFad::SFad<ValueT,Num> > {
125  static bool eval(const ELRCacheFad::SFad<ValueT,Num>& x,
127  return x.isEqualTo(y);
128  }
129  };
130 
132  template <typename ValueT, int Num>
133  struct IsStaticallySized< ELRCacheFad::SFad<ValueT,Num> > {
134  static const bool value = true;
135  };
136 
138  template <typename ValueT, int Num>
139  struct IsStaticallySized< const ELRCacheFad::SFad<ValueT,Num> > {
140  static const bool value = true;
141  };
142 
144  template <typename ValueT, int Num>
145  struct StaticSize< ELRCacheFad::SFad<ValueT,Num> > {
146  static const unsigned value = Num;
147  };
148 
150  template <typename ValueT, int Num>
151  struct StaticSize< const ELRCacheFad::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::ELRCacheFad::SFad<ValueT,Num>,
168  Sacado::ELRCacheFad::SFad<ValueT,Num> > {
171  promote;
172  };
173 
175  template <typename ValueT, int Num, typename R>
176  struct PromotionTraits< Sacado::ELRCacheFad::SFad<ValueT,Num>, R > {
178  R >::type
179  promote;
180  };
181 
183  template <typename L, typename ValueT, int Num>
184  struct PromotionTraits< L, Sacado::ELRCacheFad::SFad<ValueT,Num> > {
185  public:
186  typedef typename Sacado::Promote< L,
188  promote;
189  };
190 
192  template <typename ValueT, int Num>
193  struct ScalarTraits< Sacado::ELRCacheFad::SFad<ValueT,Num> > :
194  public Sacado::Fad::ScalarTraitsImp< Sacado::ELRCacheFad::SFad<ValueT,Num> >
195  {};
196 
198  template <typename Ordinal, typename ValueT, int Num>
199  struct SerializationTraits<Ordinal, Sacado::ELRCacheFad::SFad<ValueT,Num> > :
200  public Sacado::Fad::SerializationTraitsImp< Ordinal,
201  Sacado::ELRCacheFad::SFad<ValueT,Num> >
202  {};
203 
205  template <typename Ordinal, typename ValueT, int Num>
206  struct ValueTypeSerializer<Ordinal, Sacado::ELRCacheFad::SFad<ValueT,Num> > :
207  public Sacado::Fad::SerializerImp< Ordinal,
208  Sacado::ELRCacheFad::SFad<ValueT,Num>,
209  ValueTypeSerializer<Ordinal,ValueT> >
210  {
212  typedef ValueTypeSerializer<Ordinal,ValueT> ValueSerializer;
213  typedef Sacado::Fad::SerializerImp< Ordinal,FadType,ValueSerializer> Base;
214  ValueTypeSerializer(const Teuchos::RCP<const ValueSerializer>& vs,
215  Ordinal sz = 0) :
216  Base(vs, sz) {}
217  };
218 }
219 #endif // HAVE_SACADO_TEUCHOS
220 
221 #endif // SACADO_ELRCACHEFAD_SFADTRAITS_HPP
static KOKKOS_INLINE_FUNCTION const scalar_type & eval(const ELRCacheFad::SFad< ValueT, Num > &x)
static std::string eval()
ScalarType< ELRCacheFad::SFad< ValueT, Num > >::type scalar_type
Base template specification for ScalarValue.
Base template specification for ScalarType.
Base template specification for string names of types.
Base template specification for IsADType.
Sacado::Fad::DFad< double > FadType
static KOKKOS_INLINE_FUNCTION bool eval(const ELRCacheFad::SFad< ValueT, Num > &x, const ELRCacheFad::SFad< ValueT, Num > &y)
Base template specification for static size.
Base template specification for Value.
ValueType< ELRCacheFad::SFad< ValueT, Num > >::type value_type
#define KOKKOS_INLINE_FUNCTION
static const bool value
Base template specification for testing equivalence.
ValueType< ELRCacheFad::SFad< ValueT, Num > >::type value_type
int Ordinal
static const bool value
Base template specification for IsScalarType.
#define SACADO_SFAD_PROMOTE_SPEC(NS, FAD)
static const unsigned value
GeneralFad< StaticFixedStorage< T, Num > > SFad
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.
static KOKKOS_INLINE_FUNCTION const value_type & eval(const ELRCacheFad::SFad< ValueT, Num > &x)