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

A few improvements of TerminateSteadyState #243

Merged
merged 4 commits into from
Dec 1, 2024

Conversation

devmotion
Copy link
Member

The PR contains a few suggestions with possible improvements for TerminateSteadyState.

@@ -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
Copy link
Member Author

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.

@@ -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)
Copy link
Member Author

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

Copy link
Member Author

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.

return true
end

struct WrappedTest{T,A,R,M}
Copy link
Member Author

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))
Copy link
Member Author

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.

devmotion and others added 2 commits November 28, 2024 16:11
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>
@ChrisRackauckas
Copy link
Member

Thanks, all simple but good changes. Any tangible performance difference from the iteration change?

@ChrisRackauckas ChrisRackauckas merged commit 88f8221 into master Dec 1, 2024
24 of 25 checks passed
@ChrisRackauckas ChrisRackauckas deleted the dw/terminate_steadystate branch December 1, 2024 20:49
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.

2 participants