Skip to content

Commit 2b5b6bf

Browse files
TorkelEisaacsas
andcommitted
Update src/spatial_reaction_systems/spatial_ODE_systems.jl
Co-authored-by: Sam Isaacson <[email protected]>
1 parent 5fe0ab2 commit 2b5b6bf

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/spatial_reaction_systems/spatial_ODE_systems.jl

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,18 @@ function (f_func::LatticeTransportODEf)(du, u, p, t)
151151
f_func.ofunc((@view du[idxs]), (@view u[idxs]), vert_i_ps, t)
152152
end
153153

154-
# Updates for spatial reactions.
155-
for (s_idx, (s, rates)) in enumerate(f_func.transport_rates) # Loops through all species with transportation. Here: s_idx is its index among the species with transportations. s is its index among all species (in the species(::ReactionSystem) vector). rates is its rates values (vector length 1 if uniform, else same length as the number of edges).
156-
for vert_i in 1:(f_func.num_verts) # Loops through all vertexes.
157-
du[get_index(vert_i, s, f_func.num_species)] -= f_func.leaving_rates[s_idx, vert_i] *
158-
u[get_index(vert_i, s,
159-
f_func.num_species)] # Finds the leaving rate of this species in this vertex. Updates the du vector at that vertex/species combination with the corresponding rate (leaving rate times concentration).
154+
# s_idx is species index among transport species, s is index among all species
155+
# rates are the species' transport rates
156+
for (s_idx, (s, rates)) in enumerate(f_func.transport_rates)
157+
# rate for leaving vert_i
158+
for vert_i in 1:(f_func.num_verts)
159+
idx = get_index(vert_i, s, f_func.num_species)
160+
du[idx] -= f_func.leaving_rates[s_idx, vert_i] * u[idx]
160161
end
161-
for (e_idx, e) in f_func.enum_edges # Loops through all edges.
162-
du[get_index(e.dst, s, f_func.num_species)] += get_component_value(rates, e_idx) *
163-
u[get_index(e.src, s,
164-
f_func.num_species)] # For the destination of this edge, we want to add the influx term to du. This is ["rates" value for this edge]*[the species concentration in the source vertex].
162+
# add rates for entering a given vertex via an incoming edge
163+
for (e_idx, e) in f_func.enum_edges
164+
idx = get_index(e.dst, s, f_func.num_species)
165+
du[idx] += get_component_value(rates, e_idx) * u[idx]
165166
end
166167
end
167168
end

0 commit comments

Comments
 (0)