Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from isaacsas/massaction-rate-updates
Expanding MassActionJump input options
- Loading branch information
Showing
4 changed files
with
209 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,48 @@ | ||
############################################################################### | ||
# Stochiometry for a given reaction is a vector of pairs mapping species id to | ||
# Stochiometry for a given reaction is a vector of pairs mapping species id to | ||
# stochiometric coefficient. | ||
############################################################################### | ||
|
||
@inbounds @fastmath function evalrxrate(speciesvec::AbstractVector{T}, rateconst, | ||
stochmat::AbstractVector{Pair{S,V}})::typeof(rateconst) where {T,S,V} | ||
@fastmath function evalrxrate(speciesvec::AbstractVector{T}, rateconst, | ||
stochmat::AbstractVector{Pair{S,V}})::typeof(rateconst) where {T,S,V} | ||
val = one(T) | ||
|
||
for specstoch in stochmat | ||
@inbounds for specstoch in stochmat | ||
specpop = speciesvec[specstoch[1]] | ||
val *= specpop | ||
for k = 2:specstoch[2] | ||
@inbounds for k = 2:specstoch[2] | ||
specpop -= one(specpop) | ||
val *= specpop | ||
end | ||
end | ||
|
||
return rateconst * val | ||
rateconst * val | ||
end | ||
|
||
@inline @inbounds @fastmath function executerx!(speciesvec::AbstractVector{T}, | ||
net_stoch::AbstractVector{Pair{S,V}}) where {T,S,V} | ||
for specstoch in net_stoch | ||
@inline @fastmath function executerx!(speciesvec::AbstractVector{T}, | ||
net_stoch::AbstractVector{Pair{S,V}}) where {T,S,V} | ||
@inbounds for specstoch in net_stoch | ||
speciesvec[specstoch[1]] += specstoch[2] | ||
end | ||
nothing | ||
end | ||
|
||
|
||
@inbounds function scalerates!(unscaled_rates, stochmat::Vector{Vector{Pair{S,T}}}) where {S,T} | ||
for i in eachindex(unscaled_rates) | ||
function scalerates!(unscaled_rates::Vector{U}, stochmat::Vector{Vector{Pair{S,T}}}) where {U,S,T} | ||
@inbounds for i in eachindex(unscaled_rates) | ||
coef = one(T) | ||
for specstoch in stochmat[i] | ||
@inbounds for specstoch in stochmat[i] | ||
coef *= factorial(specstoch[2]) | ||
end | ||
unscaled_rates[i] /= coef | ||
end | ||
nothing | ||
end | ||
|
||
function scalerate(unscaled_rate::U, stochmat::Vector{Pair{S,T}}) where {U <: Number, S, T} | ||
coef = one(T) | ||
@inbounds for specstoch in stochmat | ||
coef *= factorial(specstoch[2]) | ||
end | ||
unscaled_rate /= coef | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters