44#include "Teuchos_Assert.hpp"
47template <
typename ordinal_type,
typename value_type>
51 const Teuchos::RCP<
const Teuchos::SerialDenseMatrix<ordinal_type, value_type> >& Bij_,
67 double dlange_(
char*,
int*,
int*,
double*,
int*,
double*);
70template <
typename ordinal_type,
typename value_type>
75 if (s == 0 || nrhs == 0)
81 lapack.GETRF(s, s,
A.values(),
A.numRows(), &(
piv[0]), &info);
83 Teuchos::Array<ordinal_type> iwork(4*s);
84 Teuchos::Array<value_type> work(4*s);
88 norm =
dlange_(&t, &s, &s,
A.values(), &n, &work[0]);
89 lapack.GECON(
'1', s,
A.values(),
A.numRows(), norm, &rcond, &work[0],
92 lapack.GETRS(
'N', s, nrhs,
A.values(),
A.numRows(), &(
piv[0]),
B.values(),
97template <
typename ordinal_type,
typename value_type>
115template <
typename ordinal_type,
typename value_type>
124template <
typename ordinal_type,
typename value_type>
133template <
typename ordinal_type,
typename value_type>
145template <
typename ordinal_type,
typename value_type>
157template <
typename ordinal_type,
typename value_type>
174template <
typename ordinal_type,
typename value_type>
191template <
typename ordinal_type,
typename value_type>
205 TEUCHOS_TEST_FOR_EXCEPTION(
sz < pc, std::logic_error,
206 "Stokhos::DerivOrthogPolyExpansion::timesEqual()" <<
207 ": Expansion size (" <<
sz <<
208 ") is too small for computation.");
215 if (p > 1 && xp > 1) {
224 Cijk->value(k,l,i,
j,cijk);
226 tmp += cijk*tc[i]*xc[
j];
228 cc[k] = tmp /
basis->norm_squared(k);
245template <
typename ordinal_type,
typename value_type>
251 const char* func =
"Stokhos::DerivOrthogPolyExpansion::divide()";
259 TEUCHOS_TEST_FOR_EXCEPTION(
sz < pc, std::logic_error,
260 "Stokhos::DerivOrthogPolyExpansion::divideEqual()" <<
261 ": Expansion size (" <<
sz <<
262 ") is too small for computation.");
280 Cijk->value(k,l,i,
j,cijk);
281 A(i,
j) += cijk*xc[k]/
basis->norm_squared(i);
292 int info =
solve(pc, 1);
294 TEUCHOS_TEST_FOR_EXCEPTION(info < 0, std::logic_error,
295 func <<
": Argument " << info
296 <<
" for solve had illegal value");
297 TEUCHOS_TEST_FOR_EXCEPTION(info > 0, std::logic_error,
298 func <<
": Diagonal entry " << info
299 <<
" in LU factorization is exactly zero");
311template <
typename ordinal_type,
typename value_type>
330 cc[i] = ca[i] + cb[i];
336 cc[i] = ca[i] + cb[i];
342template <
typename ordinal_type,
typename value_type>
361template <
typename ordinal_type,
typename value_type>
380template <
typename ordinal_type,
typename value_type>
399 cc[i] = ca[i] - cb[i];
405 cc[i] = ca[i] - cb[i];
411template <
typename ordinal_type,
typename value_type>
430template <
typename ordinal_type,
typename value_type>
449template <
typename ordinal_type,
typename value_type>
459 if (pa > 1 && pb > 1)
463 TEUCHOS_TEST_FOR_EXCEPTION(
sz < pc, std::logic_error,
464 "Stokhos::DerivOrthogPolyExpansion::times()" <<
465 ": Expansion size (" <<
sz <<
466 ") is too small for computation.");
474 if (pa > 1 && pb > 1) {
481 Cijk->value(k,l,i,
j,cijk);
482 if (i < pa &&
j < pb)
483 tmp += cijk*ca[i]*cb[
j];
485 cc[k] = tmp /
basis->norm_squared(k);
501template <
typename ordinal_type,
typename value_type>
519template <
typename ordinal_type,
typename value_type>
537template <
typename ordinal_type,
typename value_type>
544 const char* func =
"Stokhos::DerivOrthogPolyExpansion::divide()";
552 TEUCHOS_TEST_FOR_EXCEPTION(
sz < pc, std::logic_error,
553 "Stokhos::DerivOrthogPolyExpansion::divide()" <<
554 ": Expansion size (" <<
sz <<
555 ") is too small for computation.");
575 Cijk->value(k,l,i,
j,cijk);
576 A(i,
j) += cijk*cb[k] /
basis->norm_squared(i);
587 int info =
solve(pc, 1);
589 TEUCHOS_TEST_FOR_EXCEPTION(info < 0, std::logic_error,
590 func <<
": Argument " << info
591 <<
" for solve had illegal value");
592 TEUCHOS_TEST_FOR_EXCEPTION(info > 0, std::logic_error,
593 func <<
": Diagonal entry " << info
594 <<
" in LU factorization is exactly zero");
606template <
typename ordinal_type,
typename value_type>
613 const char* func =
"Stokhos::DerivOrthogPolyExpansion::divide()";
638 Cijk->value(k,l,i,
j,cijk);
639 A(i,
j) += cijk*cb[k] /
basis->norm_squared(i);
649 int info =
solve(pc, 1);
651 TEUCHOS_TEST_FOR_EXCEPTION(info < 0, std::logic_error,
652 func <<
": Argument " << info
653 <<
" for solve had illegal value");
654 TEUCHOS_TEST_FOR_EXCEPTION(info > 0, std::logic_error,
655 func <<
": Diagonal entry " << info
656 <<
" in LU factorization is exactly zero");
666template <
typename ordinal_type,
typename value_type>
684template <
typename ordinal_type,
typename value_type>
690 const char* func =
"Stokhos::DerivOrthogPolyExpansion::exp()";
710 A(i-1,
j-1) = (*Bij)(i-1,
j);
712 A(i-1,
j-1) -= ca[k]*(*Dijk)(i-1,
j,k);
713 B(i-1,0) += ca[
j]*(*Bij)(i-1,
j);
719 int info =
solve(pc-1, 1);
721 TEUCHOS_TEST_FOR_EXCEPTION(info < 0, std::logic_error,
722 func <<
": Argument " << info
723 <<
" for solve had illegal value");
724 TEUCHOS_TEST_FOR_EXCEPTION(info > 0, std::logic_error,
725 func <<
": Diagonal entry " << info
726 <<
" in LU factorization is exactly zero");
732 s +=
basis->evaluateZero(i) * ca[i];
733 t +=
basis->evaluateZero(i) *
B(i-1,0);
740 cc[i] =
B(i-1,0) * cc[0];
743 cc[0] = std::exp(ca[0]);
746template <
typename ordinal_type,
typename value_type>
752 const char* func =
"Stokhos::DerivOrthogPolyExpansion::log()";
774 A(i-1,
j-1) += ca[k]*(*Dijk)(i-1,k,
j);
775 B(i-1,0) += ca[
j]*(*Bij)(i-1,
j);
780 int info =
solve(pc-1, 1);
782 TEUCHOS_TEST_FOR_EXCEPTION(info < 0, std::logic_error,
783 func <<
": Argument " << info
784 <<
" for solve had illegal value");
785 TEUCHOS_TEST_FOR_EXCEPTION(info > 0, std::logic_error,
786 func <<
": Diagonal entry " << info
787 <<
" in LU factorization is exactly zero");
793 s +=
basis->evaluateZero(i) * ca[i];
794 t +=
basis->evaluateZero(i) *
B(i-1,0);
796 cc[0] = (std::log(s) - t) / psi_0;
803 cc[0] = std::log(ca[0]);
806template <
typename ordinal_type,
typename value_type>
814 divide(c,c,std::log(10.0));
819 c[0] = std::log10(a[0]);
823template <
typename ordinal_type,
typename value_type>
837 c[0] = std::sqrt(a[0]);
841template <
typename ordinal_type,
typename value_type>
855 c[0] = std::cbrt(a[0]);
859template <
typename ordinal_type,
typename value_type>
874 c[0] = std::pow(a[0], b[0]);
878template <
typename ordinal_type,
typename value_type>
886 times(c,std::log(a),b);
892 c[0] = std::pow(a, b[0]);
896template <
typename ordinal_type,
typename value_type>
911 c[0] = std::pow(a[0], b);
915template <
typename ordinal_type,
typename value_type>
922 const char* func =
"Stokhos::DerivOrthogPolyExpansion::sincos()";
950 A(i-1+offset,
j-1+offset) = tmp;
953 tmp += ca[k]*(*
Dijk)(i-1,
j,k);
954 A(i-1+offset,
j-1) = tmp;
955 A(i-1,
j-1+offset) = -tmp;
956 tmp2 += ca[
j]*(*Bij)(i-1,
j);
958 B(i-1,0) = tmp2*psi_0;
959 B(i-1+offset,1) = tmp2*psi_0;
963 int info =
solve(2*pc-2, 2);
965 TEUCHOS_TEST_FOR_EXCEPTION(info < 0, std::logic_error,
966 func <<
": Argument " << info
967 <<
" for solve had illegal value");
968 TEUCHOS_TEST_FOR_EXCEPTION(info > 0, std::logic_error,
969 func <<
": Diagonal entry " << info
970 <<
" in LU factorization is exactly zero");
981 t +=
basis->evaluateZero(i) * ca[i];
982 a00 -=
basis->evaluateZero(i) *
B(i-1,1);
983 a01 +=
basis->evaluateZero(i) *
B(i-1,0);
984 a10 -=
basis->evaluateZero(i) *
B(i-1+offset,1);
985 a11 +=
basis->evaluateZero(i) *
B(i-1+offset,0);
991 B(0,0) = std::sin(t);
992 B(1,0) = std::cos(t);
996 TEUCHOS_TEST_FOR_EXCEPTION(info < 0, std::logic_error,
997 func <<
": Argument " << info
998 <<
" for (2x2) solve had illegal value");
999 TEUCHOS_TEST_FOR_EXCEPTION(info > 0, std::logic_error,
1000 func <<
": Diagonal entry " << info
1001 <<
" in (2x2) LU factorization is exactly zero");
1009 cs[i] = cc[0]*
B(i-1,0) - cs[0]*
B(i-1,1);
1010 cc[i] = cc[0]*
B(i-1+offset,0) - cs[0]*
B(i-1+offset,1);
1014 cs[0] = std::sin(ca[0]);
1015 cc[0] = std::cos(ca[0]);
1019template <
typename ordinal_type,
typename value_type>
1032 s[0] = std::sin(a[0]);
1036template <
typename ordinal_type,
typename value_type>
1049 c[0] = std::cos(a[0]);
1053template <
typename ordinal_type,
typename value_type>
1067 t[0] = std::tan(a[0]);
1071template <
typename ordinal_type,
typename value_type>
1078 const char* func =
"Stokhos::DerivOrthogPolyExpansion::sinhcosh()";
1104 tmp = (*Bij)(i-1,
j);
1106 A(i-1+offset,
j-1+offset) = tmp;
1109 tmp += ca[k]*(*
Dijk)(i-1,
j,k);
1110 A(i-1+offset,
j-1) = -tmp;
1111 A(i-1,
j-1+offset) = -tmp;
1112 tmp2 += ca[
j]*(*Bij)(i-1,
j);
1114 B(i-1,0) = tmp2*psi_0;
1115 B(i-1+offset,1) = tmp2*psi_0;
1119 int info =
solve(2*pc-2, 2);
1121 TEUCHOS_TEST_FOR_EXCEPTION(info < 0, std::logic_error,
1122 func <<
": Argument " << info
1123 <<
" for solve had illegal value");
1124 TEUCHOS_TEST_FOR_EXCEPTION(info > 0, std::logic_error,
1125 func <<
": Diagonal entry " << info
1126 <<
" in LU factorization is exactly zero");
1137 t +=
basis->evaluateZero(i) * ca[i];
1138 a00 +=
basis->evaluateZero(i) *
B(i-1,1);
1139 a01 +=
basis->evaluateZero(i) *
B(i-1,0);
1140 a10 +=
basis->evaluateZero(i) *
B(i-1+offset,1);
1141 a11 +=
basis->evaluateZero(i) *
B(i-1+offset,0);
1147 B(0,0) = std::sinh(t);
1148 B(1,0) = std::cosh(t);
1150 TEUCHOS_TEST_FOR_EXCEPTION(info < 0, std::logic_error,
1151 func <<
": Argument " << info
1152 <<
" for (2x2) solve had illegal value");
1153 TEUCHOS_TEST_FOR_EXCEPTION(info > 0, std::logic_error,
1154 func <<
": Diagonal entry " << info
1155 <<
" in (2x2) LU factorization is exactly zero");
1163 cs[i] = cc[0]*
B(i-1,0) + cs[0]*
B(i-1,1);
1164 cc[i] = cc[0]*
B(i-1+offset,0) + cs[0]*
B(i-1+offset,1);
1168 cs[0] = std::sinh(ca[0]);
1169 cc[0] = std::cosh(ca[0]);
1173template <
typename ordinal_type,
typename value_type>
1186 s[0] = std::sinh(a[0]);
1190template <
typename ordinal_type,
typename value_type>
1203 c[0] = std::cosh(a[0]);
1207template <
typename ordinal_type,
typename value_type>
1221 t[0] = std::tanh(a[0]);
1225template <
typename ordinal_type,
typename value_type>
1226template <
typename OpT>
1229quad(
const OpT& quad_func,
1234 const char* func =
"Stokhos::DerivOrthogPolyExpansion::quad()";
1253 A(i-1,
j-1) += cb[k]*(*Dijk)(i-1,k,
j);
1256 B(i-1,0) += ca[
j]*(*Bij)(i-1,
j);
1261 int info =
solve(pc-1, 1);
1263 TEUCHOS_TEST_FOR_EXCEPTION(info < 0, std::logic_error,
1264 func <<
": Argument " << info
1265 <<
" for solve had illegal value");
1266 TEUCHOS_TEST_FOR_EXCEPTION(info > 0, std::logic_error,
1267 func <<
": Diagonal entry " << info
1268 <<
" in LU factorization is exactly zero");
1274 s +=
basis->evaluateZero(i) * ca[i];
1275 t +=
basis->evaluateZero(i) *
B(i-1,0);
1277 cc[0] = (quad_func(s) - t) / psi_0;
1284template <
typename ordinal_type,
typename value_type>
1300 c[0] = std::acos(a[0]);
1304template <
typename ordinal_type,
typename value_type>
1319 c[0] = std::asin(a[0]);
1323template <
typename ordinal_type,
typename value_type>
1337 c[0] = std::atan(a[0]);
1368template <
typename ordinal_type,
typename value_type>
1383 c[0] = std::log(a[0]+std::sqrt(a[0]*a[0]-
value_type(1.0)));
1387template <
typename ordinal_type,
typename value_type>
1402 c[0] = std::log(a[0]+std::sqrt(a[0]*a[0]+
value_type(1.0)));
1406template <
typename ordinal_type,
typename value_type>
1424template <
typename ordinal_type,
typename value_type>
1436template <
typename ordinal_type,
typename value_type>
1448template <
typename ordinal_type,
typename value_type>
1461template <
typename ordinal_type,
typename value_type>
1476template <
typename ordinal_type,
typename value_type>
1491template <
typename ordinal_type,
typename value_type>
1504template <
typename ordinal_type,
typename value_type>
1519template <
typename ordinal_type,
typename value_type>
1534template <
typename ordinal_type,
typename value_type>
1548 cc[i] += ca[
j]*(*
Bij)(i,
j);
1549 cc[i] /=
basis->norm_squared(i);
double dlange_(char *, int *, int *, double *, int *, double *)
Data structure storing a dense 3-tensor C(i,j,k).
Abstract base class for multivariate orthogonal polynomials that support computing double and triple ...
Teuchos::SerialDenseMatrix< ordinal_type, value_type > B
RHS.
void tan(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a)
void minus(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a, const OrthogPolyApprox< ordinal_type, value_type, node_type > &b)
void cbrt(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a)
Teuchos::SerialDenseMatrix< ordinal_type, value_type > A
Matrix.
void times(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a, const OrthogPolyApprox< ordinal_type, value_type, node_type > &b)
void exp(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a)
Teuchos::RCP< const Stokhos::DerivBasis< ordinal_type, value_type > > basis
Basis.
void abs(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a)
Teuchos::RCP< const Stokhos::Dense3Tensor< ordinal_type, value_type > > Dijk
Derivative Triple-product tensor.
void quad(const OpT &quad_func, OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a, const OrthogPolyApprox< ordinal_type, value_type, node_type > &b)
void cosh(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a)
void max(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a, const OrthogPolyApprox< ordinal_type, value_type, node_type > &b)
void unaryMinus(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a)
void plusEqual(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const value_type &x)
void asin(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a)
Teuchos::RCP< const Stokhos::Sparse3Tensor< ordinal_type, value_type > > Cijk
Triple-product tensor.
void sinhcosh(OrthogPolyApprox< ordinal_type, value_type, node_type > &s, OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a)
void atan(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a)
void cos(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a)
void acos(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a)
void atanh(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a)
void derivative(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a)
void divide(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a, const OrthogPolyApprox< ordinal_type, value_type, node_type > &b)
void minusEqual(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const value_type &x)
void timesEqual(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const value_type &x)
void min(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a, const OrthogPolyApprox< ordinal_type, value_type, node_type > &b)
ordinal_type sz
Workspace size.
void log10(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a)
void pow(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a, const OrthogPolyApprox< ordinal_type, value_type, node_type > &b)
void sin(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a)
ordinal_type solve(ordinal_type s, ordinal_type nrhs)
Solve linear system.
void sinh(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a)
DerivOrthogPolyExpansion(const Teuchos::RCP< const DerivBasis< ordinal_type, value_type > > &basis, const Teuchos::RCP< const Teuchos::SerialDenseMatrix< ordinal_type, value_type > > &Bij, const Teuchos::RCP< const Stokhos::Sparse3Tensor< ordinal_type, value_type > > &Cijk, const Teuchos::RCP< const Stokhos::Dense3Tensor< ordinal_type, value_type > > &Dijk)
Constructor.
void plus(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a, const OrthogPolyApprox< ordinal_type, value_type, node_type > &b)
void divideEqual(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const value_type &x)
void fabs(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a)
void asinh(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a)
Teuchos::Array< ordinal_type > piv
Pivot array.
void acosh(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a)
void sqrt(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a)
Teuchos::RCP< const Teuchos::SerialDenseMatrix< ordinal_type, value_type > > Bij
Derivative double-product tensor.
void tanh(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a)
Teuchos::LAPACK< ordinal_type, value_type > lapack
LAPACK wrappers.
void log(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a)
void sincos(OrthogPolyApprox< ordinal_type, value_type, node_type > &s, OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a)
Class to store coefficients of a projection onto an orthogonal polynomial basis.
void resize(ordinal_type sz)
Resize coefficient array (coefficients are preserved)
pointer coeff()
Return coefficient array.
ordinal_type size() const
Return size.
Data structure storing a sparse 3-tensor C(i,j,k) in a a compressed format.
static T * get_and_fill(int sz)
Get memory for new array of length sz and fill with zeros.