Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
TorkelE committed Sep 16, 2023
1 parent ab75e6f commit 5e6191a
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions src/spatial_reaction_systems/spatial_Jump_systems.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


### JumpProblem ###

# Builds a spatial DiscreteProblem from a Lattice Reaction System.
Expand All @@ -23,12 +21,14 @@ end
# Builds a spatial JumpProblem from a DiscreteProblem containg a Lattice Reaction System.
function JumpProcesses.JumpProblem(lrs::LatticeReactionSystem, dprob, aggregator, args...; name = nameof(lrs.rs), combinatoric_ratelaws = get_combinatoric_ratelaws(lrs.rs),checks = false, kwargs...)

Check warning on line 22 in src/spatial_reaction_systems/spatial_Jump_systems.jl

View check run for this annotation

Codecov / codecov/patch

src/spatial_reaction_systems/spatial_Jump_systems.jl#L22

Added line #L22 was not covered by tests
# Error checks.
println()
println(dprob.p)
println(dprob.u0)
dprob.p isa Tuple{Vector{Vector{Float64}}, Vector{Vector{Float64}}} || error("Parameters in input DiscreteProblem is of an unexpected type: $(typeof(dprob.p)). Was a LatticeReactionProblem passed into the DiscreteProblem when it was created?")
any(length.(dprob.p[1]) .> 1) && error("Spatial reaction rates are currently not supported in lattice jump simulations.")

Check warning on line 28 in src/spatial_reaction_systems/spatial_Jump_systems.jl

View check run for this annotation

Codecov / codecov/patch

src/spatial_reaction_systems/spatial_Jump_systems.jl#L24-L28

Added lines #L24 - L28 were not covered by tests

# Creates JumpProblem.
hopping_constants = make_hopping_constants(dprob, lrs)
println(typeof(hopping_constants))
___dprob = DiscreteProblem(reshape(dprob.u0, lrs.nS, lrs.nV), dprob.tspan, first.(dprob.p[1]))
majumps_ = make_majumps(___dprob, lrs.rs)
return JumpProblem(___dprob, aggregator, majumps_, hopping_constants = hopping_constants, spatial_system = lrs.lattice, save_positions = (true, false))

Check warning on line 34 in src/spatial_reaction_systems/spatial_Jump_systems.jl

View check run for this annotation

Codecov / codecov/patch

src/spatial_reaction_systems/spatial_Jump_systems.jl#L31-L34

Added lines #L31 - L34 were not covered by tests
Expand All @@ -38,18 +38,15 @@ end
function make_hopping_constants(dprob::DiscreteProblem, lrs::LatticeReactionSystem)
spatial_rates_dict = Dict(compute_all_spatial_rates(dprob.p[1], dprob.p[2], lrs))
all_diff_rates = [haskey(spatial_rates_dict, s) ? spatial_rates_dict[s] : [0.0] for s in species(lrs)]
if false #all(length.(all_diff_rates) .== 1)
return matrix_expand_component_values(all_diff_rates, length(vertices(lrs.lattice)))
else
hopping_constants = [Vector{Float64}() for i in 1:(lrs.nS), j in 1:(lrs.nV)]
for (e_idx, e) in enumerate(edges(lrs.lattice))
for s_idx in 1:(lrs.nS)
push!(hopping_constants[s_idx, e.src],
get_component_value(all_diff_rates[s_idx], e_idx))
hopping_constants = [Vector{Float64}(undef, length(lrs.lattice.fadjlist[j])) for i in 1:(lrs.nS), j in 1:(lrs.nV)]
for (e_idx, e) in enumerate(edges(lrs.lattice)), s_idx in 1:(lrs.nS)
for dst_idx in 1:length(hopping_constants[s_idx, e.src])
if (hopping_constants[s_idx, e.src][dst_idx] == undef)
hopping_constants[s_idx, e.src][dst_idx] = get_component_value(all_diff_rates[s_idx], e_idx)

Check warning on line 45 in src/spatial_reaction_systems/spatial_Jump_systems.jl

View check run for this annotation

Codecov / codecov/patch

src/spatial_reaction_systems/spatial_Jump_systems.jl#L38-L45

Added lines #L38 - L45 were not covered by tests
end
end
return hopping_constants
end
return hopping_constants

Check warning on line 49 in src/spatial_reaction_systems/spatial_Jump_systems.jl

View check run for this annotation

Codecov / codecov/patch

src/spatial_reaction_systems/spatial_Jump_systems.jl#L47-L49

Added lines #L47 - L49 were not covered by tests
end

# Creates the mass action jumps from a discrete problem and a reaction system.
Expand Down

0 comments on commit 5e6191a

Please sign in to comment.