18 #include "Sacado_Fad_DFad.hpp"
19 #include "Sacado_mpl_apply.hpp"
20 #include "Sacado_Random.hpp"
26 template <
typename PCEType,
typename FadType>
37 typedef typename Sacado::mpl::apply<FadType,PCEType>::type
FadPCEType;
48 for (
int i=0; i<d; i++)
58 Stokhos::create_product_tensor<execution_space>(*
basis, *
Cijk);
71 template <
typename PCEType>
73 const std::string& tag,
80 Ordinal count = x.
size();
81 Ordinal bytes = SerT::fromCountToIndirectBytes(count, &x[0]);
82 char *charBuffer =
new char[bytes];
83 SerT::serialize(count, &x[0], bytes, charBuffer);
84 Ordinal count2 = SerT::fromIndirectBytesToCount(bytes, charBuffer);
87 bool success = (count == count2);
88 out << tag <<
" serialize/deserialize count test";
93 out <<
": \n\tExpected: " << count <<
", \n\tGot: " << count2 <<
"."
98 for (Ordinal i=0; i<count2; i++)
99 x2[i].reset(x[i].
cijk());
100 SerT::deserialize(bytes, charBuffer, count2, &x2[0]);
102 delete [] charBuffer;
105 for (Ordinal i=0; i<count; i++) {
106 bool success2 = Sacado::IsEqual<PCEType>::eval(x[i], x2[i]);
107 out << tag <<
" serialize/deserialize pce test " << i;
112 out <<
": \n\tExpected: " << x[i] <<
", \n\tGot: " << x2[i]
114 success = success && success2;
120 template <
typename PCEType,
typename Serializer>
122 const Serializer& serializer,
123 const std::string& tag,
129 Ordinal count = x.
size();
130 Ordinal bytes = serializer.fromCountToIndirectBytes(count, &x[0]);
131 char *charBuffer =
new char[bytes];
132 serializer.serialize(count, &x[0], bytes, charBuffer);
135 for (Ordinal i=0; i<count; i++)
136 x[i].reset(serializer.getSerializerCijk());
139 Ordinal count2 = serializer.fromIndirectBytesToCount(bytes, charBuffer);
141 serializer.deserialize(bytes, charBuffer, count2, &x2[0]);
143 delete [] charBuffer;
146 bool success = (count == count2);
147 out << tag <<
" serialize/deserialize count test";
152 out <<
": \n\tExpected: " << count <<
", \n\tGot: " << count2 <<
"."
156 for (Ordinal i=0; i<count; i++) {
157 bool success2 = Sacado::IsEqual<PCEType>::eval(x[i], x2[i]);
158 out << tag <<
" serialize/deserialize pce test " << i;
163 out <<
": \n\tExpected: " << x[i] <<
", \n\tGot: " << x2[i]
165 success = success && success2;
171 template <
typename PCEType,
typename Serializer>
173 const Serializer& serializer,
174 const std::string& tag,
180 Ordinal count = x.
size();
181 Ordinal bytes = serializer.fromCountToIndirectBytes(count, &x[0]);
182 char *charBuffer =
new char[bytes];
183 serializer.serialize(count, &x[0], bytes, charBuffer);
186 Ordinal sz = serializer.getSerializerSize();
187 typedef typename Serializer::value_serializer_type VST;
189 for (Ordinal i=0; i<count; i++) {
191 for (Ordinal
j=0;
j<sz;
j++)
193 x[i].val().reset(vs->getSerializerCijk());
197 Ordinal count2 = serializer.fromIndirectBytesToCount(bytes, charBuffer);
199 serializer.deserialize(bytes, charBuffer, count2, &x2[0]);
201 delete [] charBuffer;
204 bool success = (count == count2);
205 out << tag <<
" serialize/deserialize count test";
210 out <<
": \n\tExpected: " << count <<
", \n\tGot: " << count2 <<
"."
214 for (Ordinal i=0; i<count; i++) {
215 bool success2 = Sacado::IsEqual<PCEType>::eval(x[i], x2[i]);
216 out << tag <<
" serialize/deserialize pce test " << i;
221 out <<
": \n\tExpected: " << x[i] <<
", \n\tGot: " << x2[i]
223 success = success && success2;
234 Sacado::Random<double>
rnd;
239 for (
int i=0; i<n; i++) {
241 for (
int j=0;
j<setup.
sz;
j++)
245 x, std::string(
"UQ::PCE") +
" Uniform", out);
247 x, *setup.
pce_serializer, std::string(
"UQ::PCE") +
" Uniform PTS", out);
248 success = success1 && success2;
255 for (
int i=0; i<n; i++) {
259 x, std::string(
"UQ::PCE") +
" Empty", out);
261 x, *setup.
pce_serializer, std::string(
"UQ::PCE") +
" Empty PTS", out);
262 success = success1 && success2;
268 int p[] = { 5, 0, 8, 8, 3, 0 };
270 for (
int i=0; i<n; i++) {
272 for (
int j=0;
j<p[i];
j++)
276 x, std::string(
"UQ::PCE") +
" Mixed", out);
278 x, *setup.
pce_serializer, std::string(
"UQ::PCE") +
" Mixed PTS", out);
279 success = success1 && success2;
284 typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
288 for (
int i=0; i<n; i++) {
290 for (
int k=0; k<setup.
sz; k++)
291 f.fastAccessCoeff(k) =
rnd.number();
292 x[i] = FadPCEType(p, f);
293 for (
int j=0;
j<p;
j++) {
295 for (
int k=0; k<setup.
sz; k++)
296 g.fastAccessCoeff(k) =
rnd.number();
297 x[i].fastAccessDx(
j) =
g;
302 std::string(
"UQ::PCE") +
" Nested Uniform", out);
306 typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
310 for (
int i=0; i<n; i++) {
312 for (
int k=0; k<setup.
sz; k++)
313 f.fastAccessCoeff(k) =
rnd.number();
314 x[i] = FadPCEType(p, f);
315 for (
int j=0;
j<p;
j++)
321 std::string(
"UQ::PCE") +
" Nested Empty Inner", out);
325 typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
328 for (
int i=0; i<n; i++) {
330 for (
int k=0; k<setup.
sz; k++)
331 f.fastAccessCoeff(k) =
rnd.number();
332 x[i] = FadPCEType(f);
337 std::string(
"UQ::PCE") +
" Nested Empty Outer", out);
341 typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
344 for (
int i=0; i<n; i++) {
350 std::string(
"UQ::PCE") +
" Nested Empty All", out);
Stokhos::StandardStorage< int, double > storage_type
RCP< FadPCESerializerT > fad_pce_serializer
Kokkos::DefaultExecutionSpace execution_space
RCP< const Stokhos::CompletePolynomialBasis< int, double > > basis
RCP< PCESerializerT > pce_serializer
Teuchos::ValueTypeSerializer< int, FadPCEType > FadPCESerializerT
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
UnitTestSetup< int, double > setup
Sacado::Fad::DFad< double > FadType
expr expr expr expr fastAccessDx(i, j)) FAD_UNARYOP_MACRO(exp
virtual Teuchos::RCP< Stokhos::Sparse3Tensor< ordinal_type, value_type > > computeTripleProductTensor() const
Compute triple product tensor.
bool testSerialization(const Teuchos::Array< VecType > &x, const std::string &tag, Teuchos::FancyOStream &out)
expr1 expr1 expr1 expr2 expr1 expr1 c expr2 expr1 c fastAccessCoeff(j)-expr2.val(j)
Sacado::Random< double > rnd
KOKKOS_INLINE_FUNCTION constexpr std::enable_if< is_view_uq_pce< view_type >::value, typename CijkType< view_type >::type >::type cijk(const view_type &view)
Sacado::mpl::apply< FadType, PCEType >::type FadPCEType
Legendre polynomial basis.
bool testNestedSerialization(Teuchos::Array< VecType > &x, const Serializer &serializer, const std::string &tag, Teuchos::FancyOStream &out)
Sacado::UQ::PCE< storage_type > PCEType
ScalarType f(const Teuchos::Array< ScalarType > &x, double a, double b)
PCEType::cijk_type kokkos_cijk_type
kokkos_cijk_type kokkos_cijk
ScalarType g(const Teuchos::Array< ScalarType > &x, const ScalarType &y)
RCP< Stokhos::Sparse3Tensor< int, double > > Cijk
Teuchos::ValueTypeSerializer< int, PCEType > PCESerializerT