10 #ifndef SACADO_ETPCE_ORTHOGPOLY_HPP
11 #define SACADO_ETPCE_ORTHOGPOLY_HPP
15 #ifdef HAVE_STOKHOS_SACADO
19 #include "Sacado_Traits.hpp"
20 #include "Sacado_Handle.hpp"
27 #include "Sacado_mpl_apply.hpp"
31 #ifdef HAVE_STOKHOS_THRUST
32 #include "thrust/tuple.h"
44 template <
int k,
typename T> KERNEL_PREFIX T&
45 get(T* a) {
return a[k]; }
46 template <
int k,
typename T> KERNEL_PREFIX
const T&
47 get(
const T* a) {
return a[k]; }
49 template <
int k,
int N,
typename T> KERNEL_PREFIX T&
50 get(T a[N]) {
return a[k]; }
51 template <
int k,
int N,
typename T> KERNEL_PREFIX
const T&
52 get(
const T a[N]) {
return a[k]; }
59 template <
typename ExprT>
class Expr {};
62 template <
typename T,
typename S>
class OrthogPoly;
65 template <
typename T,
typename Storage >
66 class OrthogPolyImpl {
93 typedef typename approx_type::pointer pointer;
94 typedef typename approx_type::const_pointer const_pointer;
95 typedef typename approx_type::reference reference;
96 typedef typename approx_type::const_reference const_reference;
125 OrthogPolyImpl(
const OrthogPolyImpl& x);
128 template <
typename S> OrthogPolyImpl(
const Expr<S>& x);
134 void init(
const T& v) { th_->init(v); }
137 void init(
const T* v) { th_->init(v); }
140 template <
typename S>
141 void init(
const OrthogPolyImpl<T,S>& v) { th_->init(v.getOrthogPolyApprox()); }
144 void load(T* v) { th_->load(v); }
147 template <
typename S>
148 void load(OrthogPolyImpl<T,S>& v) { th_->load(v.getOrthogPolyApprox()); }
173 void copyForWrite() { th_.makeOwnCopy(); }
183 value_type mean()
const {
return th_->mean(); }
186 value_type standard_deviation()
const {
return th_->standard_deviation(); }
189 value_type two_norm()
const {
return th_->two_norm(); }
192 value_type two_norm_squared()
const {
return th_->two_norm_squared(); }
195 value_type inner_product(
const OrthogPolyImpl& b)
const {
196 return th_->inner_product(b.getOrthogPolyApprox()); }
199 std::ostream& print(std::ostream& os)
const {
return th_->print(os); }
202 template <
typename S>
bool isEqualTo(
const Expr<S>& x)
const;
213 OrthogPolyImpl& operator=(
const OrthogPolyImpl& x);
216 template <
typename S>
217 OrthogPolyImpl& operator=(
const Expr<S>& x);
243 const_reference
val()
const {
return (*th_)[0]; }
246 reference
val() {
return (*th_)[0]; }
259 bool hasFastAccess(
ordinal_type sz)
const {
return th_->size()>=sz;}
262 const_pointer coeff()
const {
return th_->coeff();}
265 pointer coeff() {
return th_->coeff();}
269 return i<th_->size() ? (*th_)[i]:
value_type(0.); }
279 return th_->term(dimension, order); }
283 return th_->term(dimension, order); }
287 return th_->order(term); }
297 OrthogPolyImpl& operator += (
const value_type& x);
300 OrthogPolyImpl& operator -= (
const value_type& x);
303 OrthogPolyImpl& operator *= (
const value_type& x);
306 OrthogPolyImpl& operator /= (
const value_type& x);
311 const approx_type& getOrthogPolyApprox()
const {
return *th_; }
314 approx_type& getOrthogPolyApprox() {
return *th_; }
319 template <
typename S>
void expressionCopy(
const Expr<S>& x);
333 Sacado::Handle< Stokhos::OrthogPolyApprox<int,value_type,Storage> > th_;
343 template <
typename T,
typename Storage>
344 class Expr< OrthogPolyImpl<T,
Storage> > :
345 public OrthogPolyImpl<T,Storage> {
352 typedef typename OrthogPolyImpl<T,Storage>::approx_type approx_type;
354 typedef typename OrthogPolyImpl<T,Storage>::const_reference const_reference;
356 typedef OrthogPoly<T,Storage> base_expr_type;
359 static const int num_args = 1;
367 OrthogPolyImpl<T,
Storage>(x) {}
370 Expr(
const Teuchos::RCP<
typename OrthogPolyImpl<T,Storage>::expansion_type>& expansion) :
371 OrthogPolyImpl<T,
Storage>(expansion) {}
374 Expr(
const Teuchos::RCP<
typename OrthogPolyImpl<T,Storage>::expansion_type>& expansion,
376 OrthogPolyImpl<T,
Storage>(expansion, sz) {}
379 Expr(
const Expr& x) :
380 OrthogPolyImpl<T,
Storage>(static_cast<const OrthogPolyImpl<T,
Storage>&>(x)) {}
383 Expr(
const OrthogPolyImpl<T,Storage>& x) :
384 OrthogPolyImpl<T,
Storage>(x) {}
387 template <
typename S> Expr(
const Expr<S>& x) :
388 OrthogPolyImpl<T,
Storage>(x) {}
393 const approx_type& getArg(
int i)
const {
394 return this->getOrthogPolyApprox(); }
396 bool has_fast_access(
int sz)
const {
return this->size() >= sz; }
398 bool has_nonconst_expansion()
const {
399 return this->expansion_ != this->const_expansion_;
402 int order()
const {
return this->size() == 1 ? 0 : 1; }
404 value_type fast_higher_order_coeff(
int i)
const {
409 return this->coeff(i);
412 template <
int offset,
typename tuple_type>
415 return get<offset>(x);
418 std::string name()
const {
return "x"; }
436 template <
typename T,
typename Storage>
437 class OrthogPoly :
public Expr< OrthogPolyImpl<T,Storage> > {
456 typedef typename OrthogPolyImpl<T,Storage>::expansion_type expansion_type;
459 typedef typename OrthogPolyImpl<T,Storage>::approx_type approx_type;
461 typedef typename OrthogPolyImpl<T,Storage>::pointer pointer;
462 typedef typename OrthogPolyImpl<T,Storage>::const_pointer const_pointer;
463 typedef typename OrthogPolyImpl<T,Storage>::reference reference;
464 typedef typename OrthogPolyImpl<T,Storage>::const_reference const_reference;
467 template <
typename S>
469 typedef typename Sacado::mpl::apply<Storage,ordinal_type,S>::type
storage_type;
470 typedef OrthogPoly<S,storage_type> type;
478 Expr< OrthogPolyImpl<T,
Storage> >() {}
485 Expr< OrthogPolyImpl<T,
Storage> >(x) {}
492 Expr< OrthogPolyImpl<T,
Storage> >(expansion) {}
500 Expr< OrthogPolyImpl<T,
Storage> >(expansion, sz) {}
503 OrthogPoly(
const OrthogPoly& x) :
504 Expr< OrthogPolyImpl<T,
Storage> >(x) {}
507 template <
typename S> OrthogPoly(
const Expr<S>& x) :
508 Expr< OrthogPolyImpl<T,
Storage> >(x) {}
515 OrthogPolyImpl<T,Storage>::operator=(val);
520 OrthogPoly& operator=(
const OrthogPoly& x) {
521 OrthogPolyImpl<T,Storage>::operator=(
static_cast<const OrthogPolyImpl<T,Storage>&
>(x));
526 OrthogPoly& operator=(
const Expr< OrthogPolyImpl<T,Storage> >& x) {
527 OrthogPolyImpl<T,Storage>::operator=(
static_cast<const OrthogPolyImpl<T,Storage>&
>(x));
532 template <
typename S>
533 OrthogPoly& operator=(
const Expr<S>& x) {
534 OrthogPolyImpl<T,Storage>::operator=(x);
541 OrthogPoly& operator += (
const value_type& x) {
542 OrthogPolyImpl<T,Storage>::operator+=(x);
547 OrthogPoly& operator -= (
const value_type& x) {
548 OrthogPolyImpl<T,Storage>::operator-=(x);
553 OrthogPoly& operator *= (
const value_type& x) {
554 OrthogPolyImpl<T,Storage>::operator*=(x);
559 OrthogPoly& operator /= (
const value_type& x) {
560 OrthogPolyImpl<T,Storage>::operator/=(x);
565 template <
typename S>
566 OrthogPoly& operator += (
const Expr<S>& x) {
572 template <
typename S>
573 OrthogPoly& operator -= (
const Expr<S>& x) {
579 template <
typename S>
580 OrthogPoly& operator *= (
const Expr<S>& x) {
586 template <
typename S>
587 OrthogPoly& operator /= (
const Expr<S>& x) {
598 template <
typename T>
599 struct IsExpr< ETPCE::Expr<T> > {
600 static const bool value =
true;
603 template <
typename T>
604 struct BaseExprType< ETPCE::Expr<T> > {
605 typedef typename ETPCE::Expr<T>::base_expr_type type;
608 template <
typename T,
typename S>
609 struct IsExpr< ETPCE::OrthogPoly<T,S> > {
610 static const bool value =
true;
613 template <
typename T,
typename S>
614 struct BaseExprType< ETPCE::OrthogPoly<T,S> > {
615 typedef ETPCE::OrthogPoly<T,S> type;
620 #endif // HAVE_STOKHOS_SACADO
622 #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.
expr1 expr1 expr1 expr2 expr1 expr1 c expr2 expr1 c fastAccessCoeff(j)-expr2.val(j)
Class to store coefficients of a projection onto an orthogonal polynomial basis.
Orthogonal polynomial expansions based on numerical quadrature.