[codex] Fix steady state callback interval handling#1180
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1180 +/- ##
==========================================
+ Coverage 89.88% 89.93% +0.04%
==========================================
Files 133 134 +1
Lines 10452 10480 +28
==========================================
+ Hits 9395 9425 +30
+ Misses 1057 1055 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Co-authored-by: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com>
|
|
||
| # Keywords | ||
| - `interval=0`: Check steady state condition every `interval` time steps. | ||
| A value of `0` disables step-interval checks. |
There was a problem hiding this comment.
| A value of `0` disables step-interval checks. | |
| Use either `interval` or `dt`. |
| (note that this may change the solution). | ||
| - `interval_size`: The interval in which the change of the kinetic energy is considered. | ||
| `interval_size` is a (integer) multiple of `interval` or `dt`. | ||
| - Either `interval` or `dt` must be set to something larger than 0. |
There was a problem hiding this comment.
| - Either `interval` or `dt` must be set to something larger than 0. | |
| Use either `interval` or `dt`. |
|
|
||
| function initialize_steady_state_callback!(cb::SteadyStateReachedCallback, u, t, integrator) | ||
| semi = integrator.p.semi | ||
| set_callbacks_used!(semi, integrator) |
| empty!(cb.previous_ekin) | ||
| push!(cb.previous_ekin, convert(eltype(cb.previous_ekin), Inf)) | ||
|
|
||
| return nothing |
There was a problem hiding this comment.
| return nothing | |
| return cb |
| if !steady_state_condition!(cb, integrator) | ||
| u_modified!(integrator, false) |
There was a problem hiding this comment.
| if !steady_state_condition!(cb, integrator) | |
| u_modified!(integrator, false) | |
| u_modified!(integrator, false) | |
| if !steady_state_condition!(cb, integrator) |
Do we even need u_modified! in the condition? Have you checked this?
| u_modified!(integrator, false) | ||
|
|
There was a problem hiding this comment.
| u_modified!(integrator, false) |
|
|
||
| u_modified!(integrator, false) | ||
|
|
||
| return nothing |
There was a problem hiding this comment.
| return nothing | |
| return cb |
|
|
||
| u_modified!(integrator, false) | ||
|
|
||
| return nothing |
There was a problem hiding this comment.
| return nothing | |
| return cb |
|
|
||
| # `condition` (`DiscreteCallback`) | ||
| function (steady_state_callback::SteadyStateReachedCallback{Int})(vu_ode, t, integrator) | ||
| condition_steady_state_interval(steady_state_callback, integrator) || return false |
There was a problem hiding this comment.
| condition_steady_state_interval(steady_state_callback, integrator) || return false | |
| if condition_integrator_interval(integrator, cb.interval; save_final_solution=false) | |
| return false | |
| end |
No need for an extra function.
Summary
intervalbefore evaluating the steady-state kinetic-energy conditioninterval_sizevaluesRoot Cause
The discrete callback condition called
steady_state_condition!directly, sointervalwas never checked. The constructor also chose the previous kinetic-energy vector element type before converting tolerances to a floating type, which made integer tolerances try to storeInfas an integer.Validation
julia --project=. -e 'using Test, TrixiParticles; include("test/callbacks/steady_state_reached.jl")'