Skip to content

Implement velocity averaging for TLSPH#1069

Open
efaulhaber wants to merge 8 commits intotrixi-framework:mainfrom
efaulhaber:velocity-averaging
Open

Implement velocity averaging for TLSPH#1069
efaulhaber wants to merge 8 commits intotrixi-framework:mainfrom
efaulhaber:velocity-averaging

Conversation

@efaulhaber
Copy link
Member

@efaulhaber efaulhaber commented Feb 17, 2026

In challenging FSI cases with very stiff structures, penalty force and artificial viscosity might not be sufficient to prevent instabilities. High-frequency noise in the structure velocity can trigger instabilities or spurious
pressure waves (due to aliasing) in the fluid.
This PR implements velocity averaging as another stabilization technique. An exponential moving average of the structure velocity is used only for the fluid-structure viscous coupling (no-slip boundary condition).

@efaulhaber efaulhaber self-assigned this Feb 17, 2026
@codecov
Copy link

codecov bot commented Feb 17, 2026

Codecov Report

❌ Patch coverage is 93.40659% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.30%. Comparing base (1bb54d4) to head (a9335a6).

Files with missing lines Patch % Lines
...ructure/total_lagrangian_sph/velocity_averaging.jl 93.18% 3 Missing ⚠️
src/callbacks/split_integration.jl 96.00% 1 Missing ⚠️
src/preprocessing/particle_packing/system.jl 0.00% 1 Missing ⚠️
src/schemes/boundary/open_boundary/system.jl 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1069      +/-   ##
==========================================
+ Coverage   89.25%   89.30%   +0.05%     
==========================================
  Files         122      123       +1     
  Lines        8949     9032      +83     
==========================================
+ Hits         7987     8066      +79     
- Misses        962      966       +4     
Flag Coverage Δ
total 89.30% <93.40%> (+0.05%) ⬆️
unit 64.88% <22.78%> (-0.45%) ⬇️

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 force-pushed the velocity-averaging branch from 067e215 to b74d8d0 Compare March 3, 2026 15:54
Copy link

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

Implements exponential moving-average (EMA) velocity averaging for TotalLagrangianSPHSystem to stabilize challenging FSI cases by using a smoothed structure velocity only in the fluid-structure viscous (no-slip) coupling.

Changes:

  • Add VelocityAveraging option, cache fields, and averaged-velocity update routines for TLSPH.
  • Update callbacks (UpdateCallback and split integration) to initialize/update averaged velocities over time.
  • Wire averaged velocity into boundary no-slip velocity evaluation, add docs, and extend an example-based test.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
test/examples/examples.jl Enables velocity averaging in an FSI example test and adds assertions that it is being used.
src/schemes/structure/total_lagrangian_sph/velocity_averaging.jl New implementation of EMA velocity averaging and velocity_for_viscosity selector.
src/schemes/structure/total_lagrangian_sph/total_lagrangian_sph.jl Includes the new velocity averaging implementation file.
src/schemes/structure/total_lagrangian_sph/system.jl Adds velocity_averaging field/keyword, cache creation, and callback requirement logic for TLSPH.
src/schemes/fluid/shifting_techniques.jl Updates requires_update_callback signature to accept semi.
src/schemes/boundary/wall_boundary/dummy_particles.jl Uses velocity_for_viscosity when computing boundary velocity for no-slip.
src/schemes/boundary/open_boundary/system.jl Updates requires_update_callback signature to accept semi.
src/preprocessing/particle_packing/system.jl Updates requires_update_callback signature to accept semi.
src/general/semidiscretization.jl Calls requires_update_callback(system, semi) in check_update_callback.
src/callbacks/update.jl Initializes and updates averaged velocity from the UpdateCallback.
src/callbacks/split_integration.jl Injects a lightweight averaged-velocity updater into split integration and adds display support.
src/TrixiParticles.jl Exports VelocityAveraging.
examples/fsi/dam_break_plate_2d.jl Adds velocity_averaging keyword (set to nothing) in the example setup.
docs/src/systems/total_lagrangian_sph.md Adds user documentation for velocity averaging and exposes autodocs.
Comments suppressed due to low confidence (1)

test/examples/examples.jl:168

  • @test !iszero(velocity_for_viscosity(...)) is potentially flaky if the chosen particle’s velocity happens to be (near-)zero at the sampled time. A more robust check would assert that averaging was updated (e.g., system.cache.t_last_averaging[] reached the final time, or that averaged_velocity changed from its initialization) rather than relying on a nonzero value.
            @test_throws "no method" TrixiParticles.current_velocity(nothing, system, 1)
            @test !iszero(TrixiParticles.velocity_for_viscosity(nothing, system, 1))

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

@efaulhaber efaulhaber added the enhancement New feature or request label Mar 3, 2026
@efaulhaber efaulhaber requested review from LasNikas and svchb March 4, 2026 10:37
@efaulhaber efaulhaber marked this pull request as ready for review March 4, 2026 10:37
@svchb
Copy link
Collaborator

svchb commented Mar 6, 2026

this is what codex says:
Averaged velocity is updated from two callbacks, which can produce a negative EMA timestep when both UpdateCallback and SplitIntegrationCallback are active and UpdateCallback runs first in a step.
UpdateCallback always calls compute_averaged_velocity! (src/callbacks/update.jl (line 114)), while split integration also updates it every substep (src/callbacks/split_integration.jl (line 405)).
Since EMA uses dt = t_new - t_last_averaging (src/schemes/structure/total_lagrangian_sph/velocity_averaging.jl (line 98)), this can make dt < 0 during split substeps and break smoothing (alpha outside [0,1]).
Recommended fix: skip TLSPH averaging in UpdateCallback when !semi.integrate_tlsph[] (split mode), since split callback already handles it.

Copy link
Collaborator

@svchb svchb left a comment

Choose a reason for hiding this comment

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

Please add an actual unit test since this is not very hard here.


## [Velocity Averaging](@id velocity_averaging)

In challenging FSI cases with very stiff structures, the two techniques above might not be
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
In challenging FSI cases with very stiff structures, the two techniques above might not be
In FSI cases with very stiff structures, the two techniques above might not be


In challenging FSI cases with very stiff structures, the two techniques above might not be
sufficient to prevent instabilities.
High-frequency noise in the structure velocity can trigger instabilities or spurious
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
High-frequency noise in the structure velocity can trigger instabilities or spurious
High-frequency noise of the structure velocity can trigger instabilities or spurious

In challenging FSI cases with very stiff structures, the two techniques above might not be
sufficient to prevent instabilities.
High-frequency noise in the structure velocity can trigger instabilities or spurious
pressure waves (due to aliasing) in the fluid.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
pressure waves (due to aliasing) in the fluid.
pressure waves in the fluid due to aliasing.

sufficient to prevent instabilities.
High-frequency noise in the structure velocity can trigger instabilities or spurious
pressure waves (due to aliasing) in the fluid.
Another stabilization technique is an exponential moving average (EMA) of the structure
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Another stabilization technique is an exponential moving average (EMA) of the structure
Another stabilization technique is to use an exponential moving average (EMA) of the structure

High-frequency noise in the structure velocity can trigger instabilities or spurious
pressure waves (due to aliasing) in the fluid.
Another stabilization technique is an exponential moving average (EMA) of the structure
velocity used **only** for the fluid-structure viscous coupling (no-slip boundary condition).
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
velocity used **only** for the fluid-structure viscous coupling (no-slip boundary condition).
velocity used **only** for the fluid-structure viscous coupling (i.e. the no-slip boundary condition).

velocity used **only** for the fluid-structure viscous coupling (no-slip boundary condition).

The averaged velocity ``\bar v`` is updated (by the [`UpdateCallback`](@ref)
or in every sub-step of the [`SplitIntegrationCallback`](@ref) if it is used) as
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
or in every sub-step of the [`SplitIntegrationCallback`](@ref) if it is used) as
or at every sub-step of the [`SplitIntegrationCallback`](@ref) if it is used) as

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants