15
15
16
16
# From u0 input, extract their values and store them in the internal format.
17
17
# Internal format: a vector on the form [spec 1 at vert 1, spec 2 at vert 1, ..., spec 1 at vert 2, ...]).
18
- function lattice_process_u0 (u0_in, u0_syms:: Vector{BasicSymbolic{Real}} , lrs:: LatticeReactionSystem )
18
+ function lattice_process_u0 (u0_in, u0_syms:: Vector , lrs:: LatticeReactionSystem )
19
19
# u0 values can be given in various forms. This converts it to a Vector{Pair{Symbolics,...}} form.
20
20
# Top-level vector: Maps each species to its value(s).
21
21
u0 = lattice_process_input (u0_in, u0_syms)
32
32
33
33
# From a parameter input, split it into vertex parameters and edge parameters.
34
34
# Store these in the desired internal format.
35
- function lattice_process_p (ps_in, ps_vertex_syms:: Vector{BasicSymbolic{Real}} ,
36
- ps_edge_syms:: Vector{BasicSymbolic{Real}} , lrs:: LatticeReactionSystem )
35
+ function lattice_process_p (ps_in, ps_vertex_syms:: Vector ,
36
+ ps_edge_syms:: Vector , lrs:: LatticeReactionSystem )
37
37
# p values can be given in various forms. This converts it to a Vector{Pair{Symbolics,...}} form.
38
38
# Top-level vector: Maps each parameter to its value(s).
39
39
# Second-level: Contains either a vector (vertex parameters) or a sparse matrix (edge parameters).
52
52
# The input (parameters or initial conditions) may either be a dictionary (symbolics to value(s).)
53
53
# or a map (in vector or tuple form) from symbolics to value(s). This converts the input to a
54
54
# (Vector) map from symbolics to value(s), where the entries have the same order as `syms`.
55
- function lattice_process_input (input:: Dict{BasicSymbolic{Real} , T} , syms:: Vector{BasicSymbolic{Real}} ) where {T}
55
+ function lattice_process_input (input:: Dict{<:Any , T} , syms:: Vector ) where {T}
56
56
# Error checks
57
57
if ! isempty (setdiff (keys (input), syms))
58
58
error (" You have provided values for the following unrecognised parameters/initial conditions: $(setdiff (keys (input), syms)) ." )
@@ -63,16 +63,15 @@ function lattice_process_input(input::Dict{BasicSymbolic{Real}, T}, syms::Vector
63
63
64
64
return [sym => input[sym] for sym in syms]
65
65
end
66
- function lattice_process_input (input, syms:: Vector{BasicSymbolic{Real}} )
66
+ function lattice_process_input (input, syms:: Vector )
67
67
if ((input isa Vector) || (input isa Tuple)) && all (entry isa Pair for entry in input)
68
68
return lattice_process_input (Dict (input), syms)
69
69
end
70
70
error (" Input parameters/initial conditions have the wrong format ($(typeof (input)) ). These should either be a Dictionary, or a Tuple or a Vector (where each entry is a Pair taking a parameter/species to its value)." )
71
71
end
72
72
73
73
# Splits parameters into vertex and edge parameters.
74
- # function split_parameters(ps::Vector{<: Pair}, p_vertex_syms::Vector, p_edge_syms::Vector)
75
- function split_parameters (ps, p_vertex_syms:: Vector{BasicSymbolic{Real}} , p_edge_syms:: Vector{BasicSymbolic{Real}} )
74
+ function split_parameters (ps, p_vertex_syms:: Vector , p_edge_syms:: Vector )
76
75
vert_ps = [p for p in ps if any (isequal (p[1 ]), p_vertex_syms)]
77
76
edge_ps = [p for p in ps if any (isequal (p[1 ]), p_edge_syms)]
78
77
return vert_ps, edge_ps
@@ -86,7 +85,7 @@ function vertex_value_map(values, lrs::LatticeReactionSystem)
86
85
end
87
86
88
87
# Converts the values for an individual species/vertex parameter to its correct vector form.
89
- function vertex_value_form (values, lrs:: LatticeReactionSystem , sym:: BasicSymbolic{Real} )
88
+ function vertex_value_form (values, lrs:: LatticeReactionSystem , sym:: BasicSymbolic )
90
89
# If the value is a scalar (i.e. uniform across the lattice), return it in vector form.
91
90
(values isa AbstractArray) || (return [values])
92
91
112
111
113
112
# Converts values to the correct vector form for a Cartesian grid lattice.
114
113
function vertex_value_form (values:: AbstractArray , num_verts:: Int64 , lattice:: CartesianGridRej{N,T} ,
115
- sym:: BasicSymbolic{Real} ) where {N,T}
114
+ sym:: BasicSymbolic ) where {N,T}
116
115
if size (values) != lattice. dims
117
116
error (" The values for $sym did not have the same format as the lattice. Expected a $(lattice. dims) array, got one of size $(size (values)) " )
118
117
end
124
123
125
124
# Converts values to the correct vector form for a masked grid lattice.
126
125
function vertex_value_form (values:: AbstractArray , num_verts:: Int64 , lattice:: Array{Bool,T} ,
127
- sym:: BasicSymbolic{Real} ) where {T}
126
+ sym:: BasicSymbolic ) where {T}
128
127
if size (values) != size (lattice)
129
128
error (" The values for $sym did not have the same format as the lattice. Expected a $(size (lattice)) array, got one of size $(size (values)) " )
130
129
end
174
173
# The species is represented by its index (in species(lrs).
175
174
# If the rate is uniform across all edges, the transportation rate will be a size (1,1) sparse matrix.
176
175
# Else, the rate will be a size (num_verts,num_verts) sparse matrix.
177
- function make_sidxs_to_transrate_map (vert_ps:: Vector{Pair{BasicSymbolic{Real} ,Vector{T}}} ,
178
- edge_ps:: Vector{Pair{BasicSymbolic{Real} ,SparseMatrixCSC{T, Int64}}} ,
179
- lrs:: LatticeReactionSystem ) where {T}
176
+ function make_sidxs_to_transrate_map (vert_ps:: Vector{Pair{R ,Vector{T}}} ,
177
+ edge_ps:: Vector{Pair{S ,SparseMatrixCSC{T, Int64}}} ,
178
+ lrs:: LatticeReactionSystem ) where {R,S, T}
180
179
# Creates a dictionary with each parameter's value(s).
181
180
p_val_dict = Dict (vcat (vert_ps, edge_ps))
182
181
203
202
# and the values of all our parameters, compute the transport rate(s).
204
203
# If all parameters that the rate depends on are uniform across all edges, this becomes a length-1 vector.
205
204
# Else it becomes a vector where each value corresponds to the rate at one specific edge.
206
- function compute_transport_rates (s:: BasicSymbolic{Real} , p_val_dict, lrs:: LatticeReactionSystem )
205
+ function compute_transport_rates (s:: BasicSymbolic , p_val_dict, lrs:: LatticeReactionSystem )
207
206
# Find parameters involved in the rate and create a function evaluating the rate law.
208
207
rate_law = get_transport_rate_law (s, lrs)
209
208
relevant_ps = Symbolics. get_variables (rate_law)
228
227
# For a species, retrieve the symbolic expression for its transportation rate
229
228
# (likely only a single parameter, such as `D`, but could be e.g. L*D, where L and D are parameters).
230
229
# If there are several transportation reactions for the species, their sum is used.
231
- function get_transport_rate_law (s:: BasicSymbolic{Real} , lrs:: LatticeReactionSystem )
230
+ function get_transport_rate_law (s:: BasicSymbolic , lrs:: LatticeReactionSystem )
232
231
rates = filter (sr -> isequal (s, sr. species), spatial_reactions (lrs))
233
232
return sum (getfield .(rates, :rate ))
234
233
end
0 commit comments