Mundy: Multibody Nonlocal Dynamics Version of the Day
Loading...
Searching...
No Matches
GaussLegendreSphere.hpp File Reference

Gauss-Legendre product quadrature on the unit sphere, with the ring count fixed at compile time or run time. More...

Classes

class  mundy::GaussLegendreSphere< Scalar, N >
 The Gauss-Legendre product rule on the unit sphere with N rings, exact through degree 2N - 1. More...

Namespaces

namespace  mundy

Functions

template<class Scalar>
void mundy::gauss_legendre_sphere_rule (unsigned n, std::vector< Scalar > &points, std::vector< Scalar > &weights)
 The Gauss-Legendre product rule on the unit sphere with a run-time number of rings n, into std::vectors.
template<class PointsView, class WeightsView>
void mundy::gauss_legendre_sphere_rule (unsigned n, PointsView &points, WeightsView &weights)
 The Gauss-Legendre product rule on the unit sphere with a run-time number of rings n, into rank-1 views.

Detailed Description

The rule is Gauss-Legendre in z = cos(theta) on N rings times the trapezoidal rule in the longitude phi on 2N points per ring, 2N^2 points in all. Like GaussLegendre<Scalar, N>, it is exact through degree 2N - 1: for every polynomial in (x, y, z) of that degree, and so for every spherical harmonic of degree at most 2N - 1.

Points are (x, y, z) triples on the unit sphere, ring by ring from the north pole (+z) southward, and by increasing phi = 2 pi k / (2N) from +x within a ring. For a sphere of radius r, scale the points by r and the weights by r^2; the outward unit normals are the points themselves. Points and weights are correctly rounded to Scalar.

GaussLegendreSphere uses compile-time work that grows like N^2. At the time of writing, GCC 13.3.0 compiles for N <= 142 whereas clang 18.1.8 compiles for N <= 41. Larger N need -fconstexpr-ops-limit (GCC) or -fconstexpr-steps (clang). Its table holds 8N^2 scalars, so for large N or on the device prefer gauss_legendre_sphere_rule(n, points, weights), which builds the same rule, bit for bit, at run time.