Clenshaw Curtis Quadrature#

template<typename MemorySpace = Kokkos::HostSpace>
class ClenshawCurtisQuadrature : public mpart::QuadratureBase<Kokkos::HostSpace>#

USAGE

With internally constructed workspace:

unsigned int fdim = 1; // Size of vector-valued integrand.  Set to 1 for scalar integrand
auto f = [](double x, double* fval){ fval[0] = x*x;};

ClenshawCurtisQuadrature quad(5,fdim);

double integral;
quad.Integrate(f, 0, 1, &integral); // Integrate x^2 from 0 to 1 and store in "integral"

With external workspace specified at construction

unsigned int fdim = 1;
auto f = [](double x, double* fval){ fval[0] = x*x;};

std::vector<double> workspace(ClenshawCurtisQuadrature::GetWorkspaceSize(fdim));

ClenshawCurtisQuadrature quad(5, fdim, *workspace[0]);

double integral;
quad.Integrate(f, 0, 1, &integral); // Integrate x^2 from 0 to 1 and store in "integral"

With external workspace specified at integration time. This is often useful when integration is performed in a Kokkos parallel_for loop.

unsigned int fdim = 1;
auto f = [](double x, double* fval){ fval[0] = x*x;};

ClenshawCurtisQuadrature quad(5, fdim, nullptr);

std::vector<double> workspace(ClenshawCurtisQuadrature::GetWorkspaceSize(fdim));

double integral;
quad.Integrate(&workspace[0], f, 0, 1, &integral); // Integrate x^2 from 0 to 1 and store in "integral"

Public Functions

inline ClenshawCurtisQuadrature(unsigned int numPts, unsigned int maxDim)#

Construct a new Clenshaw Curtis Quadrature object using an internally allocated workspace.

Parameters:
  • numPts – The number of points in the CC rule.

  • maxDim – The maximum dimension of the integrand. Used to help set up workspace.

  • workspace – A pointer to memory that is allocated as a workspace. Must have space for at least maxDim components.

inline ClenshawCurtisQuadrature(unsigned int numPts, unsigned int maxDim, double *workspace)#

Construct a new Clenshaw Curtis Quadrature object with externally allocated workspace memory.

Parameters:
  • numPts – The number of points in the CC rule.

  • maxDim – The maximum dimension of the integrand. Used to help set up workspace.

  • workspace – A pointer to memory that is allocated as a workspace. Must have space for at least maxDim components. Set to null ptr if workspace memory will be allocated later using the SetWorkspace function.

inline void SetDim(unsigned int fdim)#
inline ClenshawCurtisQuadrature(Kokkos::View<double*, MemorySpace> pts, Kokkos::View<double*, MemorySpace> wts, unsigned int maxDim, double *workspace)#

Construct a new Clenshaw Curtis Quadrature object without allocating workspace memory and specifying views where the points and weights should be stored.

Parameters:
  • pts – A view to hold the points in the quadrature rule. Does not need to contain the points themselves, just memory to store them. The length of this view dictates how many points are in the quadrature rule.

  • wts – A view to hold the weights in the quadrature rule. Like the pts view, this does not need to contain the weights, just space to store them. Must be the same length as pts.

  • numPts – The number of points in the CC rule.

  • maxDim – The maximum dimension of the integrand. Used to help set up workspace.

  • workspace – A pointer to memory that is allocated as a workspace. Must have space for at least maxDim components. Set to null ptr if workspace memory will be allocated later using the SetWorkspace function.

template<class FunctionType>
inline void Integrate(FunctionType const &f, double lb, double ub, double *res) const#

Approximates the integral \(\int_{x_L}^{x_U} f(x) dx\) using a Clenshaw-Curtis quadrature rule.

Parameters:
  • f[in] The integrand. Can return any type that overloads multiplication with a double and the += operator. doubles and Eigen::VectorXd are examples.

  • lb[in] The lower bound \(x_L\) in the integration.

  • lb[in] The upper bound \(x_U\) in the integration.

  • res[out] A pointer to the array where the approximation of \(\int_{x_L}^{x_U} f(x) dx\) should be stored. Must have at least enough space to store a vector computed by the dimension of f. Set the dimension of f in the constructor or using the QuadratureBase::SetDim function.

Template Parameters:

FunctionType – The type of the integrand. Must have an operator()(double x) function.

template<class FunctionType>
inline void Integrate(double *workspace, FunctionType const &f, double lb, double ub, double *res) const#
inline ClenshawCurtisQuadrature(unsigned int numPts, unsigned int maxDim)
inline ClenshawCurtisQuadrature(unsigned int numPts, unsigned int maxDim, double *workspace)

Public Static Functions

static inline unsigned int GetWorkspaceSize(unsigned int fdim)#

Returns the size of a double array needed as a workspace to integrate a function with dimension fdim.

Parameters:

fdim – The dimension of a vector-valued integrand.

Returns:

The minimum length of a double array needed for the workspace.

static inline std::pair<Eigen::VectorXd, Eigen::VectorXd> GetRule(unsigned int order)#
static inline void GetRule(unsigned int numPts, double *wts, double *pts)#

Computes the weights and points in a Clenshaw-Curtis rule.

Parameters:
  • numPts[in] The number of points in the quadrature rule.

  • wts[out] A pointer to the memory where the weights will be stored. Must be at least numPts long.

  • pts[out] A pointer to the memory where the points will be stored. Must be at least numPts long.