46 template <
typename ordinal_type,
typename value_type,
typename storage_type>
57 else if (theBasis != Teuchos::null)
58 coeff_.resize(theBasis->size());
65 template <
typename ordinal_type,
typename value_type,
typename storage_type>
73 template <
typename ordinal_type,
typename value_type,
typename storage_type>
79 template <
typename ordinal_type,
typename value_type,
typename storage_type>
92 template <
typename ordinal_type,
typename value_type,
typename storage_type>
103 template <
typename ordinal_type,
typename value_type,
typename storage_type>
111 template <
typename ordinal_type,
typename value_type,
typename storage_type>
119 template <
typename ordinal_type,
typename value_type,
typename storage_type>
127 template <
typename ordinal_type,
typename value_type,
typename storage_type>
128 Teuchos::RCP<const Stokhos::OrthogPolyBasis<ordinal_type, value_type> >
135 template <
typename ordinal_type,
typename value_type,
typename storage_type>
143 else if (basis_ != Teuchos::null)
144 resize(basis_->size());
149 template <
typename ordinal_type,
typename value_type,
typename storage_type>
157 template <
typename ordinal_type,
typename value_type,
typename storage_type>
162 return coeff_.size();
165 template <
typename ordinal_type,
typename value_type,
typename storage_type>
171 TEUCHOS_TEST_FOR_EXCEPTION(coeff_.size() == 0, std::logic_error,
172 "Stokhos::OrthogPolyApprox::coeff(): " <<
173 "Coefficient array is empty!");
175 return coeff_.coeff();
178 template <
typename ordinal_type,
typename value_type,
typename storage_type>
184 TEUCHOS_TEST_FOR_EXCEPTION(coeff_.size() == 0, std::logic_error,
185 "Stokhos::OrthogPolyApprox::coeff(): " <<
186 "Coefficient array is empty!");
188 return coeff_.coeff();
191 template <
typename ordinal_type,
typename value_type,
typename storage_type>
199 template <
typename ordinal_type,
typename value_type,
typename storage_type>
207 template <
typename ordinal_type,
typename value_type,
typename storage_type>
212 Teuchos::RCP< const Stokhos::ProductBasis<ordinal_type, value_type> >
216 theTerm[dimension] = theOrder;
218 return coeff_[
index];
221 template <
typename ordinal_type,
typename value_type,
typename storage_type>
226 Teuchos::RCP< const Stokhos::ProductBasis<ordinal_type, value_type> >
230 theTerm[dimension] = theOrder;
232 return coeff_[
index];
235 template <
typename ordinal_type,
typename value_type,
typename storage_type>
240 Teuchos::RCP< const Stokhos::ProductBasis<ordinal_type, value_type> >
242 return product_basis->
term(theTerm);
245 template <
typename ordinal_type,
typename value_type,
typename storage_type>
248 evaluate(
const Teuchos::Array<value_type>& point)
const 250 Teuchos::Array<value_type> basis_vals(basis_->size());
251 basis_->evaluateBases(point, basis_vals);
252 return evaluate(point, basis_vals);
255 template <
typename ordinal_type,
typename value_type,
typename storage_type>
259 const Teuchos::Array<value_type>& basis_vals)
const 262 for (
ordinal_type i=0; i<static_cast<ordinal_type>(coeff_.size()); i++)
263 val += coeff_[i]*basis_vals[i];
268 template <
typename ordinal_type,
typename value_type,
typename storage_type>
276 template <
typename ordinal_type,
typename value_type,
typename storage_type>
282 for (
ordinal_type i=1; i<static_cast<ordinal_type>(coeff_.size()); i++) {
283 std_dev += coeff_[i]*coeff_[i]*basis_->norm_squared(i);
289 template <
typename ordinal_type,
typename value_type,
typename storage_type>
294 return std::sqrt(this->two_norm_squared());
297 template <
typename ordinal_type,
typename value_type,
typename storage_type>
303 if (basis_ == Teuchos::null) {
304 TEUCHOS_TEST_FOR_EXCEPTION(
305 coeff_.size() != 1, std::logic_error,
306 "basis_ == null && coeff_.size() > 1");
307 nrm = coeff_[0]*coeff_[0];
310 for (
ordinal_type i=0; i<static_cast<ordinal_type>(coeff_.size()); i++)
311 nrm += coeff_[i]*coeff_[i]*basis_->norm_squared(i);
316 template <
typename ordinal_type,
typename value_type,
typename storage_type>
322 TEUCHOS_TEST_FOR_EXCEPTION(
323 basis_ == Teuchos::null && coeff_.size() != 1, std::logic_error,
324 "basis_ == null && coeff_.size() > 1");
325 TEUCHOS_TEST_FOR_EXCEPTION(
327 "b.basis_ == null && b.coeff_.size() > 1");
328 TEUCHOS_TEST_FOR_EXCEPTION(
330 coeff_.size() != 1 && b.
coeff_.
size() != 1, std::logic_error,
331 "Coefficient array sizes do not match");
334 if (coeff_.size() == 1 || b.
coeff_.
size() == 1)
335 v = coeff_[0]*b.
coeff_[0];
337 for (
ordinal_type i=0; i<static_cast<ordinal_type>(coeff_.size()); i++)
338 v += coeff_[i]*b.
coeff_[i]*basis_->norm_squared(i);
343 template <
typename ordinal_type,
typename value_type,
typename storage_type>
348 os <<
"Stokhos::OrthogPolyApprox of size " << coeff_.size() <<
" in basis " 349 <<
"\n\t" << basis_->getName() <<
":" << std::endl;
351 Teuchos::RCP< const Stokhos::ProductBasis<ordinal_type, value_type> >
354 if (product_basis != Teuchos::null) {
355 for (
ordinal_type i=0; i<static_cast<ordinal_type>(coeff_.size()); i++) {
359 os << trm[
j] <<
", ";
360 os << trm[trm.
size()-1] <<
") = " << coeff_[i] << std::endl;
366 for (
ordinal_type i=0; i<static_cast<ordinal_type>(coeff_.size()); i++) {
367 os << coeff_[i] <<
" ";
376 template <
typename ordinal_type,
typename value_type,
typename storage_type>
KOKKOS_INLINE_FUNCTION PCE< Storage > sqrt(const PCE< Storage > &a)
void resize(ordinal_type sz)
Resize coefficient array (coefficients are preserved)
SparseArrayIterator< index_iterator, value_iterator >::value_type index(const SparseArrayIterator< index_iterator, value_iterator > &it)
value_type two_norm_squared() const
Compute the squared two-norm of expansion.
Teuchos::RCP< const Stokhos::OrthogPolyBasis< ordinal_type, value_type > > basis_
Basis expansion is relative to.
OrthogPolyApprox & operator=(const OrthogPolyApprox &x)
Assignment operator (deep copy)
for(IndexType row=vector_id;row< Anum_rows;row+=num_vectors)
void init(const value_type &v)
Initialize coefficients to value.
OrthogPolyApprox(const Teuchos::RCP< const Stokhos::OrthogPolyBasis< ordinal_type, value_type > > &basis=Teuchos::null, ordinal_type sz=0, const value_type *vals=NULL)
Constructor with supplied size sz.
~OrthogPolyApprox()
Destructor.
pointer coeff()
Return coefficient array.
ordinal_type size() const
Return size.
value_type inner_product(const OrthogPolyApprox &b) const
Compute the L2 inner product of 2 PCEs.
Abstract base class for multivariate orthogonal polynomials.
reference operator[](ordinal_type i)
Array access.
storage_type::reference reference
virtual const MultiIndex< ordinal_type > & term(ordinal_type i) const =0
Get orders of each coordinate polynomial given an index i.
const IndexType const IndexType const IndexType const IndexType const ValueType const ValueType * x
value_type standard_deviation() const
Compute standard deviation of expansion.
std::ostream & print(std::ostream &os) const
Print approximation in basis.
std::ostream & operator<<(std::ostream &os, const ProductContainer< coeff_type > &vec)
storage_type coeff_
OrthogPolyApprox coefficients.
void reset(const Teuchos::RCP< const Stokhos::OrthogPolyBasis< ordinal_type, value_type > > &new_basis, ordinal_type sz=0)
Reset to a new basis.
const MultiIndex< ordinal_type > & order(ordinal_type term) const
Get orders for a given term.
storage_type::pointer pointer
Abstract base class for multivariate orthogonal polynomials generated from tensor products of univari...
void load(value_type *v)
Load coefficients to an array of values.
storage_type::const_reference const_reference
storage_type::const_pointer const_pointer
Class to store coefficients of a projection onto an orthogonal polynomial basis.
value_type two_norm() const
Compute the two-norm of expansion.
value_type mean() const
Compute mean of expansion.
ordinal_type size() const
Size.
value_type evaluate(const Teuchos::Array< value_type > &point) const
Evaluate polynomial approximation at a point.
ordinal_type size() const
Return size.
Teuchos::RCP< const Stokhos::OrthogPolyBasis< ordinal_type, value_type > > basis() const
Return basis.
reference term(ordinal_type dimension, ordinal_type order)
Get coefficient term for given dimension and order.