Skip to content

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

Merged
yguclu merged 8 commits into
develfrom
yguclu-fix-eval-repeated-knots
Nov 17, 2026
Merged

yguclu merged 8 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 issue #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.

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

🟢 Coverage 64.36% diff coverage

Metric Results
Coverage variation Report missing for 9217e711
Diff coverage ✅ 64.36% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (9217e71) Report Missing Report Missing Report Missing
Head commit (b927e26) 104760 67302 64.24%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#614) 101 65 64.36%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

1 Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

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

@jowezarek jowezarek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I finally had a look, this PR looks good to me, no comments.

@yguclu
yguclu enabled auto-merge (squash) November 17, 2026 10:22
@yguclu
yguclu marked this pull request as draft November 17, 2026 16:27
auto-merge was automatically disabled November 17, 2026 16:27

Pull request was converted to draft

@yguclu
yguclu marked this pull request as ready for review November 17, 2026 16:27
@yguclu
yguclu enabled auto-merge (squash) November 17, 2026 16:30
@yguclu
yguclu merged commit a73780e into devel Nov 17, 2026
9 checks passed
@yguclu
yguclu deleted the yguclu-fix-eval-repeated-knots branch November 17, 2026 17:44
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

2 participants