From sampled functionals to sparse operators¶
Goal: describe a local approximation explicitly, then use its matrices in your own numerical algorithm. No PDE or evolution object is required.
This interface is included in RBFLAB 0.5.0 and newer. It constructs local maps for RBF-FD and scalar Hermite methods. The symbolic PDE adapter and global collocation have different roles.
1. Separate approximation, data, and evaluation¶
On a local stencil, write
Polynomial side conditions complete this construction:
With \(n\) source functionals, \(n\) trial representers, and \(q\) polynomial terms, the local interpolation system is square of size \((n+q)\times(n+q)\):
The source functionals \(\ell_i\) sample data; the trial functionals \(m_j\) build kernel representers. They coincide in the ordinary and symmetric Hermite constructions below, but need not in general.
The space supplies \(K\) and the polynomial tail. The trial supplies \(m_j\). The source samples supply \(\ell_i\) and their locations. A target supplies \(\tau s\), the quantity we want to evaluate.
For ordinary RBF-FD, \(m_j\) and \(\ell_j\) are point evaluations. For Hermite
interpolation, they can be derivative or PDE functionals. A space's
representers(source) applies each source functional to the second kernel
argument. space.translates(points) instead describes ordinary kernel translates.
The trial choice is visible, rather than hidden behind a scheme name.
2. Declare a space and value samples¶
import numpy as np
import rbflab as rbf
implementation = rbf.PythonBackend()
cloud = rbf.geometry.unit_box_grid(6)
X = cloud.points
Y = np.array([[.3, .4], [.6, .7], [.45, .55]])
space = rbf.ScalarSpace(rbf.PHS(5), polynomial_degree=2)
source = {"u": rbf.Samples(X, size=20)}
local = rbf.LocalApproximation(
source=source,
trial=space.representers(source),
backend=implementation,
stencil_policy=rbf.StencilPolicy(scaling="local"),
)
ops = local.operators(
targets=Y,
operators={"value": rbf.Identity(2), "lap": rbf.Laplacian(2)},
)
Samples(X, size=20) selects 20 source points around each target. The default
functional is value evaluation. scaling="local" evaluates the radial kernel
using a stencil distance unit, schematically \(\phi(\lVert x-z\rVert/R)\),
and returns requested derivatives in physical units. The default uses
physical distances. Shape parameters require care; see
local scaling.
The space uses the signed PHS5 kernel \(\phi(r)=-r^5\) and polynomials of
total degree at most two. These choices determine the approximation. The
requested value and lap operators determine what we evaluate from it.
3. Apply or export the maps¶
For source values \(U_j=u(x_j)\) and target points \(y_i\),
U = 1 + np.sum(X**2, axis=1)
reconstructed = ops.value @ {"u": U}
laplacian = ops.lap["u"] @ U
D = ops.lap["u"].matrix # rows: targets, columns: source values
row = ops.lap.local(0)
algebra = ops.lap.reconstruct_local(0)
ops.lap["u"] selects the block acting on the named u samples. With several
sample groups, ops.lap @ {"u": U, "pde": F, ...} sums their contributions.
Keep named blocks when building equations: their columns represent different
mathematical data. For SciPy algebra, ops.lap["u"].to_scipy() exports a
Float64 matrix; capabilities explains backend limits.
Here \(X\) has 49 points, \(Y\) has three targets, and each local solve uses 20 value samples plus six quadratic polynomial terms: a \(26\times26\) system. The resulting Laplacian map is \(3\times49\) and gives 4 for \(1+x^2+y^2\) to within about \(6\times10^{-14}\). This is a reproduction check, not a convergence study.
4. Inspect the local algebra¶
For a target functional \(\tau\), the local weights satisfy
.local(i) exposes stored weights and source membership. .reconstruct_local(i)
builds the dense local matrix and right-hand side on demand; dense matrices are
not retained for every target. Polynomial multipliers \(\eta\) are not global
solution unknowns. Repeating the local solve scatters weights into an
\(N_{\rm target}\times N_{\rm source}\) map, which may be rectangular.
There is no inverse of that global map in the weight construction.
See one stencil and the
weight derivation.
A chosen trial/data pairing must produce a square, unisolvent local system. Kernel smoothness must support the combined derivative orders. Arbitrary pairings are not automatically stable merely because their matrices can be assembled.
Optional: bring in a symbolic differential expression
A symbolic model can supply only its spatial operator:
import sympy as sp
model = rbf.SymbolicScalar(2)
u = model.field
x, y = model.coordinates
L = model.operator(-model.laplacian(u) + 2*sp.diff(u, x) + u)
transport = local.operators(targets=Y, operators={"L": L})
LU = transport.L["u"] @ U
Forcing remains separate data. Compiling this expression does not assemble boundary rows or choose a time integrator.
Change the construction¶
- Replace
Yto interpolate or differentiate on another cloud. - Add named operators to reuse a local factorization for multiple evaluations.
- Replace value samples by PDE or boundary functionals: LHI from matrices.
- Replace the space's kernel, including a symbolic kernel.
- Select a supported backend; the global sparse solver remains your choice.
python -m examples.tutorials.local_approximation
python -m examples.tutorials.local_approximation --backend cpp
python -m examples.tutorials.local_approximation --backend torch
Run these commands from a source checkout. C++ requires its optional source-build toolchain; Torch is optional and currently CPU Float64. See installation and capabilities.
Next: Assemble a stationary PDE. For the full local equation behind one row, use one stencil.