Skip to content

Document and export continuous_events and discrete_events #2567

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

Merged
merged 5 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/src/systems/JumpSystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ JumpSystem
- `get_unknowns(sys)` or `unknowns(sys)`: The set of unknowns in the jump system.
- `get_ps(sys)` or `parameters(sys)`: The parameters of the jump system.
- `get_iv(sys)`: The independent variable of the jump system.
- `discrete_events(sys)`: The set of discrete events in the jump system.

## Transformations

Expand Down
2 changes: 2 additions & 0 deletions docs/src/systems/ODESystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ ODESystem
- `get_ps(sys)` or `parameters(sys)`: The parameters of the ODE.
- `get_iv(sys)`: The independent variable of the ODE.
- `get_u0_p(sys, u0map, parammap)` Numeric arrays for the initial condition and parameters given `var => value` maps.
- `continuous_events(sys)`: The set of continuous events in the ODE
- `discrete_events(sys)`: The set of discrete events in the ODE

## Transformations

Expand Down
2 changes: 2 additions & 0 deletions docs/src/systems/SDESystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ sde = SDESystem(ode, noiseeqs)
- `get_unknowns(sys)` or `unknowns(sys)`: The set of unknowns in the SDE.
- `get_ps(sys)` or `parameters(sys)`: The parameters of the SDE.
- `get_iv(sys)`: The independent variable of the SDE.
- `continuous_events(sys)`: The set of continuous events in the SDE
- `discrete_events(sys)`: The set of discrete events in the SDE

## Transformations

Expand Down
3 changes: 2 additions & 1 deletion src/ModelingToolkit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ using PrecompileTools, Reexport
using RecursiveArrayTools

using SymbolicIndexingInterface
export independent_variables, unknowns, parameters, full_parameters
export independent_variables, unknowns, parameters, full_parameters, continuous_events,
discrete_events
import SymbolicUtils
import SymbolicUtils: istree, arguments, operation, similarterm, promote_symtype,
Symbolic, isadd, ismul, ispow, issym, FnType,
Expand Down
16 changes: 16 additions & 0 deletions src/systems/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ function namespace_callback(cb::SymbolicContinuousCallback, s)::SymbolicContinuo
namespace_affects(affects(cb), s))
end

"""
continuous_events(sys::AbstractSystem)::Vector{SymbolicContinuousCallback}

Returns a vector of all the `continuous_events` in an abstract system and its component subsystems.
The `SymbolicContinuousCallback`s in the returned vector are structs with two fields: `eqs` and
`affect` which correspond to the first and second elements of a `Pair` used to define an event, i.e.
`eqs => affect`.
"""
function continuous_events(sys::AbstractSystem)
obs = get_continuous_events(sys)
filter(!isempty, obs)
Expand Down Expand Up @@ -234,6 +242,14 @@ SymbolicDiscreteCallbacks(cb::SymbolicDiscreteCallback) = [cb]
SymbolicDiscreteCallbacks(cbs::Vector{<:SymbolicDiscreteCallback}) = cbs
SymbolicDiscreteCallbacks(::Nothing) = SymbolicDiscreteCallback[]

"""
discrete_events(sys::AbstractSystem) :: Vector{SymbolicDiscreteCallback}

Returns a vector of all the `discrete_events` in an abstract system and its component subsystems.
The `SymbolicDiscreteCallback`s in the returned vector are structs with two fields: `condition` and
`affect` which correspond to the first and second elements of a `Pair` used to define an event, i.e.
`condition => affect`.
"""
function discrete_events(sys::AbstractSystem)
obs = get_discrete_events(sys)
systems = get_systems(sys)
Expand Down