Skip to content

馃殌[FEA]: Add non-periodic boundary mode to grid-gradient operators#1852

Description

@loliverhennigh

Is this a new feature, an improvement, or a change to existing functionality?

Improvement

How would you describe the priority of this feature request?

Medium

Please provide a clear description of the problem you would like to solve.

physicsnemo.nn.functional.derivatives.rectilinear_grid_gradient and uniform_grid_gradient currently use periodic wrapping (for example, via torch.roll) at domain boundaries. On bounded, non-periodic domains this mixes values from opposite edges and produces incorrect boundary-row gradients.

Add an opt-in non-periodic boundary mode that:

  • preserves the existing 3-point non-uniform central stencil in the interior;
  • uses appropriate one-sided stencils only at the lower and upper boundaries;
  • is implemented consistently in the torch and Warp backends, including forward and backward paths; and
  • keeps periodic behavior as the default, so existing callers see no behavior change.

A suggested API is:

boundary: Literal["periodic", "one_sided"] = "periodic"

An explicit boundary mode is preferable to periodic: bool because it is self-documenting and leaves room for other boundary treatments later.

Suggested validation and acceptance criteria:

  • analytic checks for both interior and boundary derivatives;
  • equivalence between rectilinear and uniform-grid implementations on uniform coordinates;
  • parity between torch and Warp backends;
  • autograd coverage;
  • documentation for the new argument; and
  • a CHANGELOG entry.

This would make the gradient helpers reusable for bounded-domain problems without requiring each caller to mask or replace corrupted boundary values.

Describe any alternatives you have considered

Callers can currently ignore or mask the boundary rows, or implement separate one-sided differences outside PhysicsNeMo. That duplicates numerical logic across applications and still requires special handling around the existing operator. Changing the current behavior globally is not viable because it would break callers that depend on periodic wrapping.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ? - Needs TriageNeed team to review and classifyenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions