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 2 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
8 changes: 8 additions & 0 deletions docs/src/basics/Events.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ be handled via more [general functional affects](@ref func_affects).

Finally, multiple events can be encoded via a `Vector{Pair{Vector{Equation}, Vector{Equation}}}`.

Given an `AbstractSystem`, one can fetch its continuous events, and the continuous events of any
subsystem inside of it using the `continuous_events(::AbstractSystem)` method, returning a vector
of `ModelingToolkit.SymbolicContinuousCallback` objects.

### Example: Friction

The system below illustrates how continuous events can be used to model Coulomb
Expand Down Expand Up @@ -221,6 +225,10 @@ equations can either all change unknowns (i.e. variables) or all change
parameters, but one cannot currently mix unknown variable and parameter changes within one
individual event.

Given an `AbstractSystem`, one can fetch its discrete events, and the discrete events of any
Copy link
Member

Choose a reason for hiding this comment

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

Add it to the system docs for the docstrings of the available functions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh, I see, I missed that section.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I remove the mention of it from Events.md and just have it in the system docs?

Copy link
Member

Choose a reason for hiding this comment

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

Yes

subsystem inside of it using the `discrete_events(::AbstractSystem)` method, returning a vector
of `ModelingToolkit.SymbolicDiscreteCallback` objects.

### Example: Injecting cells into a population

Suppose we have a population of `N(t)` cells that can grow and die, and at time
Expand Down
2 changes: 1 addition & 1 deletion src/ModelingToolkit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ 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
10 changes: 10 additions & 0 deletions src/systems/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ function namespace_callback(cb::SymbolicContinuousCallback, s)::SymbolicContinuo
namespace_affects(affects(cb), s))
end

"""
continuous_events(sys::AbstractSystem)

Returns a vector of all the `continuous_events` in an abstract system and its component subsystems.
"""
function continuous_events(sys::AbstractSystem)
obs = get_continuous_events(sys)
filter(!isempty, obs)
Expand Down Expand Up @@ -234,6 +239,11 @@ SymbolicDiscreteCallbacks(cb::SymbolicDiscreteCallback) = [cb]
SymbolicDiscreteCallbacks(cbs::Vector{<:SymbolicDiscreteCallback}) = cbs
SymbolicDiscreteCallbacks(::Nothing) = SymbolicDiscreteCallback[]

"""
discrete_events(sys::AbstractSystem)

Returns a vector of all the `discrete_events` in an abstract system and its component subsystems.
"""
function discrete_events(sys::AbstractSystem)
obs = get_discrete_events(sys)
systems = get_systems(sys)
Expand Down