52 namespace ExponentialRandomFieldUnitTest {
62 solverParams.
set(
"Nonlinear Solver Tolerance", 1e-8);
64 typedef cov_type::eigen_pair_type eigen_pair_type;
65 cov_type cov(M, a, b, L, 0, solverParams);
72 for (
int i=0; i<M-1; i++) {
73 out <<
"eigs[" << i <<
"] = " << eigs[i].eig_val << std::endl;
74 if (eigs[i].eig_val < eigs[i+1].eig_val)
87 solverParams.
set(
"Nonlinear Solver Tolerance", 1e-8);
89 typedef cov_type::eigen_pair_type eigen_pair_type;
90 cov_type cov(M, a, b, L, 0, solverParams);
98 for (
int i=0; i<M-1; i++) {
99 double omega1 = eigs[i].eig_func.getFrequency();
100 double omega2 = eigs[i].eig_func.getFrequency();
102 out <<
"eigs[" << i <<
"].frequency = " << omega1 << std::endl;
103 if (omega2 - omega1 > pi)
114 double center = (b+a)/2.0;
115 double width = (b-a)/2.0;
116 double w_coeff = 2.0*width;
122 basis.
getQuadPoints(p, quad_points, quad_weights, quad_values);
127 typedef cov_type::eigen_pair_type eigen_pair_type;
128 cov_type cov(M, a, b, L, 0, solverParams);
133 int nqp = quad_weights.
size();
138 for (
int i=0; i<M; i++) {
141 double integral = 0.0;
143 for (
int qp=0; qp<nqp; qp++) {
144 double xp = center + quad_points[qp]*width;
145 double w = w_coeff*quad_weights[qp];
146 double val = eigs[i].eig_func.evaluate(xp);
147 integral += w*val*
val;
150 out <<
"lambda = " << eigs[i].eig_val <<
", integral = " << integral
151 <<
", rhs = " << rhs <<
", error = " << integral-rhs << std::endl;
164 double center = (b+a)/2.0;
165 double width = (b-a)/2.0;
166 double w_coeff = 2.0*width;
172 basis.
getQuadPoints(p, quad_points, quad_weights, quad_values);
177 typedef cov_type::eigen_pair_type eigen_pair_type;
178 cov_type cov(M, a, b, L, 0, solverParams);
183 int nqp = quad_weights.
size();
187 for (
int i=0; i<M; i++) {
188 for (
int j=0;
j<i;
j++) {
191 double integral = 0.0;
193 for (
int qp=0; qp<nqp; qp++) {
194 double xp = center + quad_points[qp]*width;
195 double w = w_coeff*quad_weights[qp];
196 double val1 = eigs[i].eig_func.evaluate(xp);
197 double val2 = eigs[
j].eig_func.evaluate(xp);
198 integral += w*val1*val2;
201 out <<
"lambda = " << eigs[i].eig_val <<
", integral = " << integral
202 <<
", rhs = " << rhs <<
", error = " << integral-rhs << std::endl;
216 double center = (b+a)/2.0;
217 double width = (b-a)/2.0;
218 double x = center + 0.25*width;
219 double w_coeff = 2.0*width;
225 basis.
getQuadPoints(p, quad_points, quad_weights, quad_values);
230 typedef cov_type::eigen_pair_type eigen_pair_type;
231 cov_type cov(M, a, b, L, 0, solverParams);
236 int nqp = quad_weights.
size();
241 for (
int i=0; i<M; i++) {
244 double integral = 0.0;
245 for (
int qp=0; qp<nqp; qp++) {
246 double xp = center + quad_points[qp]*width;
247 double w = w_coeff*quad_weights[qp];
249 w*cov.evaluateCovariance(x,xp)*eigs[i].eig_func.evaluate(xp);
253 double rhs = eigs[i].eig_val*eigs[i].eig_func.evaluate(x);
254 out <<
"lambda = " << eigs[i].eig_val <<
", integral = " << integral
255 <<
", rhs = " << rhs <<
", error = " << integral-rhs << std::endl;
268 for (
int i=0; i<d; i++)
281 solverParams.
set(
"Number of KL Terms", M);
282 solverParams.
set(
"Mean", 0.5);
283 solverParams.
set(
"Standard Deviation", 1.25);
287 for (
int i=0; i<d; i++) {
288 domain_upper[i] = 1.5;
289 domain_lower[i] = -1.0;
290 correlation_length[i] = 10.0;
292 solverParams.
set(
"Domain Upper Bounds", domain_upper);
293 solverParams.
set(
"Domain Lower Bounds", domain_lower);
294 solverParams.
set(
"Correlation Lengths", correlation_length);
297 int nqp = quad_weights.
size();
304 double w_coeff = 1.0;
305 for (
int i=0; i<d; i++) {
306 domain_center[i] = (domain_upper[i] + domain_lower[i])/2.0;
307 domain_width[i] = (domain_upper[i] - domain_lower[i])/2.0;
308 x[i] = domain_center[i] + 0.25*domain_width[i];
309 w_coeff *= 2.0*domain_width[i];
314 for (
int i=0; i<M; i++) {
317 double integral = 0.0;
318 for (
int qp=0; qp<nqp; qp++) {
320 for (
int j=0;
j<d;
j++)
321 xp[
j] = domain_center[
j] + xp[
j]*domain_width[
j];
323 for (
int j=0;
j<d;
j++)
324 val +=
std::abs(x[
j] - xp[
j])/correlation_length[
j];
325 double w = w_coeff*quad_weights[qp];
332 out <<
"lambda = " << rf.
eigenvalue(i) <<
", integral = " << integral
333 <<
", rhs = " << rhs <<
", error = " << integral-rhs << std::endl;
344 Kokkos::initialize();
virtual const Teuchos::Array< Teuchos::Array< value_type > > & getQuadPoints() const
Get quadrature points.
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
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.
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)
static int runUnitTestsFromMain(int argc, char *argv[])
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.
int main(int argc, char **argv)
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...