17 #ifdef HAVE_STOKHOS_FORUQTK
21 namespace LegendreBasisUnitTest {
24 template <
typename OrdinalType,
typename ValueType>
37 int order =
setup.basis.order();
42 int size =
setup.basis.size();
49 for (
int i=0; i<=
setup.p; i++)
50 n2[i] = 1.0/(2.0*i+1.0);
58 for (
int i=0; i<=
setup.p; i++) {
59 n1[i] =
setup.basis.norm_squared(i);
60 n2[i] = 1.0/(2.0*i+1.0);
73 for (
int i=0; i<=
setup.p; i++) {
75 for (
int j=0;
j<nqp;
j++)
76 n2[i] += w[
j]*v[
j][i]*v[
j][i];
90 for (
int i=0; i<=
setup.p; i++) {
92 for (
int k=0; k<nqp; k++)
93 mat(i,
j) += w[k]*v[k][i]*v[k][
j];
100 out <<
"\n Error, mat.normInf() < atol = " << mat.
normInf()
101 <<
" < " <<
setup.atol <<
": failed!\n";
102 out <<
"mat = " <<
printMat(mat) << std::endl;
108 setup.basis.computeTripleProductTensor();
112 setup.basis.getQuadPoints(3*
setup.p, x, w, v);
115 for (
int i=0; i<=
setup.p; i++) {
117 for (
int k=0; k<=
setup.p; k++) {
120 for (
int qp=0; qp<nqp; qp++)
121 c += w[qp]*v[qp][i]*v[qp][
j]*v[qp][k];
122 std::stringstream ss;
123 ss <<
"Cijk(" << i <<
"," <<
j <<
"," << k <<
")";
134 setup.basis.computeDerivDoubleProductTensor();
138 setup.basis.getQuadPoints(3*
setup.p, x, w, v);
142 for (
int i=0; i<nqp; i++) {
145 setup.basis.evaluateBasesAndDerivatives(x[i], val[i], deriv[i]);
149 for (
int i=0; i<=
setup.p; i++) {
152 for (
int qp=0; qp<nqp; qp++)
153 b += w[qp]*deriv[qp][i]*val[qp][
j];
154 std::stringstream ss;
155 ss <<
"Bij(" << i <<
"," <<
j <<
")";
165 setup.basis.computeDerivDoubleProductTensor();
172 deriv_coeffs[1][0] = 1.0;
176 deriv_coeffs[2][1] = 3.0;
178 for (
int k=3; k<=
setup.p; k++) {
180 deriv_coeffs[k][0] = 1.0/3.0*deriv_coeffs[k-1][1];
181 for (
int i=1; i<=k-3; i++)
182 deriv_coeffs[k][i] = i/(2.0*i - 1.0)*deriv_coeffs[k-1][i-1] +
183 (i+1.0)/(2.0*i + 3.0)*deriv_coeffs[k-1][i+1];
184 deriv_coeffs[k][k-2] = (k-2.0)/(2.0*k-5.0)*deriv_coeffs[k-1][k-3];
185 deriv_coeffs[k][k-1] = (k-1.0)/(2.0*k-3.0)*deriv_coeffs[k-1][k-2] + k;
189 for (
int i=0; i<=
setup.p; i++) {
191 double b = deriv_coeffs[i][
j]*n[
j];
192 std::stringstream ss;
193 ss <<
"Bij(" << i <<
"," <<
j <<
")";
204 setup.basis.evaluateBases(x, v1);
213 for (
int i=2; i<=
setup.p; i++)
214 v2[i] = (2.0*i-1.0)/i*x*v2[i-1] - (i-1.0)/i*v2[i-2];
223 setup.basis.evaluateBasesAndDerivatives(x, val1, deriv1);
235 for (
int i=2; i<=
setup.p; i++)
236 val2[i] = (2.0*i-1.0)/i*x*val2[i-1] - (i-1.0)/i*val2[i-2];
241 for (
int i=2; i<=
setup.p; i++)
242 deriv2[i] = i*val2[i-1] + x*deriv2[i-1];
255 for (
int i=0; i<=
setup.p; i++)
256 v1[i] =
setup.basis.evaluate(x, i);
265 for (
int i=2; i<=
setup.p; i++)
266 v2[i] = (2.0*i-1.0)/i*x*v2[i-1] - (i-1.0)/i*v2[i-2];
276 setup.basis.getRecurrenceCoefficients(a1, b1, c1, d1);
279 a2[0] = 0.0; b2[0] = 1.0; c2[0] = 1.0; d2[0] = 1.0;
280 for (
int i=1; i<=
setup.p; i++) {
283 c2[i] = (2.0*i+1.0)/(i+1);
302 setup.basis.getRecurrenceCoefficients(a1, b1, c1, d1);
308 setup.basis.getQuadPoints(2*
setup.p, x, w, v);
310 for (
int i=0; i<=
setup.p; i++) {
312 for (
int j=0;
j<nqp;
j++)
313 a2[i] += w[
j]*x[
j]*v[
j][i]*v[
j][i];
314 a2[i] = a2[i]*c1[i]/n1[i];
326 setup.basis.getRecurrenceCoefficients(a1, b1, c1, d1);
331 for (
int i=1; i<=
setup.p; i++) {
332 b2[i] = d1[i]*(c1[i]/c1[i-1])*(n1[i]/n1[i-1]);
338 #ifdef HAVE_STOKHOS_DAKOTA
343 setup.basis.getQuadPoints(
setup.p, x1, w1, v1);
347 webbur::legendre_compute(n, &x2[0], &w2[0]);
349 for (
int i=0; i<n; i++) {
351 v2[i].resize(
setup.p+1);
352 setup.basis.evaluateBases(x2[i], v2[i]);
359 for (
int i=0; i<n; i++) {
360 std::stringstream ss1, ss2;
361 ss1 <<
"v1[" << i <<
"]";
362 ss2 <<
"v2[" << i <<
"]";
370 #ifdef HAVE_STOKHOS_FORUQTK
375 setup.basis.getQuadPoints(
setup.p, x1, w1, v1);
381 double endpts[2] = {0.0, 0.0};
385 GAUSSQ_F77(&kind, &n, &alpha, &beta, &kpts, endpts, &b[0], &x2[0], &w2[0]);
387 for (
int i=0; i<n; i++) {
389 v2[i].resize(
setup.p+1);
390 setup.basis.evaluateBases(x2[i], v2[i]);
397 for (
int i=0; i<n; i++) {
398 std::stringstream ss1, ss2;
399 ss1 <<
"v1[" << i <<
"]";
400 ss2 <<
"v2[" << i <<
"]";
KOKKOS_INLINE_FUNCTION PCE< Storage > sqrt(const PCE< Storage > &a)
SerialBandDenseMatrixPrinter< OrdinalType, ScalarType > printMat(const SerialBandDenseMatrix< OrdinalType, ScalarType > &obj)
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)
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[])
KOKKOS_INLINE_FUNCTION PCE< Storage > ceil(const PCE< Storage > &a)
Stokhos::LegendreBasis< OrdinalType, ValueType > basis
void resize(size_type new_size, const value_type &x=value_type())
TEUCHOS_UNIT_TEST(Stokhos_LegendreBasis, Order)
UnitTestSetup< int, double > setup
int main(int argc, char **argv)
ScalarTraits< ScalarType >::magnitudeType normInf() const
#define TEUCHOS_TEST_EQUALITY(v1, v2, out, success)
void GAUSSQ_F77(int *kind, int *n, double *alpha, double *beta, int *kpts, double *endpts, double *b, double *x, double *w)