Quadrature#
Base classes#
- class modepy.Quadrature(nodes, weights, exact_to=None)[source]#
The basic interface for a quadrature rule.
- nodes#
An array of shape (d, nnodes), where d is the dimension of the qudrature rule. In 1D, the shape is just (nnodes,).
- weights#
A vector of length nnodes.
- exact_to#
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, attr:exact_to will not be set, and an AttributeError will be raised when attempting to access this information.
- __init__(nodes, weights, exact_to=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 symmed polynomial degree to which the quadrature is exact. By default, exact_to is None and will not be set as an attribute.
- class modepy.ZeroDimensionalQuadrature[source]#
A quadrature rule that should be used for 0d domains (i.e. points).
Inherits from
Quadrature
.
- modepy.quadrature_for_space(space: FunctionSpace, shape: Shape) Quadrature [source]#
- modepy.quadrature_for_space(space: PN, shape: Simplex)
- modepy.quadrature_for_space(space: TensorProductSpace, shape: TensorProductShape)
- Returns:
a
Quadrature
that exactly integrates the functions in space over shape.
Jacobi-Gauss quadrature in one dimension#
- class modepy.JacobiGaussQuadrature(alpha, beta, N, backend=None, force_dim_axis=False)[source]#
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\).
Inherits from
modepy.Quadrature
. See there for the interface to obtain nodes and weights.- __init__(alpha, beta, N, backend=None, force_dim_axis=False)[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.
- class modepy.LegendreGaussQuadrature(N, backend=None, force_dim_axis=False)[source]#
A Gauss quadrature rule with weight \(1\).
Corresponds to a Gauss-Jacobi quadrature rule with \(\alpha = \beta = 0\).
- class modepy.ChebyshevGaussQuadrature(N, kind=1, backend=None, force_dim_axis=False)[source]#
A Gauss quadrature rule with weight \(\sqrt{1-x^2}^{\mp 1}\).
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.
New in version 2019.1.
- class modepy.GaussGegenbauerQuadrature(alpha, N, backend=None, force_dim_axis=False)[source]#
Gauss-Gegenbauer quadrature is a special case of Gauss-Jacobi quadrature with \(\alpha = \beta\).
New in version 2019.1.
- modepy.quadrature.jacobi_gauss.jacobi_gauss_lobatto_nodes(alpha, beta, N, backend=None, force_dim_axis=False)[source]#
Compute the Gauss-Lobatto quadrature nodes corresponding to the
JacobiGaussQuadrature
with the same parameters.Exact to degree \(2N - 3\).
Clenshaw-Curtis and FejĂ©r quadrature in one dimension#
- class modepy.ClenshawCurtisQuadrature(N, force_dim_axis=False)[source]#
Clenshaw-Curtis quadrature of order N (having N + 1 points).
Inherits from
modepy.Quadrature
. See there for the interface to obtain nodes and weights.Integrates on the interval \((-1, 1)\). The quadrature rule is exact up to degree \(N\); however, its performance for differentiable functions is comparable with the classic Gauss-Legendre quadrature which is exact for polynomials of degree up to \(2N + 1\).
- class modepy.FejerQuadrature(N, kind=1, force_dim_axis=False)[source]#
FejĂ©râ€™s quadrature rules of order N, categorized in two kinds. The FejĂ©râ€™s quadrature rule of first kind has N points; while the second kind has N - 1 points.
The first kind uses Chebyshev nodes, i.e. roots of the Chebyshev polynomials. The second kind uses the interior extrema of the Chebyshev polynomials, i.e. the true stationary points.
The second-kind FejĂ©râ€™s quadrature rule is nearly identical to Clenshaw-Curtis. Both can also be nested.
Inherits from
modepy.Quadrature
. See there for the interface to obtain nodes and weights.Integrates on the interval \((-1, 1)\).
Quadratures on the simplex#
New in version 2013.3.
- class modepy.GrundmannMoellerSimplexQuadrature(order, dimension)[source]#
Cubature on an n-simplex.
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)
- exact_to#
The total degree up to which the quadrature is exact.
See
A. Grundmann and H.M. Moeller, Invariant integration formulas for the n-simplex by combinatorial methods, SIAM J. Numer. Anal. 15 (1978), 282â€“290. http://dx.doi.org/10.1137/0715019
- class modepy.XiaoGimbutasSimplexQuadrature(order, dims)[source]#
A (nearly) Gaussian simplicial quadrature with very few quadrature nodes, available for low-to-moderate orders.
Raises
modepy.QuadratureRuleUnavailable
if no quadrature rule for the requested parameters is available.The integration domain is the unit simplex. (see Coordinates on the triangle and Coordinates on the tetrahedron)
Inherits from
modepy.Quadrature
. See there for the interface to obtain nodes and weights.- exact_to#
The total degree up to which the quadrature is exact.
See
H. Xiao and Z. Gimbutas, â€śA numerical algorithm for the construction of efficient quadrature rules in two and higher dimensions,â€ť Computers & Mathematics with Applications, vol. 59, no. 2, pp. 663-676, 2010. http://dx.doi.org/10.1016/j.camwa.2009.10.027
- class modepy.VioreanuRokhlinSimplexQuadrature(order, dims)[source]#
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)
Raises
modepy.QuadratureRuleUnavailable
if no quadrature rule for the requested parameters is available.Inherits from
modepy.Quadrature
. See there for the interface to obtain nodes and weights.- exact_to#
The total degree up to which the quadrature is exact.
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
B. Vioreanu and V. Rokhlin, â€śSpectra of Multiplication Operators as a Numerical Tool,â€ť Yale CS Tech Report 1443
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
B. Vioreanu, â€śSpectra of Multiplication Operators as a Numerical Toolâ€ť, Yale University, 2012. Dissertation
New in version 2013.3.
Quadratures on the hypercube#
- class modepy.WitherdenVincentQuadrature(order, dims)[source]#
Symmetric quadrature rules with positive weights for rectangles and hexahedra.
The integration domain is the unit hypercube \([-1, 1]^d\), where \(d\) is the dimension. The quadrature rules are adapted from:
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, dims)[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 symmed polynomial degree to which the quadrature is exact. By default, exact_to is None and will not be set as an attribute.