Laplace on an annulus¶
A hole changes both domain membership and the direction of the inner normal. This example solves a known harmonic field before trying a more complex geometry.
Here \(a=0.4\) and \(b=1\). Start with 240 Halton interior nodes, 48 inner and 96 outer boundary nodes, seed 42. All arithmetic is Float64.
import sympy as sp
import rbflab as rbf
from rbflab import geometry, meshgen
domain = geometry.Annulus(.4, 1.)
cloud = meshgen.generate(domain, interior=240,
boundary={"inner": 48, "outer": 96}, seed=42)
m = rbf.SymbolicScalar(2)
u = m.field
problem = m.stationary(sp.Eq(-m.laplacian(u), 0), boundary=[
m.bc("inner", sp.Eq(u, 0)), m.bc("outer", sp.Eq(u, 1)),
])
method = rbf.RBFFD(rbf.PHS(5), 35, polynomial_degree=3,
local_backend=rbf.CppBackend(threads=4),
stencil_policy=rbf.StencilPolicy(scaling="local"))
solution = problem.solve(cloud, method)
Use PythonBackend() for a compiler-free run, or
TorchBackend(threads=4) with the optional tensor package.
See backend setup. The signed PHS5 kernel is
augmented with all polynomials through degree three; the fixed 35-node stencil
policy is shared. scaling="local" divides kernel distances by the stencil radius
and includes the physical derivative factors automatically. Read
local stencil scaling before
reusing this setting with an IMQ or hybrid kernel.

Compare methods¶
python -m examples.annulus --method rbffd --backend cpp
python -m examples.annulus --method rbffd --backend torch
python -m examples.annulus --method global
python -m examples.annulus --method lhi
Global asymmetric collocation uses the same PHS/polynomial family over all nodes. LHI uses its local Hermite functional systems; RBF-FD uses local value interpolation. These are different discretizations even when the cloud and kernel agree.
On the default cloud, independent sampled maximum errors are about \(3.1\times10^{-3}\) (RBF-FD), \(1.8\times10^{-3}\) (global), and \(3.1\times10^{-3}\) (LHI). These are solution errors against the logarithmic formula, not sparse residuals. The query points use an independent seed. See the validation record.
Complete runnable source
"""Laplace on an annulus: compare global, LHI and RBF-FD against log(r/a)/log(b/a).
Run: python -m examples.annulus --backend cpp
"""
import argparse
import numpy as np
import sympy as sp
import rbflab as rbf
from rbflab import geometry, meshgen
from examples._curved import local_method, solve, errors, report
def run(interior=240, seed=42, method="rbffd", backend="python", plot=None):
"""Solve the same labeled problem with selectable spatial discretization."""
domain=geometry.Annulus(.4, 1.)
cloud=meshgen.generate(domain, interior=interior, boundary={"inner":max(12,round(48*np.sqrt(interior/240))),"outer":max(24,round(96*np.sqrt(interior/240)))}, seed=seed)
model=rbf.SymbolicScalar(2); u=model.field
problem=model.stationary(sp.Eq(-model.laplacian(u),0), boundary=[
model.bc("inner",sp.Eq(u,0)), model.bc("outer",sp.Eq(u,1))])
if method != "rbffd" and backend != "python":
raise ValueError("This example exposes C++/Torch through RBF-FD; use --method rbffd")
methods={"rbffd":lambda:local_method(backend),
"global":lambda:rbf.GlobalCollocation(rbf.PHS(5),scheme="asymmetric",polynomial_degree=3),
"lhi":lambda:rbf.LHI(rbf.PHS(5),35,polynomial_degree=3)}
solution,timing=solve(problem,cloud,methods[method]())
exact=lambda p:np.log(np.linalg.norm(p,axis=1)/.4)/np.log(2.5)
metrics=report("annulus/"+method+"/"+backend,cloud,timing,errors(solution,cloud,domain,exact))
if plot:
from rbflab import viz
fig,_=viz.plot_scalar(solution,domain=domain,title="Harmonic field / annulus")
fig.savefig(plot,dpi=160)
return domain,cloud,solution,metrics
if __name__=="__main__":
p=argparse.ArgumentParser(description=__doc__)
p.add_argument("--interior",type=int,default=240);p.add_argument("--seed",type=int,default=42)
p.add_argument("--method",choices=("rbffd","global","lhi"),default="rbffd")
p.add_argument("--backend",choices=("python","cpp","torch"),default="python")
p.add_argument("--plot")
run(**vars(p.parse_args()))
The common example helper selects backends, measures stages and reports errors; it contains no hidden PDE formulation.
Try next: change the inner radius, then refine both interior and boundary counts. Keep kernel and stencil settings fixed across seeds when assessing consistency.