Skip to content

Commit 7b48d55

Browse files
refactor: move jumpsystem functions to generalized locations
1 parent 5b7bcf2 commit 7b48d55

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/problems/jumpproblem.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,18 @@ function (ratemap::JumpSysMajParamMapper{U, V, W})(maj::MassActionJump, newparam
151151
nothing
152152
end
153153

154+
# create the initial parameter vector for use in a MassActionJump
155+
function (ratemap::JumpSysMajParamMapper{
156+
U,
157+
V,
158+
W
159+
})(params) where {U <: AbstractArray,
160+
V <: AbstractArray, W}
161+
updateparams!(ratemap, params)
162+
[convert(W, value(substitute(paramexpr, ratemap.subdict)))
163+
for paramexpr in ratemap.paramexprs]
164+
end
165+
154166
##### MTK dispatches for Symbolic jumps #####
155167
eqtype_supports_collect_vars(j::MassActionJump) = true
156168
function collect_vars!(unknowns, parameters, j::MassActionJump, iv; depth = 0,

src/systems/codegen.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,31 @@ function assemble_maj(majv::Vector{U}, unknowntoid, pmapper) where {U <: MassAct
545545
MassActionJump(rs, ns; param_mapper = pmapper, nocopy = true)
546546
end
547547

548+
function numericrstoich(mtrs::Vector{Pair{V, W}}, unknowntoid) where {V, W}
549+
rs = Vector{Pair{Int, W}}()
550+
for (wspec, stoich) in mtrs
551+
spec = value(wspec)
552+
if !iscall(spec) && _iszero(spec)
553+
push!(rs, 0 => stoich)
554+
else
555+
push!(rs, unknowntoid[spec] => stoich)
556+
end
557+
end
558+
sort!(rs)
559+
rs
560+
end
561+
562+
function numericnstoich(mtrs::Vector{Pair{V, W}}, unknowntoid) where {V, W}
563+
ns = Vector{Pair{Int, W}}()
564+
for (wspec, stoich) in mtrs
565+
spec = value(wspec)
566+
!iscall(spec) && _iszero(spec) &&
567+
error("Net stoichiometry can not have a species labelled 0.")
568+
push!(ns, unknowntoid[spec] => stoich)
569+
end
570+
sort!(ns)
571+
end
572+
548573
"""
549574
build_explicit_observed_function(sys, ts; kwargs...) -> Function(s)
550575

0 commit comments

Comments
 (0)