Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_LanczosPCEBasisImp.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 "Teuchos_Assert.hpp"
11 #include "Teuchos_BLAS.hpp"
12 #include "Teuchos_TimeMonitor.hpp"
13 
14 template <typename ordinal_type, typename value_type>
17  ordinal_type p,
20  bool normalize,
21  bool limit_integration_order_) :
22  RecurrenceBasis<ordinal_type, value_type>("Lanczos PCE", p, normalize),
23  pce(pce_),
24  quad(quad_),
25  limit_integration_order(limit_integration_order_),
26  nqp(quad->size()),
27  pce_weights(Teuchos::Copy,
28  const_cast<value_type*>(quad->getQuadWeights().getRawPtr()),
29  nqp),
30  pce_vals(nqp),
31  u0(nqp),
32  lanczos_vecs(nqp, p+1),
33  fromStieltjesMat(),
34  new_pce()
35 {
36  // Evaluate PCE at quad points
37  const Teuchos::Array< Teuchos::Array<value_type> >& quad_points =
38  quad->getQuadPoints();
39  const Teuchos::Array< Teuchos::Array<value_type> >& basis_values =
40  quad->getBasisAtQuadPoints();
41  for (ordinal_type i=0; i<nqp; i++) {
42  pce_vals[i] = pce->evaluate(quad_points[i], basis_values[i]);
43  u0[i] = value_type(1);
44  }
45 
46  // Setup rest of basis
47  this->setup();
48 }
49 
50 template <typename ordinal_type, typename value_type>
53 {
54 }
55 
56 template <typename ordinal_type, typename value_type>
57 void
60  Teuchos::Array<value_type>& quad_points,
61  Teuchos::Array<value_type>& quad_weights,
62  Teuchos::Array< Teuchos::Array<value_type> >& quad_values) const
63 {
64 #ifdef STOKHOS_TEUCHOS_TIME_MONITOR
65  TEUCHOS_FUNC_TIME_MONITOR("Stokhos::LanczosPCEBasis -- compute Gauss points");
66 #endif
67 
68  // Call base class
69  ordinal_type num_points =
70  static_cast<ordinal_type>(std::ceil((quad_order+1)/2.0));
71 
72  // We can't always reliably generate quadrature points of order > 2*p
73  // when using sparse grids for the underlying quadrature
74  if (limit_integration_order && quad_order > 2*this->p)
75  quad_order = 2*this->p;
77  quad_points,
78  quad_weights,
79  quad_values);
80 
81  // Fill in the rest of the points with zero weight
82  if (quad_weights.size() < num_points) {
83  ordinal_type old_size = quad_weights.size();
84  quad_weights.resize(num_points);
85  quad_points.resize(num_points);
86  quad_values.resize(num_points);
87  for (ordinal_type i=old_size; i<num_points; i++) {
88  quad_weights[i] = value_type(0);
89  quad_points[i] = quad_points[0];
90  quad_values[i].resize(this->p+1);
91  this->evaluateBases(quad_points[i], quad_values[i]);
92  }
93  }
94 }
95 
96 template <typename ordinal_type, typename value_type>
100 {
102  p,*this));
103 }
104 
105 template <typename ordinal_type, typename value_type>
109 {
110  return new_pce[i];
111 }
112 
113 template <typename ordinal_type, typename value_type>
114 void
117 {
119  ordinal_type sz = fromStieltjesMat.numRows();
120  blas.GEMV(Teuchos::NO_TRANS, sz, this->p+1,
121  value_type(1.0), fromStieltjesMat.values(), sz,
122  in, ordinal_type(1), value_type(0.0), out, ordinal_type(1));
123 }
124 
125 template <typename ordinal_type, typename value_type>
126 bool
132  Teuchos::Array<value_type>& gamma) const
133 {
135  vectorspace_type vs(pce_weights);
136  operator_type A(pce_vals);
137 
138  // Create space to store lanczos vectors -- use lanczos_vecs if
139  // we are requesting p+1 vectors
141  if (n == this->p+1)
142  lv = Teuchos::rcp(&lanczos_vecs, false);
143  else
144  lv = Teuchos::rcp(new matrix_type(nqp,n));
145 
146  if (this->normalize)
147  lanczos_type::computeNormalized(n, vs, A, u0, *lv, alpha, beta, nrm);
148  else
149  lanczos_type::compute(n, vs, A, u0, *lv, alpha, beta, nrm);
150 
151  for (ordinal_type i=0; i<n; i++) {
152  delta[i] = value_type(1.0);
153  }
154  if (this->normalize)
155  gamma = beta;
156  else
157  for (ordinal_type i=0; i<n; i++)
158  gamma[i] = value_type(1.0);
159 
160  return this->normalize;
161 }
162 
163 template <typename ordinal_type, typename value_type>
164 void
167 {
169 
170  // Compute transformation matrix back to original basis
171  ordinal_type sz = pce->size();
172  fromStieltjesMat.shape(sz, this->p+1);
173  fromStieltjesMat.putScalar(0.0);
174  const Teuchos::Array< Teuchos::Array<value_type> >& basis_values =
175  quad->getBasisAtQuadPoints();
176  for (ordinal_type i=0; i<sz; i++) {
177  for (ordinal_type j=0; j<=this->p; j++) {
178  for (ordinal_type k=0; k<nqp; k++)
179  fromStieltjesMat(i,j) +=
180  pce_weights[k]*lanczos_vecs(k,j)*basis_values[k][i];
181  fromStieltjesMat(i,j) /= pce->basis()->norm_squared(i);
182  }
183  }
184 
185  // Project original PCE into the new basis
186  new_pce.resize(this->p+1);
187  vector_type u(sz);
188  for (ordinal_type i=0; i<sz; i++)
189  u[i] = (*pce)[i]*pce->basis()->norm_squared(i);
190  new_pce.multiply(Teuchos::TRANS, Teuchos::NO_TRANS, 1.0, fromStieltjesMat, u,
191  0.0);
192  for (ordinal_type i=0; i<=this->p; i++)
193  new_pce[i] /= this->norms[i];
194 }
195 
196 template <typename ordinal_type, typename value_type>
200  pce(basis.pce),
201  quad(basis.quad),
202  limit_integration_order(basis.limit_integration_order),
203  nqp(basis.nqp),
204  pce_weights(basis.pce_weights),
205  pce_vals(basis.pce_vals),
206  u0(basis.u0),
207  lanczos_vecs(nqp, p+1),
208  fromStieltjesMat(),
209  new_pce()
210 {
211  this->setup();
212 }
vector_type pce_vals
Values of PCE at quadrature points.
#define TEUCHOS_FUNC_TIME_MONITOR(FUNCNAME)
Generates three-term recurrence using the Lanczos procedure applied to a polynomial chaos expansion i...
Implementation of OneDOrthogPolyBasis based on the general three-term recurrence relationship: for ...
void GEMV(ETransp trans, const OrdinalType &m, const OrdinalType &n, const alpha_type alpha, const A_type *A, const OrdinalType &lda, const x_type *x, const OrdinalType &incx, const beta_type beta, ScalarType *y, const OrdinalType &incy) const
int multiply(ETransp transa, ETransp transb, ScalarType alpha, const SerialDenseMatrix< OrdinalType, ScalarType > &A, const SerialDenseMatrix< OrdinalType, ScalarType > &B, ScalarType beta)
virtual void getQuadPoints(ordinal_type quad_order, Teuchos::Array< value_type > &points, Teuchos::Array< value_type > &weights, Teuchos::Array< Teuchos::Array< value_type > > &values) const
Compute quadrature points, weights, and values of basis polynomials at given set of points points...
RawPointerConversionTraits< Container >::Ptr_t getRawPtr(const Container &c)
value_type getNewCoeffs(ordinal_type i) const
Get new coefficients in this new basis.
virtual void getQuadPoints(ordinal_type quad_order, Teuchos::Array< value_type > &points, Teuchos::Array< value_type > &weights, Teuchos::Array< Teuchos::Array< value_type > > &values) const
Get Gauss quadrature points, weights, and values of basis at points.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Abstract base class for quadrature methods.
KOKKOS_INLINE_FUNCTION PCE< Storage > ceil(const PCE< Storage > &a)
LanczosPCEBasis(ordinal_type p, const Teuchos::RCP< const Stokhos::OrthogPolyApprox< ordinal_type, value_type > > &pce, const Teuchos::RCP< const Stokhos::Quadrature< ordinal_type, value_type > > &quad, bool normalize, bool limit_integration_order)
Constructor.
ordinal_type nqp
Number of quadrature points.
void resize(size_type new_size, const value_type &x=value_type())
virtual void setup()
Setup basis after computing recurrence coefficients.
Teuchos::RCP< const Stokhos::OrthogPolyApprox< ordinal_type, value_type > > pce
PCE Lanczos procedure is based on.
size_type size() const
virtual bool computeRecurrenceCoefficients(ordinal_type n, Teuchos::Array< value_type > &alpha, Teuchos::Array< value_type > &beta, Teuchos::Array< value_type > &delta, Teuchos::Array< value_type > &gamma) const
Compute recurrence coefficients.
vector_type u0
Initial Lanczos vector.
void transformCoeffsFromLanczos(const value_type *in, value_type *out) const
Map expansion coefficients from this basis to original.
virtual Teuchos::RCP< OneDOrthogPolyBasis< ordinal_type, value_type > > cloneWithOrder(ordinal_type p) const
Clone this object with the option of building a higher order basis.
virtual void setup()
Setup basis after computing recurrence coefficients.
Teuchos::RCP< const Stokhos::Quadrature< ordinal_type, value_type > > quad
Quadrature object.