archimedes.quadrature.QuadratureRule¶
- class archimedes.quadrature.QuadratureRule(
- reference: QuadratureReferenceData,
- name: str,
- params: Parameters | None = None,
Fixed-node Gauss quadrature rule, optionally mapped onto a target domain.
Approximates the weighted integral
\[\int_\mathcal{D} f(x) \, w(x) \, dx \approx \sum_{i=1}^n w_i f(x_i)\]where \(w\) and \(\mathcal{D}\) are the weight function and reference domain of
measure, andnodes/weightsare the \(x_i\)/\(w_i\) above.referenceholds the rule’s static, always-reference-domain payload (nodes, weights, measure, breakpoints, elements) and never changes;nodes/weightsare properties that apply whatever mappingparamscurrently holds (seemap_to).- Parameters:
reference (QuadratureReferenceData) – The rule’s static, always-reference-domain data. Use
from_arrays()for the more convenient raw-array constructor.name (str) – Name identifying the rule.
params (ReferenceDomain.Parameters, optional) – The currently-set mapping onto a target domain, as set by
map_to().None(the default) means the reference domain.
Methods
from_arrays(nodes, weights, *, name, measure)Build a rule from raw nodes/weights on the reference domain.
integrate(f, *[, axis, args, density])Approximate the weighted integral of
fover the domain.map_to(*params, **kwparams)A new rule mapped onto the target domain.
replace(**updates)Returns a new object replacing the specified fields with new values.
sum(values, *[, axis, density])Quadrature applied to values already sampled at the nodes.
Attributes
Element boundaries, on the reference domain.
Owning element per node.
Weight function and reference domain the rule is defined on.
This rule's single
measure, as a length-1 tuple.always 1.
Nodes on the target domain.
paramsWeights including the Jacobian of the domain mapping.
referencename- classmethod from_arrays(
- nodes: ndarray,
- weights: ndarray,
- *,
- name: str,
- measure: Measure,
- breakpoints: ndarray | None = None,
- elements: ndarray | None = None,
Build a rule from raw nodes/weights on the reference domain.
- __init__(
- reference: QuadratureReferenceData,
- name: str,
- params: Parameters | None = None,
- integrate(
- f: Callable[[...], ndarray],
- *,
- axis: int = -1,
- args: Sequence[Any] | None = None,
- density: bool = False,
Approximate the weighted integral of
fover the domain.\[\int f(x) \, w(x) \, dx \approx \sum_{i=1}^n \tilde{w}_i f(x_i)\]where \(x_i\) =
nodesand \(\tilde{w}_i\) =weights; seemap_toto set the target domain first.- Parameters:
f (callable) – Integrand, called once as
f(x, *args)on the full node array.axis (int, optional) – Axis holding the nodes in the output of
f. Default -1.args (tuple, optional) – Extra arguments passed to
fafter the node array.density (bool, optional) – If
True, normalize by the target measure’s total mass, so the result approximates \(\int f(x) \, w(x) \, dx / \int w(x) \, dx\) – e.g. an expectation under the corresponding probability density. Seesum. DefaultFalse.
- Returns:
integral – Approximated integral. Shape (m,) for vector-valued integrands, or () for scalar integrands.
- Return type:
ndarray
- map_to(
- *params,
- **kwparams,
A new rule mapped onto the target domain.
Given
target = measure.domain.resolve_params(*params, **kwparams)and(scale, shift) = measure.affine_paramsfor those same arguments,nodes/weightson the returned rule become\[x_i = \mathrm{scale} \cdot t_i + \mathrm{shift}, \qquad \tilde{w}_i = \mathrm{scale} \cdot w_i\]for reference node/weight \(t_i\)/\(w_i\). Called with no arguments, maps onto the reference domain (the identity).
The meaning of
params/kwparamsis specific tomeasure:Legendre/Jacobi:
(a, b)bounds of the target interval.Laguerre:
rate(and optionalstart) of the target exponential weight.Hermite:
loc,scaleof the target Gaussian-shaped weight.
See the measure’s
affine_paramsdocstring for details.Never composes with a prior
map_to; each call resolves fresh from(*params, **kwparams)against the reference domain, sorule.map_to(0, 1).map_to(2, 3)is exactlyrule.map_to(2, 3), not a further mapping of[0, 1].- Raises:
ValueError – If called with any argument and
measure.affine_invariantisFalse; seeMeasure.affine_invariant.
- replace(**updates) T¶
Returns a new object replacing the specified fields with new values.
- sum(
- values: ndarray,
- *,
- axis: int = -1,
- density: bool = False,
Quadrature applied to values already sampled at the nodes.
\[\sum_{i=1}^n \tilde{w}_i \, \mathrm{values}_i\]where \(\tilde{w}_i\) =
weights(seemap_toto set the target domain first).- Parameters:
values (array_like) – Sampled values, with the quadrature nodes along
axis. Shape (n,) for scalar integrands or (m, n) for vector-valued integrands under the defaultaxis=-1.axis (int, optional) – Axis holding the nodes. Default -1 (nodes last), matching the natural output of a vectorized
f. Useaxis=0for nodes-first data.density (bool, optional) – If
True, normalize the weights so they sum to 1 – equivalently divide by the target measure’s total mass, since ann>=1-point Gauss rule is exact for the constant integrand. DefaultFalse.
- Returns:
integral – Approximated integral of the sampled values, with the quadrature nodes integrated out along
axis. Shape (m,) for vector-valued integrands, or () for scalar integrands.- Return type:
ndarray
- Raises:
ValueError – If
valueshas more than 2 dimensions, or ifvalues.shape[axis]does not match the number of quadrature nodes.
- property breakpoints: ndarray | None¶
Element boundaries, on the reference domain.
Always reference domain, not affected by
map_to.
- property ndim: int¶
always 1.
Note this is the dimension of the domain, not of the
nodesarray (which is 1-D here and N-D for aTensorQuadratureRule).- Type:
Dimension of the domain integrated over