20 namespace ExponentialRandomFieldUnitTest {
30 solverParams.
set(
"Nonlinear Solver Tolerance", 1e-8);
32 typedef cov_type::eigen_pair_type eigen_pair_type;
33 cov_type cov(M, a, b, L, 0, solverParams);
40 for (
int i=0; i<M-1; i++) {
41 out <<
"eigs[" << i <<
"] = " << eigs[i].eig_val << std::endl;
42 if (eigs[i].eig_val < eigs[i+1].eig_val)
55 solverParams.
set(
"Nonlinear Solver Tolerance", 1e-8);
57 typedef cov_type::eigen_pair_type eigen_pair_type;
58 cov_type cov(M, a, b, L, 0, solverParams);
66 for (
int i=0; i<M-1; i++) {
67 double omega1 = eigs[i].eig_func.getFrequency();
68 double omega2 = eigs[i].eig_func.getFrequency();
70 out <<
"eigs[" << i <<
"].frequency = " << omega1 << std::endl;
71 if (omega2 - omega1 > pi)
82 double center = (b+a)/2.0;
83 double width = (b-a)/2.0;
84 double w_coeff = 2.0*width;
90 basis.
getQuadPoints(p, quad_points, quad_weights, quad_values);
95 typedef cov_type::eigen_pair_type eigen_pair_type;
96 cov_type cov(M, a, b, L, 0, solverParams);
101 int nqp = quad_weights.
size();
106 for (
int i=0; i<M; i++) {
109 double integral = 0.0;
111 for (
int qp=0; qp<nqp; qp++) {
112 double xp = center + quad_points[qp]*width;
113 double w = w_coeff*quad_weights[qp];
114 double val = eigs[i].eig_func.evaluate(xp);
115 integral += w*val*
val;
118 out <<
"lambda = " << eigs[i].eig_val <<
", integral = " << integral
119 <<
", rhs = " << rhs <<
", error = " << integral-rhs << std::endl;
132 double center = (b+a)/2.0;
133 double width = (b-a)/2.0;
134 double w_coeff = 2.0*width;
140 basis.
getQuadPoints(p, quad_points, quad_weights, quad_values);
145 typedef cov_type::eigen_pair_type eigen_pair_type;
146 cov_type cov(M, a, b, L, 0, solverParams);
151 int nqp = quad_weights.
size();
155 for (
int i=0; i<M; i++) {
156 for (
int j=0;
j<i;
j++) {
159 double integral = 0.0;
161 for (
int qp=0; qp<nqp; qp++) {
162 double xp = center + quad_points[qp]*width;
163 double w = w_coeff*quad_weights[qp];
164 double val1 = eigs[i].eig_func.evaluate(xp);
165 double val2 = eigs[
j].eig_func.evaluate(xp);
166 integral += w*val1*val2;
169 out <<
"lambda = " << eigs[i].eig_val <<
", integral = " << integral
170 <<
", rhs = " << rhs <<
", error = " << integral-rhs << std::endl;
184 double center = (b+a)/2.0;
185 double width = (b-a)/2.0;
186 double x = center + 0.25*width;
187 double w_coeff = 2.0*width;
193 basis.
getQuadPoints(p, quad_points, quad_weights, quad_values);
198 typedef cov_type::eigen_pair_type eigen_pair_type;
199 cov_type cov(M, a, b, L, 0, solverParams);
204 int nqp = quad_weights.
size();
209 for (
int i=0; i<M; i++) {
212 double integral = 0.0;
213 for (
int qp=0; qp<nqp; qp++) {
214 double xp = center + quad_points[qp]*width;
215 double w = w_coeff*quad_weights[qp];
217 w*cov.evaluateCovariance(x,xp)*eigs[i].eig_func.evaluate(xp);
221 double rhs = eigs[i].eig_val*eigs[i].eig_func.evaluate(x);
222 out <<
"lambda = " << eigs[i].eig_val <<
", integral = " << integral
223 <<
", rhs = " << rhs <<
", error = " << integral-rhs << std::endl;
236 for (
int i=0; i<d; i++)
249 solverParams.
set(
"Number of KL Terms", M);
250 solverParams.
set(
"Mean", 0.5);
251 solverParams.
set(
"Standard Deviation", 1.25);
255 for (
int i=0; i<d; i++) {
256 domain_upper[i] = 1.5;
257 domain_lower[i] = -1.0;
258 correlation_length[i] = 10.0;
260 solverParams.
set(
"Domain Upper Bounds", domain_upper);
261 solverParams.
set(
"Domain Lower Bounds", domain_lower);
262 solverParams.
set(
"Correlation Lengths", correlation_length);
268 int nqp = quad_weights.
size();
275 double w_coeff = 1.0;
276 for (
int i=0; i<d; i++) {
277 domain_center[i] = (domain_upper[i] + domain_lower[i])/2.0;
278 domain_width[i] = (domain_upper[i] - domain_lower[i])/2.0;
279 x[i] = domain_center[i] + 0.25*domain_width[i];
280 w_coeff *= 2.0*domain_width[i];
285 for (
int i=0; i<M; i++) {
288 double integral = 0.0;
289 for (
int qp=0; qp<nqp; qp++) {
291 for (
int j=0;
j<d;
j++)
292 xp[
j] = domain_center[
j] + xp[
j]*domain_width[
j];
294 for (
int j=0;
j<d;
j++)
295 val +=
std::abs(x[
j] - xp[
j])/correlation_length[
j];
296 double w = w_coeff*quad_weights[qp];
303 out <<
"lambda = " << rf.
eigenvalue(i) <<
", integral = " << integral
304 <<
", rhs = " << rhs <<
", error = " << integral-rhs << std::endl;
virtual const Teuchos::Array< Teuchos::Array< value_type > > & getQuadPoints() const
Get quadrature points.
virtual void getQuadPoints(ordinal_type quad_order, Teuchos::Array< value_type > &points, Teuchos::Array< value_type > &weights, Teuchos::Array< Teuchos::Array< value_type > > &values) const
Compute quadrature points, weights, and values of basis polynomials at given set of points points...
virtual const Teuchos::Array< value_type > & getQuadWeights() const
Get quadrature weights.
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
bool compareValues(const ValueType &a1, const std::string &a1_name, const ValueType &a2, const std::string &a2_name, const ValueType &rel_tol, const ValueType &abs_tol, Teuchos::FancyOStream &out)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
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 PCE< Storage > abs(const PCE< Storage > &a)
Class representing an exponential covariance function and its KL eigevalues/eigenfunctions.
KOKKOS_INLINE_FUNCTION PCE< Storage > atan(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > exp(const PCE< Storage > &a)
Legendre polynomial basis.
TEUCHOS_UNIT_TEST(Stokhos_ExponentialRandomField, OneD_Eigenvalue_Ordering)
Class representing a KL expansion of an exponential random field.
value_type KOKKOS_INLINE_FUNCTION eigenvalue(int i) const
Return eigenvalue.
Defines quadrature for a tensor product basis by tensor products of 1-D quadrature rules...