@@ -160,13 +160,40 @@ function JumpSystem(eqs, iv, unknowns, ps;
160
160
metadata = nothing ,
161
161
gui_metadata = nothing ,
162
162
kwargs... )
163
+
164
+ # variable processing, similar to ODESystem
163
165
name === nothing &&
164
166
throw (ArgumentError (" The `name` keyword must be provided. Please consider using the `@named` macro" ))
165
- eqs = scalarize .(eqs)
167
+ iv′ = value (iv)
168
+ us′ = value .(unknowns)
169
+ ps′ = value .(ps)
170
+ parameter_dependencies, ps′ = process_parameter_dependencies (
171
+ parameter_dependencies, ps′)
172
+ if ! (isempty (default_u0) && isempty (default_p))
173
+ Base. depwarn (
174
+ " `default_u0` and `default_p` are deprecated. Use `defaults` instead." ,
175
+ :JumpSystem , force = true )
176
+ end
177
+ defaults = Dict {Any, Any} (todict (defaults))
178
+ var_to_name = Dict ()
179
+ process_variables! (var_to_name, defaults, us′)
180
+ process_variables! (var_to_name, defaults, ps′)
181
+ process_variables! (var_to_name, defaults, [eq. lhs for eq in parameter_dependencies])
182
+ process_variables! (var_to_name, defaults, [eq. rhs for eq in parameter_dependencies])
183
+ # ! format: off
184
+ defaults = Dict {Any, Any} (value (k) => value (v) for (k, v) in pairs (defaults) if value (v) != = nothing )
185
+ # ! format: on
186
+ isempty (observed) || collect_var_to_name! (var_to_name, (eq. lhs for eq in observed))
187
+
166
188
sysnames = nameof .(systems)
167
189
if length (unique (sysnames)) != length (sysnames)
168
190
throw (ArgumentError (" System names must be unique." ))
169
191
end
192
+
193
+ # equation processing
194
+ # this and the treatment of continuous events are the only part
195
+ # unique to JumpSystems
196
+ eqs = scalarize .(eqs)
170
197
ap = ArrayPartition (MassActionJump[], ConstantRateJump[], VariableRateJump[])
171
198
for eq in eqs
172
199
if eq isa MassActionJump
@@ -179,30 +206,42 @@ function JumpSystem(eqs, iv, unknowns, ps;
179
206
error (" JumpSystem equations must contain MassActionJumps, ConstantRateJumps, or VariableRateJumps." )
180
207
end
181
208
end
182
- if ! (isempty (default_u0) && isempty (default_p))
183
- Base. depwarn (
184
- " `default_u0` and `default_p` are deprecated. Use `defaults` instead." ,
185
- :JumpSystem , force = true )
186
- end
187
- defaults = todict (defaults)
188
- defaults = Dict (value (k) => value (v)
189
- for (k, v) in pairs (defaults) if value (v) != = nothing )
190
209
191
- unknowns, ps = value .(unknowns), value .(ps)
192
- var_to_name = Dict ()
193
- process_variables! (var_to_name, defaults, unknowns)
194
- process_variables! (var_to_name, defaults, ps)
195
- isempty (observed) || collect_var_to_name! (var_to_name, (eq. lhs for eq in observed))
196
210
(continuous_events === nothing ) ||
197
211
error (" JumpSystems currently only support discrete events." )
198
212
disc_callbacks = SymbolicDiscreteCallbacks (discrete_events)
199
- parameter_dependencies, ps = process_parameter_dependencies (parameter_dependencies, ps)
213
+
200
214
JumpSystem {typeof(ap)} (Threads. atomic_add! (SYSTEM_COUNT, UInt (1 )),
201
- ap, value (iv), unknowns , ps, var_to_name, observed, name, description, systems,
215
+ ap, iv′, us′ , ps′ , var_to_name, observed, name, description, systems,
202
216
defaults, connector_type, disc_callbacks, parameter_dependencies,
203
217
metadata, gui_metadata, checks = checks)
204
218
end
205
219
220
+ # #### MTK dispatches for JumpSystems #####
221
+ eqtype_supports_collect_vars (j:: MassActionJump ) = true
222
+ function collect_vars! (unknowns, parameters, j:: MassActionJump , iv; depth = 0 ,
223
+ op = Differential)
224
+ collect_vars! (unknowns, parameters, j. scaled_rates, iv; depth, op)
225
+ for field in (j. reactant_stoch, j. net_stoch)
226
+ for el in field
227
+ collect_vars! (unknowns, parameters, el, iv; depth, op)
228
+ end
229
+ end
230
+ return nothing
231
+ end
232
+
233
+ eqtype_supports_collect_vars (j:: Union{ConstantRateJump, VariableRateJump} ) = true
234
+ function collect_vars! (unknowns, parameters, j:: Union{ConstantRateJump, VariableRateJump} ,
235
+ iv; depth = 0 , op = Differential)
236
+ collect_vars! (unknowns, parameters, j. rate, iv; depth, op)
237
+ for eq in j. affect!
238
+ (eq isa Equation) && collect_vars! (unknowns, parameters, eq, iv; depth, op)
239
+ end
240
+ return nothing
241
+ end
242
+
243
+ # #########################################
244
+
206
245
has_massactionjumps (js:: JumpSystem ) = ! isempty (equations (js). x[1 ])
207
246
has_constantratejumps (js:: JumpSystem ) = ! isempty (equations (js). x[2 ])
208
247
has_variableratejumps (js:: JumpSystem ) = ! isempty (equations (js). x[3 ])
@@ -240,9 +279,8 @@ function assemble_vrj(
240
279
241
280
outputvars = (value (affect. lhs) for affect in vrj. affect!)
242
281
outputidxs = [unknowntoid[var] for var in outputvars]
243
- affect = eval_or_rgf (
244
- generate_affect_function (js, vrj. affect!,
245
- outputidxs); eval_expression, eval_module)
282
+ affect = eval_or_rgf (generate_affect_function (js, vrj. affect!, outputidxs);
283
+ eval_expression, eval_module)
246
284
VariableRateJump (rate, affect)
247
285
end
248
286
@@ -269,9 +307,8 @@ function assemble_crj(
269
307
270
308
outputvars = (value (affect. lhs) for affect in crj. affect!)
271
309
outputidxs = [unknowntoid[var] for var in outputvars]
272
- affect = eval_or_rgf (
273
- generate_affect_function (js, crj. affect!,
274
- outputidxs); eval_expression, eval_module)
310
+ affect = eval_or_rgf (generate_affect_function (js, crj. affect!, outputidxs);
311
+ eval_expression, eval_module)
275
312
ConstantRateJump (rate, affect)
276
313
end
277
314
0 commit comments