Skip to content

Commit 4341962

Browse files
committed
reduce more lines.
1 parent 2a81fca commit 4341962

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

src/spatial_reaction_systems/spatial_ODE_systems.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
### Spatial ODE Functor Structures ###
22

3-
# Functor structure containing the information for the forcing function of a spatial ODE with spatial movement on a lattice.
3+
# Functor with information for the forcing function of a spatial ODE with spatial movement on a lattice.
44
struct LatticeTransportODEf{Q,R,S,T}
55
"""The ODEFunction of the (non-spatial) reaction system which generated this function."""
66
ofunc::Q
@@ -65,7 +65,7 @@ struct LatticeTransportODEf{Q,R,S,T}
6565
end
6666
end
6767

68-
# Functor structure containing the information for the forcing function of a spatial ODE with spatial movement on a lattice.
68+
# Functor with information for the Jacobian function of a spatial ODE with spatial movement on a lattice.
6969
struct LatticeTransportODEjac{Q,R,S,T}
7070
"""The ODEFunction of the (non-spatial) reaction system which generated this function."""
7171
ofunc::Q
@@ -123,7 +123,7 @@ function DiffEqBase.ODEProblem(lrs::LatticeReactionSystem, u0_in, tspan,
123123
end
124124

125125
# Converts potential symmaps to varmaps
126-
# Parameter conversion complicated since the vertex and edge parameters may be given in a tuple, or in a common vector.
126+
# Vertex and edge parameters may be given in a tuple, or in a common vector, making parameter case complicated.
127127
u0_in = symmap_to_varmap(lrs, u0_in)
128128
p_in = (p_in isa Tuple{<:Any,<:Any}) ?
129129
(symmap_to_varmap(lrs, p_in[1]),symmap_to_varmap(lrs, p_in[2])) :

src/spatial_reaction_systems/spatial_reactions.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ function check_spatial_reaction_validity(rs::ReactionSystem, tr::TransportReacti
9595
if any([isequal(tr.species, s) && !isequivalent(tr.species, s) for s in species(rs)])
9696
error("A transport reaction used a species, $(tr.species), with metadata not matching its lattice reaction system. Please fetch this species from the reaction system and used in transport reaction creation.")
9797
end
98-
if any([isequal(rs_p, tr_p) && !equivalent_metadata(rs_p, tr_p) for rs_p in parameters(rs), tr_p in Symbolics.get_variables(tr.rate)])
98+
if any([isequal(rs_p, tr_p) && !equivalent_metadata(rs_p, tr_p)
99+
for rs_p in parameters(rs), tr_p in Symbolics.get_variables(tr.rate)])
99100
error("A transport reaction used a parameter with metadata not matching its lattice reaction system. Please fetch this parameter from the reaction system and used in transport reaction creation.")
100101
end
101102

src/spatial_reaction_systems/utility.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ end
9595
# If the input is given in a map form, the vector needs sorting and the first value removed.
9696
# The creates a Vector{Vector{Value}} or Vector{value} form, which is then again sent to lattice_process_input for reprocessing.
9797
function lattice_process_input(input::Vector{<:Pair}, syms::Vector{BasicSymbolic{Real}}, args...)
98-
isempty(setdiff(first.(input), syms)) || error("Some input symbols are not recognised: $(setdiff(first.(input), syms)).")
98+
if !isempty(setdiff(first.(input), syms))
99+
error("Some input symbols are not recognised: $(setdiff(first.(input), syms)).")
100+
end
99101
sorted_input = sort(input; by = p -> findfirst(isequal(p[1]), syms))
100102
return lattice_process_input(last.(sorted_input), syms, args...)
101103
end
@@ -148,7 +150,7 @@ function duplicate_trans_params!(edge_ps::Vector{Vector{Float64}}, lrs::LatticeR
148150

149151
# A vector where we will put the edge parameters new values.
150152
# Has the correct length (the number of directed edges in the lattice).
151-
new_vals = Vector{Float64}(undef,lrs.num_edges)
153+
new_vals = Vector{Float64}(undef, lrs.num_edges)
152154
# As we loop through the edges of the di-graph, this keeps track of each edge's index in the original graph.
153155
original_edge_count = 0
154156
for edge in edges(lrs.lattice) # For each edge.
@@ -219,9 +221,11 @@ end
219221

220222
# Creates a map, taking each species (with transportation) to its transportation rate.
221223
# The species is represented by its index (in species(lrs).
222-
# If the rate is uniform across all edges, the vector will be length 1 (with this value), else there will be a separate value for each edge.
224+
# If the rate is uniform across all edges, the vector will be length 1 (with this value),
225+
# else there will be a separate value for each edge.
223226
# Pair{Int64, Vector{T}}[] is required in case vector is empty (otherwise it becomes Any[], causing type error later).
224-
function make_sidxs_to_transrate_map(vert_ps::Vector{Vector{Float64}}, edge_ps::Vector{Vector{T}}, lrs::LatticeReactionSystem) where T
227+
function make_sidxs_to_transrate_map(vert_ps::Vector{Vector{Float64}}, edge_ps::Vector{Vector{T}},
228+
lrs::LatticeReactionSystem) where T
225229
transport_rates_speciesmap = compute_all_transport_rates(vert_ps, edge_ps, lrs)
226230
return Pair{Int64, Vector{T}}[
227231
speciesmap(lrs.rs)[spat_rates[1]] => spat_rates[2] for spat_rates in transport_rates_speciesmap

0 commit comments

Comments
 (0)