Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 9 additions & 4 deletions src/systems/system.jl
Copy link
Member

Choose a reason for hiding this comment

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

This adds the field to the system, but does not handle it in flatten and the other functions that operate on (hierarchical) systems.

Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ struct System <: IntermediateDeprecationSystem
"""
tstops::Vector{Any}
"""
The time span for time-dependent systems. This is a tuple of the start and end
time for the system, which can be symbolic expressions involving parameters.
"""
tspan::Union{Nothing, Tuple{Any, Any}}
"""
The `TearingState` of the system post-simplification with `mtkcompile`.
"""
tearing_state::Any
Expand Down Expand Up @@ -256,7 +261,7 @@ struct System <: IntermediateDeprecationSystem
defaults, guesses, systems, initialization_eqs, continuous_events, discrete_events,
connector_type, assertions = Dict{BasicSymbolic, String}(),
metadata = MetadataT(), gui_metadata = nothing,
is_dde = false, tstops = [], tearing_state = nothing, namespacing = true,
is_dde = false, tstops = [], tspan = nothing, tearing_state = nothing, namespacing = true,
complete = false, index_cache = nothing, ignored_connections = nothing,
preface = nothing, parent = nothing, initializesystem = nothing,
is_initializesystem = false, is_discrete = false, isscheduled = false,
Expand Down Expand Up @@ -296,7 +301,7 @@ struct System <: IntermediateDeprecationSystem
observed, parameter_dependencies, var_to_name, name, description, defaults,
guesses, systems, initialization_eqs, continuous_events, discrete_events,
connector_type, assertions, metadata, gui_metadata, is_dde,
tstops, tearing_state, namespacing, complete, index_cache, ignored_connections,
tstops, tspan, tearing_state, namespacing, complete, index_cache, ignored_connections,
preface, parent, initializesystem, is_initializesystem, is_discrete,
isscheduled, schedule)
end
Expand Down Expand Up @@ -332,7 +337,7 @@ function System(eqs::Vector{Equation}, iv, dvs, ps, brownians = [];
continuous_events = SymbolicContinuousCallback[], discrete_events = SymbolicDiscreteCallback[],
connector_type = nothing, assertions = Dict{BasicSymbolic, String}(),
metadata = MetadataT(), gui_metadata = nothing,
is_dde = nothing, tstops = [], tearing_state = nothing,
is_dde = nothing, tstops = [], tspan = nothing, tearing_state = nothing,
ignored_connections = nothing, parent = nothing,
description = "", name = nothing, discover_from_metadata = true,
initializesystem = nothing, is_initializesystem = false, is_discrete = false,
Expand Down Expand Up @@ -417,7 +422,7 @@ function System(eqs::Vector{Equation}, iv, dvs, ps, brownians = [];
costs, consolidate, dvs, ps, brownians, iv, observed, Equation[],
var_to_name, name, description, defaults, guesses, systems, initialization_eqs,
continuous_events, discrete_events, connector_type, assertions, metadata, gui_metadata, is_dde,
tstops, tearing_state, true, false, nothing, ignored_connections, preface, parent,
tstops, tspan, tearing_state, true, false, nothing, ignored_connections, preface, parent,
initializesystem, is_initializesystem, is_discrete; checks)
end

Expand Down
28 changes: 28 additions & 0 deletions test/odesystem.jl
Copy link
Member

Choose a reason for hiding this comment

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

The tests are weirdly redundant, and don't actually test creating an ODEProblem with symbolic tspan - it just uses a normal numeric tspan.

Original file line number Diff line number Diff line change
Expand Up @@ -1614,3 +1614,31 @@ end
@test_nowarn push!(arr, sys)
@test_nowarn TestWrapper(sys)
end

@testset "Symbolic tspan" begin
@variables x(t) y(t)
@parameters σ ρ β

# Test creating a system with tspan
eqs = [D(x) ~ σ * (y - x),
D(y) ~ x * (ρ - x) - y]

Comment on lines +1624 to +1625
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
D(y) ~ x *- x) - y]
D(y) ~ x *- x) - y]

# Test with numeric tspan
@named sys1 = System(eqs, t, [x, y], [σ, ρ, β]; tspan = (0.0, 10.0))
@test ModelingToolkit.get_tspan(sys1) == (0.0, 10.0)
@test ModelingToolkit.has_tspan(sys1) == true

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

# Test with symbolic tspan
@parameters t0 tf
@named sys2 = System(eqs, t, [x, y], [σ, ρ, β]; tspan = (t0, tf))
@test isequal(ModelingToolkit.get_tspan(sys2), (t0, tf))

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

# Test without tspan
@named sys3 = System(eqs, t, [x, y], [σ, ρ, β])
@test ModelingToolkit.get_tspan(sys3) === nothing
@test ModelingToolkit.has_tspan(sys3) == true # Field exists but is nothing

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

# Test that tspan is preserved through system completion
sys1_complete = complete(sys1)
@test ModelingToolkit.get_tspan(sys1_complete) == (0.0, 10.0)
end
Loading