16 template <
typename value_type,
typename execution_space>
21 num_KL = solverParams.
get<
int>(
"Number of KL Terms");
22 mean = solverParams.
get<
double>(
"Mean");
23 std_dev = solverParams.
get<
double>(
"Standard Deviation");
30 if (solverParams.
isType<std::string>(
"Domain Upper Bounds"))
31 domain_upper_bound_double =
32 Teuchos::getArrayFromStringParameter<double>(
33 solverParams,
"Domain Upper Bounds");
35 domain_upper_bound_double =
40 for (
int i=0; i<domain_upper_bound.size(); i++)
41 domain_upper_bound[i]=domain_upper_bound_double[i];
44 if (solverParams.
isType<std::string>(
"Domain Lower Bounds"))
45 domain_lower_bound_double =
46 Teuchos::getArrayFromStringParameter<double>(
47 solverParams,
"Domain Lower Bounds");
49 domain_lower_bound_double =
54 for (
int i=0; i<domain_lower_bound.size(); i++)
55 domain_lower_bound[i]=domain_lower_bound_double[i];
58 if (solverParams.
isType<std::string>(
"Correlation Lengths"))
59 correlation_length_double =
60 Teuchos::getArrayFromStringParameter<double>(
61 solverParams,
"Correlation Lengths");
63 correlation_length_double =
68 for (
int i=0; i<correlation_length.size(); i++)
69 correlation_length[i]=correlation_length_double[i];
72 dim = domain_upper_bound.
size();
74 for (
int i=0; i<dim; i++) {
75 eig_pairs[i].
resize(num_KL);
77 num_KL, domain_lower_bound[i], domain_upper_bound[i],
78 correlation_length[i], i, solverParams);
83 int num_prod =
static_cast<int>(
std::pow(static_cast<double>(num_KL),
84 static_cast<double>(dim)));
90 while (cnt < num_prod) {
91 for (
int i=0; i<dim; i++) {
92 eigs[i] = eig_pairs[i][index[i]];
94 product_eig_pairs[cnt].set(eigs);
97 while (j < dim-1 && index[j] == num_KL) {
106 std::sort(product_eig_pairs.
begin(), product_eig_pairs.
end(),
110 product_eigen_funcs =
112 product_eigen_values =
114 typename eigen_func_array_type::HostMirror host_product_eigen_funcs =
116 typename eigen_value_array_type::HostMirror host_product_eigen_values =
118 for (
int i=0; i<num_prod; ++i) {
119 host_product_eigen_values(i) = 1.0;
120 for (
int j=0;
j<dim; ++
j) {
121 host_product_eigen_values(i) *= product_eig_pairs[i].eig_pairs[
j].eig_val;
122 host_product_eigen_funcs(i,
j) =
123 product_eig_pairs[i].eig_pairs[
j].eig_func;
130 template <
typename value_type,
typename execution_space>
131 template <
typename po
int_type,
typename rv_type>
132 KOKKOS_INLINE_FUNCTION
135 evaluate(
const point_type& point,
const rv_type& random_variables)
const
138 result_type result = mean;
139 for (
int i=0; i<num_KL; ++i) {
140 result_type t = std_dev*
std::sqrt(product_eigen_values(i));
141 for (
int j=0;
j<dim; ++
j)
142 t *= product_eigen_funcs(i,
j).evaluate(point[
j]);
143 result += random_variables[i]*t;
148 template <
typename value_type,
typename execution_space>
149 template <
typename po
int_type>
150 KOKKOS_INLINE_FUNCTION
156 result_type result = 0.0;
157 for (
int i=0; i<num_KL; i++) {
159 for (
int j=0;
j<dim; ++
j)
160 t *= product_eigen_funcs(i,
j).evaluate(point[
j]);
161 result += product_eigen_values(i).eig_val*t*t;
166 template <
typename value_type,
typename execution_space>
167 template <
typename po
int_type>
168 KOKKOS_INLINE_FUNCTION
174 result_type t = std_dev*
std::sqrt(product_eigen_values(i));
175 for (
int j=0;
j<dim; ++
j)
176 t *= product_eigen_funcs(i,
j).evaluate(point[
j]);
180 template <
typename value_type,
typename execution_space>
185 os <<
"KL expansion using " << num_KL <<
" terms in " << dim
186 <<
" dimensions:" << std::endl;
187 os <<
"\tMean = " << mean <<
", standard deviation = " << std_dev
189 os <<
"\tEigenvalues, Eigenfunctions:" << std::endl;
190 for (
int i=0; i<num_KL; i++) {
191 os <<
"\t\t" << product_eigen_values(i) <<
", ";
192 for (
int j=0;
j<dim-1; ++
j) {
194 product_eigen_funcs(i,
j).print(os);
198 product_eigen_funcs(i,dim-1).print(os);
199 os <<
")" << std::endl;
KOKKOS_INLINE_FUNCTION PCE< Storage > sqrt(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION Teuchos::PromotionTraits< typename rv_type::value_type, value_type >::promote evaluate(const point_type &point, const rv_type &random_variables) const
Evaluate random field at a point.
SparseArrayIterator< index_iterator, value_iterator >::value_type index(const SparseArrayIterator< index_iterator, value_iterator > &it)
Kokkos::View< one_d_eigen_func_type **, execution_space > eigen_func_array_type
KOKKOS_INLINE_FUNCTION PCE< Storage > pow(const PCE< Storage > &a, const PCE< Storage > &b)
T & get(ParameterList &l, const std::string &name)
Kokkos::View< value_type *, execution_space > eigen_value_array_type
void print(std::ostream &os) const
Print KL expansion.
KOKKOS_INLINE_FUNCTION Teuchos::PromotionTraits< typename point_type::value_type, value_type >::promote evaluate_eigenfunction(const point_type &point, int i) const
Evaluate given eigenfunction at a point.
KOKKOS_INLINE_FUNCTION Teuchos::PromotionTraits< typename point_type::value_type, value_type >::promote evaluate_standard_deviation(const point_type &point) const
Evaluate standard deviation of random field at a point.
void deep_copy(const Stokhos::CrsMatrix< ValueType, DstDevice, Layout > &dst, const Stokhos::CrsMatrix< ValueType, SrcDevice, Layout > &src)
void resize(size_type new_size, const value_type &x=value_type())
Class representing an exponential covariance function and its KL eigevalues/eigenfunctions.
Predicate class for sorting product eigenfunctions based on eigenvalue.
bool isType(const std::string &name) const
ExponentialRandomField()
Default constructor.
const Teuchos::Array< eigen_pair_type > & getEigenPairs() const
Get eigenpairs.
Stokhos::CrsMatrix< ValueType, Device, Layout >::HostMirror create_mirror_view(const Stokhos::CrsMatrix< ValueType, Device, Layout > &A)