Skip to content

Make continuity_equation! and density_diffusion! work on Ref values#1130

Merged
efaulhaber merged 9 commits intotrixi-framework:mainfrom
efaulhaber:continuity-equation-ref
Apr 14, 2026
Merged

Make continuity_equation! and density_diffusion! work on Ref values#1130
efaulhaber merged 9 commits intotrixi-framework:mainfrom
efaulhaber:continuity-equation-ref

Conversation

@efaulhaber
Copy link
Copy Markdown
Member

@efaulhaber efaulhaber commented Apr 2, 2026

This PR makes continuity_equation! and density_diffusion! work on Ref values instead of directly writing to dv. Together with #1116, it makes it possible to accumulate drho_particle over all neighbors and only once write it to dv.
It is part of #1131.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 7, 2026

Codecov Report

❌ Patch coverage is 94.36620% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.06%. Comparing base (419d5b9) to head (5f36a06).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/schemes/fluid/shifting_techniques.jl 63.63% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1130      +/-   ##
==========================================
+ Coverage   89.00%   89.06%   +0.06%     
==========================================
  Files         128      128              
  Lines        9838     9868      +30     
==========================================
+ Hits         8756     8789      +33     
+ Misses       1082     1079       -3     
Flag Coverage Δ
total 89.06% <94.36%> (+0.06%) ⬆️
unit 67.18% <76.05%> (+0.05%) ⬆️

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.

Copy link
Copy Markdown

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 density-rate updates so continuity_equation! and density_diffusion! can accumulate into a Ref (e.g., drho_particle) rather than writing directly into dv, enabling a later optimization to write dv once per particle (as described in #1116 / #1131).

Changes:

  • Update fluid WCSPH and EDAC RHS interaction loops to pass v_a/v_b and accumulate drho_particle::Ref via continuity_equation!, then write via write_drho_particle!.
  • Refactor density_diffusion! to accumulate into drho_particle::Ref and adjust call sites accordingly.
  • Adjust shifting-technique helpers to operate on/return a transformed v_diff value.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/schemes/structure/structure.jl Switch structure–fluid continuity update to accumulate into Ref and add a write_drho_particle! writeback path.
src/schemes/fluid/weakly_compressible_sph/rhs.jl Accumulate density-rate in Ref and write once via write_drho_particle!.
src/schemes/fluid/weakly_compressible_sph/density_diffusion.jl Make density diffusion accumulate into Ref instead of writing to dv.
src/schemes/fluid/shifting_techniques.jl Update shifting continuity helpers to accept/return v_diff directly.
src/schemes/fluid/fluid.jl Refactor continuity_equation! to write into Ref and introduce write_drho_particle! dispatch.
src/schemes/fluid/entropically_damped_sph/rhs.jl Use Ref accumulation for continuity equation and defer writeback.
src/schemes/boundary/wall_boundary/rhs.jl Use Ref accumulation for boundary dummy-particle continuity update.
src/schemes/boundary/open_boundary/rhs.jl Update density diffusion call to use Ref accumulation (continuity term remains direct).

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

Comment thread src/schemes/structure/structure.jl
Comment thread src/schemes/fluid/shifting_techniques.jl Outdated
@efaulhaber efaulhaber marked this pull request as ready for review April 7, 2026 16:37
@efaulhaber efaulhaber requested a review from svchb April 7, 2026 16:37
Comment thread src/schemes/fluid/weakly_compressible_sph/density_diffusion.jl Outdated
Comment thread src/schemes/fluid/weakly_compressible_sph/density_diffusion.jl Outdated
@efaulhaber efaulhaber requested review from LasNikas and svchb April 14, 2026 09:25
@svchb
Copy link
Copy Markdown
Collaborator

svchb commented Apr 14, 2026

I found one blocker in the current head.

Blocker: open-boundary continuity path lost its dispatch target

In src/schemes/boundary/open_boundary/rhs.jl, the PR now calls:

continuity_equation!(drho_particle, ContinuityDensity(),
                     particle_system, neighbor_system, ...)

where particle_system is an OpenBoundarySystem{<:BoundaryModelDynamicalPressureZhang}.

But after the refactor, the relevant overload in src/schemes/fluid/fluid.jl is only defined for

particle_system::AbstractFluidSystem

and OpenBoundarySystem is not an AbstractFluidSystem; it is an AbstractSystem{NDIMS}.

Before this PR, there was still a generic helper

continuity_equation!(dv, particle_system, neighbor_system, ...)

with no AbstractFluidSystem restriction, and the open-boundary code reused that path. This PR removes that generic path by folding the logic into the typed overload, so this looks like a regression that should surface as a MethodError once the open-boundary interaction is exercised.

Why I think this is the intended fix direction

The helpers used inside the continuity update already have open-boundary support: OpenBoundarySystem defines density_diffusion and shifting_technique, and density_diffusion! already accepts OpenBoundarySystem{<:BoundaryModelDynamicalPressureZhang}. So the missing piece is the continuity_equation! dispatch, not the underlying math.

Suggested fix

Either:

  1. Restore the generic helper that computes the continuity contribution for any system supporting the required accessors, then let both fluid and open-boundary code call it, or
  2. Add a dedicated overload for OpenBoundarySystem{<:BoundaryModelDynamicalPressureZhang} mirroring the previous generic behavior.

What looks fine now

The earlier Copilot concern about write_drho_particle! for structure systems seems already addressed: structure.jl now has a generic no-op write_drho_particle!(dv, ::AbstractSystem, ...), so that specific MethodError no longer looks live.

So my review would be: request changes for the open-boundary continuity dispatch regression.

@efaulhaber
Copy link
Copy Markdown
Member Author

/run-gpu-tests

@efaulhaber efaulhaber enabled auto-merge (squash) April 14, 2026 14:26
@efaulhaber efaulhaber merged commit 379db88 into trixi-framework:main Apr 14, 2026
17 of 18 checks passed
@efaulhaber efaulhaber deleted the continuity-equation-ref branch April 14, 2026 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants