// @HEADER // ***************************************************************************** // Stokhos Package // // Copyright 2009 NTESS and the Stokhos contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER #ifndef STOKHOS_QUADORTHOGPOLYEXPANSION_HPP #define STOKHOS_QUADORTHOGPOLYEXPANSION_HPP #include "Stokhos_OrthogPolyExpansionBase.hpp" #include "Stokhos_Quadrature.hpp" #include "Teuchos_RCP.hpp" #include "Teuchos_Array.hpp" #include "Teuchos_SerialDenseMatrix.hpp" #include "Teuchos_SerialDenseVector.hpp" #include "Teuchos_BLAS.hpp" namespace Stokhos { //! Orthogonal polynomial expansions based on numerical quadrature template > class QuadOrthogPolyExpansion : public OrthogPolyExpansionBase { public: //! Constructor QuadOrthogPolyExpansion( const Teuchos::RCP >& basis, const Teuchos::RCP >& Cijk, const Teuchos::RCP >& quad, const Teuchos::RCP& params = Teuchos::null); //! Destructor virtual ~QuadOrthogPolyExpansion() {} void timesEqual( OrthogPolyApprox& c, const value_type& x); void divideEqual( OrthogPolyApprox& c, const value_type& x); void timesEqual( OrthogPolyApprox& c, const OrthogPolyApprox& x); void divideEqual( OrthogPolyApprox& c, const OrthogPolyApprox& x); void times(OrthogPolyApprox& c, const OrthogPolyApprox& a, const OrthogPolyApprox& b); void times(OrthogPolyApprox& c, const value_type& a, const OrthogPolyApprox& b); void times(OrthogPolyApprox& c, const OrthogPolyApprox& a, const value_type& b); void divide(OrthogPolyApprox& c, const OrthogPolyApprox& a, const OrthogPolyApprox& b); void divide(OrthogPolyApprox& c, const value_type& a, const OrthogPolyApprox& b); void divide(OrthogPolyApprox& c, const OrthogPolyApprox& a, const value_type& b); void exp(OrthogPolyApprox& c, const OrthogPolyApprox& a); void log(OrthogPolyApprox& c, const OrthogPolyApprox& a); void log10(OrthogPolyApprox& c, const OrthogPolyApprox& a); void sqrt(OrthogPolyApprox& c, const OrthogPolyApprox& a); void cbrt(OrthogPolyApprox& c, const OrthogPolyApprox& a); void pow(OrthogPolyApprox& c, const OrthogPolyApprox& a, const OrthogPolyApprox& b); void pow(OrthogPolyApprox& c, const value_type& a, const OrthogPolyApprox& b); void pow(OrthogPolyApprox& c, const OrthogPolyApprox& a, const value_type& b); void cos(OrthogPolyApprox& c, const OrthogPolyApprox& a); void sin(OrthogPolyApprox& c, const OrthogPolyApprox& a); void tan(OrthogPolyApprox& c, const OrthogPolyApprox& a); void cosh(OrthogPolyApprox& c, const OrthogPolyApprox& a); void sinh(OrthogPolyApprox& c, const OrthogPolyApprox& a); void tanh(OrthogPolyApprox& c, const OrthogPolyApprox& a); void acos(OrthogPolyApprox& c, const OrthogPolyApprox& a); void asin(OrthogPolyApprox& c, const OrthogPolyApprox& a); void atan(OrthogPolyApprox& c, const OrthogPolyApprox& a); void atan2(OrthogPolyApprox& c, const OrthogPolyApprox& a, const OrthogPolyApprox& b); void atan2(OrthogPolyApprox& c, const value_type& a, const OrthogPolyApprox& b); void atan2(OrthogPolyApprox& c, const OrthogPolyApprox& a, const value_type& b); void acosh(OrthogPolyApprox& c, const OrthogPolyApprox& a); void asinh(OrthogPolyApprox& c, const OrthogPolyApprox& a); void atanh(OrthogPolyApprox& c, const OrthogPolyApprox& a); template void nary_op(const FuncT& func, OrthogPolyApprox& c, const OrthogPolyApprox** a); template value_type compute_times_coeff(ordinal_type k, const ExprT1& a, const ExprT2& b) const; template value_type fast_compute_times_coeff(ordinal_type k, const ExprT1& a, const ExprT2& b) const; private: // Prohibit copying QuadOrthogPolyExpansion(const QuadOrthogPolyExpansion&); // Prohibit Assignment QuadOrthogPolyExpansion& operator=(const QuadOrthogPolyExpansion& b); protected: //! Short-hand for Cijk typedef typename OrthogPolyExpansionBase::Cijk_type Cijk_type; //! Quadrature routine Teuchos::RCP > quad; //! Use quadrature for times functions bool use_quad_for_times; //! Use quadrature for division functions bool use_quad_for_division; //! Expansions size ordinal_type sz; //! BLAS wrappers Teuchos::BLAS blas; //! Array of Quad points const Teuchos::Array< Teuchos::Array >& quad_points; //! Array of Quad weights const Teuchos::Array& quad_weights; //! Values of basis at Quad points const Teuchos::Array< Teuchos::Array >& quad_values; //! Norms of basis vectors const Teuchos::Array& norms; //! Number of Quad points ordinal_type nqp; //! Temporary array for values of first argument at quad points Teuchos::Array avals; //! Temporary array for values of second argument at quad points Teuchos::Array bvals; //! Temporary array for values of n-ary arguments at quad points Teuchos::Array< Teuchos::Array< Teuchos::Array > > navals; //! Temporary array for values of operation at quad points Teuchos::Array fvals; //! Reshaped quad values into 1D array Teuchos::Array qv; //! Quad values scaled by norms Teuchos::Array sqv; public: //! Nonlinear unary function template void unary_op( const FuncT& func, OrthogPolyApprox& c, const OrthogPolyApprox& a); //! Nonlinear binary function template void binary_op( const FuncT& func, OrthogPolyApprox& c, const OrthogPolyApprox& a, const OrthogPolyApprox& b); //! Nonlinear binary function template void binary_op( const FuncT& func, OrthogPolyApprox& c, const value_type& a, const OrthogPolyApprox& b); //! Nonlinear binary function template void binary_op( const FuncT& func, OrthogPolyApprox& c, const OrthogPolyApprox& a, const value_type& b); protected: struct times_quad_func { value_type operator() (const value_type& a, const value_type& b) const { return a * b; } }; struct div_quad_func { value_type operator() (const value_type& a, const value_type& b) const { return a / b; } }; struct exp_quad_func { value_type operator() (const value_type& a) const { return std::exp(a); } }; struct log_quad_func { value_type operator() (const value_type& a) const { return std::log(a); } }; struct log10_quad_func { value_type operator() (const value_type& a) const { return std::log10(a); } }; struct sqrt_quad_func { value_type operator() (const value_type& a) const { return std::sqrt(a); } }; struct cbrt_quad_func { value_type operator() (const value_type& a) const { return std::cbrt(a); } }; struct pow_quad_func { value_type operator() (const value_type& a, const value_type& b) const { return std::pow(a,b); } }; struct cos_quad_func { value_type operator() (const value_type& a) const { return std::cos(a); } }; struct sin_quad_func { value_type operator() (const value_type& a) const { return std::sin(a); } }; struct tan_quad_func { value_type operator() (const value_type& a) const { return std::tan(a); } }; struct cosh_quad_func { value_type operator() (const value_type& a) const { return std::cosh(a); } }; struct sinh_quad_func { value_type operator() (const value_type& a) const { return std::sinh(a); } }; struct tanh_quad_func { value_type operator() (const value_type& a) const { return std::tanh(a); } }; struct acos_quad_func { value_type operator() (const value_type& a) const { return std::acos(a); } }; struct asin_quad_func { value_type operator() (const value_type& a) const { return std::asin(a); } }; struct atan_quad_func { value_type operator() (const value_type& a) const { return std::atan(a); } }; struct atan2_quad_func { value_type operator() (const value_type& a, const value_type& b) const { return std::atan2(a,b); } }; struct acosh_quad_func { value_type operator() (const value_type & a) const { return std::log(a+std::sqrt(a*a-value_type(1.0))); } }; struct asinh_quad_func { value_type operator() (const value_type& a) const { return std::log(a+std::sqrt(a*a+value_type(1.0))); } }; struct atanh_quad_func { value_type operator() (const value_type& a) const { return 0.5*std::log((value_type(1.0)+a)/(value_type(1.0)-a)); } }; }; // class QuadOrthogPolyExpansion } // namespace Stokhos #include "Stokhos_QuadOrthogPolyExpansionImp.hpp" #endif // STOKHOS_QUADORTHOGPOLYEXPANSION_HPP