Skip to content

Implement NHS handlers to avoid redundant copies of the same grid NHS#1222

Open
efaulhaber wants to merge 12 commits into
trixi-framework:mainfrom
efaulhaber:nhs-handler1
Open

Implement NHS handlers to avoid redundant copies of the same grid NHS#1222
efaulhaber wants to merge 12 commits into
trixi-framework:mainfrom
efaulhaber:nhs-handler1

Conversation

@efaulhaber
Copy link
Copy Markdown
Member

@efaulhaber efaulhaber commented May 27, 2026

Extracted from #1088.

This is the first part of improving NHS efficiency. It builds the handler structure and avoids storing multiple identical neighborhood searches without touching the NHS update process. This means instead of updating multiple redundant searches, we now update one search multiple times. The next PR avoids the redundant updates.

Co-authored-by: RubberLanding <nico.schumann@tutanota.com>
@efaulhaber efaulhaber self-assigned this May 27, 2026
@efaulhaber efaulhaber added enhancement New feature or request performance labels May 27, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 28, 2026

Codecov Report

❌ Patch coverage is 84.05797% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.02%. Comparing base (6bb102a) to head (5a03ef8).

Files with missing lines Patch % Lines
src/general/gpu.jl 0.00% 8 Missing ⚠️
src/general/semidiscretization.jl 66.66% 2 Missing ⚠️
src/general/neighborhood_search.jl 97.72% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1222      +/-   ##
==========================================
- Coverage   90.05%   90.02%   -0.03%     
==========================================
  Files         136      136              
  Lines       10594    10641      +47     
==========================================
+ Hits         9540     9580      +40     
- Misses       1054     1061       +7     
Flag Coverage Δ
total 90.03% <84.05%> (-0.02%) ⬇️
unit 70.81% <69.56%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@efaulhaber efaulhaber marked this pull request as ready for review May 30, 2026 11:56
@efaulhaber efaulhaber requested a review from Copilot May 30, 2026 11:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors how Semidiscretization stores neighborhood searches by introducing an AbstractNHSHandler abstraction with two concrete implementations: PairsNHSHandler (one NHS per ordered system pair, the previous behavior) and SharedNHSHandler (one NHS per neighbor system and required radius, used by default for GridNeighborhoodSearch). The motivation is to avoid storing and updating redundant copies of identical grid-based neighborhood searches when the underlying search supports querying arbitrary points after an update.

Changes:

  • Introduce AbstractNHSHandler, PairsNHSHandler, SharedNHSHandler, and default_neighborhood_search_handler; route lookups, GPU adaptation, and display through the handler.
  • Replace Semidiscretization.neighborhood_searches matrix with neighborhood_search_handler; update all downstream code (interpolation, split integration, GPU transfer, TLSPH path, tests).
  • Add documentation section for handlers and new tests covering default selection, explicit handler choices, lookup radius semantics, and invalid handler arguments.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/TrixiParticles.jl Export PairsNHSHandler/SharedNHSHandler and re-export AbstractNeighborhoodSearch.
src/general/neighborhood_search.jl Add handler abstraction, two implementations, default selection, and refactored lookups.
src/general/semidiscretization.jl Replace neighborhood_searches field with neighborhood_search_handler; update constructor, show, and semidiscretize.
src/general/gpu.jl Provide handler-aware GPU/CPU adaptation.
src/general/interpolation.jl Switch from matrix slice to per-system handler lookup.
src/callbacks/split_integration.jl Use get_neighborhood_search instead of direct matrix indexing for periodic box extraction.
src/preprocessing/particle_packing/nhs_faces.jl Use re-exported AbstractNeighborhoodSearch.
docs/src/general/neighborhood_search.md Document handler selection with examples.
test/general/semidiscretization.jl Add tests for default handler selection, explicit handlers, and invalid handler arguments.
test/examples/examples_fluid.jl Add PairsNHSHandler fluid example and update field accesses.
test/examples/gpu.jl Add PairsNHSHandler GPU variant and update GPU field accesses.
test/callbacks/mechanical_work_calculator.jl Use PairsNHSHandler (no grid NHS available for the mock system).
test/count_allocations.jl Wrap handler internals with NoUpdateNeighborhoodSearch.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/general/neighborhood_search.jl
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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

Labels

enhancement New feature or request performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants