Skip to content

Commit 9fb6da1

Browse files
committed
a different fix
1 parent 7628ddd commit 9fb6da1

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/massaction_rates.jl

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# stochiometric coefficient.
44
###############################################################################
55

6-
@inline function num_substrate_combos(speciesvec::AbstractVector{T}, rxidx,
7-
majump::MassActionJump) where {T}
6+
@inline function evalrxrate(speciesvec::AbstractVector{T}, rxidx,
7+
majump::MassActionJump{U})::R where {T <: Integer, R, U <: AbstractVector{R}}
88
val = one(T)
99
@inbounds for specstoch in majump.reactant_stoch[rxidx]
1010
specpop = speciesvec[specstoch[1]]
@@ -14,20 +14,26 @@
1414
val *= specpop
1515
end
1616
end
17-
18-
return val
19-
end
2017

21-
@inline function evalrxrate(speciesvec::AbstractVector{T}, rxidx,
22-
majump::MassActionJump{U})::R where {T <: Integer, R, U <: AbstractVector{R}}
23-
val = num_substrate_combos(speciesvec, rxidx, majump)
2418
@inbounds return val * majump.scaled_rates[rxidx]
2519
end
2620

2721
@inline function evalrxrate(speciesvec::AbstractVector{T}, rxidx,
2822
majump::MassActionJump{U})::R where {T <: Real, R, U <: AbstractVector{R}}
29-
val = num_substrate_combos(speciesvec, rxidx, majump)
30-
@inbounds return abs(val) * majump.scaled_rates[rxidx]
23+
val = one(T)
24+
@inbounds for specstoch in majump.reactant_stoch[rxidx]
25+
specpop = speciesvec[specstoch[1]]
26+
val *= specpop
27+
@inbounds for k in 2:specstoch[2]
28+
specpop -= one(specpop)
29+
val *= specpop
30+
end
31+
# we need to check the smallest rate law term is positive
32+
# i.e. for an order k reaction: x - k + 1 > 0
33+
(specpop <= 0) && return zero(R)
34+
end
35+
36+
@inbounds return val * majump.scaled_rates[rxidx]
3137
end
3238

3339

0 commit comments

Comments
 (0)