@@ -88,6 +88,11 @@ struct JumpSystem{U <: ArrayPartition} <: AbstractTimeDependentSystem
88
88
"""
89
89
connector_type:: Any
90
90
"""
91
+ A `Vector{SymbolicContinuousCallback}` that model events.
92
+ The integrator will use root finding to guarantee that it steps at each zero crossing.
93
+ """
94
+ continuous_events:: Vector{SymbolicContinuousCallback}
95
+ """
91
96
A `Vector{SymbolicDiscreteCallback}` that models events. Symbolic
92
97
analog to `SciMLBase.DiscreteCallback` that executes an affect when a given condition is
93
98
true at the end of an integration step. Note, one must make sure to call
@@ -120,8 +125,7 @@ struct JumpSystem{U <: ArrayPartition} <: AbstractTimeDependentSystem
120
125
121
126
function JumpSystem {U} (
122
127
tag, ap:: U , iv, unknowns, ps, var_to_name, observed, name, description,
123
- systems,
124
- defaults, connector_type, devents, parameter_dependencies,
128
+ systems, defaults, connector_type, cevents, devents, parameter_dependencies,
125
129
metadata = nothing , gui_metadata = nothing ,
126
130
complete = false , index_cache = nothing , isscheduled = false ;
127
131
checks:: Union{Bool, Int} = true ) where {U <: ArrayPartition }
@@ -136,8 +140,8 @@ struct JumpSystem{U <: ArrayPartition} <: AbstractTimeDependentSystem
136
140
end
137
141
new {U} (tag, ap, iv, unknowns, ps, var_to_name,
138
142
observed, name, description, systems, defaults,
139
- connector_type, devents, parameter_dependencies, metadata, gui_metadata,
140
- complete, index_cache, isscheduled)
143
+ connector_type, cevents, devents, parameter_dependencies, metadata,
144
+ gui_metadata, complete, index_cache, isscheduled)
141
145
end
142
146
end
143
147
function JumpSystem (tag, ap, iv, states, ps, var_to_name, args... ; kwargs... )
@@ -210,13 +214,12 @@ function JumpSystem(eqs, iv, unknowns, ps;
210
214
end
211
215
end
212
216
213
- (continuous_events === nothing ) ||
214
- error (" JumpSystems currently only support discrete events." )
217
+ cont_callbacks = SymbolicContinuousCallbacks (continuous_events)
215
218
disc_callbacks = SymbolicDiscreteCallbacks (discrete_events)
216
219
217
220
JumpSystem {typeof(ap)} (Threads. atomic_add! (SYSTEM_COUNT, UInt (1 )),
218
221
ap, iv′, us′, ps′, var_to_name, observed, name, description, systems,
219
- defaults, connector_type, disc_callbacks, parameter_dependencies,
222
+ defaults, connector_type, cont_callbacks, disc_callbacks, parameter_dependencies,
220
223
metadata, gui_metadata, checks = checks)
221
224
end
222
225
@@ -399,6 +402,10 @@ function DiffEqBase.DiscreteProblem(sys::JumpSystem, u0map, tspan::Union{Tuple,
399
402
error (" The passed in JumpSystem contains `Equations`, please use a problem type that supports equations such as such as ODEProblem." )
400
403
end
401
404
405
+ if ! isempty (continuous_events (sys))
406
+ error (" The passed in JumpSystem contains `ContinuousEvents`, please use a problem type that supports continuous events such as such as ODEProblem." )
407
+ end
408
+
402
409
_, u0, p = process_SciMLProblem (EmptySciMLFunction, sys, u0map, parammap;
403
410
t = tspan === nothing ? nothing : tspan[1 ], use_union, tofloat = false , check_length = false )
404
411
f = DiffEqBase. DISCRETE_INPLACE_DEFAULT
@@ -488,12 +495,12 @@ function DiffEqBase.ODEProblem(sys::JumpSystem, u0map, tspan::Union{Tuple, Nothi
488
495
error (" A completed `JumpSystem` is required. Call `complete` or `structural_simplify` on the system before creating a `DiscreteProblem`" )
489
496
end
490
497
491
- # forward everything to be an ODESystem but the jumps
498
+ # forward everything to be an ODESystem but the jumps and discrete events
492
499
if has_equations (sys)
493
500
osys = ODESystem (equations (sys). x[4 ], get_iv (sys), unknowns (sys), parameters (sys);
494
501
observed = observed (sys), name = nameof (sys), description = description (sys),
495
502
systems = get_systems (sys), defaults = defaults (sys),
496
- discrete_events = discrete_events (sys),
503
+ continuous_events = continuous_events (sys),
497
504
parameter_dependencies = parameter_dependencies (sys),
498
505
metadata = get_metadata (sys), gui_metadata = get_gui_metadata (sys))
499
506
osys = complete (osys)
@@ -542,8 +549,11 @@ function JumpProcesses.JumpProblem(js::JumpSystem, prob,
542
549
for j in eqs. x[2 ]]
543
550
vrjs = VariableRateJump[assemble_vrj (js, j, unknowntoid; eval_expression, eval_module)
544
551
for j in eqs. x[3 ]]
545
- ((prob isa DiscreteProblem) && (! isempty (vrjs) || has_equations (js))) &&
546
- error (" Use continuous problems such as an ODEProblem or a SDEProblem with VariableRateJumps and/or coupled differential equations." )
552
+ if prob isa DiscreteProblem
553
+ if (! isempty (vrjs) || has_equations (js) || ! isempty (continous_events (js)))
554
+ error (" Use continuous problems such as an ODEProblem or a SDEProblem with VariableRateJumps, coupled differential equations, or continuous events." )
555
+ end
556
+ end
547
557
jset = JumpSet (Tuple (vrjs), Tuple (crjs), nothing , majs)
548
558
549
559
# dep graphs are only for constant rate jumps
0 commit comments