Boundary Conditions (ND)

In ND, boundary conditions are specified per-axis via Tuples. A single BC value is broadcast to all axes.

Method Applicability
  • Constant / Linear: No BC needed
  • Quadratic: One BC per axis (Left(...) or Right(...))
  • Cubic: Paired BCs per axis (NaturalBC(), PeriodicBC(), BCPair(...), etc.)

For BC type details, see the 1D Boundary Conditions.


Example Data

using FastInterpolations
x = range(1, 10, length = 10)
y = range(0, 2pi, length = 5)
z = [0, 1, 3, 5, 10]
data2d = [cos(xi)*sin(yi) for xi in x, yi in y] # Real 2D data
data3d = [cos(xi)*sin(yi)+ zi*1im for xi in x, yi in y, zi in z] # Complex 3D data

Broadcast vs Per-Axis

# Broadcast: same BC on all axes
itp = cubic_interp((x, y, z), data3d; bc=NaturalBC())
# Equivalent to: bc=(NaturalBC(), NaturalBC(), NaturalBC())
CubicInterpolantND{Float64, ComplexF64, 3}
├─ Grids: 3D, 10×5×5 points
│  ├─ x₁: Range ∈ [1, 10]
│  ├─ x₂: Range ∈ [0, 6.28]
│  └─ x₃: Vector ∈ [0, 10]
├─ Extrap: :none (all axes)
├─ Search: Binary (all axes)
└─ BC: Natural (S''=0 at ends) (all axes)
# Per-axis: different BC per axis
itp = cubic_interp((x, y, z), data3d;
    bc=(NaturalBC(), PeriodicBC(), CubicFit()))
CubicInterpolantND{Float64, ComplexF64, 3}
├─ Grids: 3D, 10×5×5 points
│  ├─ x₁: Range ∈ [1, 10]
│  ├─ x₂: Range ∈ [0, 6.28]
│  └─ x₃: Vector ∈ [0, 10]
├─ Extrap: (:none, :wrap, :none)
├─ Search: Binary (all axes)
└─ BC:
   ├─ x₁: Natural (S''=0 at ends)
   ├─ x₂: Periodic
   └─ x₃: CubicFit | CubicFit

Cubic ND

All 1D cubic BCs are available per-axis:

# Natural in x, periodic in y
bc = (NaturalBC(), PeriodicBC())
itp = cubic_interp((x, y), data2d; bc=bc)
CubicInterpolantND{Float64, 2}
├─ Grids: 2D, 10×5 points
│  ├─ x₁: Range ∈ [1, 10]
│  └─ x₂: Range ∈ [0, 6.28]
├─ Extrap: (:none, :wrap)
└─ BC:
   ├─ x₁: Natural (S''=0 at ends)
   └─ x₂: Periodic
PeriodicBC + Extrapolation

PeriodicBC() on an axis automatically forces extrap=:wrap on that axis.

# Custom: known slope at x-left, auto-fit in y
bc = (BCPair(Deriv1(0.0), CubicFit()), CubicFit())
itp = cubic_interp((x, y), data2d; bc=bc)
CubicInterpolantND{Float64, 2}
├─ Grids: 2D, 10×5 points
│  ├─ x₁: Range ∈ [1, 10]
│  └─ x₂: Range ∈ [0, 6.28]
├─ Extrap: :none (all axes)
└─ BC:
   ├─ x₁: Deriv1(0.0) | CubicFit
   └─ x₂: CubicFit | CubicFit

Quadratic ND

Quadratic BCs use Left(...) / Right(...) wrappers per-axis:

# Broadcast: same BC on all axes
itp = quadratic_interp((x, y), data2d; bc=Left(QuadraticFit()))

# Per-axis
itp = quadratic_interp((x, y), data2d;
    bc=(Left(QuadraticFit()), Right(Deriv1(0.0))))
QuadraticInterpolantND{Float64, 2}
├─ Grids: 2D, 10×5 points
│  ├─ x₁: Range ∈ [1, 10]
│  └─ x₂: Range ∈ [0, 6.28]
├─ Extrap: :none (all axes)
└─ BC:
   ├─ x₁: Left(QuadraticFit)
   └─ x₂: Right(Deriv1(0.0))
BCDescription
Left(QuadraticFit())3-point auto-fit at left (default)
Right(Deriv1(v))Known slope at right
MinCurvFit()Minimize total curvature

See Also