44#include "Teuchos_UnitTestHarness.hpp"
45#include "Teuchos_TestingHelpers.hpp"
46#include "Teuchos_UnitTestRepository.hpp"
47#include "Teuchos_GlobalMPISession.hpp"
51#ifdef HAVE_STOKHOS_FORUQTK
58 template <
typename OrdinalType,
typename ValueType>
68 UnitTestSetup<int,double>
setup;
71 int order =
setup.basis.order();
72 TEUCHOS_TEST_EQUALITY(order,
setup.p, out, success);
76 int size =
setup.basis.size();
77 TEUCHOS_TEST_EQUALITY(size,
setup.p+1, out, success);
81 const Teuchos::Array<double>& n1 =
setup.basis.norm_squared();
82 Teuchos::Array<double> n2(
setup.p+1);
84 for (
int i=1; i<=
setup.p; i++)
91 Teuchos::Array<double> n1(
setup.p+1);
92 Teuchos::Array<double> n2(
setup.p+1);
93 n1[0] =
setup.basis.norm_squared(0);
95 for (
int i=1; i<=
setup.p; i++) {
96 n1[i] =
setup.basis.norm_squared(i);
104 const Teuchos::Array<double>& n1 =
setup.basis.norm_squared();
105 Teuchos::Array<double> n2(
setup.p+1);
106 Teuchos::Array<double> x, w;
107 Teuchos::Array< Teuchos::Array<double> > v;
108 setup.basis.getQuadPoints(2*
setup.p, x, w, v);
110 for (
int i=0; i<=
setup.p; i++) {
112 for (
int j=0;
j<nqp;
j++)
113 n2[i] += w[
j]*v[
j][i]*v[
j][i];
121 const Teuchos::Array<double>& norms =
setup.basis.norm_squared();
122 Teuchos::Array<double> x, w;
123 Teuchos::Array< Teuchos::Array<double> > v;
124 setup.basis.getQuadPoints(2*
setup.p, x, w, v);
126 Teuchos::SerialDenseMatrix<int,double> mat(
setup.p+1,
setup.p+1);
127 for (
int i=0; i<=
setup.p; i++) {
129 for (
int k=0; k<nqp; k++)
130 mat(i,
j) += w[k]*v[k][i]*v[k][
j];
131 mat(i,
j) /= std::sqrt(norms[i]*norms[
j]);
135 success = mat.normInf() <
setup.atol;
137 out <<
"\n Error, mat.normInf() < atol = " << mat.normInf()
138 <<
" < " <<
setup.atol <<
": failed!\n";
139 out <<
"mat = " <<
printMat(mat) << std::endl;
144 Teuchos::RCP< Stokhos::Dense3Tensor<int, double> > Cijk =
145 setup.basis.computeTripleProductTensor();
147 Teuchos::Array<double> x, w;
148 Teuchos::Array< Teuchos::Array<double> > v;
149 setup.basis.getQuadPoints(3*
setup.p, x, w, v);
152 for (
int i=0; i<=
setup.p; i++) {
154 for (
int k=0; k<=
setup.p; k++) {
157 for (
int qp=0; qp<nqp; qp++)
158 c += w[qp]*v[qp][i]*v[qp][
j]*v[qp][k];
159 std::stringstream ss;
160 ss <<
"Cijk(" << i <<
"," <<
j <<
"," << k <<
")";
170 Teuchos::RCP< Teuchos::SerialDenseMatrix<int, double> > Bij =
171 setup.basis.computeDerivDoubleProductTensor();
173 Teuchos::Array<double> x, w;
174 Teuchos::Array< Teuchos::Array<double> > v,
val, deriv;
175 setup.basis.getQuadPoints(2*
setup.p, x, w, v);
179 for (
int i=0; i<nqp; i++) {
181 deriv[i].resize(
setup.p+1);
182 setup.basis.evaluateBasesAndDerivatives(x[i],
val[i], deriv[i]);
186 for (
int i=0; i<=
setup.p; i++) {
189 for (
int qp=0; qp<nqp; qp++)
190 b += w[qp]*deriv[qp][i]*
val[qp][
j];
191 std::stringstream ss;
192 ss <<
"Bij(" << i <<
"," <<
j <<
")";
222 Teuchos::Array<double> v1(
setup.p+1), v2(
setup.p+1);
223 setup.basis.evaluateBases(x, v1);
232 for (
int i=2; i<=
setup.p; i++)
233 v2[i] = (x*v2[i-1] - std::sqrt(i-1.0)*v2[i-2])/std::sqrt(1.0*i);
240 Teuchos::Array<double> val1(
setup.p+1), deriv1(
setup.p+1),
242 setup.basis.evaluateBasesAndDerivatives(x, val1, deriv1);
251 for (
int i=2; i<=
setup.p; i++)
252 val2[i] = (x*val2[i-1] - std::sqrt(i-1.0)*val2[i-2])/std::sqrt(1.0*i);
257 for (
int i=2; i<=
setup.p; i++)
258 deriv2[i] = (val2[i-1] + x*deriv2[i-1] - std::sqrt(i-1.0)*deriv2[i-2]) /
269 Teuchos::Array<double> v1(
setup.p+1), v2(
setup.p+1);
270 for (
int i=0; i<=
setup.p; i++)
271 v1[i] =
setup.basis.evaluate(x, i);
280 for (
int i=2; i<=
setup.p; i++)
281 v2[i] = (x*v2[i-1] - std::sqrt(i-1.0)*v2[i-2])/std::sqrt(1.0*i);
291 setup.basis.getRecurrenceCoefficients(a1, b1, c1, d1);
294 a2[0] = 0.0; b2[0] = 1.0; c2[0] = 1.0; d2[0] = 1.0;
295 for (
int i=1; i<=
setup.p; i++) {
297 b2[i] = std::sqrt(1.0*i);
299 d2[i] = std::sqrt(1.0*i);
317 setup.basis.getRecurrenceCoefficients(a1, b1, c1, d1);
319 Teuchos::Array<double> a2(
setup.p+1);
320 const Teuchos::Array<double>& n1 =
setup.basis.norm_squared();
321 Teuchos::Array<double> x, w;
322 Teuchos::Array< Teuchos::Array<double> > v;
323 setup.basis.getQuadPoints(2*
setup.p, x, w, v);
325 for (
int i=0; i<=
setup.p; i++) {
327 for (
int j=0;
j<nqp;
j++)
328 a2[i] += w[
j]*x[
j]*v[
j][i]*v[
j][i];
329 a2[i] = a2[i]*c1[i]/n1[i];
341 setup.basis.getRecurrenceCoefficients(a1, b1, c1, d1);
343 Teuchos::Array<double> b2(
setup.p+1);
344 const Teuchos::Array<double>& n1 =
setup.basis.norm_squared();
346 for (
int i=1; i<=
setup.p; i++) {
347 b2[i] = d1[i]*(c1[i]/c1[i-1])*(n1[i]/n1[i-1]);
353#ifdef HAVE_STOKHOS_DAKOTA
355 int n =
static_cast<int>(std::ceil((
setup.p+1)/2.0));
356 Teuchos::Array<double> x1, w1;
357 Teuchos::Array< Teuchos::Array<double> > v1;
358 setup.basis.getQuadPoints(
setup.p, x1, w1, v1);
360 Teuchos::Array<double> x2(n), w2(n);
361 Teuchos::Array< Teuchos::Array<double> > v2(n);
362 webbur::hermite_compute(n, &x2[0], &w2[0]);
364 for (
int i=0; i<n; i++) {
365 w2[i] *= 0.5/std::sqrt(std::atan(1.0));
366 x2[i] *= std::sqrt(2.0);
367 v2[i].resize(
setup.p+1);
368 setup.basis.evaluateBases(x2[i], v2[i]);
375 for (
int i=0; i<n; i++) {
376 std::stringstream ss1, ss2;
377 ss1 <<
"v1[" << i <<
"]";
378 ss2 <<
"v2[" << i <<
"]";
386#ifdef HAVE_STOKHOS_FORUQTK
388 int n =
static_cast<int>(std::ceil((
setup.p+1)/2.0));
389 Teuchos::Array<double> x1, w1;
390 Teuchos::Array< Teuchos::Array<double> > v1;
391 setup.basis.getQuadPoints(
setup.p, x1, w1, v1);
393 Teuchos::Array<double> x2(n), w2(n);
394 Teuchos::Array< Teuchos::Array<double> > v2(n);
397 double endpts[2] = {0.0, 0.0};
398 Teuchos::Array<double> b(n);
401 GAUSSQ_F77(&kind, &n, &alpha, &beta, &kpts, endpts, &b[0], &x2[0], &w2[0]);
403 for (
int i=0; i<n; i++) {
404 w2[i] *= 0.5/std::sqrt(std::atan(1.0));
405 x2[i] *= std::sqrt(2.0);
406 v2[i].resize(
setup.p+1);
407 setup.basis.evaluateBases(x2[i], v2[i]);
414 for (
int i=0; i<n; i++) {
415 std::stringstream ss1, ss2;
416 ss1 <<
"v1[" << i <<
"]";
417 ss2 <<
"v2[" << i <<
"]";
428 Teuchos::GlobalMPISession mpiSession(&argc, &
argv);
429 return Teuchos::UnitTestRepository::runUnitTestsFromMain(argc,
argv);
int main(int argc, char *argv[])
Hermite polynomial basis.
UnitTestSetup< int, double > setup
TEUCHOS_UNIT_TEST(Stokhos_HermiteBasis, Order)
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)
bool compareArrays(const Array1 &a1, const std::string &a1_name, const Array2 &a2, const std::string &a2_name, const ValueType &rel_tol, const ValueType &abs_tol, Teuchos::FancyOStream &out)
Stokhos::HermiteBasis< OrdinalType, ValueType > basis
void printMat(const char *name, Epetra_IntSerialDenseMatrix &matrix)