42 #ifndef SACADO_ETPCE_ORTHOGPOLY_HPP
43 #define SACADO_ETPCE_ORTHOGPOLY_HPP
47 #ifdef HAVE_STOKHOS_SACADO
51 #include "Sacado_Traits.hpp"
52 #include "Sacado_Handle.hpp"
59 #include "Sacado_mpl_apply.hpp"
63 #ifdef HAVE_STOKHOS_THRUST
64 #include "thrust/tuple.h"
76 template <
int k,
typename T> KERNEL_PREFIX T&
77 get(T* a) {
return a[k]; }
78 template <
int k,
typename T> KERNEL_PREFIX
const T&
79 get(
const T* a) {
return a[k]; }
81 template <
int k,
int N,
typename T> KERNEL_PREFIX T&
82 get(T a[N]) {
return a[k]; }
83 template <
int k,
int N,
typename T> KERNEL_PREFIX
const T&
84 get(
const T a[N]) {
return a[k]; }
91 template <
typename ExprT>
class Expr {};
94 template <
typename T,
typename S>
class OrthogPoly;
97 template <
typename T,
typename Storage >
98 class OrthogPolyImpl {
125 typedef typename approx_type::pointer pointer;
126 typedef typename approx_type::const_pointer const_pointer;
127 typedef typename approx_type::reference reference;
128 typedef typename approx_type::const_reference const_reference;
157 OrthogPolyImpl(
const OrthogPolyImpl& x);
160 template <
typename S> OrthogPolyImpl(
const Expr<S>& x);
166 void init(
const T& v) { th_->init(v); }
169 void init(
const T* v) { th_->init(v); }
172 template <
typename S>
173 void init(
const OrthogPolyImpl<T,S>& v) { th_->init(v.getOrthogPolyApprox()); }
176 void load(T* v) { th_->load(v); }
179 template <
typename S>
180 void load(OrthogPolyImpl<T,S>& v) { th_->load(v.getOrthogPolyApprox()); }
205 void copyForWrite() { th_.makeOwnCopy(); }
215 value_type mean()
const {
return th_->mean(); }
218 value_type standard_deviation()
const {
return th_->standard_deviation(); }
221 value_type two_norm()
const {
return th_->two_norm(); }
224 value_type two_norm_squared()
const {
return th_->two_norm_squared(); }
227 value_type inner_product(
const OrthogPolyImpl& b)
const {
228 return th_->inner_product(b.getOrthogPolyApprox()); }
231 std::ostream& print(std::ostream& os)
const {
return th_->print(os); }
234 template <
typename S>
bool isEqualTo(
const Expr<S>& x)
const;
245 OrthogPolyImpl& operator=(
const OrthogPolyImpl& x);
248 template <
typename S>
249 OrthogPolyImpl& operator=(
const Expr<S>& x);
275 const_reference
val()
const {
return (*th_)[0]; }
278 reference
val() {
return (*th_)[0]; }
291 bool hasFastAccess(
ordinal_type sz)
const {
return th_->size()>=sz;}
294 const_pointer coeff()
const {
return th_->coeff();}
297 pointer coeff() {
return th_->coeff();}
301 return i<th_->size() ? (*th_)[i]:
value_type(0.); }
311 return th_->term(dimension, order); }
315 return th_->term(dimension, order); }
319 return th_->order(term); }
329 OrthogPolyImpl& operator += (
const value_type& x);
332 OrthogPolyImpl& operator -= (
const value_type& x);
335 OrthogPolyImpl& operator *= (
const value_type& x);
338 OrthogPolyImpl& operator /= (
const value_type& x);
343 const approx_type& getOrthogPolyApprox()
const {
return *th_; }
346 approx_type& getOrthogPolyApprox() {
return *th_; }
351 template <
typename S>
void expressionCopy(
const Expr<S>& x);
365 Sacado::Handle< Stokhos::OrthogPolyApprox<int,value_type,Storage> > th_;
369 template <
typename T,
typename Storage>
371 OrthogPolyImpl<T,Storage>::const_expansion_ =
380 template <
typename T,
typename Storage>
381 class Expr< OrthogPolyImpl<T,
Storage> > :
382 public OrthogPolyImpl<T,Storage> {
389 typedef typename OrthogPolyImpl<T,Storage>::approx_type approx_type;
391 typedef typename OrthogPolyImpl<T,Storage>::const_reference const_reference;
393 typedef OrthogPoly<T,Storage> base_expr_type;
396 static const int num_args = 1;
404 OrthogPolyImpl<T,
Storage>(x) {}
407 Expr(
const Teuchos::RCP<
typename OrthogPolyImpl<T,Storage>::expansion_type>& expansion) :
408 OrthogPolyImpl<T,
Storage>(expansion) {}
411 Expr(
const Teuchos::RCP<
typename OrthogPolyImpl<T,Storage>::expansion_type>& expansion,
413 OrthogPolyImpl<T,
Storage>(expansion, sz) {}
416 Expr(
const Expr& x) :
417 OrthogPolyImpl<T,
Storage>(static_cast<const OrthogPolyImpl<T,
Storage>&>(x)) {}
420 Expr(
const OrthogPolyImpl<T,Storage>& x) :
421 OrthogPolyImpl<T,
Storage>(x) {}
424 template <
typename S> Expr(
const Expr<S>& x) :
425 OrthogPolyImpl<T,
Storage>(x) {}
430 const approx_type& getArg(
int i)
const {
431 return this->getOrthogPolyApprox(); }
433 bool has_fast_access(
int sz)
const {
return this->size() >= sz; }
435 bool has_nonconst_expansion()
const {
436 return this->expansion_ != this->const_expansion_;
439 int order()
const {
return this->size() == 1 ? 0 : 1; }
441 value_type fast_higher_order_coeff(
int i)
const {
446 return this->coeff(i);
449 template <
int offset,
typename tuple_type>
452 return get<offset>(x);
455 std::string name()
const {
return "x"; }
473 template <
typename T,
typename Storage>
474 class OrthogPoly :
public Expr< OrthogPolyImpl<T,Storage> > {
493 typedef typename OrthogPolyImpl<T,Storage>::expansion_type expansion_type;
496 typedef typename OrthogPolyImpl<T,Storage>::approx_type approx_type;
498 typedef typename OrthogPolyImpl<T,Storage>::pointer pointer;
499 typedef typename OrthogPolyImpl<T,Storage>::const_pointer const_pointer;
500 typedef typename OrthogPolyImpl<T,Storage>::reference reference;
501 typedef typename OrthogPolyImpl<T,Storage>::const_reference const_reference;
504 template <
typename S>
506 typedef typename Sacado::mpl::apply<Storage,ordinal_type,S>::type
storage_type;
507 typedef OrthogPoly<S,storage_type> type;
515 Expr< OrthogPolyImpl<T,
Storage> >() {}
522 Expr< OrthogPolyImpl<T,
Storage> >(x) {}
529 Expr< OrthogPolyImpl<T,
Storage> >(expansion) {}
537 Expr< OrthogPolyImpl<T,
Storage> >(expansion, sz) {}
540 OrthogPoly(
const OrthogPoly& x) :
541 Expr< OrthogPolyImpl<T,
Storage> >(x) {}
544 template <
typename S> OrthogPoly(
const Expr<S>& x) :
545 Expr< OrthogPolyImpl<T,
Storage> >(x) {}
552 OrthogPolyImpl<T,Storage>::operator=(val);
557 OrthogPoly& operator=(
const OrthogPoly& x) {
558 OrthogPolyImpl<T,Storage>::operator=(
static_cast<const OrthogPolyImpl<T,Storage>&
>(x));
563 OrthogPoly& operator=(
const Expr< OrthogPolyImpl<T,Storage> >& x) {
564 OrthogPolyImpl<T,Storage>::operator=(
static_cast<const OrthogPolyImpl<T,Storage>&
>(x));
569 template <
typename S>
570 OrthogPoly& operator=(
const Expr<S>& x) {
571 OrthogPolyImpl<T,Storage>::operator=(x);
578 OrthogPoly& operator += (
const value_type& x) {
579 OrthogPolyImpl<T,Storage>::operator+=(x);
584 OrthogPoly& operator -= (
const value_type& x) {
585 OrthogPolyImpl<T,Storage>::operator-=(x);
590 OrthogPoly& operator *= (
const value_type& x) {
591 OrthogPolyImpl<T,Storage>::operator*=(x);
596 OrthogPoly& operator /= (
const value_type& x) {
597 OrthogPolyImpl<T,Storage>::operator/=(x);
602 template <
typename S>
603 OrthogPoly& operator += (
const Expr<S>& x) {
609 template <
typename S>
610 OrthogPoly& operator -= (
const Expr<S>& x) {
616 template <
typename S>
617 OrthogPoly& operator *= (
const Expr<S>& x) {
623 template <
typename S>
624 OrthogPoly& operator /= (
const Expr<S>& x) {
635 template <
typename T>
636 struct IsExpr< ETPCE::Expr<T> > {
637 static const bool value =
true;
640 template <
typename T>
641 struct BaseExprType< ETPCE::Expr<T> > {
642 typedef typename ETPCE::Expr<T>::base_expr_type type;
645 template <
typename T,
typename S>
646 struct IsExpr< ETPCE::OrthogPoly<T,S> > {
647 static const bool value =
true;
650 template <
typename T,
typename S>
651 struct BaseExprType< ETPCE::OrthogPoly<T,S> > {
652 typedef ETPCE::OrthogPoly<T,S> type;
657 #endif // HAVE_STOKHOS_SACADO
659 #endif // SACADO_ETPCE_ORTHOGPOLY_HPP
Stokhos::StandardStorage< int, double > storage_type
Stokhos::LegendreBasis< int, double > basis_type
Abstract base class for orthogonal polynomial-based expansions.
Abstract base class for multivariate orthogonal polynomials.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
expr1 expr1 expr1 expr2 expr1 expr1 c expr2 expr1 c fastAccessCoeff(j)-expr2.val(j)
Orthogonal polynomial expansion class for constant (size 1) expansions.
Class to store coefficients of a projection onto an orthogonal polynomial basis.
Orthogonal polynomial expansions based on numerical quadrature.