Skip to content

Commit 3c6f703

Browse files
feat: add is_discrete flag to systems
1 parent 5d06442 commit 3c6f703

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/systems/abstractsystem.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,7 @@ for prop in [:eqs
760760
:metadata
761761
:gui_metadata
762762
:is_initializesystem
763+
:is_discrete
763764
:parameter_dependencies
764765
:assertions
765766
:ignored_connections

src/systems/system.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ struct System <: AbstractSystem
235235
Whether the current system is an initialization system.
236236
"""
237237
is_initializesystem::Bool
238+
is_discrete::Bool
238239
"""
239240
$INTERNAL_FIELD_WARNING
240241
Whether the system has been simplified by `mtkcompile`.
@@ -255,8 +256,8 @@ struct System <: AbstractSystem
255256
is_dde = false, tstops = [], tearing_state = nothing, namespacing = true,
256257
complete = false, index_cache = nothing, ignored_connections = nothing,
257258
preface = nothing, parent = nothing, initializesystem = nothing,
258-
is_initializesystem = false, isscheduled = false, schedule = nothing;
259-
checks::Union{Bool, Int} = true)
259+
is_initializesystem = false, is_discrete = false, isscheduled = false,
260+
schedule = nothing; checks::Union{Bool, Int} = true)
260261
if is_initializesystem && iv !== nothing
261262
throw(ArgumentError("""
262263
Expected initialization system to be time-independent. Found independent
@@ -293,7 +294,8 @@ struct System <: AbstractSystem
293294
guesses, systems, initialization_eqs, continuous_events, discrete_events,
294295
connector_type, assertions, metadata, gui_metadata, is_dde,
295296
tstops, tearing_state, namespacing, complete, index_cache, ignored_connections,
296-
preface, parent, initializesystem, is_initializesystem, isscheduled, schedule)
297+
preface, parent, initializesystem, is_initializesystem, is_discrete,
298+
isscheduled, schedule)
297299
end
298300
end
299301

@@ -330,8 +332,8 @@ function System(eqs::Vector{Equation}, iv, dvs, ps, brownians = [];
330332
is_dde = nothing, tstops = [], tearing_state = nothing,
331333
ignored_connections = nothing, parent = nothing,
332334
description = "", name = nothing, discover_from_metadata = true,
333-
initializesystem = nothing, is_initializesystem = false, preface = [],
334-
checks = true)
335+
initializesystem = nothing, is_initializesystem = false, is_discrete = false,
336+
preface = [], checks = true)
335337
name === nothing && throw(NoNameError())
336338
if !isempty(parameter_dependencies)
337339
@warn """
@@ -411,7 +413,7 @@ function System(eqs::Vector{Equation}, iv, dvs, ps, brownians = [];
411413
var_to_name, name, description, defaults, guesses, systems, initialization_eqs,
412414
continuous_events, discrete_events, connector_type, assertions, metadata, gui_metadata, is_dde,
413415
tstops, tearing_state, true, false, nothing, ignored_connections, preface, parent,
414-
initializesystem, is_initializesystem; checks)
416+
initializesystem, is_initializesystem, is_discrete; checks)
415417
end
416418

417419
"""
@@ -668,7 +670,7 @@ callbacks, so checking if any LHS is shifted is sufficient. If a variable is shi
668670
the input equations there _will_ be a `Shift` equation in the simplified system.
669671
"""
670672
function is_discrete_system(sys::System)
671-
any(eq -> isoperator(eq.lhs, Shift), equations(sys))
673+
get_is_discrete(sys) || any(eq -> isoperator(eq.lhs, Shift), equations(sys))
672674
end
673675

674676
SymbolicIndexingInterface.is_time_dependent(sys::System) = get_iv(sys) !== nothing

0 commit comments

Comments
 (0)