Quadrature¶
Base classes¶
- class modepy.Quadrature(nodes: ndarray, weights: ndarray, exact_to: int | _Inf | None = None)[source]¶
The basic interface for a quadrature rule.
- nodes: ndarray¶
An array of shape (dim, nnodes), where dim is the dimension of the qudrature rule. In 1D, the shape is just (nnodes,).
- property exact_to: int | _Inf¶
Summed polynomial degree up to which the quadrature is exact.
In higher-dimensions, the quadrature is supposed to be exact on (at least) \(P^N\), where \(N\) =
exact_to
. If the quadrature accuracy is not known,exact_to
will not be set, and anAttributeError
will be raised when attempting to access this information.
- class modepy.ZeroDimensionalQuadrature[source]¶
Bases:
Quadrature
A quadrature rule that should be used for 0d domains (i.e. points).
- modepy.quadrature_for_space(space: FunctionSpace, shape: Shape) Quadrature [source]¶
- modepy.quadrature_for_space(space: PN, shape: Simplex) Quadrature
- modepy.quadrature_for_space(space: TensorProductSpace, shape: TensorProductShape) Quadrature
- Returns:
a
Quadrature
that exactly integrates the functions in space over shape.
- class modepy.quadrature.Quadrature[source]¶
See
modepy.Quadrature
.
Jacobi-Gauss quadrature in one dimension¶
- class modepy.JacobiGaussQuadrature(alpha: float, beta: float, N: int, backend: str | None = None, force_dim_axis: bool = False)[source]¶
Bases:
Quadrature
A Gauss quadrature of order N associated with the Jacobi polynomials.
The quadrature rule can be used for weighted integrals of the form
\[I[f] = \int_{-1}^1 f(x) (1 - x)^\alpha (1 + x)^\beta\, \mathrm{d}x,\]where \(\alpha, \beta > -1\). The quadrature rule is exact up to degree \(2N + 1\). The quadrature has N+1 nodes.
- __init__(alpha: float, beta: float, N: int, backend: str | None = None, force_dim_axis: bool = False) None [source]¶
- Parameters:
backend – Either
"builtin"
or"scipy"
. When the"builtin"
backend is in use, there is an additional requirement that \(\alpha + \beta \ne -1\), with the exception of the Chebyshev quadrature \(\alpha = \beta = -1/2\). The"scipy"
backend has no such restriction.
- static compute_weights_and_nodes(N: int, alpha: float, beta: float) tuple[ndarray, ndarray] [source]¶
- Parameters:
N – order of the Gauss quadrature (the order of exactly integrated polynomials is \(2 N + 1\)).
alpha – power of \(1 - x\) in the Jacobi polynomial weight.
beta – power of \(1 + x\) in the Jacobi polynomial weight.
- Returns:
a tuple
(nodes, weights)
of quadrature notes and weights.
- class modepy.LegendreGaussQuadrature(N: int, backend: str | None = None, force_dim_axis: bool = False)[source]¶
Bases:
JacobiGaussQuadrature
A Gauss quadrature rule with weight \(1\) and N+1 nodes.
Corresponds to a Gauss-Jacobi quadrature rule with \(\alpha = \beta = 0\).
- class modepy.ChebyshevGaussQuadrature(N: int, kind: int = 1, backend: str | None = None, force_dim_axis: bool = False)[source]¶
Bases:
JacobiGaussQuadrature
A Gauss quadrature rule with weight \(\sqrt{1-x^2}^{\mp 1}\) and N+1 nodes.
The Chebyshev-Gauss quadrature rules of the first kind and second kind correspond to Gauss-Jacobi quadrature rules with \(\alpha = \beta = -0.5\) and \(\alpha = \beta = 0.5\), respectively.
Added in version 2019.1.
- class modepy.GaussGegenbauerQuadrature(alpha: float, N: int, backend: str | None = None, force_dim_axis: bool = False)[source]¶
Bases:
JacobiGaussQuadrature
Gauss-Gegenbauer quadrature is a special case of Gauss-Jacobi quadrature with \(\alpha = \beta\) and N+1 nodes.
Added in version 2019.1.
- modepy.quadrature.jacobi_gauss.jacobi_gauss_lobatto_nodes(alpha: float, beta: float, N: int, backend: str | None = None, force_dim_axis: bool = False) ndarray [source]¶
Compute the Gauss-Lobatto quadrature nodes corresponding to the
JacobiGaussQuadrature
with the same parameters. There will be N+1 nodes.Exact to degree \(2N - 3\).
- modepy.quadrature.jacobi_gauss.legendre_gauss_lobatto_nodes(N: int, backend: str | None = None, force_dim_axis: bool = False) ndarray [source]¶
Compute the Legendre-Gauss-Lobatto quadrature nodes. N+1 is the number of nodes.
Exact to degree \(2N - 1\).
- class modepy.JacobiGaussLobattoQuadrature(alpha: float, beta: float, N: int, *, backend: str | None = None, force_dim_axis: bool = False)[source]¶
Compute the Jacobi-Gauss-Lobatto quadrature with respect to the Jacobi weight function
\[I[f] = \int_{-1}^1 f(x) (1 - x)^\alpha (1 + x)^\beta\, \mathrm{d}x,\]There will be N+1 nodes. Exact to degree \(2N - 3\).
Added in version 2024.2.
Clenshaw-Curtis and Fejér quadrature in one dimension¶
- class modepy.ClenshawCurtisQuadrature(N: int, force_dim_axis: bool = False)[source]¶
Bases:
Quadrature
Clenshaw-Curtis quadrature of order N with N + 1 points.
The quadrature rule is exact up to degree \(N\) and can be nested. Its performance for differentiable functions is comparable with the classic Gauss-Legendre quadrature, which is exact for polynomials of degree up to \(2N + 1\). Implementation is based on [Waldvogel2003].
Integrates on the interval \((-1, 1)\).
- class modepy.FejerQuadrature(N: int, kind: int = 1, force_dim_axis: bool = False)[source]¶
Bases:
Quadrature
Fejér quadrature rules of order N.
Fejér quadrature of the first kind has N points and uses Chebyshev nodes, i.e. the roots of Chebyshev polynomials.
Fejér quadrature of the second kind has N - 1 points and uses only the interior extrema of the Chebyshev nodes, i.e. the true stationary points. This rule is almost identical to Clenshaw-Curtis and can be nested.
Integrates on the interval \((-1, 1)\). Implementation is based on [Waldvogel2003].
Quadratures on the simplex¶
Added in version 2013.3.
- class modepy.GrundmannMoellerSimplexQuadrature(order: int, dimension: int)[source]¶
Bases:
Quadrature
Cubature on an n-simplex from [Grundmann1978].
This cubature rule has both negative and positive weights. It is exact for polynomials up to order \(2s + 1\), where \(s\) is given as order. The integration domain is the unit simplex (see Coordinates on the triangle and Coordinates on the tetrahedron).
[Grundmann1978]A. Grundmann and H.M. Moeller, Invariant integration formulas for the n-simplex by combinatorial methods, SIAM J. Numer. Anal. 15 (1978), 282–290. DOI
- class modepy.XiaoGimbutasSimplexQuadrature(order: int, dims: int)[source]¶
Bases:
Quadrature
A (nearly) Gaussian simplicial quadrature with very few quadrature nodes from [Xiao2010].
This rule is available for low-to-moderate orders. The integration domain is the unit simplex (see Coordinates on the triangle and Coordinates on the tetrahedron).
- __init__(order: int, dims: int) None [source]¶
- Parameters:
order – the total degree to which the quadrature rule is exact.
dims – the number of dimensions for the quadrature rule. 2 for quadrature on triangles and 3 for tetrahedra.
- Raises:
modepy.QuadratureRuleUnavailable
if no quadrature rule for therequested parameters is available.
- class modepy.VioreanuRokhlinSimplexQuadrature(order: int, dims: int)[source]¶
Bases:
Quadrature
Simplicial quadratures with symmetric node sets and positive weights suitable for well-conditioned interpolation.
The integration domain is the unit simplex (see Coordinates on the triangle and Coordinates on the tetrahedron). When using these nodes, please acknowledge Zydrunas Gimbutas, who generated them as follows:
The 2D nodes are based on the interpolation node set derived in the article [Vioreanu2011].
Note that in Vioreanu’s tables, only orders 5, 6, 9, and 12 are rotationally symmetric, which gives one extra order for integration and better interpolation conditioning. Also note that since the tables have been re-generated independently, the nodes and weights may be different.
The 3D nodes were derived from the
modepy.warp_and_blend_nodes()
.A tightening algorithm was then applied, as described in [Vioreanu2012].
[Vioreanu2011]B. Vioreanu and V. Rokhlin, Spectra of Multiplication Operators as a Numerical Tool, Yale CS Tech Report 1443. PDF
[Vioreanu2012]B. Vioreanu, Spectra of Multiplication Operators as a Numerical Tool, Yale University, 2012. PDF
Added in version 2013.3.
- __init__(order: int, dims: int) None [source]¶
- Parameters:
order – The total degree to which the quadrature rule is exact for interpolation.
dims – The number of dimensions for the quadrature rule. 2 for quadrature on triangles and 3 for tetrahedra.
- Raises:
modepy.QuadratureRuleUnavailable
if no quadrature rule for the requested parameters is available.
- class modepy.JaskowiecSukumarQuadrature(order: int, dims: int)[source]¶
Bases:
Quadrature
Symmetric quadrature rules with positive weights for tetrahedra from [Jaskowiec2021].
The integration domain is the unit tetrahedron.
[Jaskowiec2021]J. Jaśkowiec, N. Sukumar, High‐order Symmetric Cubature Rules for Tetrahedra and Pyramids, International Journal for Numerical Methods in Engineering, Vol. 122, pp. 148–171, 2021, DOI
- __init__(order: int, dims: int) None [source]¶
- Parameters:
nodes – an array of shape (d, nnodes), where d is the dimension of the qudrature rule.
weights – an array of length nnodes.
exact_to – an optional argument denoting the summed polynomial degree to which the quadrature is exact. By default, exact_to is None and will not be set as an attribute.
Quadratures on the hypercube¶
- class modepy.WitherdenVincentQuadrature(order: int, dims: int)[source]¶
Bases:
Quadrature
Symmetric quadrature rules with positive weights for rectangles and hexahedra from [Witherden2015].
The integration domain is the unit hypercube \([-1, 1]^d\), where \(d\) is the dimension.
[Witherden2015]F. D. Witherden, P. E. Vincent, On the Identification of Symmetric Quadrature Rules for Finite Element Methods, Computers & Mathematics with Applications, Vol. 69, pp. 1232–1241, 2015. DOI
- __init__(order: int, dims: int) None [source]¶
- Parameters:
nodes – an array of shape (d, nnodes), where d is the dimension of the qudrature rule.
weights – an array of length nnodes.
exact_to – an optional argument denoting the summed polynomial degree to which the quadrature is exact. By default, exact_to is None and will not be set as an attribute.
- class modepy.TensorProductQuadrature(quads: Iterable[Quadrature])[source]¶
Bases:
Quadrature
A tensor product quadrature of one-dimensional
Quadrature
s.- quadratures: Sequence[Quadrature]¶
The lower-dimensional quadratures from which the tensor product quadrature is composed.
- __init__(quads: Iterable[Quadrature]) None [source]¶
- Parameters:
quad – a iterable of
Quadrature
objects for one-dimensional intervals, one for each dimension of the tensor product.
- class modepy.LegendreGaussTensorProductQuadrature(N: int, dims: int, backend: str | None = None)[source]¶
Bases:
TensorProductQuadrature
A tensor product using only
LegendreGaussQuadrature
one-dimenisonal rules.