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, and nodes/weights are the \(x_i\)/\(w_i\) above.

reference holds the rule’s static, always-reference-domain payload (nodes, weights, measure, breakpoints, elements) and never changes; nodes/weights are properties that apply whatever mapping params currently holds (see map_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 f over 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

breakpoints

Element boundaries, on the reference domain.

elements

Owning element per node.

measure

Weight function and reference domain the rule is defined on.

measures

This rule's single measure, as a length-1 tuple.

ndim

always 1.

nodes

Nodes on the target domain.

params

weights

Weights including the Jacobian of the domain mapping.

reference

name

classmethod from_arrays(
nodes: ndarray,
weights: ndarray,
*,
name: str,
measure: Measure,
breakpoints: ndarray | None = None,
elements: ndarray | None = None,
) → QuadratureRule¶

Build a rule from raw nodes/weights on the reference domain.

__init__(
reference: QuadratureReferenceData,
name: str,
params: Parameters | None = None,
) → None¶
integrate(
f: Callable[[...], ndarray],
*,
axis: int = -1,
args: Sequence[Any] | None = None,
density: bool = False,
) → ndarray¶

Approximate the weighted integral of f over the domain.

\[\int f(x) \, w(x) \, dx \approx \sum_{i=1}^n \tilde{w}_i f(x_i)\]

where \(x_i\) = nodes and \(\tilde{w}_i\) = weights; see map_to to 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 f after 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. See sum. Default False.

Returns:

integral – Approximated integral. Shape (m,) for vector-valued integrands, or () for scalar integrands.

Return type:

ndarray

map_to(
*params,
**kwparams,
) → QuadratureRule¶

A new rule mapped onto the target domain.

Given target = measure.domain.resolve_params(*params, **kwparams) and (scale, shift) = measure.affine_params for those same arguments, nodes/weights on 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/kwparams is specific to measure:

  • Legendre/Jacobi: (a, b) bounds of the target interval.

  • Laguerre: rate (and optional start) of the target exponential weight.

  • Hermite: loc, scale of the target Gaussian-shaped weight.

See the measure’s affine_params docstring for details.

Never composes with a prior map_to; each call resolves fresh from (*params, **kwparams) against the reference domain, so rule.map_to(0, 1).map_to(2, 3) is exactly rule.map_to(2, 3), not a further mapping of [0, 1].

Raises:

ValueError – If called with any argument and measure.affine_invariant is False; see Measure.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,
) → ndarray¶

Quadrature applied to values already sampled at the nodes.

\[\sum_{i=1}^n \tilde{w}_i \, \mathrm{values}_i\]

where \(\tilde{w}_i\) = weights (see map_to to 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 default axis=-1.

  • axis (int, optional) – Axis holding the nodes. Default -1 (nodes last), matching the natural output of a vectorized f. Use axis=0 for 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 an n>=1-point Gauss rule is exact for the constant integrand. Default False.

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 values has more than 2 dimensions, or if values.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 elements: ndarray | None¶

Owning element per node.

property measure: Measure¶

Weight function and reference domain the rule is defined on.

property measures: tuple[Measure, ...]¶

This rule’s single measure, as a length-1 tuple.

property ndim: int¶

always 1.

Note this is the dimension of the domain, not of the nodes array (which is 1-D here and N-D for a TensorQuadratureRule).

Type:

Dimension of the domain integrated over

property nodes: ndarray¶

Nodes on the target domain.

property weights: ndarray¶

Weights including the Jacobian of the domain mapping.