Debian Codegraph @

packages/stokhos/src/sacado/kokkos/pce/Sacado_UQ_PCE_Traits.hpp

raw
1 // @HEADER
2 // *****************************************************************************
3 // Stokhos Package
4 //
5 // Copyright 2009 NTESS and the Stokhos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9
10 #ifndef SACADO_UQ_PCE_TRAITS_HPP
11 #define SACADO_UQ_PCE_TRAITS_HPP
12
13 #include "Sacado_Traits.hpp"
14 #include "Sacado_mpl_apply.hpp"
15
16 // Forward declarations
17 namespace Sacado {
18 namespace UQ {
19 template <typename S> class PCE;
20 }
21 }
22
23 namespace Sacado {
24
25 //! Specialization of %Promote to PCE types
26 SACADO_AD_PROMOTE_SPEC( UQ, PCE )
27
28 //! Specialization of %ScalarType to PCE types
29 template <typename S>
30 struct ScalarType< UQ::PCE<S> > {
31 typedef typename ScalarType<typename UQ::PCE<S>::value_type>::type type;
32 };
33
34 //! Specialization of %ValueType to PCE types
35 template <typename S>
36 struct ValueType< UQ::PCE<S> > {
37 typedef typename UQ::PCE<S>::value_type type;
38 };
39
40 //! Specialization of %IsADType to PCE types
41 template <typename S>
42 struct IsADType< UQ::PCE<S> > {
43 static const bool value = true;
44 };
45
46 //! Specialization of %IsADType to PCE types
47 template <typename S>
48 struct IsScalarType< UQ::PCE<S> > {
49 static const bool value = false;
50 };
51
52 //! Specialization of %Value to PCE types
53 template <typename S>
54 struct Value< UQ::PCE<S> > {
55 typedef typename ValueType< UQ::PCE<S> >::type value_type;
56 KOKKOS_INLINE_FUNCTION
57 static const value_type& eval(const UQ::PCE<S>& x) {
58 return x.val(); }
59 };
60
61 //! Specialization of %ScalarValue to PCE types
62 template <typename S>
63 struct ScalarValue< UQ::PCE<S> > {
64 typedef typename ValueType< UQ::PCE<S> >::type value_type;
65 typedef typename ScalarType< UQ::PCE<S> >::type scalar_type;
66 KOKKOS_INLINE_FUNCTION
67 static const scalar_type& eval(const UQ::PCE<S>& x) {
68 return ScalarValue<value_type>::eval(x.val()); }
69 };
70
71 //! Specialization of %StringName to PCE types
72 template <typename S>
73 struct StringName< UQ::PCE<S> > {
74 static std::string eval() {
75 return std::string("Sacado::UQ::PCE< ") +
76 StringName<S>::eval() + " >"; }
77 };
78
79 //! Specialization of %IsEqual to PCE types
80 template <typename S>
81 struct IsEqual< UQ::PCE<S> > {
82 KOKKOS_INLINE_FUNCTION
83 static bool eval(const UQ::PCE<S>& x,
84 const UQ::PCE<S>& y) {
85 return x.isEqualTo(y);
86 }
87 };
88
89 //! Specialization of %IsStaticallySized to PCE types
90 template <typename S>
91 struct IsStaticallySized< UQ::PCE<S> > {
92 static const bool value = S::is_static;
93 };
94
95 } // namespace Sacado
96
97 // Define Teuchos traits classes
98 // Note Stokhos has required dependency on all Teuchos sub-packages
99 #include "Teuchos_PromotionTraits.hpp"
100 #include "Teuchos_ScalarTraits.hpp"
101 #include "Sacado_UQ_PCE_ScalarTraitsImp.hpp"
102 #include "Teuchos_SerializationTraits.hpp"
103
104 namespace Teuchos {
105
106 //! Specialization of %Teuchos::PromotionTraits to DFad types
107 template <typename S>
108 struct PromotionTraits< Sacado::UQ::PCE<S>,
109 Sacado::UQ::PCE<S> > {
110 typedef typename Sacado::Promote< Sacado::UQ::PCE<S>,
111 Sacado::UQ::PCE<S> >::type
112 promote;
113 };
114
115 //! Specialization of %Teuchos::PromotionTraits to DFad types
116 template <typename S, typename R>
117 struct PromotionTraits< Sacado::UQ::PCE<S>, R > {
118 typedef typename Sacado::Promote< Sacado::UQ::PCE<S>, R >::type
119 promote;
120 };
121
122 //! Specialization of %Teuchos::PromotionTraits to DFad types
123 template <typename L, typename S>
124 struct PromotionTraits< L, Sacado::UQ::PCE<S> > {
125 public:
126 typedef typename Sacado::Promote< L, Sacado::UQ::PCE<S> >::type
127 promote;
128 };
129
130 //! Specializtion of %Teuchos::ScalarTraits
131 template <typename S>
132 struct ScalarTraits< Sacado::UQ::PCE<S> > :
133 public Sacado::UQ::PCEScalarTraitsImp< Sacado::UQ::PCE<S> > {};
134
135 //! Specializtion of %Teuchos::ValueTypeConversionTraits
136 template <typename TypeTo, typename S>
137 struct ValueTypeConversionTraits< TypeTo, Sacado::UQ::PCE<S> > :
138 public Sacado::UQ::PCEValueTypeConversionTraitsImp< TypeTo,
139 Sacado::UQ::PCE<S> > {};
140
141 //! Specialization of %Teuchos::SerializationTraits
142 template <typename Ordinal, typename S>
143 struct SerializationTraits<Ordinal, Sacado::UQ::PCE<S> > :
144 public Sacado::UQ::PCESerializationTraitsImp< Ordinal,
145 Sacado::UQ::PCE<S> >
146 {};
147
148 //! Specialization of %Teuchos::ValueTypeSerializer
149 template <typename Ordinal, typename S>
150 struct ValueTypeSerializer<Ordinal, Sacado::UQ::PCE<S> > :
151 public Sacado::UQ::PCESerializerImp< Ordinal,
152 Sacado::UQ::PCE<S>,
153 ValueTypeSerializer<Ordinal,typename S::value_type> >
154 {
155 typedef Sacado::UQ::PCE<S> PCEType;
156 typedef ValueTypeSerializer<Ordinal,typename S::value_type> ValueSerializer;
157 typedef Sacado::UQ::PCESerializerImp< Ordinal,PCEType,ValueSerializer> Base;
158 typedef typename Base::cijk_type cijk_type;
159 ValueTypeSerializer(const cijk_type& cijk,
160 const Teuchos::RCP<const ValueSerializer>& vs) :
161 Base(cijk,vs) {}
162 };
163
164 // Should also do TypeTo, and TypeTo,TypeFrom as UQ::PCE, but the real way
165 // to fix is to make sure it is never called at all (requires fixing
166 // magnitudeType)
167
168 }
169
170 #endif // SACADO_UQ_PCE_TRAITS_HPP