49 #include "Sacado_Fad_DFad.hpp"
50 #include "Sacado_mpl_apply.hpp"
51 #include "Sacado_Random.hpp"
57 template <
typename PCEType,
typename FadType>
68 typedef typename Sacado::mpl::apply<FadType,PCEType>::type
FadPCEType;
79 for (
int i=0; i<d; i++)
89 Stokhos::create_product_tensor<execution_space>(*
basis, *
Cijk);
102 template <
typename PCEType>
104 const std::string& tag,
111 Ordinal count = x.
size();
112 Ordinal bytes = SerT::fromCountToIndirectBytes(count, &x[0]);
113 char *charBuffer =
new char[bytes];
114 SerT::serialize(count, &x[0], bytes, charBuffer);
115 Ordinal count2 = SerT::fromIndirectBytesToCount(bytes, charBuffer);
118 bool success = (count == count2);
119 out << tag <<
" serialize/deserialize count test";
124 out <<
": \n\tExpected: " << count <<
", \n\tGot: " << count2 <<
"."
129 for (Ordinal i=0; i<count2; i++)
130 x2[i].reset(x[i].
cijk());
131 SerT::deserialize(bytes, charBuffer, count2, &x2[0]);
133 delete [] charBuffer;
136 for (Ordinal i=0; i<count; i++) {
137 bool success2 = Sacado::IsEqual<PCEType>::eval(x[i], x2[i]);
138 out << tag <<
" serialize/deserialize pce test " << i;
143 out <<
": \n\tExpected: " << x[i] <<
", \n\tGot: " << x2[i]
145 success = success && success2;
151 template <
typename PCEType,
typename Serializer>
153 const Serializer& serializer,
154 const std::string& tag,
160 Ordinal count = x.
size();
161 Ordinal bytes = serializer.fromCountToIndirectBytes(count, &x[0]);
162 char *charBuffer =
new char[bytes];
163 serializer.serialize(count, &x[0], bytes, charBuffer);
166 for (Ordinal i=0; i<count; i++)
167 x[i].reset(serializer.getSerializerCijk());
170 Ordinal count2 = serializer.fromIndirectBytesToCount(bytes, charBuffer);
172 serializer.deserialize(bytes, charBuffer, count2, &x2[0]);
174 delete [] charBuffer;
177 bool success = (count == count2);
178 out << tag <<
" serialize/deserialize count test";
183 out <<
": \n\tExpected: " << count <<
", \n\tGot: " << count2 <<
"."
187 for (Ordinal i=0; i<count; i++) {
188 bool success2 = Sacado::IsEqual<PCEType>::eval(x[i], x2[i]);
189 out << tag <<
" serialize/deserialize pce test " << i;
194 out <<
": \n\tExpected: " << x[i] <<
", \n\tGot: " << x2[i]
196 success = success && success2;
202 template <
typename PCEType,
typename Serializer>
204 const Serializer& serializer,
205 const std::string& tag,
211 Ordinal count = x.
size();
212 Ordinal bytes = serializer.fromCountToIndirectBytes(count, &x[0]);
213 char *charBuffer =
new char[bytes];
214 serializer.serialize(count, &x[0], bytes, charBuffer);
217 Ordinal sz = serializer.getSerializerSize();
218 typedef typename Serializer::value_serializer_type VST;
220 for (Ordinal i=0; i<count; i++) {
222 for (Ordinal
j=0;
j<sz;
j++)
224 x[i].val().reset(vs->getSerializerCijk());
228 Ordinal count2 = serializer.fromIndirectBytesToCount(bytes, charBuffer);
230 serializer.deserialize(bytes, charBuffer, count2, &x2[0]);
232 delete [] charBuffer;
235 bool success = (count == count2);
236 out << tag <<
" serialize/deserialize count test";
241 out <<
": \n\tExpected: " << count <<
", \n\tGot: " << count2 <<
"."
245 for (Ordinal i=0; i<count; i++) {
246 bool success2 = Sacado::IsEqual<PCEType>::eval(x[i], x2[i]);
247 out << tag <<
" serialize/deserialize pce test " << i;
252 out <<
": \n\tExpected: " << x[i] <<
", \n\tGot: " << x2[i]
254 success = success && success2;
265 Sacado::Random<double>
rnd;
270 for (
int i=0; i<n; i++) {
272 for (
int j=0;
j<setup.
sz;
j++)
276 x, std::string(
"UQ::PCE") +
" Uniform", out);
278 x, *setup.
pce_serializer, std::string(
"UQ::PCE") +
" Uniform PTS", out);
279 success = success1 && success2;
286 for (
int i=0; i<n; i++) {
290 x, std::string(
"UQ::PCE") +
" Empty", out);
292 x, *setup.
pce_serializer, std::string(
"UQ::PCE") +
" Empty PTS", out);
293 success = success1 && success2;
299 int p[] = { 5, 0, 8, 8, 3, 0 };
301 for (
int i=0; i<n; i++) {
303 for (
int j=0;
j<p[i];
j++)
307 x, std::string(
"UQ::PCE") +
" Mixed", out);
309 x, *setup.
pce_serializer, std::string(
"UQ::PCE") +
" Mixed PTS", out);
310 success = success1 && success2;
315 typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
319 for (
int i=0; i<n; i++) {
321 for (
int k=0; k<setup.
sz; k++)
322 f.fastAccessCoeff(k) =
rnd.number();
323 x[i] = FadPCEType(p, f);
324 for (
int j=0;
j<p;
j++) {
326 for (
int k=0; k<setup.
sz; k++)
327 g.fastAccessCoeff(k) =
rnd.number();
328 x[i].fastAccessDx(
j) =
g;
333 std::string(
"UQ::PCE") +
" Nested Uniform", out);
337 typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
341 for (
int i=0; i<n; i++) {
343 for (
int k=0; k<setup.
sz; k++)
344 f.fastAccessCoeff(k) =
rnd.number();
345 x[i] = FadPCEType(p, f);
346 for (
int j=0;
j<p;
j++)
352 std::string(
"UQ::PCE") +
" Nested Empty Inner", out);
356 typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
359 for (
int i=0; i<n; i++) {
361 for (
int k=0; k<setup.
sz; k++)
362 f.fastAccessCoeff(k) =
rnd.number();
363 x[i] = FadPCEType(f);
368 std::string(
"UQ::PCE") +
" Nested Empty Outer", out);
372 typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
375 for (
int i=0; i<n; i++) {
381 std::string(
"UQ::PCE") +
" Nested Empty All", out);
387 Kokkos::initialize();
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
static int runUnitTestsFromMain(int argc, char *argv[])
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)
int main(int argc, char **argv)
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