@@ -27,7 +27,7 @@ js = JumpSystem([j₁,j₂,j₃], t, [S,I,R], [β,γ])
27
27
"""
28
28
struct JumpSystem{U <: ArrayPartition } <: AbstractSystem
29
29
"""
30
- The jumps of the system. Allowable types are `ConstantRateJump`,
30
+ The jumps of the system. Allowable types are `ConstantRateJump`,
31
31
`VariableRateJump`, `MassActionJump`.
32
32
"""
33
33
eqs:: U
@@ -48,7 +48,7 @@ function JumpSystem(eqs, iv, states, ps; systems = JumpSystem[],
48
48
49
49
ap = ArrayPartition (MassActionJump[], ConstantRateJump[], VariableRateJump[])
50
50
for eq in eqs
51
- if eq isa MassActionJump
51
+ if eq isa MassActionJump
52
52
push! (ap. x[1 ], eq)
53
53
elseif eq isa ConstantRateJump
54
54
push! (ap. x[2 ], eq)
@@ -63,17 +63,19 @@ function JumpSystem(eqs, iv, states, ps; systems = JumpSystem[],
63
63
end
64
64
65
65
66
- generate_rate_function (js, rate) = build_function (rate, states (js), parameters (js),
67
- independent_variable (js),
68
- expression= Val{false })
66
+ generate_rate_function (js, rate) = ModelingToolkit. eval (
67
+ build_function (rate, states (js), parameters (js),
68
+ independent_variable (js),
69
+ expression= Val{true }))
69
70
70
- generate_affect_function (js, affect, outputidxs) = build_function (affect, states (js),
71
+ generate_affect_function (js, affect, outputidxs) = ModelingToolkit. eval (
72
+ build_function (affect, states (js),
71
73
parameters (js),
72
74
independent_variable (js),
73
- expression= Val{false },
75
+ expression= Val{true },
74
76
headerfun= add_integrator_header,
75
- outputidxs= outputidxs)[2 ]
76
-
77
+ outputidxs= outputidxs)[2 ])
78
+
77
79
function assemble_vrj (js, vrj, statetoid)
78
80
rate = generate_rate_function (js, vrj. rate)
79
81
outputvars = (convert (Variable,affect. lhs) for affect in vrj. affect!)
@@ -124,11 +126,13 @@ end
124
126
125
127
"""
126
128
```julia
127
- function DiffEqBase.DiscreteProblem(sys::AbstractSystem , u0map, tspan,
129
+ function DiffEqBase.DiscreteProblem(sys::JumpSystem , u0map, tspan,
128
130
parammap=DiffEqBase.NullParameters; kwargs...)
129
131
```
130
132
131
- Generates a DiscreteProblem from an AbstractSystem.
133
+ Generates a black DiscreteProblem for a JumpSystem to utilize as its
134
+ solving `prob.prob`. This is used in the case where there are no ODEs
135
+ and no SDEs associated with the system.
132
136
133
137
Continuing the example from the [`JumpSystem`](@ref) definition:
134
138
```julia
@@ -139,11 +143,13 @@ tspan = (0.0, 250.0)
139
143
dprob = DiscreteProblem(js, u₀map, tspan, parammap)
140
144
```
141
145
"""
142
- function DiffEqBase. DiscreteProblem (sys:: AbstractSystem , u0map, tspan:: Tuple ,
146
+ function DiffEqBase. DiscreteProblem (sys:: JumpSystem , u0map, tspan:: Tuple ,
143
147
parammap= DiffEqBase. NullParameters (); kwargs... )
144
148
u0 = varmap_to_vars (u0map, states (sys))
145
149
p = varmap_to_vars (parammap, parameters (sys))
146
- f = (du,u,p,t) -> du.= u # identity function to make syms works
150
+ # identity function to make syms works
151
+ # EvalFunc because we know that the jump functions are generated via eval
152
+ f = DiffEqBase. EvalFunc (DiffEqBase. DISCRETE_INPLACE_DEFAULT)
147
153
df = DiscreteFunction (f, syms= Symbol .(states (sys)))
148
154
DiscreteProblem (df, u0, tspan, p; kwargs... )
149
155
end
@@ -164,19 +170,19 @@ sol = solve(jprob, SSAStepper())
164
170
"""
165
171
function DiffEqJump. JumpProblem (js:: JumpSystem , prob, aggregator; kwargs... )
166
172
167
- statetoid = Dict (convert (Variable,state) => i for (i,state) in enumerate (states (js)))
173
+ statetoid = Dict (convert (Variable,state) => i for (i,state) in enumerate (states (js)))
168
174
eqs = equations (js)
169
175
invttype = typeof (1 / prob. tspan[2 ])
170
176
171
177
# handling parameter substition and empty param vecs
172
178
p = (prob. p == DiffEqBase. NullParameters ()) ? Operation[] : prob. p
173
179
parammap = map ((x,y)-> Pair (x (),y), parameters (js), p)
174
180
subber = substituter (first .(parammap), last .(parammap))
175
-
181
+
176
182
majs = MassActionJump[assemble_maj (js, j, statetoid, subber, invttype) for j in eqs. x[1 ]]
177
183
crjs = ConstantRateJump[assemble_crj (js, j, statetoid) for j in eqs. x[2 ]]
178
184
vrjs = VariableRateJump[assemble_vrj (js, j, statetoid) for j in eqs. x[3 ]]
179
- ((prob isa DiscreteProblem) && ! isempty (vrjs)) && error (" Use continuous problems such as an ODEProblem or a SDEProblem with VariableRateJumps" )
185
+ ((prob isa DiscreteProblem) && ! isempty (vrjs)) && error (" Use continuous problems such as an ODEProblem or a SDEProblem with VariableRateJumps" )
180
186
jset = JumpSet (Tuple (vrjs), Tuple (crjs), nothing , isempty (majs) ? nothing : majs)
181
187
182
188
if needs_vartojumps_map (aggregator) || needs_depgraph (aggregator)
207
213
# ## Functions to determine which states are modified by a given jump
208
214
function modified_states! (mstates, jump:: Union{ConstantRateJump,VariableRateJump} , sts)
209
215
for eq in jump. affect!
210
- st = eq. lhs
216
+ st = eq. lhs
211
217
(st. op in sts) && push! (mstates, st)
212
218
end
213
219
end
0 commit comments