-
-
Notifications
You must be signed in to change notification settings - Fork 49
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
A few improvements of TerminateSteadyState #243
Conversation
@@ -2,6 +2,11 @@ | |||
# Terminate when all derivatives fall below a threshold or | |||
# when derivatives are smaller than a fraction of state | |||
function allDerivPass(integrator, abstol, reltol, min_t) | |||
# Early exit | |||
if min_t !== nothing && integrator.t < min_t |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to perform all evaluations below in this case.
src/terminatesteadystate.jl
Outdated
@@ -16,21 +21,25 @@ function allDerivPass(integrator, abstol, reltol, min_t) | |||
end | |||
|
|||
if integrator.u isa Array | |||
any(abs(d) > abstol && abs(d) > reltol * abs(u) | |||
any(abs(d) > abstol || abs(d) > reltol * abs(u) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the docstring the default check ensures that
all derivatives should become smaller than
abstol
and the states times
reltol
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe better to change the docstring though, to be consistent with isapprox
.
src/terminatesteadystate.jl
Outdated
return true | ||
end | ||
|
||
struct WrappedTest{T,A,R,M} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the let
-trick leads to a bit ugly code 😄
else | ||
test | ||
end | ||
affect! = (integrator) -> terminate!(integrator) | ||
DiscreteCallback(condition, affect!; save_positions = (true, false)) | ||
DiscreteCallback(condition, terminate!; save_positions = (true, false)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for a separate affect!
function.
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Thanks, all simple but good changes. Any tangible performance difference from the iteration change? |
The PR contains a few suggestions with possible improvements for TerminateSteadyState.