Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Steady state callback #601

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

LasNikas
Copy link
Collaborator

I tested the callback with the pipe_flow_2d.jl example. It terminates after ~0.8sec.
I consider the change in kinetic energy in a 0.002*10 interval.

pp_callback = PostprocessCallback(; dt=0.02, kinetic_energy)

steady_state = SteadyStateCallback(; dt=0.002, interval_size=10, abstol=1.0e-8, reltol=1.0e-6)

image

Copy link

codecov bot commented Aug 14, 2024

Codecov Report

Attention: Patch coverage is 12.50000% with 63 lines in your changes missing coverage. Please review.

Project coverage is 69.08%. Comparing base (c565f67) to head (a1d69d6).

Files Patch % Lines
src/callbacks/steady_state.jl 0.00% 63 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #601      +/-   ##
==========================================
- Coverage   69.92%   69.08%   -0.84%     
==========================================
  Files          86       87       +1     
  Lines        5120     5185      +65     
==========================================
+ Hits         3580     3582       +2     
- Misses       1540     1603      +63     
Flag Coverage Δ
unit 69.08% <12.50%> (-0.84%) ⬇️

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.

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.

There is one mistake in the condition since you pop/push the current ekin one value is always 0.0 which will effectively reduce the interval size by one.

src/callbacks/steady_state.jl Show resolved Hide resolved
src/callbacks/steady_state.jl Outdated Show resolved Hide resolved
src/callbacks/steady_state.jl Outdated Show resolved Hide resolved
src/callbacks/steady_state.jl Outdated Show resolved Hide resolved
src/callbacks/steady_state.jl Outdated Show resolved Hide resolved
src/callbacks/steady_state.jl Outdated Show resolved Hide resolved
src/callbacks/steady_state.jl Outdated Show resolved Hide resolved
src/callbacks/steady_state.jl Show resolved Hide resolved
src/callbacks/steady_state.jl Outdated Show resolved Hide resolved
src/callbacks/steady_state.jl Outdated Show resolved Hide resolved
@@ -0,0 +1,175 @@
"""
SteadyStateCallback(; interval::Integer=0, dt=0.0, interval_size::Integer=10,
Copy link
Member

Choose a reason for hiding this comment

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

I find the name a bit misleading. In grid-based methods, when simulating a physical instability arising from a slightly perturbed steady state, you sometimes subtract the right-hand side of the steady state to remove errors.
From this name, I would expect something like this here.

I'll think about other naming suggestions.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ConvergenceConditionCallBack
ConvergenceTerminationCallBack
TerminationConditionCallBack

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

SteadyStateDetector
SteadyStateTerminator

src/callbacks/steady_state.jl Outdated Show resolved Hide resolved
src/callbacks/steady_state.jl Outdated Show resolved Hide resolved
src/callbacks/steady_state.jl Outdated Show resolved Hide resolved
src/callbacks/steady_state.jl Show resolved Hide resolved
Comment on lines +110 to +111
# `terminate!(integrator)` terminates the simulation immediately and might cause an error message.
integrator.opts.maxiters = integrator.iter
Copy link
Collaborator Author

@LasNikas LasNikas Sep 26, 2024

Choose a reason for hiding this comment

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

This causes a warning message.
A more elegant solution would be to initially (in initialize!) sort the CallbackSet in such a way that the SteadyStateCallback is last.
The set is stored in integrator.opts.callback. However, I have no idea how to check if the actual callback is the last element or not.

Any idea @efaulhaber and @svchb ?

edit: The reason for this is the following.

  • CallbackSet(some_callback, steady_state_callback) is totally fine
  • CallbackSet(steady_state_callback, some_callback) causes an error message when terminating. ERROR: MethodError: reducing over an empty collection is not allowed; consider supplying init to the reducer

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Another (simpler) solution:
@suppress integrator.opts.maxiters = integrator.iter

from https://github.com/JuliaIO/Suppressor.jl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants