Skip to content

Commit

Permalink
format update
Browse files Browse the repository at this point in the history
  • Loading branch information
TorkelE committed Jul 9, 2024
1 parent a98f4be commit c70e716
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
8 changes: 4 additions & 4 deletions src/spatial_reaction_systems/lattice_jump_systems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ function DiffEqBase.DiscreteProblem(lrs::LatticeReactionSystem, u0_in, tspan,
# vert_ps values are vectors. Here, index (i) is a parameter's value in vertex i.
# edge_ps values are sparse matrices. Here, index (i,j) is a parameter's value in the edge from vertex i to vertex j.
# Uniform vertex/edge parameters store only a single value (a length 1 vector, or size 1x1 sparse matrix).
vert_ps, edge_ps = lattice_process_p(p_in, vertex_parameters(lrs), edge_parameters(lrs),
lrs)
vert_ps, edge_ps = lattice_process_p(p_in, vertex_parameters(lrs),
edge_parameters(lrs), lrs)

# Returns a DiscreteProblem (which basically just stores the processed input).
return DiscreteProblem(u0, tspan, [vert_ps; edge_ps], args...; kwargs...)
end

# Builds a spatial JumpProblem from a DiscreteProblem containing a `LatticeReactionSystem`.
function JumpProcesses.JumpProblem(lrs::LatticeReactionSystem, dprob, aggregator,args...;
combinatoric_ratelaws = get_combinatoric_ratelaws(reactionsystem(lrs)),
function JumpProcesses.JumpProblem(lrs::LatticeReactionSystem, dprob, aggregator, args...;
combinatoric_ratelaws = get_combinatoric_ratelaws(reactionsystem(lrs)),
name = nameof(reactionsystem(lrs)), kwargs...)
# Error checks.
if !isnothing(dprob.f.sys)
Expand Down
13 changes: 7 additions & 6 deletions src/spatial_reaction_systems/lattice_reaction_systems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ struct LatticeReactionSystem{Q, R, S, T} <: MT.AbstractTimeDependentSystem
edge_iterator::T

function LatticeReactionSystem(rs::ReactionSystem{Q}, spatial_reactions::Vector{R},
lattice::S, num_verts::Int64, num_edges::Int64, edge_iterator::T) where {Q, R, S, T}
lattice::S, num_verts::Int64, num_edges::Int64,
edge_iterator::T) where {Q, R, S, T}
# Error checks.
if !(R <: AbstractSpatialReaction)
throw(ArgumentError("The second argument must be a vector of AbstractSpatialReaction subtypes."))
Expand Down Expand Up @@ -121,7 +122,7 @@ end

# Creates a LatticeReactionSystem from a CartesianGrid lattice (cartesian grid) or a Boolean Array
# lattice (masked grid). These two are quite similar, so much code can be reused in a single interface.
function LatticeReactionSystem(rs, srs, lattice::GridLattice{N, T};
function LatticeReactionSystem(rs, srs, lattice::GridLattice{N, T};
diagonal_connections = false) where {N, T}
# Error checks.
(N > 3) && error("Grids of higher dimension than 3 is currently not supported.")
Expand All @@ -144,7 +145,7 @@ function LatticeReactionSystem(rs, srs, lattice::GridLattice{N, T};
edge_iterator = Vector{Pair{Int64, Int64}}(undef, num_edges)
for (flat_idx, grid_idx) in enumerate(flat_to_grid_idx)
for neighbour_grid_idx in get_neighbours(lattice, grid_idx, g_size;
diagonal_connections)
diagonal_connections)
cur_vert += 1
edge_iterator[cur_vert] = flat_idx => grid_to_flat_idx[neighbour_grid_idx...]
end
Expand Down Expand Up @@ -270,7 +271,7 @@ edge_iterator(lrs::LatticeReactionSystem) = getfield(lrs, :edge_iterator)
Returns `true` if all spatial reactions in `lrs` are `TransportReaction`s.
"""
function is_transport_system(lrs::LatticeReactionSystem)
function is_transport_system(lrs::LatticeReactionSystem)
return all(sr -> sr isa TransportReaction, spatial_reactions(lrs))
end

Expand All @@ -296,7 +297,7 @@ has_masked_lattice(lrs::LatticeReactionSystem) = lattice(lrs) isa Array{Bool, N}
Returns `true` if `lrs` was created using a cartesian or masked grid lattice. Otherwise, returns `false`.
"""
function has_grid_lattice(lrs::LatticeReactionSystem)
function has_grid_lattice(lrs::LatticeReactionSystem)
return has_cartesian_lattice(lrs) || has_masked_lattice(lrs)
end

Expand Down Expand Up @@ -445,7 +446,7 @@ function make_edge_p_values(lrs::LatticeReactionSystem, make_edge_p_value::Funct
# If not, then the sparse matrix simply becomes empty in that position.
values[e[1], e[2]] = eps()

values[e[1], e[2]] = make_edge_p_value(flat_to_grid_idx[e[1]],
values[e[1], e[2]] = make_edge_p_value(flat_to_grid_idx[e[1]],
flat_to_grid_idx[e[2]])
end

Expand Down
16 changes: 8 additions & 8 deletions src/spatial_reaction_systems/spatial_ODE_systems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct LatticeTransportODEFunction{P, Q, R, S, T}

function LatticeTransportODEFunction(ofunc::P, ps::Vector{<:Pair},
lrs::LatticeReactionSystem, sparse::Bool,
jac_transport::Union{Nothing, Matrix{S}, SparseMatrixCSC{S, Int64}},
jac_transport::Union{Nothing, Matrix{S}, SparseMatrixCSC{S, Int64}},
transport_rates::Vector{Pair{Int64, SparseMatrixCSC{S, Int64}}}) where {P, S}
# Computes `LatticeTransportODEFunction` functor fields.
heterogeneous_vert_p_idxs = make_heterogeneous_vert_p_idxs(ps, lrs)
Expand All @@ -75,9 +75,9 @@ struct LatticeTransportODEFunction{P, Q, R, S, T}
lrs)

# Creates and returns the `LatticeTransportODEFunction` functor.
new{P, typeof(mtk_ps), typeof(p_setters), S, typeof(jac_transport)}(ofunc,
new{P, typeof(mtk_ps), typeof(p_setters), S, typeof(jac_transport)}(ofunc,
num_verts(lrs), num_species(lrs), heterogeneous_vert_p_idxs, mtk_ps, p_setters,
transport_rates, t_rate_idx_types, leaving_rates, Catalyst.edge_iterator(lrs),
transport_rates, t_rate_idx_types, leaving_rates, Catalyst.edge_iterator(lrs),
jac_transport, sparse, lrs)
end
end
Expand All @@ -88,7 +88,7 @@ end
function make_heterogeneous_vert_p_idxs(ps, lrs)
p_dict = Dict(ps)
return findall((p_dict[p] isa Vector) && (length(p_dict[p]) > 1)
for p in parameters(lrs))
for p in parameters(lrs))
end

# Creates the MTKParameters structure and `p_setters` vector (which are used to manage
Expand All @@ -110,7 +110,7 @@ function make_t_types_and_leaving_rates(transport_rates, lrs)
for (s_idx, tr_pair) in enumerate(transport_rates)
for e in Catalyst.edge_iterator(lrs)
# Updates the exit rate for species s_idx from vertex e.src.
leaving_rates[s_idx, e[1]] += get_transport_rate(tr_pair[2], e,
leaving_rates[s_idx, e[1]] += get_transport_rate(tr_pair[2], e,
t_rate_idx_types[s_idx])
end
end
Expand Down Expand Up @@ -196,8 +196,8 @@ function DiffEqBase.ODEProblem(lrs::LatticeReactionSystem, u0_in, tspan,
# edge_ps values are sparse matrices. Here, index (i,j) is a parameter's value in the edge from vertex i to vertex j.
# Uniform vertex/edge parameters store only a single value (a length 1 vector, or size 1x1 sparse matrix).
# In the `ODEProblem` vert_ps and edge_ps are merged (but for building the ODEFunction, they are separate).
vert_ps, edge_ps = lattice_process_p(p_in, vertex_parameters(lrs), edge_parameters(lrs),
lrs)
vert_ps, edge_ps = lattice_process_p(p_in, vertex_parameters(lrs),
edge_parameters(lrs), lrs)

# Creates the ODEFunction.
ofun = build_odefunction(lrs, vert_ps, edge_ps, jac, sparse, name, include_zero_odes,
Expand Down Expand Up @@ -347,7 +347,7 @@ function rebuild_lat_internals!(lt_ofun::LatticeTransportODEFunction, ps_new,
# Recreates the new parameters on the requisite form.
ps_new = [(length(p) == 1) ? p[1] : p for p in deepcopy(ps_new)]
ps_new = [p => p_val for (p, p_val) in zip(parameters(lrs), deepcopy(ps_new))]
vert_ps, edge_ps = lattice_process_p(ps_new, vertex_parameters(lrs),
vert_ps, edge_ps = lattice_process_p(ps_new, vertex_parameters(lrs),
edge_parameters(lrs), lrs)
ps_new = [vert_ps; edge_ps]

Expand Down

0 comments on commit c70e716

Please sign in to comment.