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 //
4 // Stokhos Package
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Eric T. Phipps (etphipp@sandia.gov).
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #include "Stokhos_SDMUtils.hpp"
44 
45 template <typename ordinal_type, typename value_type>
48  ordinal_type max_p,
51  const Teuchos::ParameterList& params) :
52  GSReducedPCEBasisBase<ordinal_type,value_type>(max_p, pce, quad, params),
53  name("Monomial Proj Gram Schmidt PCE Basis")
54 {
55  this->setup(max_p, pce, quad);
56 }
57 
58 template <typename ordinal_type, typename value_type>
61 {
62 }
63 
64 template <typename ordinal_type, typename value_type>
65 const std::string&
67 getName() const
68 {
69  return name;
70 }
71 
72 template <typename ordinal_type, typename value_type>
76  ordinal_type max_p,
77  value_type threshold,
80  const Teuchos::Array<value_type>& weights,
82  Teuchos::Array<ordinal_type>& num_terms_,
85 {
86  // Compute basis terms -- 2-D array giving powers for each linear index
87  ordinal_type max_sz;
88  CPBUtils::compute_terms(max_p, this->d, max_sz, terms_, num_terms_);
89 
90  // Compute B matrix -- monomials in F
91  // for i=0,...,nqp-1
92  // for j=0,...,sz-1
93  // B(i,j) = F(i,1)^terms_[j][1] * ... * F(i,d)^terms_[j][d]
94  // where sz is the total size of a basis up to order p and terms_[j]
95  // is an array of powers for each term in the total-order basis
96  ordinal_type nqp = weights.size();
97  SDM B(nqp, max_sz);
98  for (ordinal_type i=0; i<nqp; i++) {
99  for (ordinal_type j=0; j<max_sz; j++) {
100  B(i,j) = 1.0;
101  for (ordinal_type k=0; k<this->d; k++)
102  B(i,j) *= std::pow(F(i,k), terms_[j][k]);
103  }
104  }
105 
106  // Project B into original basis -- should use SPAM for this
107  SDM Bp(this->pce_sz, max_sz);
108  const Teuchos::Array<value_type>& basis_norms =
109  this->pce_basis->norm_squared();
110  for (ordinal_type i=0; i<this->pce_sz; i++) {
111  for (ordinal_type j=0; j<max_sz; j++) {
112  Bp(i,j) = 0.0;
113  for (ordinal_type k=0; k<nqp; k++)
114  Bp(i,j) += weights[k]*B(k,j)*A(k,i);
115  Bp(i,j) /= basis_norms[i];
116  }
117  }
118 
119  // Rescale columns of Bp to have unit norm
120  for (ordinal_type j=0; j<max_sz; j++) {
121  value_type nrm = 0.0;
122  for (ordinal_type i=0; i<this->pce_sz; i++)
123  nrm += Bp(i,j)*Bp(i,j)*basis_norms[i];
124  nrm = std::sqrt(nrm);
125  for (ordinal_type i=0; i<this->pce_sz; i++)
126  Bp(i,j) /= nrm;
127  }
128 
129  // Compute our new basis -- each column of Qp is the coefficients of the
130  // new basis in the original basis. Constraint pivoting so first d+1
131  // columns and included in Qp.
132  Teuchos::Array<value_type> w(this->pce_sz, 1.0);
133  SDM R;
134  Teuchos::Array<ordinal_type> piv(max_sz);
135  for (int i=0; i<this->d+1; i++)
136  piv[i] = 1;
138  ordinal_type sz_ = SOF::createOrthogonalBasis(
139  this->orthogonalization_method, threshold, this->verbose, Bp, w,
140  Qp_, R, piv);
141 
142  // Evaluate new basis at original quadrature points
143  Q_.reshape(nqp, sz_);
144  ordinal_type ret =
145  Q_.multiply(Teuchos::NO_TRANS, Teuchos::NO_TRANS, 1.0, A, Qp_, 0.0);
146  TEUCHOS_ASSERT(ret == 0);
147 
148  return sz_;
149 }
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.