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

Create CheckInit and add tagging of initializations to callbacks #783

Merged
merged 4 commits into from
Sep 10, 2024

Conversation

ChrisRackauckas
Copy link
Member

No description provided.

src/callbacks.jl Outdated Show resolved Hide resolved
src/callbacks.jl Outdated
"""
struct ContinuousCallback{F1, F2, F3, F4, F5, T, T2, T3, I, R} <: AbstractContinuousCallback
struct ContinuousCallback{F1, F2, F3, F4, F5, T, T2, T3, T4, I, R} <: AbstractContinuousCallback
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
struct ContinuousCallback{F1, F2, F3, F4, F5, T, T2, T3, T4, I, R} <: AbstractContinuousCallback
struct ContinuousCallback{F1, F2, F3, F4, F5, T, T2, T3, T4, I, R} <:
AbstractContinuousCallback

src/callbacks.jl Outdated
Comment on lines 329 to 339
The effect of using a callback with a DAE needs to be done with care because the solution
`u` needs to satisfy the algebraic constraints before taking the next step. For this reason,
a consistent initialization calculation must be run after running the callback. If the
chosen initialization alg is `BrownBasicInit()` (the default for `solve`), then the initialization
will change the algebraic variables to satisfy the conditions. Thus if `x` is an algebraic
variable and the callback performs `x+=1`, the initialization may "revert" the change to
satisfy the constraints. This behavior can be removed by setting `initializealg = CheckInit()`,
which simply checks that the state `u` is consistent, but requires that the result of the
`affect!` satisfies the constraints (or else errors). It is not recommended that `NoInit()` is
used as that will lead to an unstable step following initialization. This warning can be
ignored for non-DAE ODEs.
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
The effect of using a callback with a DAE needs to be done with care because the solution
`u` needs to satisfy the algebraic constraints before taking the next step. For this reason,
a consistent initialization calculation must be run after running the callback. If the
chosen initialization alg is `BrownBasicInit()` (the default for `solve`), then the initialization
will change the algebraic variables to satisfy the conditions. Thus if `x` is an algebraic
variable and the callback performs `x+=1`, the initialization may "revert" the change to
satisfy the constraints. This behavior can be removed by setting `initializealg = CheckInit()`,
which simply checks that the state `u` is consistent, but requires that the result of the
`affect!` satisfies the constraints (or else errors). It is not recommended that `NoInit()` is
used as that will lead to an unstable step following initialization. This warning can be
ignored for non-DAE ODEs.
The effect of using a callback with a DAE needs to be done with care because the solution
`u` needs to satisfy the algebraic constraints before taking the next step. For this reason,
a consistent initialization calculation must be run after running the callback. If the
chosen initialization alg is `BrownBasicInit()` (the default for `solve`), then the initialization
will change the algebraic variables to satisfy the conditions. Thus if `x` is an algebraic
variable and the callback performs `x+=1`, the initialization may "revert" the change to
satisfy the constraints. This behavior can be removed by setting `initializealg = CheckInit()`,
which simply checks that the state `u` is consistent, but requires that the result of the
`affect!` satisfies the constraints (or else errors). It is not recommended that `NoInit()` is
used as that will lead to an unstable step following initialization. This warning can be
ignored for non-DAE ODEs.

src/callbacks.jl Outdated
DiscreteCallback(condition, affect!, initialize, finalize, save_positions)
save_positions = (true, true),
initializealg = nothing)
DiscreteCallback(condition, affect!, initialize, finalize, save_positions, initializealg)
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
DiscreteCallback(condition, affect!, initialize, finalize, save_positions, initializealg)
DiscreteCallback(
condition, affect!, initialize, finalize, save_positions, initializealg)

ChrisRackauckas and others added 3 commits September 10, 2024 07:39
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@ChrisRackauckas ChrisRackauckas merged commit b714f2d into master Sep 10, 2024
37 of 44 checks passed
@ChrisRackauckas ChrisRackauckas deleted the checkinit_callbacks branch September 10, 2024 08:13
ChrisRackauckas added a commit to SciML/OrdinaryDiffEq.jl that referenced this pull request Sep 10, 2024
ChrisRackauckas added a commit to SciML/OrdinaryDiffEq.jl that referenced this pull request Sep 10, 2024
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.

1 participant