MLS Approximation — Basis, Moment Matrix, and Shape Functions

Implemented in: shape_functions/mls.py, shape_functions/mls_numba_kernel.py, shape_functions/weight_functions.py

1. The Moving Least Squares Approximation

The displacement field is approximated by Moving Least Squares (Lancaster & Salkauskas, 1981). Given a set of nodes {xI} with nodal parameters {uI}, the MLS approximation at any point x is:

uh(x) = pT(x) a(x)

where p(x) is the polynomial basis vector and a(x) are coefficient functions determined by minimising a weighted least-squares functional:

J(x) = ∑I wI(x) [pT(xI) a(x) − uI]2

Stationarity (∂J / ∂a = 0) yields the normal equations A(x) a(x) = B(x) u, where:

A(x) = ∑I wI(x) p(xI) pT(xI)    (Moment matrix)
B(x) = [w1(x) p(x1), …, wN(x) p(xN)]

Substituting a = A−1 B u gives the MLS shape functions:

φI(x) = pT(x) A−1(x) p(xI) wI(x)

2. Polynomial Bases Implemented

2.1. Linear Basis (default)

p(x) = [1, x, y]T     (m = 3 terms)

Properties guaranteed:

2.2. Quadratic Basis

p(x) = [1, x, y, x2, xy, y2]T     (m = 6 terms)

Reproduces quadratic displacement fields exactly. Recommended with rectangular MLPG5 subdomains. Minimum support nodes: 6 (recommended: 12+).

3. Numerical Stability: Shifted and Scaled Coordinates

To improve moment-matrix conditioning, the implementation builds the basis using coordinates shifted to the evaluation point and scaled by the maximum local support radius R:

XI = (xIx − x) / R,     YI = (xIy − y) / R

The evaluation point maps to (0, 0), so p(x) = [1, 0, 0]T (linear). The physical derivatives are recovered by chain rule: ∂φ/∂x = (∂φ/∂X) × (1/R).

4. Shape Function Derivatives

The MLS shape function derivatives are needed to build the B matrix. Differentiating φI = (P c)I wI with respect to xk:

∂φI/∂xk = (P ∂c/∂xk)I wI + (P c)I ∂wI/∂xk

where ∂c/∂xk = A−1(∂p/∂xk − ∂A/∂xk c) and the weight gradient is:

∂wI/∂xk = (dw/ds) × (xk − xIk) / (rI × rsupp,I)

This is the direct differentiation approach: no additional equations are solved. Two linear systems A ck = rhsk are solved per evaluation point, one for each coordinate direction.

5. Weight Functions

Three compactly-supported weight functions w(s), where s = r/rsupp ∈ [0, 1], are implemented:

NameFormulaContinuityDefault
cubic_spline 1−6s2+6s3 (s≤0.5)
2(1−s)3 (0.5<s≤1)
C² Yes
quartic_spline 1−6s2+8s3−3s4 C² No
gaussian (e−s2/β2−e−1/β2) / (1−e−1/β2), β=0.3 C∞ (cut off at s=1) No

All functions satisfy w(0) = 1, w(1) = 0, and are zero for s ≥ 1. The cubic and quartic splines are C2-continuous, ensuring smooth shape-function derivatives. The Gaussian is cut off at s = 1 to create compact support.

6. Numba JIT Acceleration

When numba is installed, the MLS kernel is JIT-compiled using @njit(cache=True). The Numba kernel operates on scalar weights (calling _cubic_spline_s, _cubic_spline_deriv_s, etc.) and builds the moment matrix entry-by-entry in optimised machine code. The NumPy fallback path provides identical results.

The solver checks for Numba availability at runtime and falls back to NumPy with a warning if not found. The setting use_numba=True (default) enables the JIT path.

Singularity handling: If the moment matrix A is singular (fewer support nodes than basis terms, or degenerate configuration), mls_shape_functions() returns three zero arrays silently. The caller must detect this and handle it (e.g., skip the Gauss point).

7. References