Fix interpolation with VelocityAveraging - #1235
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
7b89225 to
5350281
Compare
| foreach_system(semi) do system | ||
| initialize_averaged_velocity!(system, v0_ode, semi, tspan[1]) | ||
| end |
There was a problem hiding this comment.
| 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.
| end | ||
| end | ||
|
|
||
| return cb(integrator) |
There was a problem hiding this comment.
| 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.
| return DiscreteCallback(update_averaged_velocity_callback!, | ||
| update_averaged_velocity_callback!, | ||
| initialize=(initialize_averaged_velocity_callback!), | ||
| save_positions=(false, false)) | ||
| end |
There was a problem hiding this comment.
| 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.
|
Add @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
endThis 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. |
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.