Skip to content

Fix interpolation with VelocityAveraging - #1235

Open
efaulhaber wants to merge 3 commits into
trixi-framework:mainfrom
efaulhaber:fix-interpolation-averaging
Open

Fix interpolation with VelocityAveraging#1235
efaulhaber wants to merge 3 commits into
trixi-framework:mainfrom
efaulhaber:fix-interpolation-averaging

Conversation

@efaulhaber

Copy link
Copy Markdown
Member

Based on #1037.

When interpolating the initial state or after restarting from files (especially when interpolating from VTK files in postprocessing), velocity averaging is not initialized correctly, which leads to zero wall velocity even if the structure is moving. With this PR, interpolation from VTK files in postprocessing works as intended.

@efaulhaber efaulhaber self-assigned this Jun 18, 2026
@efaulhaber efaulhaber added the bug Something isn't working label Jun 18, 2026
@codecov

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.13%. Comparing base (4b44813) to head (740ed27).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1235      +/-   ##
==========================================
- Coverage   90.14%   90.13%   -0.01%     
==========================================
  Files         138      138              
  Lines       10803    10797       -6     
==========================================
- Hits         9738     9732       -6     
  Misses       1065     1065              
Flag Coverage Δ
total 90.14% <100.00%> (-0.01%) ⬇️
unit 76.47% <100.00%> (+0.04%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 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 fix-interpolation-averaging branch from 7b89225 to 5350281 Compare June 29, 2026 10:24
@efaulhaber
efaulhaber marked this pull request as ready for review June 29, 2026 10:24
@efaulhaber
efaulhaber requested review from LasNikas and svchb June 29, 2026 10:24
Comment on lines +325 to +327
foreach_system(semi) do system
initialize_averaged_velocity!(system, v0_ode, semi, tspan[1])
end

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
foreach_system(semi) do system
initialize_averaged_velocity!(system, v0_ode, semi, tspan[1])
end
foreach_system(semi_new) do system
initialize_averaged_velocity!(system, v0_ode, semi_new, tspan[1])
end

This initializes the adapted semidiscretization that is stored in ode.p.semi.

Comment thread src/callbacks/update.jl
end
end

return cb(integrator)

@svchb svchb Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return cb(integrator)
if semi.integrate_tlsph[]
foreach_system(semi) do system
initialize_averaged_velocity!(system, v_ode, semi, t)
end
end
return cb(integrator)

This resets the averaged velocity when each integrator starts; the regression test shows that a second regular integration otherwise keeps data from the first run.

Comment on lines 539 to 542
return DiscreteCallback(update_averaged_velocity_callback!,
update_averaged_velocity_callback!,
initialize=(initialize_averaged_velocity_callback!),
save_positions=(false, false))
end

@svchb svchb Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return DiscreteCallback(update_averaged_velocity_callback!,
update_averaged_velocity_callback!,
initialize=(initialize_averaged_velocity_callback!),
save_positions=(false, false))
end
return DiscreteCallback(update_averaged_velocity_callback!,
update_averaged_velocity_callback!,
initialize=(initialize_averaged_velocity_callback!),
save_positions=(false, false))
end
# `initialize`
function initialize_averaged_velocity_callback!(cb, vu_ode, t, integrator)
v_ode, u_ode = vu_ode.x
semi = integrator.p.semi
foreach_system(semi) do system
initialize_averaged_velocity!(system, v_ode, semi, t)
end
return cb
end

This resets the averaged velocity when each split integrator starts; the regression test shows that a second split integration otherwise keeps the old velocity and time.

@svchb

svchb commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Add using OrdinaryDiffEqLowStorageRK at the top of test/schemes/structure/total_lagrangian_sph/velocity_averaging.jl, then add this inside the existing Velocity Averaging test set:

@testset "Reinitialize averaged velocity for integration" begin
    algorithm = CarpenterKennedy2N54(williamson_condition=false)
    callbacks = (("update", () -> UpdateCallback()),
                 ("split", () -> SplitIntegrationCallback(algorithm; dt=0.01)))

    for (name, callback) in callbacks
        @testset "$name integration" begin
            velocity_averaging = VelocityAveraging(time_constant=0.5)
            system = velocity_averaging_test_system(; velocity_averaging)
            semi = Semidiscretization(system, neighborhood_search=nothing)
            ode = semidiscretize(semi, (0.0, 0.1))
            system = ode.p.semi.systems[1]

            TrixiParticles.SciMLBase.solve(ode, algorithm; dt=0.01, adaptive=false,
                                          callback=callback(), save_everystep=false)

            @test system.cache.t_last_averaging[] == last(ode.tspan)

            TrixiParticles.SciMLBase.init(ode, algorithm; dt=0.01, adaptive=false,
                                         callback=callback(), save_everystep=false)

            @test system.cache.t_last_averaging[] == first(ode.tspan)
            @test system.cache.averaged_velocity == [1.0 3.0 5.0
                                                     2.0 4.0 6.0]
        end
    end
end

This reproduces stale data for both regular and split integration: three assertions fail with the current changes, while all twenty-one tests pass when both initialization hooks are restored.

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants