Skip to content

Commit 2f66602

Browse files
computegi and comutehor changes
1 parent 6e6631c commit 2f66602

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
@@ -84,19 +84,33 @@ end
8484
function compute_hor(nu)
8585
hor = zeros(Int, size(nu, 2))
8686
for j in 1:size(nu, 2)
87-
hor[j] = sum(abs.(nu[:, j])) > maximum(abs.(nu[:, j])) ? 2 : 1
87+
order = sum(abs(stoich) for stoich in nu[:, j] if stoich < 0; init=0)
88+
if order > 3
89+
error("Reaction $j has order $order, which is not supported (maximum order is 3).")
90+
end
91+
hor[j] = order
8892
end
8993
return hor
9094
end
9195

9296
function compute_gi(u, nu, hor, i)
93-
max_order = 1.0
97+
max_gi = 1
9498
for j in 1:size(nu, 2)
95-
if abs(nu[i, j]) > 0
96-
max_order = max(max_order, float(hor[j]))
99+
if nu[i, j] < 0 # Species i is a substrate
100+
if hor[j] == 1
101+
max_gi = max(max_gi, 1)
102+
elseif hor[j] == 2 || hor[j] == 3
103+
stoich = abs(nu[i, j])
104+
if stoich >= 2
105+
gi = 2 / stoich + 1 / (stoich - 1)
106+
max_gi = max(max_gi, ceil(Int, gi))
107+
elseif stoich == 1
108+
max_gi = max(max_gi, hor[j])
109+
end
110+
end
97111
end
98112
end
99-
return max_order
113+
return max_gi
100114
end
101115

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

0 commit comments

Comments
 (0)