Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_QuadraturePseudoSpectralOperator.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 #ifndef STOKHOS_QUADRATURE_PSEUDO_SPECTRAL_OPERATOR_HPP
11 #define STOKHOS_QUADRATURE_PSEUDO_SPECTRAL_OPERATOR_HPP
12 
14 #include "Stokhos_Quadrature.hpp"
16 #include "Teuchos_BLAS.hpp"
17 
18 namespace Stokhos {
19 
24  template <typename ordinal_t,
25  typename value_t,
26  typename point_compare_type =
27  typename DefaultPointCompare<ordinal_t,value_t>::type>
29  public PseudoSpectralOperator<ordinal_t,value_t,point_compare_type> {
30  public:
31 
32  typedef ordinal_t ordinal_type;
33  typedef value_t value_type;
38  typedef typename base_type::iterator iterator;
42 
44 
49  const point_compare_type& point_compare = point_compare_type()) :
50  coeff_sz(basis.size()),
51  points(point_compare) {
52 
53  const Teuchos::Array<value_type>& quad_weights = quad.getQuadWeights();
54  const Teuchos::Array< Teuchos::Array<value_type> >& quad_points =
55  quad.getQuadPoints();
56  const Teuchos::Array< Teuchos::Array<value_type> > & quad_vals =
57  quad.getBasisAtQuadPoints();
58 
59  ordinal_type nqp = quad.size();
60  ordinal_type npc = basis.size();
61  ordinal_type dim = basis.dimension();
62 
63  // Generate point set
64  point_type thePoint(dim);
65  for (ordinal_type i=0; i<nqp; ++i) {
66  for (ordinal_type k=0; k<dim; k++) {
67  thePoint[k] = quad_points[i][k];
68  }
69  points[thePoint] = std::make_pair(quad_weights[i],i);
70  }
71 
72  // Generate quadrature operator
73  // This has to happen before we change the global index since
74  // the point set likely will reorder the points
75  qp2pce.reshape(npc,nqp);
76  pce2qp.reshape(nqp,npc);
77  typename point_set_type::iterator di = points.begin();
78  typename point_set_type::iterator di_end = points.end();
79  ordinal_type jdx = 0;
80  for (; di != di_end; ++di) {
81  ordinal_type j = di->second.second;
82  for (ordinal_type i=0; i<npc; i++) {
83  qp2pce(i,jdx) = quad_weights[j]*quad_vals[j][i] /
84  basis.norm_squared(i);
85  pce2qp(jdx,i) = quad_vals[j][i];
86  }
87  ++jdx;
88  }
89 
90  // Generate linear ordering of points
91  point_map.resize(nqp);
92  ordinal_type idx=0;
93  di = points.begin();
94  while (di != di_end) {
95  di->second.second = idx;
96  point_map[idx] = di->first;
97  ++idx;
98  ++di;
99  }
100 
101 
102  }
103 
106 
108  ordinal_type point_size() const { return points.size(); }
109 
111  ordinal_type coeff_size() const { return coeff_sz; }
112 
114  iterator begin() { return point_map.begin(); }
115 
117  iterator end() { return point_map.end(); }
118 
120  const_iterator begin() const { return point_map.begin(); }
121 
123  const_iterator end() const { return point_map.end(); }
124 
126  set_iterator set_begin() { return points.begin(); }
127 
129  set_iterator set_end() { return points.end(); }
130 
132  const_set_iterator set_begin() const { return points.begin(); }
133 
135  const_set_iterator set_end() const { return points.end(); }
136 
139  const_set_iterator it = points.find(point);
141  it == points.end(), std::logic_error, "Invalid term " << point);
142  return it->second.second;
143  }
144 
146  const point_type& point(ordinal_type n) const { return point_map[n]; }
147 
149 
156  virtual void transformQP2PCE(
157  const value_type& alpha,
160  const value_type& beta,
161  bool trans = false) const {
162  ordinal_type ret;
163  if (trans)
164  ret = result.multiply(Teuchos::NO_TRANS, Teuchos::TRANS, alpha,
165  input, qp2pce, beta);
166  else
167  ret = result.multiply(Teuchos::NO_TRANS, Teuchos::NO_TRANS, alpha,
168  qp2pce, input, beta);
169  TEUCHOS_ASSERT(ret == 0);
170  }
171 
173 
180  virtual void transformPCE2QP(
181  const value_type& alpha,
184  const value_type& beta,
185  bool trans = false) const {
186  if (trans) {
187  TEUCHOS_ASSERT(input.numCols() <= pce2qp.numCols());
188  TEUCHOS_ASSERT(result.numCols() == pce2qp.numRows());
189  TEUCHOS_ASSERT(result.numRows() == input.numRows());
191  pce2qp.numRows(), input.numCols(), alpha, input.values(),
192  input.stride(), pce2qp.values(), pce2qp.stride(), beta,
193  result.values(), result.stride());
194  }
195  else {
196  TEUCHOS_ASSERT(input.numRows() <= pce2qp.numCols());
197  TEUCHOS_ASSERT(result.numRows() == pce2qp.numRows());
198  TEUCHOS_ASSERT(result.numCols() == input.numCols());
200  input.numCols(), input.numRows(), alpha, pce2qp.values(),
201  pce2qp.stride(), input.values(), input.stride(), beta,
202  result.values(), result.stride());
203  }
204  }
205 
206  protected:
207 
210 
213 
216 
219 
222 
225 
226  };
227 
228 }
229 
230 #endif
set_iterator set_begin()
Iterator to begining of point set.
ScalarType * values() const
Teuchos::BLAS< ordinal_type, value_type > blas
BLAS wrappers.
std::map< point_type, std::pair< value_type, ordinal_type >, point_compare_type > point_set_type
Teuchos::SerialDenseMatrix< ordinal_type, value_type > pce2qp
Matrix mapping coefficients to points.
const_set_iterator set_begin() const
Iterator to begining of point set.
Container storing a term in a generalized tensor product.
int multiply(ETransp transa, ETransp transb, ScalarType alpha, const SerialDenseMatrix< OrdinalType, ScalarType > &A, const SerialDenseMatrix< OrdinalType, ScalarType > &B, ScalarType beta)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual void transformQP2PCE(const value_type &alpha, const Teuchos::SerialDenseMatrix< ordinal_type, value_type > &input, Teuchos::SerialDenseMatrix< ordinal_type, value_type > &result, const value_type &beta, bool trans=false) const
Transform values at quadrature points to PCE coefficients.
An operator interface for building pseudo-spectral approximations.
virtual ordinal_type size() const =0
Get number of quadrature points.
virtual const Teuchos::Array< Teuchos::Array< value_type > > & getBasisAtQuadPoints() const =0
Get values of basis at quadrature points.
ordinal_type index(const point_type &point) const
Get point index for given point.
Teuchos::SerialDenseMatrix< ordinal_type, value_type > qp2pce
Matrix mapping points to coefficients.
void GEMM(ETransp transa, ETransp transb, const OrdinalType &m, const OrdinalType &n, const OrdinalType &k, const alpha_type alpha, const A_type *A, const OrdinalType &lda, const B_type *B, const OrdinalType &ldb, const beta_type beta, ScalarType *C, const OrdinalType &ldc) const
virtual ordinal_type dimension() const =0
Return dimension of basis.
virtual const Teuchos::Array< value_type > & getQuadWeights() const =0
Get quadrature weights.
ordinal_type coeff_size() const
Number of coefficients.
Abstract base class for multivariate orthogonal polynomials.
virtual const Teuchos::Array< Teuchos::Array< value_type > > & getQuadPoints() const =0
Get quadrature points.
virtual void transformPCE2QP(const value_type &alpha, const Teuchos::SerialDenseMatrix< ordinal_type, value_type > &input, Teuchos::SerialDenseMatrix< ordinal_type, value_type > &result, const value_type &beta, bool trans=false) const
Transform PCE coefficients to quadrature values.
Abstract base class for quadrature methods.
PseudoSpectralOperator< ordinal_type, value_type, point_compare_type > base_type
void resize(size_type new_size, const value_type &x=value_type())
const_iterator end() const
Iterator to end of point set.
virtual const Teuchos::Array< value_type > & norm_squared() const =0
Return array storing norm-squared of each basis polynomial.
iterator end()
OrdinalType numCols() const
int reshape(OrdinalType numRows, OrdinalType numCols)
const point_type & point(ordinal_type n) const
Get point for given index.
const_set_iterator set_end() const
Iterator to end of point set.
#define TEUCHOS_ASSERT(assertion_test)
const_iterator begin() const
Iterator to begining of point set.
An operator for building pseudo-spectral coefficients using an arbitrary quadrature rule...
iterator begin()
virtual ordinal_type size() const =0
Return total size of basis.
OrdinalType stride() const
OrdinalType numRows() const
QuadraturePseudoSpectralOperator(const OrthogPolyBasis< ordinal_type, value_type > &basis, const Quadrature< ordinal_type, value_type > &quad, const point_compare_type &point_compare=point_compare_type())
Constructor.