Skip to content

Scalar periodic spline eval ignores x_min #201

@krystophny

Description

@krystophny

Problem

The scalar spline path in src/interpolate/interpolate.f90 wraps periodic coordinates using modulo(x, period) and ignores x_min, effectively enforcing a periodic origin at 0.0.

Example (1D):

  • src/interpolate/interpolate.f90:108 uses xj = modulo(x, spl%h_step*(spl%num_points-1))
  • The batch spline path (src/interpolate/batch_interpolate_1d.f90) instead uses modulo(x - spl%x_min, period) + spl%x_min.

The same scalar pattern appears in the 2D/3D scalar evaluation routines and their derivative variants (multiple sites in src/interpolate/interpolate.f90).

Impact

  • Periodic scalar spline evaluation is inconsistent with the batch spline evaluation for nonzero x_min.
  • Derivative variants in the scalar path are also inconsistent: some do not apply periodic wrapping at all.

Expected

For periodic splines, scalar spline evaluation should wrap relative to the spline grid origin:

xj = modulo(x - x_min, period) + x_min

and do so consistently across value/derivative routines.

Suggested fix

  • Update scalar evaluate_splines_{1d,2d,3d}* routines to wrap with x - x_min (per-dimension).
  • Add a targeted unit test that constructs a periodic scalar spline with nonzero x_min and checks equivalence of values (and derivatives where applicable) under shifts by integer multiples of the period.

Notes

This should be fixed before using scalar spline routines as a behavioral harness for GPU-ready refactors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions