Skip to content

Fix NaN in parallel point evaluation with repeated knots - #614

Open
yguclu wants to merge 6 commits into
develfrom
yguclu-fix-eval-repeated-knots
Open

yguclu wants to merge 6 commits into
develfrom
yguclu-fix-eval-repeated-knots

Conversation

@yguclu

@yguclu yguclu commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Fix NaN values in the parallel point evaluation of fields at subdomain boundaries with repeated knots, as reported in #612, and make TensorFemSpace.eval_field_gradient behave like eval_field.

Fixes #612

Changes

  • psydac.core.bsplines.find_span: add the option side, with values 'right' (default, unchanged behavior) or 'left'. With side='left', if x is an interior knot of any multiplicity, the function selects the non-empty knot span on the left of x, i.e. such that knots[span] < x <= knots[span+1]. It does so by skipping back over all copies of x in the knot sequence.
  • TensorFemSpace._find_local_span: new private method, which replaces the code duplicated in eval_field and eval_field_gradient. It moves a point lying outside of the local interval by at most one machine epsilon onto its closest bound, and uses find_span with side='left' on the right bound of the local interval, whose right knot span belongs to the next process. The special case of the domain end is no longer needed.
  • TensorFemSpace.eval_field_gradient: like eval_field, update the ghost regions of the coefficients if they are not in sync, and check the space of the weights. In both methods, check the weights with is not None.

Tests

  • psydac/core/tests/test_bsplines.py: new test_find_span_side, for degrees 1 to 3 and simple, repeated, and mixed knot multiplicities.
  • psydac/fem/tests/test_tensor.py:
    • test_TensorFemSpace_eval_field_parallel (MPI): evaluates the linear field f(x, y) = x + 2y and its gradient on the closed local subdomains, with simple, repeated, and mixed knot multiplicities. Without the fix, the repeated and mixed cases fail (NaN) on all processes except the last one along each direction.
    • test_TensorFemSpace_eval_field_ghost_regions (MPI): evaluates the field or its gradient (separately), starting from coefficients whose ghost regions are not in sync. Without the change to eval_field_gradient, the gradient case fails.

The MPI tests pass on 1, 2, and 4 processes.

Notes

On devel, psydac/fem/tests/test_plot_field_2d.py::test_plot_field[True-*] fails because a two-patch domain is built without interface orientation; this is fixed in #527 and unrelated to this PR.

Related bugs: #474, #613.

yguclu added 2 commits October 9, 2026 17:14
At the right bound of the local subdomain, `TensorFemSpace.eval_field`
and `eval_field_gradient` moved back by one knot from the span given by
`find_span`, which selects an empty knot span (and yields NaN) if the
bound is a knot of multiplicity larger than one.

Add the option `side='left'` to `psydac.core.bsplines.find_span`, which
selects the non-empty knot span on the left of an interior knot of any
multiplicity. Use it in the new private method
`TensorFemSpace._find_local_span`, which replaces the code duplicated in
`eval_field` and `eval_field_gradient`.

Add unit tests for `find_span` with `side='left'`, and an MPI test which
evaluates a linear field and its gradient on the closed local subdomains
with simple, repeated and mixed knot multiplicities.

Fixes #612.
Unlike `TensorFemSpace.eval_field`, `eval_field_gradient` did not update
the ghost regions of the field coefficients when they were not in sync,
and did not check the space of the weights. Add both, and check the
weights with `is not None` in both methods.

Add helper functions to the tests in `psydac.fem.tests.test_tensor`, and
add an MPI test which evaluates the field or its gradient (separately)
on the closed local subdomains, starting from coefficients whose ghost
regions are not in sync.
@codacy-production

codacy-production Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 16 complexity · 4 duplication

Metric Results
Complexity 16
Duplication 4

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@yguclu
yguclu requested a review from a team October 9, 2026 16:05
@yguclu
yguclu marked this pull request as ready for review October 9, 2026 16:05
@yguclu
yguclu marked this pull request as draft October 9, 2026 22:20
@yguclu
yguclu marked this pull request as ready for review October 9, 2026 22:21
@yguclu yguclu added the Next Release Must be in next release label Oct 11, 2026
@jowezarek
jowezarek self-requested a review October 15, 2026 12:37
@yguclu yguclu self-assigned this Oct 15, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Next Release Must be in next release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NaN in parallel point evaluation at subdomain boundaries with repeated knots

1 participant