42 #ifndef SACADO_ETPCE_ORTHOGPOLY_HPP 43 #define SACADO_ETPCE_ORTHOGPOLY_HPP 47 #ifdef HAVE_STOKHOS_SACADO 49 #include "Teuchos_RCP.hpp" 51 #include "Sacado_Traits.hpp" 52 #include "Sacado_Handle.hpp" 58 #include "Sacado_mpl_apply.hpp" 62 #ifdef HAVE_STOKHOS_THRUST 63 #include "thrust/tuple.h" 75 template <
int k,
typename T> KERNEL_PREFIX T&
76 get(T* a) {
return a[k]; }
77 template <
int k,
typename T> KERNEL_PREFIX
const T&
78 get(
const T* a) {
return a[k]; }
80 template <
int k,
int N,
typename T> KERNEL_PREFIX T&
81 get(T a[N]) {
return a[k]; }
82 template <
int k,
int N,
typename T> KERNEL_PREFIX
const T&
83 get(
const T a[N]) {
return a[k]; }
90 template <
typename ExprT>
class Expr {};
93 template <
typename T,
typename S>
class OrthogPoly;
96 template <
typename T,
typename Storage >
97 class OrthogPolyImpl {
124 typedef typename approx_type::pointer pointer;
125 typedef typename approx_type::const_pointer const_pointer;
126 typedef typename approx_type::reference reference;
127 typedef typename approx_type::const_reference const_reference;
146 OrthogPolyImpl(
const Teuchos::RCP<expansion_type>& expansion);
152 OrthogPolyImpl(
const Teuchos::RCP<expansion_type>& expansion,
156 OrthogPolyImpl(
const OrthogPolyImpl&
x);
159 template <
typename S> OrthogPolyImpl(
const Expr<S>&
x);
165 void init(
const T& v) { th_->init(v); }
168 void init(
const T* v) { th_->init(v); }
171 template <
typename S>
172 void init(
const OrthogPolyImpl<T,S>& v) { th_->init(v.getOrthogPolyApprox()); }
175 void load(T* v) { th_->load(v); }
178 template <
typename S>
179 void load(OrthogPolyImpl<T,S>& v) { th_->load(v.getOrthogPolyApprox()); }
185 void reset(
const Teuchos::RCP<expansion_type>& expansion);
191 void reset(
const Teuchos::RCP<expansion_type>& expansion,
204 void copyForWrite() { th_.makeOwnCopy(); }
207 value_type evaluate(
const Teuchos::Array<value_type>& point)
const;
210 value_type evaluate(
const Teuchos::Array<value_type>& point,
211 const Teuchos::Array<value_type>& bvals)
const;
214 value_type mean()
const {
return th_->mean(); }
217 value_type standard_deviation()
const {
return th_->standard_deviation(); }
220 value_type two_norm()
const {
return th_->two_norm(); }
223 value_type two_norm_squared()
const {
return th_->two_norm_squared(); }
226 value_type inner_product(
const OrthogPolyImpl& b)
const {
227 return th_->inner_product(b.getOrthogPolyApprox()); }
230 std::ostream& print(std::ostream& os)
const {
return th_->print(os); }
233 template <
typename S>
bool isEqualTo(
const Expr<S>&
x)
const;
244 OrthogPolyImpl& operator=(
const OrthogPolyImpl&
x);
247 template <
typename S>
248 OrthogPolyImpl& operator=(
const Expr<S>&
x);
258 Teuchos::RCP<basis_type> basis()
const {
return th_->basis(); }
261 Teuchos::RCP<expansion_type> expansion()
const {
return expansion_; }
264 Teuchos::RCP<quad_expansion_type> quad_expansion()
const {
return quad_expansion_; }
274 const_reference
val()
const {
return (*th_)[0]; }
277 reference
val() {
return (*th_)[0]; }
290 bool hasFastAccess(
ordinal_type sz)
const {
return th_->size()>=sz;}
293 const_pointer coeff()
const {
return th_->coeff();}
296 pointer coeff() {
return th_->coeff();}
300 return i<th_->size() ? (*th_)[i]:
value_type(0.); }
310 return th_->term(dimension, order); }
314 return th_->term(dimension, order); }
317 Teuchos::Array<ordinal_type> order(
ordinal_type term)
const {
318 return th_->order(term); }
342 const approx_type& getOrthogPolyApprox()
const {
return *th_; }
345 approx_type& getOrthogPolyApprox() {
return *th_; }
350 template <
typename S>
void expressionCopy(
const Expr<S>&
x);
355 Teuchos::RCP<expansion_type> expansion_;
358 Teuchos::RCP<quad_expansion_type> quad_expansion_;
361 static Teuchos::RCP<expansion_type> const_expansion_;
364 Sacado::Handle< Stokhos::OrthogPolyApprox<int,value_type,Storage> > th_;
374 template <
typename T,
typename Storage>
375 class Expr< OrthogPolyImpl<T,
Storage> > :
376 public OrthogPolyImpl<T,Storage> {
383 typedef typename OrthogPolyImpl<T,Storage>::approx_type approx_type;
385 typedef typename OrthogPolyImpl<T,Storage>::const_reference const_reference;
387 typedef OrthogPoly<T,Storage> base_expr_type;
390 static const int num_args = 1;
401 Expr(
const Teuchos::RCP<
typename OrthogPolyImpl<T,Storage>::expansion_type>& expansion) :
402 OrthogPolyImpl<T,
Storage>(expansion) {}
405 Expr(
const Teuchos::RCP<
typename OrthogPolyImpl<T,Storage>::expansion_type>& expansion,
407 OrthogPolyImpl<T,
Storage>(expansion, sz) {}
410 Expr(
const Expr&
x) :
411 OrthogPolyImpl<T,
Storage>(static_cast<const OrthogPolyImpl<T,
Storage>&>(
x)) {}
414 Expr(
const OrthogPolyImpl<T,Storage>&
x) :
418 template <
typename S> Expr(
const Expr<S>&
x) :
424 const approx_type& getArg(
int i)
const {
425 return this->getOrthogPolyApprox(); }
427 bool has_fast_access(
int sz)
const {
return this->size() >= sz; }
429 bool has_nonconst_expansion()
const {
430 return this->expansion_ != this->const_expansion_;
433 int order()
const {
return this->size() == 1 ? 0 : 1; }
435 value_type fast_higher_order_coeff(
int i)
const {
440 return this->coeff(i);
443 template <
int offset,
typename tuple_type>
446 return get<offset>(
x);
449 std::string name()
const {
return "x"; }
467 template <
typename T,
typename Storage>
468 class OrthogPoly :
public Expr< OrthogPolyImpl<T,Storage> > {
487 typedef typename OrthogPolyImpl<T,Storage>::expansion_type expansion_type;
490 typedef typename OrthogPolyImpl<T,Storage>::approx_type approx_type;
492 typedef typename OrthogPolyImpl<T,Storage>::pointer pointer;
493 typedef typename OrthogPolyImpl<T,Storage>::const_pointer const_pointer;
494 typedef typename OrthogPolyImpl<T,Storage>::reference reference;
495 typedef typename OrthogPolyImpl<T,Storage>::const_reference const_reference;
498 template <
typename S>
500 typedef typename Sacado::mpl::apply<Storage,ordinal_type,S>::type
storage_type;
501 typedef OrthogPoly<S,storage_type> type;
509 Expr< OrthogPolyImpl<T,
Storage> >() {}
516 Expr< OrthogPolyImpl<T,
Storage> >(
x) {}
522 OrthogPoly(
const Teuchos::RCP<expansion_type>& expansion) :
523 Expr< OrthogPolyImpl<T,
Storage> >(expansion) {}
529 OrthogPoly(
const Teuchos::RCP<expansion_type>& expansion,
531 Expr< OrthogPolyImpl<T,
Storage> >(expansion, sz) {}
534 OrthogPoly(
const OrthogPoly&
x) :
535 Expr< OrthogPolyImpl<T,
Storage> >(
x) {}
538 template <
typename S> OrthogPoly(
const Expr<S>&
x) :
539 Expr< OrthogPolyImpl<T,
Storage> >(
x) {}
546 OrthogPolyImpl<T,Storage>::operator=(
val);
551 OrthogPoly& operator=(
const OrthogPoly&
x) {
552 OrthogPolyImpl<T,Storage>::operator=(
static_cast<const OrthogPolyImpl<T,Storage>&
>(
x));
557 OrthogPoly& operator=(
const Expr< OrthogPolyImpl<T,Storage> >&
x) {
558 OrthogPolyImpl<T,Storage>::operator=(
static_cast<const OrthogPolyImpl<T,Storage>&
>(
x));
563 template <
typename S>
564 OrthogPoly& operator=(
const Expr<S>&
x) {
565 OrthogPolyImpl<T,Storage>::operator=(
x);
573 OrthogPolyImpl<T,Storage>::operator+=(
x);
579 OrthogPolyImpl<T,Storage>::operator-=(
x);
585 OrthogPolyImpl<T,Storage>::operator*=(
x);
591 OrthogPolyImpl<T,Storage>::operator/=(
x);
596 template <
typename S>
597 OrthogPoly& operator += (
const Expr<S>&
x) {
603 template <
typename S>
604 OrthogPoly& operator -= (
const Expr<S>&
x) {
610 template <
typename S>
611 OrthogPoly& operator *= (
const Expr<S>&
x) {
617 template <
typename S>
618 OrthogPoly& operator /= (
const Expr<S>&
x) {
629 template <
typename T>
630 struct IsExpr< ETPCE::Expr<T> > {
631 static const bool value =
true;
634 template <
typename T>
635 struct BaseExprType< ETPCE::Expr<T> > {
636 typedef typename ETPCE::Expr<T>::base_expr_type type;
639 template <
typename T,
typename S>
640 struct IsExpr< ETPCE::OrthogPoly<T,S> > {
641 static const bool value =
true;
644 template <
typename T,
typename S>
645 struct BaseExprType< ETPCE::OrthogPoly<T,S> > {
646 typedef ETPCE::OrthogPoly<T,S> type;
651 #endif // HAVE_STOKHOS_SACADO 653 #endif // SACADO_ETPCE_ORTHOGPOLY_HPP
Stokhos::StandardStorage< int, double > storage_type
expr1 expr1 expr1 expr2 expr1 expr1 c expr2 expr1 c fastAccessCoeff(j) - expr2.val(j)
Stokhos::LegendreBasis< int, double > basis_type
Abstract base class for orthogonal polynomial-based expansions.
Abstract base class for multivariate orthogonal polynomials.
const IndexType const IndexType const IndexType const IndexType const ValueType const ValueType * x
Class to store coefficients of a projection onto an orthogonal polynomial basis.
Orthogonal polynomial expansions based on numerical quadrature.