Skip to content

Commit 25d0acd

Browse files
committed
recrete get_variables from before
1 parent 580f117 commit 25d0acd

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

src/systems/reaction/reactionsystem.jl

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ end
226226
function var2op(var)
227227
Sym{symtype(var)}(nameof(var.op))
228228
end
229+
function var2op(var::Sym)
230+
var
231+
end
229232

230233
# Calculate the Jump rate law (like ODE, but uses X instead of X(t).
231234
# The former generates a "MethodError: objects of type Int64 are not callable" when trying to solve the problem.
@@ -300,9 +303,10 @@ function ismassaction(rx, rs; rxvars = get_variables(rx.rate),
300303
stateset = Set(states(rs)))
301304
# if no dependencies must be zero order
302305
(length(rxvars)==0) && return true
303-
(haveivdep || rx.only_use_rate) && return false
306+
haveivdep && return false
307+
rx.only_use_rate && return false
304308
@inbounds for i = 1:length(rxvars)
305-
(rxvars[i].op in stateset) && return false
309+
(rxvars[i] in stateset) && return false
306310
end
307311
return true
308312
end
@@ -327,20 +331,24 @@ function assemble_jumps(rs; combinatoric_ratelaws=true)
327331
meqs = MassActionJump[]; ceqs = ConstantRateJump[]; veqs = VariableRateJump[]
328332
stateset = Set(states(rs))
329333
#rates = []; rstoich = []; nstoich = []
330-
rxvars = Operation[]
334+
rxvars = []
331335
ivname = rs.iv.name
332336

333337
isempty(equations(rs)) && error("Must give at least one reaction before constructing a JumpSystem.")
334338
for rx in equations(rs)
335339
empty!(rxvars)
336-
(rx.rate isa Operation) && get_variables!(rxvars, rx.rate)
340+
@show rx.rate
341+
@show typeof(rx.rate)
342+
(rx.rate isa Term) && get_variables!(rxvars, rx.rate)
337343
haveivdep = false
338344
@inbounds for i = 1:length(rxvars)
339-
if rxvars[i].op.name == ivname
345+
if isequal(rxvars[i], rs.iv)
340346
haveivdep = true
341347
break
342348
end
343349
end
350+
@show rx.rate
351+
@show haveivdep
344352
if ismassaction(rx, rs; rxvars=rxvars, haveivdep=haveivdep, stateset=stateset)
345353
push!(meqs, makemajump(rx, combinatoric_ratelaw=combinatoric_ratelaws))
346354
else
@@ -520,11 +528,11 @@ end
520528

521529
# determine which species a reaction depends on
522530
function get_variables!(deps::Set, rx::Reaction, variables)
523-
(rx.rate isa Operation) && get_variables!(deps, rx.rate, variables)
531+
(rx.rate isa Term) && get_variables!(deps, rx.rate, variables)
524532
for s in rx.substrates
525533
push!(deps, s)
526534
end
527-
deps
535+
@show deps
528536
end
529537

530538
# determine which species a reaction modifies

src/utils.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,18 @@ get_variables(e::Num, varlist=nothing) = get_variables(value(e), varlist)
6767
get_variables!(vars, e, varlist=nothing) = vars
6868
get_variables!(vars, e::Sym, varlist=nothing) = push!(vars, e)
6969

70+
is_singleton(e::Term) = e.op isa Sym
71+
is_singleton(e::Sym) = true
72+
is_singleton(e) = false
73+
7074
function get_variables!(vars, e::Term, varlist=nothing)
71-
foreach(x -> get_variables!(vars, x, varlist), e.args)
75+
if is_singleton(e)
76+
if isnothing(varlist) || e in varlist
77+
push!(vars, e)
78+
end
79+
else
80+
foreach(x -> get_variables!(vars, x, varlist), e.args)
81+
end
7282
return (vars isa AbstractVector) ? unique!(vars) : vars
7383
end
7484

0 commit comments

Comments
 (0)