Implemented in: shape_functions/mls.py, shape_functions/mls_numba_kernel.py, shape_functions/weight_functions.py
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:
where p(x) is the polynomial basis vector and a(x) are coefficient functions determined by minimising a weighted least-squares functional:
Stationarity (∂J / ∂a = 0) yields the normal equations A(x) a(x) = B(x) u, where:
Substituting a = A−1 B u gives the MLS shape functions:
Properties guaranteed:
Reproduces quadratic displacement fields exactly. Recommended with rectangular MLPG5 subdomains. Minimum support nodes: 6 (recommended: 12+).
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:
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).
The MLS shape function derivatives are needed to build the B matrix. Differentiating φI = (P c)I wI with respect to xk:
where ∂c/∂xk = A−1(∂p/∂xk − ∂A/∂xk c) and the weight gradient is:
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.
Three compactly-supported weight functions w(s), where s = r/rsupp ∈ [0, 1], are implemented:
| Name | Formula | Continuity | Default |
|---|---|---|---|
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.
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.
mls_shape_functions() returns three zero arrays silently. The caller must detect this and handle it (e.g., skip the Gauss point).