Skip to content

Commit 864abb9

Browse files
committed
fix dispatch for symbolic types
1 parent 1f37bfd commit 864abb9

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

src/PhaseState.jl

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ using LinearAlgebra
44
using Tracker
55
using ReverseDiff
66
using RecursiveArrayTools
7+
using ModelingToolkit
78

89
@inline function calcgibbs(ph::U,T::W) where {U<:IdealPhase,W<:Real}
910
return getGibbs.(getfield.(ph.species,:thermo),T)
@@ -181,12 +182,12 @@ export getKcs
181182
Calculates the forward and reverse rate coefficients for a given reaction, phase and state
182183
Maintains diffusion limitations if the phase has diffusionlimited=true
183184
"""
184-
@inline function getkfkrev(rxn::ElementaryReaction,ph::U,T::W1,P::W2,C::W3,N::W4,ns::Q1,Gs::Q2,diffs::Q3,V::W5,phi::W8;kf::W6=-1.0,f::W7=-1.0) where {U<:AbstractPhase,W8,W6,W7,W5,W4,W1,W2,W3<:Real,Q1,Q2,Q3<:AbstractArray}
185+
@inline function getkfkrev(rxn::ElementaryReaction,ph::U,T::W1,P::W2,C::W3,N::W4,ns::Vector{Q1},Gs::Q2,diffs,V::W5,phi::W8;kf::W6=-1.0,f=-1.0) where {U<:AbstractPhase,W8,W6,W5,W4,W1,W2,W3,Q1<:Real,Q2}
185186
if signbit(kf)
186-
if signbit(f)
187-
kf = getkf(rxn,ph,T,P,C,ns,V,phi)
188-
else
187+
if isa(f,Num) || !signbit(f)
189188
kf = getkf(rxn,ph,T,P,C,ns,V,phi)*f
189+
else
190+
kf = getkf(rxn,ph,T,P,C,ns,V,phi)
190191
end
191192
end
192193
Kc = getKc(rxn,ph,T,Gs,phi)
@@ -221,6 +222,41 @@ Maintains diffusion limitations if the phase has diffusionlimited=true
221222
krev *= rxn.reversible
222223
return (kf,krev)
223224
end
225+
226+
@inline function getkfkrev(rxn::ElementaryReaction,ph::U,T::W1,P::W2,C::W3,N::W4,ns::Vector{Q1},Gs::Q2,diffs,V::W5,phi::W8;kf::W6=-1.0,f=-1.0) where {U<:AbstractPhase,W8,W6,W5,W4,W1,W2,W3,Q1<:Num,Q2}
227+
kf = getkf(rxn,ph,T,P,C,ns,V,phi)*f
228+
Kc = getKc(rxn,ph,T,Gs,phi)
229+
@fastmath krev = kf/Kc
230+
if ph.diffusionlimited
231+
if length(rxn.reactants) == 1
232+
if length(rxn.products) > 1
233+
krevdiff = getDiffusiveRate(rxn.products,diffs)
234+
@fastmath krev = krev*krevdiff/(krev+krevdiff)
235+
@fastmath kf = Kc*krev
236+
end
237+
elseif length(rxn.products) == 1
238+
kfdiff = getDiffusiveRate(rxn.reactants,diffs)
239+
@fastmath kf = kf*kfdiff/(kf+kfdiff)
240+
@fastmath krev = kf/Kc
241+
elseif length(rxn.products) == length(rxn.reactants)
242+
kfdiff = getDiffusiveRate(rxn.reactants,diffs)
243+
krevdiff = getDiffusiveRate(rxn.products,diffs)
244+
@fastmath kff = kf*kfdiff/(kf+kfdiff)
245+
@fastmath krevr = krev*krevdiff/(krev+krevdiff)
246+
@fastmath kfr = Kc*krevr
247+
if kff > kfr
248+
kf = kfr
249+
krev = krevr
250+
else
251+
kf = kff
252+
@fastmath krev = kf/Kc
253+
end
254+
end
255+
end
256+
kf *= rxn.forwardable
257+
krev *= rxn.reversible
258+
return (kf,krev)
259+
end
224260
export getkfkrev
225261

226262
@inline function getkfkrevs(phase::U,T::W1,P::W2,C::W3,N::W4,ns::Q1,Gs::Q2,diffs::Q3,V::W5,phi::W7;kfs::W6=nothing) where {U,W7,W6,W5<:Real,W1<:Real,W2<:Real,W3,W4,Q1<:AbstractArray,Q2,Q3<:AbstractArray}

0 commit comments

Comments
 (0)