Fundamentals / Numerical mathematics / Approximation and quadrature / Function approximation and numerical integration

Measuring an area integral with finitely many samples

Build deterministic multidimensional rules from moments and geometry. Compare tensor products, symmetric triangle rules and sparse combinations at a fixed number of evaluations.

Which polynomials does a product rule integrate?

On a rectangle Fubini's theorem factors integrals of \(x^iy^j\). Applying a one-dimensional rule in each direction forms weights \(w_aw_b\) at pairs \((x_a,y_b)\). If each factor integrates through degree \(2n-1\), the tensor rule integrates every monomial with each exponent at most \(2n-1\), including some of total degree above that number. For \(d\) axes the price is \(n^d\) values. Unequal smoothness can justify different orders on different axes.

On the reference triangle \(x,y\ge0,\ x+y\le1\), integration of the inner monomial followed by the beta integral gives

\[\int_T x^i y^j\,dA=\frac{i!j!}{(i+j+2)!}.\]

Seek a symmetric three-node rule at permutations of barycentric coordinates \((a,b,b)\). Symmetry integrates affine functions once the weights each equal \(1/6\). Matching \(x^2\) gives \((a^2+2b^2)/6=1/12\) with \(a+2b=1\). One solution uses \(a=2/3,b=1/6\). The quadratic cross moment follows from barycentric symmetry and \((x+y+z)^2=1\). For a physical triangle multiply the reference weights by the absolute Jacobian determinant. For a curved mapping the determinant may itself vary across nodes.

Move the singularity into the Jacobian

Suppose a surface flux density on the same triangle is \(1/\sqrt{x+y}\). With \(s=x+y,\ v=y/(x+y)\), the map \(x=s(1-v),y=sv\) has determinant \(s\). Hence the total is \(\int_0^1\int_0^1 s^{1/2}\,dv\,ds=2/3\). Substituting \(s=u^2\) gives integrand \(2u^2\). Two Gauss nodes along \(u\) and one along \(v\) now suffice in exact arithmetic. A Cartesian mapping \(x=u,y=(1-u)v\) leaves an endpoint singularity even after multiplication by its Jacobian.

OneSimulation experiment · Integrate a singular field over a triangle

Vary the tensor order. Predict which transformed integrand is exactly integrated first.

Download the executable notebook · Python source

Adjust the experiment in the browser. Generalise the flux to \((x+y)^{-p}\), with \(0\le p<2\). Writing \(s=x+y\) gives \(\int_0^1s^{1-p}\,ds=1/(2-p)\). The squared radial map has transformed integrand \(2u^{3-2p}\). Change the exponent and quadrature order, then predict when a polynomial integrand permits exact Gauss integration. In particular, increasing \(p\) past \(3/2\) leaves an integrable singularity even in the radial coordinate. The browser constructs the Gauss nodes by Legendre root iteration; the notebook obtains the same rules from OneSimulation for the \(p=1/2\) reference case.

"""Integrate a corner singularity over the unit right triangle by two maps."""
import matplotlib.pyplot as plt
import numpy as np
from onesim.numerics.discretization.geometry.carriers.kernels.quadrature.rules.reference_quadrature import gauss_legendre

orders = [1, 2, 3, 4]
errors = [[], []]
for order in orders:
    points, weights = np.asarray(gauss_legendre(order)).T
    nodes, weights = (points+1)/2, weights/2
    u, v = np.meshgrid(nodes, nodes, indexing="ij")
    # First map x=u, y=(1-u)v. Second map x=u²(1-v), y=u²v.
    values = [(1-u) / np.sqrt(u+(1-u)*v), 2*u**2 * np.ones_like(v)]
    for sequence, integrand in zip(errors, values):
        sequence.append(abs(weights @ integrand @ weights - 2/3))
print(f"Order {orders[-1]} errors: Cartesian map {errors[0][-1]:.6g}, radial map {errors[1][-1]:.3g}")
assert max(errors[1][1:]) < 1e-13
fig, ax = plt.subplots(figsize=(7, 4), layout="constrained")
for err, label in zip(errors, ["Cartesian map", "Radial map"]):
    ax.semilogy(np.square(orders), np.maximum(err, 1e-16), "o-", label=label)
ax.set(xlabel="Number of function values", ylabel="Absolute error (plot floor 1e−16)")
ax.legend()
fig.savefig("numerics-triangle-cubature.png", dpi=170)

Output from the reference run

Order 4 errors: Cartesian map 0.00311717, radial map 1.11e-16
Two transformations of the same triangle lead to different quadrature errors.
Two transformations of the same triangle lead to different quadrature errors.

Buy mixed resolution only where it matters

Let \(Q_l\) be nested one-dimensional rules of growing order, \(Q_0=0,\Delta_l=Q_l-Q_{l-1}\). Telescoping the full tensor rule gives a sum of products of increments. In two dimensions retain terms with \(l_1+l_2\le q\), \(l_i\ge1\). This construction spends few evaluations at points fine in both directions. If mixed derivatives control the product increments, many omitted terms are small. A sharp oblique ridge can violate that premise. Refining only along individual axes then misses the ridge.

For \(q=3\), the combination is \(Q_2\otimes Q_1+Q_1\otimes Q_2-Q_1\otimes Q_1\). Take midpoint and Simpson as nested levels on \([0,1]\). Five distinct points replace the nine in the full tensor Simpson grid. A test on \(x^2y^2\) gives \(1/12+1/12-1/16=5/48\), compared with exact \(1/9\). The difference is exactly the mixed increment omitted from this level.

How can two deterministic estimates agree for the wrong reason?

A compact nonnegative bump placed between all sampled nodes returns zero on both grids. To certify an error, use an available derivative or interval bound on each region, or change the sampling geometry independently. An observed difference is an estimator whose reliability depends on resolving the integrand.

Tutorial on domains and evaluation budgets

Transport the triangle rule to vertices (0,0), (4,0), (1,2)

Work through the solution

The matrix mapping coordinate differences has columns \((4,0),(1,2)\) and determinant 8. The three weights are \(8/6\). Their sum is the area 4. Compute each physical node as the same barycentric combination of the physical vertices.

Decide which quadrature to buy for three dimensions

Work through the solution

With five levels of points per coordinate, the tensor rule costs \(5^3=125\). If the integrand is a sum \(g(x)+h(y)+k(z)\), product increments involving refinement in two directions vanish because differences annihilate constants. A sparse rule can recover the separate one-dimensional accuracy. A dependence on \(x+y+z\) generally reintroduces mixed terms.

Davis and Rabinowitz · Methods of Numerical Integration