// @HEADER // ***************************************************************************** // Stokhos Package // // Copyright 2009 NTESS and the Stokhos contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER #include "Sacado_DynamicArrayTraits.hpp" #include "Teuchos_TimeMonitor.hpp" #include "Stokhos_ConstantOrthogPolyExpansion.hpp" namespace Sacado { namespace ETPCE { template struct ExprQuadFuncWrapper { static const int N = NN; typedef typename ExprT::value_type value_type; const ExprT& expr_; ExprQuadFuncWrapper(const ExprT& expr) : expr_(expr) {} template KERNEL_PREFIX value_type operator() (tuple_type x) const { return expr_.template eval_sample<0>(x); } }; template template void OrthogPolyImpl:: expressionCopy(const Expr& x) { #ifdef STOKHOS_TEUCHOS_TIME_MONITOR TEUCHOS_FUNC_TIME_MONITOR("ETPCE ExpressionCopy(" << x.name() << ")"); #endif int p = x.order(); if (p == 0) { (*th_)[0] = x.val(); } else if (p <= 2) { int sz = th_->size(); approx_type* tc = th_.get(); bool on_rhs = false; // Check if *this is on the right-hand-side of the expression if (p == 2) { const int N = Expr::num_args; for (int i=0; igetBasis(), sz); (*tc)[0] = x.val(); if (x.has_fast_access(sz)) { for (int i=1; i(tc); } } else { const int N = Expr::num_args; const approx_type* opas[N]; for (int i=0; i > func(x); quad_expansion_->nary_op(func, *th_, opas); } } template OrthogPolyImpl:: OrthogPolyImpl() : expansion_(), quad_expansion_(), th_(new Stokhos::OrthogPolyApprox) { const_expansion_ = Teuchos::rcp(new Stokhos::ConstantOrthogPolyExpansion); expansion_ = const_expansion_; } template OrthogPolyImpl:: OrthogPolyImpl(const typename OrthogPolyImpl::value_type& x) : expansion_(), quad_expansion_(), th_(new Stokhos::OrthogPolyApprox(Teuchos::null, 1, &x)) { const_expansion_ = Teuchos::rcp(new Stokhos::ConstantOrthogPolyExpansion); expansion_ = const_expansion_; } template OrthogPolyImpl:: OrthogPolyImpl(const Teuchos::RCP& expansion) : expansion_(expansion), quad_expansion_(Teuchos::rcp_dynamic_cast(expansion_)), th_(new Stokhos::OrthogPolyApprox(expansion_->getBasis())) { const_expansion_ = Teuchos::rcp(new Stokhos::ConstantOrthogPolyExpansion); } template OrthogPolyImpl:: OrthogPolyImpl(const Teuchos::RCP& expansion, ordinal_type sz) : expansion_(expansion), quad_expansion_(Teuchos::rcp_dynamic_cast(expansion_)), th_(new Stokhos::OrthogPolyApprox(expansion_->getBasis(), sz)) { const_expansion_ = Teuchos::rcp(new Stokhos::ConstantOrthogPolyExpansion); } template OrthogPolyImpl:: OrthogPolyImpl(const OrthogPolyImpl& x) : expansion_(x.expansion_), quad_expansion_(x.quad_expansion_), th_(x.th_) { const_expansion_ = Teuchos::rcp(new Stokhos::ConstantOrthogPolyExpansion); } template template OrthogPolyImpl:: OrthogPolyImpl(const Expr& x) : expansion_(x.expansion()), quad_expansion_(Teuchos::rcp_dynamic_cast(expansion_)), th_(new Stokhos::OrthogPolyApprox(expansion_->getBasis(), x.size())) { const_expansion_ = Teuchos::rcp(new Stokhos::ConstantOrthogPolyExpansion); expressionCopy(x); } template void OrthogPolyImpl:: reset(const Teuchos::RCP& expansion) { expansion_ = expansion; quad_expansion_ = Teuchos::rcp_dynamic_cast(expansion_); th_->reset(expansion_->getBasis()); } template void OrthogPolyImpl:: reset(const Teuchos::RCP& expansion, ordinal_type sz) { expansion_ = expansion; quad_expansion_ = Teuchos::rcp_dynamic_cast(expansion_); th_->reset(expansion_->getBasis(), sz); } template typename OrthogPolyImpl::value_type OrthogPolyImpl:: evaluate(const Teuchos::Array::value_type>& point) const { return th_->evaluate(point); } template typename OrthogPolyImpl::value_type OrthogPolyImpl:: evaluate( const Teuchos::Array::value_type>& point, const Teuchos::Array::value_type>& bvals) const { return th_->evaluate(point, bvals); } template template bool OrthogPolyImpl:: isEqualTo(const Expr& x) const { typedef IsEqual IE; if (x.size() != this->size()) return false; // Allow expansions to be different if their size is 1 and one // of them is a constant expansion if (expansion_ != x.expansion_) { if (x.size() != 1) return false; if ((expansion_ != const_expansion_) && (x.expansion_ != x.const_expansion_)) return false; } bool eq = true; for (int i=0; isize(); i++) eq = eq && IE::eval(x.coeff(i), this->coeff(i)); return eq; } template OrthogPolyImpl& OrthogPolyImpl:: operator=(const typename OrthogPolyImpl::value_type& v) { th_.makeOwnCopy(); *th_ = v; return *this; } template OrthogPolyImpl& OrthogPolyImpl:: operator=(const OrthogPolyImpl& x) { expansion_ = x.expansion_; quad_expansion_ = x.quad_expansion_; th_ = x.th_; return *this; } template template OrthogPolyImpl& OrthogPolyImpl:: operator=(const Expr& x) { th_.makeOwnCopy(); expansion_ = x.expansion(); quad_expansion_ = Teuchos::rcp_dynamic_cast(expansion_); th_->reset(expansion_->getBasis(), x.size()); expressionCopy(x); return *this; } template OrthogPolyImpl& OrthogPolyImpl:: operator+=(const typename OrthogPolyImpl::value_type& v) { th_.makeOwnCopy(); expansion_->plusEqual(*th_, v); return *this; } template OrthogPolyImpl& OrthogPolyImpl:: operator-=(const typename OrthogPolyImpl::value_type& v) { th_.makeOwnCopy(); expansion_->minusEqual(*th_, v); return *this; } template OrthogPolyImpl& OrthogPolyImpl:: operator*=(const typename OrthogPolyImpl::value_type& v) { th_.makeOwnCopy(); expansion_->timesEqual(*th_, v); return *this; } template OrthogPolyImpl& OrthogPolyImpl:: operator/=(const typename OrthogPolyImpl::value_type& v) { th_.makeOwnCopy(); expansion_->divideEqual(*th_, v); return *this; } template std::ostream& operator << (std::ostream& os, const OrthogPoly& a) { typedef typename OrthogPoly::ordinal_type ordinal_type; os << "[ "; for (ordinal_type i=0; i std::istream& operator >> (std::istream& is, OrthogPoly& a) { typedef typename OrthogPoly::ordinal_type ordinal_type; // Read in the opening "[" char bracket; is >> bracket; for (ordinal_type i=0; i> a.fastAccessCoeff(i); } // Read in the closing "]" is >> bracket; return is; } } // namespace PCE } // namespace Sacado