Reactions at the sites of a graph or a Cartesian grid and hops of the
species between neighboring sites, as in JumpProcesses.jl.
CartesianGrid(dims) (or CartesianGridRej(dims), or
CartesianGridRej(dimension, linear_size)) is a grid with one, two or
three dimensions whose sites are numbered in column major order; a graph
is given as a list of neighbor index vectors or as a symmetric adjacency
matrix. num_sites(), neighbors() and outdegree() query either.
Usage
CartesianGridRej(dims, linear_size = NULL)
CartesianGrid(dims)
num_sites(spatial_system)
neighbors(spatial_system, site)
outdegree(spatial_system, site)
SpatialMassActionJump(
uniform_rates = NULL,
spatial_rates = NULL,
reactant_stoch,
net_stoch,
scale_rates = TRUE,
useiszero = TRUE
)
NSM()
DirectCRDirect()
flatten_spatial(jumps, prob, spatial_system, hopping_constants)Arguments
- dims
Side lengths of the grid.
- linear_size
With
linear_size,dimsis the number of dimensions of a hypercube grid.- spatial_system
A grid or a graph.
- site
A site index.
- uniform_rates, spatial_rates
Reaction rate constants.
- reactant_stoch, net_stoch
Stoichiometry per reaction.
- scale_rates
Divide the rates by the factorials of the reactant stoichiometry.
- useiszero
Treat a single reactant entry with species 0 as no reactant.
- jumps
A
SpatialMassActionJumporMassActionJump.- prob
A
DiscreteProblemwith a species by sites initial matrix.- hopping_constants
Hopping constants, see Details.
Value
A grid, a jump, an aggregator, a number or neighbor vector, or (for
flatten_spatial()) a list with prob and jumps.
Details
SpatialMassActionJump(uniform_rates, spatial_rates, reactant_stoch, net_stoch) holds mass action reactions whose rates are the same at all
sites (uniform_rates, a vector) or depend on the site (spatial_rates,
a matrix with one row per reaction and one column per site); uniform
reactions come first. The stoichiometry refers to species by index, as for
MassActionJump(); a plain MassActionJump has uniform rates.
JumpProblem(prob, NSM(), jumps, hopping_constants = , spatial_system = )
with prob = DiscreteProblem(u0, tspan, p) and u0 a species by sites
matrix builds the spatial problem; SSAStepper() solves it with the next
subvolume method NSM() or with DirectCRDirect(). The solution holds
the state in column major order; matrix(sol$u[[k]], nspecies) is the
species by sites matrix. hopping_constants is one of
a vector
D(speciesshops to each neighbor with rateD[s]),a species by sites matrix
D(rateD[s, i]from sitei),a species by sites matrix of lists, each element the vector of rates to the neighbors of the site (
D[[s, i]][j]),list(D, L)withDa vector or a species by sites matrix andLa list with, for each site, the vector of factors for its neighbors (rateD[s] L[[i]][j]orD[s, i] L[[i]][j]).
flatten_spatial(jumps, prob, spatial_system, hopping_constants) returns
the equivalent non spatial problem: a DiscreteProblem with one unknown
per species and site and mass action jumps for the reactions at each site
and for each hop, for any aggregator (JumpProcesses' flatten).
Examples
grid <- CartesianGrid(c(3, 3))
neighbors(grid, 1)
#> [1] 2 4
u0 <- matrix(0, 1, 9); u0[1, 5] <- 100
jp <- JumpProblem(DiscreteProblem(u0, c(0, 1)), NSM(),
SpatialMassActionJump(0.1, NULL, list(list(c(1, 1))), list(list(c(1, -1)))),
hopping_constants = 1, spatial_system = grid)
sol <- solve(jp, SSAStepper(), seed = 1)
matrix(tail(sol$u, 1)[[1]], 1)
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
#> [1,] 11 13 7 12 9 10 8 12 9