1
+ JumpType = Union{VariableRateJump, ConstantRateJump, MassActionJump}
2
+
3
+ struct JumpSystem <: AbstractSystem
4
+ eqs:: Vector{JumpType}
5
+ iv:: Variable
6
+ states:: Vector{Variable}
7
+ ps:: Vector{Variable}
8
+ name:: Symbol
9
+ systems:: Vector{JumpSystem}
10
+ end
11
+
12
+ function JumpSystem (eqs, iv, states, ps; systems = JumpSystem[],
13
+ name = gensym (:JumpSystem ))
14
+ JumpSystem (eqs, iv, convert .(Variable, states), convert .(Variable, ps), name, systems)
15
+ end
16
+
17
+ function generate_rate_function (js, rate)
18
+ f = striplines (build_function (rate, states (js), parameters (js), independent_variable (js)))
19
+ end
20
+
21
+ function generate_affect_function (js, affect)
22
+ # waiting on integrator build_function form
23
+ end
24
+
25
+ function assemble_vrj (js, vrj)
26
+ rate = generate_rate_function (js, vrj. rate)
27
+ affect = generate_affect_function (js, vrj. affect)
28
+ VariableRateJump (rate, affect)
29
+ end
30
+
31
+ function assemble_crj (js, crj)
32
+ rate = generate_rate_function (js, vrj. rate)
33
+ affect = generate_affect_function (js, vrj. affect)
34
+ ConstantRateJump (rate, affect)
35
+ end
36
+
37
+ function assemble_maj (maj, states_to_idxs, ps_to_idxs; scale_rate= false )
38
+
39
+ # mass action scaled_rates need to be a Number, but
40
+ # operations are numbers, so can't check the type directly
41
+ @assert ! isa (maj. scaled_rates, Union{Operation,Variable})
42
+
43
+ rstype = fieldtypes (eltype (maj. reactant_stoch))[2 ]
44
+ rs = Vector {Pair{valtype(states_to_idxs),rstype}} ()
45
+ for (spec,stoich) in maj. reactant_stoch
46
+ push! (rs, states_to_idxs[spec] => stoich)
47
+ end
48
+
49
+ nstype = fieldtypes (eltype (maj. net_stoch))[2 ]
50
+ ns = Vector {Pair{valtype(states_to_idxs),nstype}} ()
51
+ for (spec,stoich) in maj. net_stoch
52
+ push! (ns, states_to_idxs[spec] => stoich)
53
+ end
54
+
55
+ MassActionJump (maj. scaled_rates, rs, ns, scale_rates= scale_rate)
56
+ end
0 commit comments