54template <
typename Value,
typename Device = Kokkos::DefaultExecutionSpace>
60 typedef Kokkos::View<value_type*,execution_space>
point_type;
61 typedef Kokkos::View<value_type*,execution_space>
rv_type;
62 typedef Kokkos::View<value_type*,execution_space>
result_type;
69 rf(rf_),
x(x_),
rv(rv_),
y(
"y",1)
71 Kokkos::parallel_for(1, *
this);
74 KOKKOS_INLINE_FUNCTION
88 Teuchos::ParameterList solverParams;
89 solverParams.set(
"Number of KL Terms", M);
90 solverParams.set(
"Mean", 1.0);
91 solverParams.set(
"Standard Deviation", 0.1);
93 Teuchos::Array<double> domain_upper(ndim), domain_lower(ndim),
94 correlation_length(ndim);
95 for (
int i=0; i<ndim; i++) {
96 domain_upper[i] = 1.0;
97 domain_lower[i] = 0.0;
98 correlation_length[i] = 10.0;
100 solverParams.set(
"Domain Upper Bounds", domain_upper);
101 solverParams.set(
"Domain Lower Bounds", domain_lower);
102 solverParams.set(
"Correlation Lengths", correlation_length);
107 Teuchos::Array<double> x(ndim);
108 for (
int i=0; i<ndim; i++)
109 x[i] = (domain_upper[i] + domain_lower[i])/2.0 +
110 0.1*(domain_upper[i] - domain_lower[i])/2.0;
111 Teuchos::Array<double> rvar(M);
112 for (
int i=0; i<M; i++)
114 double result = rf.
evaluate(x, rvar);
115 std::cout <<
"result (host) = " << result << std::endl;
118 typedef Kokkos::View<double*> view_type;
119 typedef view_type::HostMirror host_view_type;
120 view_type x_view(
"x", ndim);
121 host_view_type host_x = Kokkos::create_mirror_view(x_view);
122 for (
int i=0; i<ndim; i++)
124 Kokkos::deep_copy(x_view, host_x);
125 view_type rvar_view(
"rvar", M);
126 host_view_type host_rvar = Kokkos::create_mirror_view(rvar_view);
127 for (
int i=0; i<M; i++)
128 host_rvar(i) = rvar[i];
129 Kokkos::deep_copy(rvar_view, host_rvar);
131 host_view_type host_y = Kokkos::create_mirror_view(rf_func.
y);
132 Kokkos::deep_copy(host_y, rf_func.
y);
133 double result2 = host_y(0);
134 std::cout <<
"result (device)= " << result2 << std::endl;
136 catch (std::exception& e) {
137 std::cout << e.what() << std::endl;
Class representing a KL expansion of an exponential random field.
KOKKOS_INLINE_FUNCTION Teuchos::PromotionTraits< typenamerv_type::value_type, value_type >::promote evaluate(const point_type &point, const rv_type &random_variables) const
Evaluate random field at a point.
void print(std::ostream &os) const
Print KL expansion.
int main(int argc, char **argv)
RF(const rf_type &rf_, const point_type &x_, const rv_type &rv_)
Kokkos::View< value_type *, execution_space > rv_type
Kokkos::View< value_type *, execution_space > result_type
KOKKOS_INLINE_FUNCTION void operator()(const unsigned i) const
Stokhos::KL::ExponentialRandomField< value_type, execution_space > rf_type
Kokkos::View< value_type *, execution_space > point_type