Skip to content

A 3D Poisson problem inside a ball

The geometry and scalar RBF-FD API work in three dimensions. A nonpolynomial manufactured solution tests more than exact polynomial reproduction:

\[ \Omega=\{\boldsymbol x:\|\boldsymbol x\|<1\},\qquad u_{\rm exact}=e^{(x+y+z)/2},\qquad -\Delta u=-\tfrac34 e^{(x+y+z)/2}. \]

Set \(u=u_{\rm exact}\) on the sphere.

domain = geometry.Sphere()
cloud = meshgen.generate(domain, interior=300, boundary=180, seed=42)
model = rbf.SymbolicScalar(3)

All subsequent operators use dimension three. The default method uses 55-node RBF-FD stencils, PHS5, all degree-three polynomials (20 terms), local scaling (kernel distances divided by the stencil radius) and Float64. The independent sampled maximum error is about \(2.0\times10^{-4}\).

The 3D ball cloud and a numerical cross-section

python -m examples.ball_poisson --backend cpp --plot ball.png
python -m examples.ball_poisson --backend torch

viz.plot_slice(solution, domain, axis=2, coordinate=0) samples the solved field in the plane \(z=0\) and masks points outside the ball. These points are for display, not a hidden structured discretization. No tetrahedral connectivity is generated.

Complete runnable source
"""A nonpolynomial 3D manufactured Poisson solution inside a ball."""
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=300, seed=42, backend="python", plot=None):
    """Solve -Laplacian(u)=-3u/4, u=exp((x+y+z)/2), with exact boundary values."""
    domain=geometry.Sphere()
    cloud=meshgen.generate(domain,interior=interior,boundary=max(40,round(180*(interior/300)**(2/3))),seed=seed)
    model=rbf.SymbolicScalar(3);u=model.field;x,y,z=model.coordinates
    exact=sp.exp((x+y+z)/2);lhs=-model.laplacian(u)
    problem=model.stationary(sp.Eq(lhs,lhs.subs(u,exact).doit()),
                              boundary=[model.bc("boundary",sp.Eq(u,exact))])
    solution,timing=solve(problem,cloud,local_method(backend,stencil=55))
    metrics=report("3D ball/"+backend,cloud,timing,
                   errors(solution,cloud,domain,lambda p:np.exp(p.sum(axis=1)/2)))
    if plot:
        from rbflab import viz
        fig,_=viz.plot_slice(solution,domain,title="Poisson in a ball / z = 0")
        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=300);p.add_argument("--seed",type=int,default=42)
    p.add_argument("--backend",choices=("python","cpp","torch"),default="python");p.add_argument("--plot")
    run(**vars(p.parse_args()))

Try next: use an ellipsoidal ImplicitRegion with its analytic gradient and repeat the manufactured-solution test. 3D scalar support does not imply a 3D staggered Navier–Stokes implementation.