Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_MonomialGramSchmidtPCEBasisImp.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 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  // Rescale columns of B to have unit norm
75  for (ordinal_type j=0; j<max_sz; j++) {
76  value_type nrm = 0.0;
77  for (ordinal_type i=0; i<nqp; i++)
78  nrm += B(i,j)*B(i,j)*weights[i];
79  nrm = std::sqrt(nrm);
80  for (ordinal_type i=0; i<nqp; i++)
81  B(i,j) /= nrm;
82  }
83 
84  // Compute our new basis -- each column of Q is the new basis evaluated
85  // at the original quadrature points. Constraint pivoting so first d+1
86  // columns and included in Q.
87  SDM R;
88  Teuchos::Array<ordinal_type> piv(max_sz);
89  for (int i=0; i<this->d+1; i++)
90  piv[i] = 1;
92  ordinal_type sz_ = SOF::createOrthogonalBasis(
93  this->orthogonalization_method, threshold, this->verbose, B, weights,
94  Q_, R, piv);
95 
96  // Compute Qp = A^T*W*Q
97  SDM tmp(nqp, sz_);
98  Qp_.reshape(this->pce_sz, sz_);
99  for (ordinal_type i=0; i<nqp; i++)
100  for (ordinal_type j=0; j<sz_; j++)
101  tmp(i,j) = Q_(i,j)*weights[i];
102  ordinal_type ret =
103  Qp_.multiply(Teuchos::TRANS, Teuchos::NO_TRANS, 1.0, A, tmp, 0.0);
104  TEUCHOS_ASSERT(ret == 0);
105 
106  // It isn't clear that Qp is orthogonal, but if you derive the projection
107  // matrix from the original space to the reduced, you end up with
108  // Q^T*W*A = Qp^T
109 
110  return sz_;
111 }
KOKKOS_INLINE_FUNCTION PCE< Storage > sqrt(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > pow(const PCE< Storage > &a, const PCE< Storage > &b)
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.
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...
MonomialGramSchmidtPCEBasis(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.
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)
Abstract base class for quadrature methods.
int reshape(OrdinalType numRows, OrdinalType numCols)
size_type size() const
#define TEUCHOS_ASSERT(assertion_test)
virtual const std::string & getName() const
Return string name of basis.
Encapsulate various orthogonalization (ie QR) methods.