Skip to content

Commit 8e7ff16

Browse files
computegi and comutehor changes
1 parent fe7cec0 commit 8e7ff16

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/simple_regular_solve.jl

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,33 @@ end
8383
function compute_hor(nu)
8484
hor = zeros(Int, size(nu, 2))
8585
for j in 1:size(nu, 2)
86-
hor[j] = sum(abs.(nu[:, j])) > maximum(abs.(nu[:, j])) ? 2 : 1
86+
order = sum(abs(stoich) for stoich in nu[:, j] if stoich < 0; init=0)
87+
if order > 3
88+
error("Reaction $j has order $order, which is not supported (maximum order is 3).")
89+
end
90+
hor[j] = order
8791
end
8892
return hor
8993
end
9094

9195
function compute_gi(u, nu, hor, i)
92-
max_order = 1.0
96+
max_gi = 1
9397
for j in 1:size(nu, 2)
94-
if abs(nu[i, j]) > 0
95-
max_order = max(max_order, float(hor[j]))
98+
if nu[i, j] < 0 # Species i is a substrate
99+
if hor[j] == 1
100+
max_gi = max(max_gi, 1)
101+
elseif hor[j] == 2 || hor[j] == 3
102+
stoich = abs(nu[i, j])
103+
if stoich >= 2
104+
gi = 2 / stoich + 1 / (stoich - 1)
105+
max_gi = max(max_gi, ceil(Int, gi))
106+
elseif stoich == 1
107+
max_gi = max(max_gi, hor[j])
108+
end
109+
end
96110
end
97111
end
98-
return max_order
112+
return max_gi
99113
end
100114

101115
function compute_tau_explicit(u, rate_cache, nu, hor, p, t, epsilon, rate, dtmin)

0 commit comments

Comments
 (0)