Skip to content

Commit 56d5f86

Browse files
committed
save progress
1 parent 115b966 commit 56d5f86

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

src/spatial_reaction_systems/spatial_ODE_systems.jl

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ struct LatticeTransportODEf{S,T}
1717
"""
1818
mtk_ps
1919
"""
20+
Work in progress.
21+
"""
22+
p_setters
23+
"""
2024
The non-spatial `ReactionSystem` which was used to create the `LatticeReactionSystem` contain
2125
a set of parameters (either identical to, or a sub set of, `parameters(lrs)`). This vector
2226
contain the indexes of the non-spatial system's parameters in `parameters(lrs)`. These are
@@ -77,7 +81,9 @@ struct LatticeTransportODEf{S,T}
7781
nonspatial_rs_p_idxs = subset_indexes_of(parameters(reactionsystem(lrs)), parameters(lrs))
7882

7983
# WIP.
80-
mtk_ps = ModelingToolkit.MTKParameters(complete(convert(ODESystem, reactionsystem(lrs))), [e[1] => e[2][1] for e in vert_ps])
84+
nonspatial_osys = complete(convert(ODESystem, reactionsystem(lrs)))
85+
mtk_ps = MT.MTKParameters(nonspatial_osys, [e[1] => e[2][1] for e in vert_ps])
86+
p_setters = [MT.setp(nonspatial_osys, p) for p in parameters(nonspatial_osys)]
8187

8288
# Computes the indexes of the vertex parameters in the vector of parameters.
8389
# Input `vert_ps` is a vector map taking each parameter symbolic to its value (potentially a
@@ -97,7 +103,7 @@ struct LatticeTransportODEf{S,T}
97103
# Declares `work_ps` (used as storage during computation) and the edge iterator.
98104
work_ps = zeros(length(parameters(lrs)))
99105
edge_iterator = Catalyst.edge_iterator(lrs)
100-
new{S,T}(ofunc, num_verts(lrs), num_species(lrs), vert_p_idxs, edge_p_idxs, mtk_ps,
106+
new{S,T}(ofunc, num_verts(lrs), num_species(lrs), vert_p_idxs, edge_p_idxs, mtk_ps, p_setters,
101107
nonspatial_rs_p_idxs, vert_ps, work_ps, v_ps_idx_types, transport_rates,
102108
t_rate_idx_types, leaving_rates, edge_iterator)
103109
end
@@ -120,6 +126,10 @@ struct LatticeTransportODEjac{R,S,T}
120126
"""
121127
mtk_ps
122128
"""
129+
Work in progress.
130+
"""
131+
p_setters
132+
"""
123133
The non-spatial `ReactionSystem` which was used to create the `LatticeReactionSystem` contain
124134
a set of parameters (either identical to, or a sub set of, `parameters(lrs)`). This vector
125135
contain the indexes of the non-spatial system's parameters in `parameters(lrs)`. These are
@@ -157,7 +167,9 @@ struct LatticeTransportODEjac{R,S,T}
157167
nonspatial_rs_p_idxs = subset_indexes_of(parameters(reactionsystem(lrs)), parameters(lrs))
158168

159169
# WIP.
160-
mtk_ps = ModelingToolkit.MTKParameters(complete(convert(ODESystem, reactionsystem(lrs))), [e[1] => e[2][1] for e in vert_ps])
170+
nonspatial_osys = complete(convert(ODESystem, reactionsystem(lrs)))
171+
mtk_ps = MT.MTKParameters(nonspatial_osys, [e[1] => e[2][1] for e in vert_ps])
172+
p_setters = [MT.setp(nonspatial_osys, p) for p in parameters(nonspatial_osys)]
161173

162174
# Input `vert_ps` is a vector map taking each parameter symbolic to its value (potentially a
163175
# vector). This vector is already sorted according to the order of the parameters. Here, we extract
@@ -167,7 +179,7 @@ struct LatticeTransportODEjac{R,S,T}
167179
work_ps = zeros(length(parameters(lrs)))
168180
v_ps_idx_types = map(vp -> length(vp) == 1, vert_ps)
169181
new{R,S,typeof(jac_transport)}(ofunc, num_verts(lrs), num_species(lrs) , vert_p_idxs,
170-
edge_p_idxs, mtk_ps, nonspatial_rs_p_idxs, vert_ps,
182+
edge_p_idxs, mtk_ps, p_setters, nonspatial_rs_p_idxs, vert_ps,
171183
work_ps, v_ps_idx_types, sparse, jac_transport)
172184
end
173185
end
@@ -344,7 +356,7 @@ function (f_func::LatticeTransportODEf)(du, u, p, t)
344356
update_work_vert_ps!(f_func, p, vert_i)
345357

346358
# Evaluate reaction contributions to du at vert_i.
347-
f_func.ofunc((@view du[idxs]), (@view u[idxs]), nonspatial_ps(f_func), t)
359+
f_func.ofunc((@view du[idxs]), (@view u[idxs]), f_func.mtk_ps, t)
348360
end
349361

350362
# s_idx is the species index among transport species, s is the index among all species.
@@ -372,7 +384,7 @@ function (jac_func::LatticeTransportODEjac)(J, u, p, t)
372384
for vert_i in 1:(jac_func.num_verts)
373385
idxs = get_indexes(vert_i, jac_func.num_species)
374386
update_work_vert_ps!(jac_func, p, vert_i)
375-
jac_func.ofunc.jac((@view J[idxs, idxs]), (@view u[idxs]), nonspatial_ps(jac_func), t)
387+
jac_func.ofunc.jac((@view J[idxs, idxs]), (@view u[idxs]), jac_func.mtk_ps, t)
376388
end
377389

378390
# Updates for the spatial reactions (adds the Jacobian values from the transportation reactions).

src/spatial_reaction_systems/utility.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,14 @@ function update_work_vert_ps!(lt_ode_func, all_ps::Vector{T}, vert::Int64) where
287287
return update_work_vert_ps!(lt_ode_func.work_ps, lt_ode_func.vert_p_idxs, all_ps, vert, lt_ode_func.v_ps_idx_types)
288288
end
289289

290+
# Input is either a LatticeTransportODEf or LatticeTransportODEjac function (which fields we pass on).
291+
function update_work_vert_ps!(lt_ode_func, all_ps::Vector{T}, vert::Int64) where {T}
292+
for (setp, (idx, loc_type)) in zip(lt_ode_func.p_setters, enumerate(lt_ode_func.v_ps_idx_types))
293+
p_val = (loc_type ? all_ps[lt_ode_func.vert_p_idxs[idx]][1] : all_ps[lt_ode_func.vert_p_idxs[idx]][vert])
294+
setp(lt_ode_func.mtk_ps, p_val)
295+
end
296+
end
297+
290298
# Fetches the parameter values that currently are in the work parameter vector and which
291299
# corresponds to the parameters of the non-spatial `ReactionSystem` stored in the `ReactionSystem`.
292300
function nonspatial_ps(lt_ode_func)

0 commit comments

Comments
 (0)