Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_MonomialProjGramSchmidtPCEBasisImp.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Stokhos Package
4 //
5 // Copyright 2009 NTESS and the Stokhos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #include "Stokhos_SDMUtils.hpp"
12 
13 template <typename ordinal_type, typename value_type>
16  ordinal_type max_p,
19  const Teuchos::ParameterList& params) :
20  GSReducedPCEBasisBase<ordinal_type,value_type>(max_p, pce, quad, params),
21  name("Monomial Proj Gram Schmidt PCE Basis")
22 {
23  this->setup(max_p, pce, quad);
24 }
25 
26 template <typename ordinal_type, typename value_type>
29 {
30 }
31 
32 template <typename ordinal_type, typename value_type>
33 const std::string&
35 getName() const
36 {
37  return name;
38 }
39 
40 template <typename ordinal_type, typename value_type>
44  ordinal_type max_p,
45  value_type threshold,
48  const Teuchos::Array<value_type>& weights,
50  Teuchos::Array<ordinal_type>& num_terms_,
53 {
54  // Compute basis terms -- 2-D array giving powers for each linear index
55  ordinal_type max_sz;
56  CPBUtils::compute_terms(max_p, this->d, max_sz, terms_, num_terms_);
57 
58  // Compute B matrix -- monomials in F
59  // for i=0,...,nqp-1
60  // for j=0,...,sz-1
61  // B(i,j) = F(i,1)^terms_[j][1] * ... * F(i,d)^terms_[j][d]
62  // where sz is the total size of a basis up to order p and terms_[j]
63  // is an array of powers for each term in the total-order basis
64  ordinal_type nqp = weights.size();
65  SDM B(nqp, max_sz);
66  for (ordinal_type i=0; i<nqp; i++) {
67  for (ordinal_type j=0; j<max_sz; j++) {
68  B(i,j) = 1.0;
69  for (ordinal_type k=0; k<this->d; k++)
70  B(i,j) *= std::pow(F(i,k), terms_[j][k]);
71  }
72  }
73 
74  // Project B into original basis -- should use SPAM for this
75  SDM Bp(this->pce_sz, max_sz);
76  const Teuchos::Array<value_type>& basis_norms =
77  this->pce_basis->norm_squared();
78  for (ordinal_type i=0; i<this->pce_sz; i++) {
79  for (ordinal_type j=0; j<max_sz; j++) {
80  Bp(i,j) = 0.0;
81  for (ordinal_type k=0; k<nqp; k++)
82  Bp(i,j) += weights[k]*B(k,j)*A(k,i);
83  Bp(i,j) /= basis_norms[i];
84  }
85  }
86 
87  // Rescale columns of Bp to have unit norm
88  for (ordinal_type j=0; j<max_sz; j++) {
89  value_type nrm = 0.0;
90  for (ordinal_type i=0; i<this->pce_sz; i++)
91  nrm += Bp(i,j)*Bp(i,j)*basis_norms[i];
92  nrm = std::sqrt(nrm);
93  for (ordinal_type i=0; i<this->pce_sz; i++)
94  Bp(i,j) /= nrm;
95  }
96 
97  // Compute our new basis -- each column of Qp is the coefficients of the
98  // new basis in the original basis. Constraint pivoting so first d+1
99  // columns and included in Qp.
100  Teuchos::Array<value_type> w(this->pce_sz, 1.0);
101  SDM R;
102  Teuchos::Array<ordinal_type> piv(max_sz);
103  for (int i=0; i<this->d+1; i++)
104  piv[i] = 1;
106  ordinal_type sz_ = SOF::createOrthogonalBasis(
107  this->orthogonalization_method, threshold, this->verbose, Bp, w,
108  Qp_, R, piv);
109 
110  // Evaluate new basis at original quadrature points
111  Q_.reshape(nqp, sz_);
112  ordinal_type ret =
113  Q_.multiply(Teuchos::NO_TRANS, Teuchos::NO_TRANS, 1.0, A, Qp_, 0.0);
114  TEUCHOS_ASSERT(ret == 0);
115 
116  return sz_;
117 }
KOKKOS_INLINE_FUNCTION PCE< Storage > sqrt(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > pow(const PCE< Storage > &a, const PCE< Storage > &b)
int multiply(ETransp transa, ETransp transb, ScalarType alpha, const SerialDenseMatrix< OrdinalType, ScalarType > &A, const SerialDenseMatrix< OrdinalType, ScalarType > &B, ScalarType beta)
Generate a basis from a given set of PCE expansions that is orthogonal with respect to the product me...
virtual ordinal_type buildReducedBasis(ordinal_type max_p, value_type threshold, const Teuchos::SerialDenseMatrix< ordinal_type, value_type > &A, const Teuchos::SerialDenseMatrix< ordinal_type, value_type > &F, const Teuchos::Array< value_type > &weights, Teuchos::Array< Stokhos::MultiIndex< ordinal_type > > &terms_, Teuchos::Array< ordinal_type > &num_terms_, Teuchos::SerialDenseMatrix< ordinal_type, value_type > &Qp_, Teuchos::SerialDenseMatrix< ordinal_type, value_type > &Q_)
Build the reduced basis, parameterized by total order max_p.
void setup(ordinal_type p, const Teuchos::Array< Stokhos::OrthogPolyApprox< ordinal_type, value_type > > &pce, const Teuchos::RCP< const Stokhos::Quadrature< ordinal_type, value_type > > &quad)
virtual const std::string & getName() const
Return string name of basis.
Abstract base class for quadrature methods.
MonomialProjGramSchmidtPCEBasis(ordinal_type p, const Teuchos::Array< Stokhos::OrthogPolyApprox< ordinal_type, value_type > > &pce, const Teuchos::RCP< const Stokhos::Quadrature< ordinal_type, value_type > > &quad, const Teuchos::ParameterList &params=Teuchos::ParameterList())
Constructor.
int reshape(OrdinalType numRows, OrdinalType numCols)
size_type size() const
#define TEUCHOS_ASSERT(assertion_test)
Encapsulate various orthogonalization (ie QR) methods.