Skip to content

Commit 4ea5501

Browse files
authored
Merge pull request #37 from ReactionMechanismGenerator/jacobians
Enable manipulation of parameters and reverse mode differentiation
2 parents e522b7d + 523a37b commit 4ea5501

10 files changed

Lines changed: 1320 additions & 305 deletions

File tree

Manifest.toml

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,9 @@ version = "1.4.0"
256256

257257
[[FiniteDiff]]
258258
deps = ["ArrayInterface", "LinearAlgebra", "Requires", "SparseArrays", "StaticArrays"]
259-
git-tree-sha1 = "80becc23db3942d9e5eb8d0d42e725b9c46616f8"
259+
git-tree-sha1 = "43b397bf66d07d113cc2cc012dd2029d336c3894"
260260
uuid = "6a86dc24-6348-571c-b903-95158fe2bd41"
261-
version = "2.5.0"
261+
version = "2.5.1"
262262

263263
[[FixedPointNumbers]]
264264
git-tree-sha1 = "4aaea64dd0c30ad79037084f8ca2b94348e65eaa"
@@ -537,6 +537,18 @@ git-tree-sha1 = "ea172c86745810136d744fc67650d2e2de669c4f"
537537
uuid = "2774e3e8-f4cf-5e23-947b-6d7e65073b56"
538538
version = "4.4.0"
539539

540+
[[NNPACK_jll]]
541+
deps = ["Libdl", "Pkg"]
542+
git-tree-sha1 = "c3d1a616362645754b18e12dbba96ec311b0867f"
543+
uuid = "a6bfbf70-4841-5cb9-aa18-3a8ad3c413ee"
544+
version = "2018.6.22+0"
545+
546+
[[NNlib]]
547+
deps = ["Libdl", "LinearAlgebra", "LoopVectorization", "NNPACK_jll", "Pkg", "Requires", "Statistics"]
548+
git-tree-sha1 = "1d8128735fdf3ab1643dd8bc9499e4b34ccb718d"
549+
uuid = "872c559c-99b0-510c-b3b7-b6c96a88d5cd"
550+
version = "0.7.3"
551+
540552
[[NaNMath]]
541553
git-tree-sha1 = "c84c576296d0e2fbb3fc134d3e09086b3ea617cd"
542554
uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
@@ -679,6 +691,12 @@ git-tree-sha1 = "d37400976e98018ee840e0ca4f9d20baa231dc6b"
679691
uuid = "ae029012-a4dd-5104-9daa-d747884805df"
680692
version = "1.0.1"
681693

694+
[[ReverseDiff]]
695+
deps = ["DiffResults", "DiffRules", "ForwardDiff", "FunctionWrappers", "LinearAlgebra", "MacroTools", "NaNMath", "Random", "SpecialFunctions", "StaticArrays", "Statistics"]
696+
git-tree-sha1 = "d10f33d434e920442cc6e88fdd5bbc8a5b54494f"
697+
uuid = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
698+
version = "1.4.1"
699+
682700
[[Roots]]
683701
deps = ["Printf"]
684702
git-tree-sha1 = "7bd9d7eee602f0413f24c394386a18cb0d515f36"
@@ -702,9 +720,9 @@ version = "0.8.16"
702720

703721
[[SLEEFPirates]]
704722
deps = ["Libdl", "SIMDPirates", "VectorizationBase"]
705-
git-tree-sha1 = "c750d618b7c8268a97e55c70e8c88e56080d30fa"
723+
git-tree-sha1 = "67ae90a18aa8c22bf159318300e765fbd89ddf6e"
706724
uuid = "476501e8-09a2-5ece-8869-fb82de89a1fa"
707-
version = "0.5.4"
725+
version = "0.5.5"
708726

709727
[[SentinelArrays]]
710728
deps = ["Dates", "Random"]
@@ -822,6 +840,12 @@ git-tree-sha1 = "98693daea9bb49aba71eaad6b168b152d2310358"
822840
uuid = "06e1c1a7-607b-532d-9fad-de7d9aa2abac"
823841
version = "0.2.4"
824842

843+
[[Tracker]]
844+
deps = ["Adapt", "DiffRules", "ForwardDiff", "LinearAlgebra", "MacroTools", "NNlib", "NaNMath", "Printf", "Random", "Requires", "SpecialFunctions", "Statistics", "Test"]
845+
git-tree-sha1 = "d8173d93a7b4e74d7ab898874f2a4ca04f0cae1a"
846+
uuid = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c"
847+
version = "0.2.8"
848+
825849
[[TreeViews]]
826850
deps = ["Test"]
827851
git-tree-sha1 = "8d0d7a3fe2f30d6a7f833a5f19f7c7a5b396eae6"

Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
1717
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
1818
PyPlot = "d330b81b-6aea-500a-939a-2ce795aea3ee"
1919
QuartzImageIO = "dca85d43-d64c-5e67-8c65-017450d5d020"
20+
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
2021
SmoothingSplines = "102930c3-cf33-599f-b3b1-9a29a5acab30"
2122
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
2223
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
2324
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
2425
Sundials = "c3572dad-4567-51f8-b174-8c6c989267f4"
2526
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
27+
Tracker = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c"
2628
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
2729
YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"
2830

@@ -39,6 +41,7 @@ Parameters = "<1"
3941
PyCall = "1.91.4"
4042
PyPlot = "2.9.0"
4143
QuartzImageIO = "<1"
44+
ReverseDiff = "<2"
4245
SmoothingSplines = "<1"
4346
SpecialFunctions = "<1"
4447
StaticArrays = "<1"

src/Calculators/Rate.jl

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export AbstractFalloffRate
1313
Ea::Q
1414
unc::P = EmptyRateUncertainty()
1515
end
16-
@inline (arr::Arrhenius)(;T::Q,P::N=0.0,C::S=0.0) where {Q<:Real,N<:Real,S<:Real} = @fastmath arr.A*T^arr.n*exp(-arr.Ea/(R*T))::Q
17-
@inline (arr::Arrhenius)(T::Q;P::N=0.0,C::S=0.0) where {Q<:Real,N<:Real,S<:Real} = @fastmath arr.A*T^arr.n*exp(-arr.Ea/(R*T))::Q
16+
@inline (arr::Arrhenius)(;T::Q,P::N=0.0,C::S=0.0) where {Q<:Real,N<:Real,S<:Real} = @fastmath arr.A*T^arr.n*exp(-arr.Ea/(R*T))
17+
@inline (arr::Arrhenius)(T::Q;P::N=0.0,C::S=0.0) where {Q<:Real,N<:Real,S<:Real} = @fastmath arr.A*T^arr.n*exp(-arr.Ea/(R*T))
1818
export Arrhenius
1919

2020
@with_kw struct PdepArrhenius{T<:Real,Q<:AbstractRateUncertainty,Z<:AbstractRate} <: AbstractRate
@@ -28,10 +28,10 @@ PdepArrhenius(Ps::Array{Q,1},arrs::Array{Z,1}) where {Q<:Real,Z<:AbstractRate} =
2828
inds = getBoundingIndsSorted(P,parr.Ps)::Tuple{Int64,Int64}
2929

3030
if inds[2] == -1
31-
return @inbounds parr.arrs[inds[1]](T=T)::Q
31+
return @inbounds parr.arrs[inds[1]](T=T)
3232
else
33-
@inbounds highk = parr.arrs[inds[2]](T=T)::Q
34-
@inbounds lowk = parr.arrs[inds[1]](T=T)::Q
33+
@inbounds highk = parr.arrs[inds[2]](T=T)
34+
@inbounds lowk = parr.arrs[inds[1]](T=T)
3535
@inbounds Plow = parr.Ps[inds[1]]
3636
@inbounds Phigh = parr.Ps[inds[2]]
3737
return @inbounds @fastmath lowk*10^(log10(P/Plow)/log10(Phigh/Plow)*log10(highk/lowk))
@@ -44,10 +44,10 @@ export PdepArrhenius
4444
unc::Q = EmptyRateUncertainty()
4545
end
4646

47-
@inline function (marr::MultiArrhenius)(;T::Q=nothing,P::R=0.0,C::S=0.0) where {Q<:Real,R<:Real,S<:Real}
47+
@inline function (marr::MultiArrhenius)(;T::Q,P::R=0.0,C::S=0.0) where {Q<:Real,R<:Real,S<:Real}
4848
out = 0.0
4949
for arr in marr.arrs
50-
@fastmath out += arr(T)::Q
50+
@fastmath out += arr(T)
5151
end
5252
return out
5353
end
@@ -58,10 +58,10 @@ export MultiArrhenius
5858
unc::Q = EmptyRateUncertainty()
5959
end
6060

61-
@inline function (parr::MultiPdepArrhenius)(;T::Q=nothing,P::R=0.0,C::S=0.0) where {Q<:Real,R<:Real,S<:Real}
61+
@inline function (parr::MultiPdepArrhenius)(;T::Q,P::R=0.0,C::S=0.0) where {Q<:Real,R<:Real,S<:Real}
6262
out = 0.0
6363
for pdar in parr.parrs
64-
@fastmath out += pdar(T=T,P=P)::Q
64+
@fastmath out += pdar(T=T,P=P)
6565
end
6666
return out
6767
end
@@ -73,7 +73,7 @@ export MultiPdepArrhenius
7373
unc::Q = EmptyRateUncertainty()
7474
end
7575

76-
(tbarr::ThirdBody)(;T::Q=nothing,P::R=0.0,C::S=nothing) where {Q<:Real,R<:Real,S<:Real} = C*(tbarr.arr(T)::Q)
76+
(tbarr::ThirdBody)(;T::Q=nothing,P::R=0.0,C::S=nothing) where {Q<:Real,R<:Real,S<:Real} = C*(tbarr.arr(T))
7777
export ThirdBody
7878

7979
@with_kw struct Lindemann{N<:Integer,K<:AbstractFloat,Q<:AbstractRateUncertainty} <: AbstractFalloffRate
@@ -84,8 +84,8 @@ export ThirdBody
8484
end
8585

8686
@inline function (lnd::Lindemann)(;T::Q=nothing,P::R=0.0,C::S=nothing) where {Q<:Real,R<:Real,S<:Real}
87-
k0 = lnd.arrlow(T=T)::Q
88-
kinf = lnd.arrhigh(T=T)::Q
87+
k0 = lnd.arrlow(T=T)
88+
kinf = lnd.arrhigh(T=T)
8989
@fastmath Pr = k0*C/kinf
9090
return @fastmath kinf*Pr/(1.0+Pr)
9191
end
@@ -102,9 +102,9 @@ export Lindemann
102102
unc::R = EmptyRateUncertainty()
103103
end
104104

105-
@inline function (tr::Troe)(;T::Q=nothing,P::R=0.0,C::S=nothing) where {Q<:Real,R<:Real,S<:Real}
106-
k0 = tr.arrlow(T=T)::Q
107-
kinf = tr.arrhigh(T=T)::Q
105+
@inline function (tr::Troe)(;T::Q,P::R=0.0,C::S=nothing) where {Q<:Real,R<:Real,S<:Real}
106+
k0 = tr.arrlow(T=T)
107+
kinf = tr.arrhigh(T=T)
108108
@fastmath Pr = k0*C/kinf
109109

110110
if tr.T1 == 0.0 && tr.T3 == 0.0
@@ -119,7 +119,7 @@ end
119119
@fastmath c = -0.4-0.67*log10(Fcent)
120120
@fastmath F = 10^(log10(Fcent)/(1+((log10(Pr)+c)/(n-d*(log10(Pr))))^2))
121121
end
122-
return @fastmath kinf*(Pr/(1+Pr))*F::S
122+
return @fastmath kinf*(Pr/(1+Pr))*F
123123
end
124124
export Troe
125125

@@ -200,4 +200,4 @@ end
200200
@inline function getkineticstype(kin::Chebyshev)
201201
return (string(typeof(kin).name),kin.Tmin,kin.Tmax,kin.Pmin,kin.Pmax,size(kin.coefs)) #different opt functions, but always can do
202202
end
203-
export getkineticstype
203+
export getkineticstype

src/Calculators/Ratevec.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using Parameters
2+
using ReverseDiff
3+
using ForwardDiff
24

35
abstract type AbstractRatevec end
46
export AbstractRatevec
@@ -19,8 +21,8 @@ function Arrheniusvec(arrs::T) where {T<:AbstractArray}
1921
end
2022
return Arrheniusvec(A=A,n=n,Ea=Ea)
2123
end
22-
@inline (arr::Arrheniusvec)(;T::Q,P::N=0.0,C::S=0.0) where {Q<:Real,N<:Real,S<:Real} = @fastmath @inbounds arr.A.*exp.(arr.n.*log(T).-arr.Ea.*(1.0/(R*T)))::Array{Q,1}
23-
@inline (arr::Arrheniusvec)(T::Q;P::N=0.0,C::S=0.0) where {Q<:Real,N<:Real,S<:Real} = @fastmath @inbounds arr.A.*exp.(arr.n.*log(T).-arr.Ea.*(1.0/(R*T)))::Array{Q,1}
24+
@inline (arr::Arrheniusvec)(;T::Q,P::N=0.0,C::S=0.0) where {Q<:Real,N<:Real,S<:Real} = @fastmath @inbounds arr.A.*exp.(arr.n.*log(T).-arr.Ea.*(1.0/(R*T)))
25+
@inline (arr::Arrheniusvec)(T::Q;P::N=0.0,C::S=0.0) where {Q<:Real,N<:Real,S<:Real} = @fastmath @inbounds arr.A.*exp.(arr.n.*log(T).-arr.Ea.*(1.0/(R*T)))
2426
export Arrheniusvec
2527

2628
@with_kw struct Chebyshevvec{T<:AbstractArray,Q<:Real,S<:Real,V<:Real,B<:Real} <: AbstractRate
@@ -85,7 +87,7 @@ end
8587
export getredpress
8688

8789
@inline function (ch::Chebyshevvec)(;T::N,P::Q=0.0,C::B=0.0) where {N<:Real,B<:Real,Q<:Real}
88-
k = zeros(size(ch.coefs)[1])
90+
k = zeros(N,size(ch.coefs)[1])
8991
Tred = getredtemp(ch,T)
9092
Pred = getredpress(ch,P)
9193
klen,Tlen,Plen = size(ch.coefs)

src/Calculators/Thermo.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ end
1414
end
1515
export NASApolynomial
1616

17-
@inline function calcHSCpdless(poly::NASApolynomial,T::Float64)
17+
@inline function calcHSCpdless(poly::NASApolynomial,T::X) where {X<:Real}
1818
if length(poly.coefs) != 7
1919
Tpoly0 = T
2020
Tpoly1 = T*T

src/Calculators/Thermovec.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ end
7373
end
7474
export selectPoly
7575

76-
@inline function calcHSCpdless(poly::NASApolynomialvec,T::Float64)
76+
@inline function calcHSCpdless(poly::NASApolynomialvec,T::X) where {X<:Real}
7777
if size(poly.coefs)[1] != 7
7878
Tpoly0 = T
7979
Tpoly1 = T*T
@@ -118,7 +118,7 @@ export selectPoly
118118
return (cpdivR,hdivRT,sdivR)
119119
end
120120

121-
@inline function calcHSCpdless(nasavec::NASAvec,T::Float64)
121+
@inline function calcHSCpdless(nasavec::NASAvec,T::X) where {X<:Real}
122122
poly = selectPoly(nasavec,T)
123123
return calcHSCpdless(poly,T)
124124
end

0 commit comments

Comments
 (0)