diff --git a/src/spatial_reaction_systems/spatial_Jump_systems.jl b/src/spatial_reaction_systems/spatial_Jump_systems.jl index 37fac4eaf6..0757e2efb9 100644 --- a/src/spatial_reaction_systems/spatial_Jump_systems.jl +++ b/src/spatial_reaction_systems/spatial_Jump_systems.jl @@ -1,5 +1,3 @@ - - ### JumpProblem ### # Builds a spatial DiscreteProblem from a Lattice Reaction System. @@ -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...) # 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.") # 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)) @@ -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) end end - return hopping_constants end + return hopping_constants end # Creates the mass action jumps from a discrete problem and a reaction system.