You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
functionReactor(domain::T,y0::Array{W,1},tspan::Tuple,interfaces::Z=[];p::X=DiffEqBase.NullParameters(),forwardsensitivities=false,forwarddiff=false,modelingtoolkit=false) where {T<:AbstractDomain,W<:Real,Z<:AbstractArray,X}
19
+
functionReactor(domain::T,y0::Array{T1,1},tspan::Tuple,interfaces::Z=[];p::X=DiffEqBase.NullParameters(),forwardsensitivities=false,forwarddiff=false,modelingtoolkit=false,tau=1e-3) where {T<:AbstractDomain,T1<:Real,Z<:AbstractArray,X}
20
20
dydt(dy::X,y::T,p::V,t::Q) where {X,T,Q,V} =dydtreactor!(dy,y,t,domain,interfaces,p=p)
21
21
jacy!(J::Q2,y::T,p::V,t::Q) where {Q2,T,Q,V} =jacobiany!(J,y,p,t,domain,interfaces,nothing)
22
22
jacyforwarddiff!(J::Q2,y::T,p::V,t::Q) where {Q2,T,Q,V} =jacobianyforwarddiff!(J,y,p,t,domain,interfaces,nothing)
23
23
jacp!(J::Q2,y::T,p::V,t::Q) where {Q2,T,Q,V} =jacobianp!(J,y,p,t,domain,interfaces,nothing)
24
24
jacpforwarddiff!(J::Q2,y::T,p::V,t::Q) where {Q2,T,Q,V} =jacobianpforwarddiff!(J,y,p,t,domain,interfaces,nothing)
25
25
26
+
psetupsundials(p::T1, t::T2, u::T3, du::T4, jok::Bool, jcurPtr::T5, gamma::T6) where {T1,T2,T3,T4,T5,T6} =_psetup(p, t, u, du, jok, jcurPtr, gamma, jacy!, W::SparseMatrixCSC{Float64, Int64}, preccache::Base.RefValue{IncompleteLU.ILUFactorization{Float64, Int64}}, tau::Float64)
precsjulia(W::T1,du::T2,u::T3,p::T4,t::T5,newW::T6,Plprev::T7,Prprev::T8,solverdata::T9) where {T1,T2,T3,T4,T5,T6,T7,T8,T9} =_precsjulia(W,du,u,p,t,newW,Plprev,Prprev,solverdata,tau)
29
+
30
+
# determine worst sparsity
31
+
y0length =length(y0)
32
+
J =spzeros(y0length,y0length)
33
+
jacyforwarddiff!(J,NaN*ones(y0length),p,0.0)
34
+
@. J.nzval =1.0
35
+
sparsity =1.0-length(J.nzval)/(y0length*y0length)
36
+
37
+
# preconditioner caches for Sundials solver
38
+
W =spzeros(y0length,y0length)
39
+
jacyforwarddiff!(W,y0,p,0.0)
40
+
@. W.nzval =-1.0*W.nzval
41
+
idxs =diagind(W)
42
+
@inbounds@views@. W[idxs] = W[idxs] +1
43
+
prectmp =ilu(W, τ = tau)
44
+
preccache =Ref(prectmp)
45
+
26
46
if (forwardsensitivities ||!forwarddiff) && domain isa Union{ConstantTPDomain,ConstantVDomain,ConstantPDomain,ParametrizedTPDomain,ParametrizedVDomain,ParametrizedPDomain,ConstantTVDomain,ParametrizedTConstantVDomain,ConstantTAPhiDomain}
odefcn =ODEFunction(dydt;jac=jacyforwarddiff!,paramjac=jacpforwarddiff!,jac_prototype=float.(J)) #jac_prototype is not needed/used for Sundials solvers but maybe needed for Julia solvers
functionReactor(domains::T,y0s::W,tspan::W2,interfaces::Z=Tuple(),ps::X=DiffEqBase.NullParameters();forwardsensitivities=false,modelingtoolkit=false) where {T<:Tuple,W<:Tuple,Z,X,W2}
82
+
functionReactor(domains::T,y0s::W1,tspan::W2,interfaces::Z=Tuple(),ps::X=DiffEqBase.NullParameters();forwardsensitivities=false,modelingtoolkit=false,tau=1e-3) where {T<:Tuple,W1<:Tuple,Z,X,W2}
59
83
#adjust indexing
60
84
y0 =zeros(sum(length(y) for y in y0s))
61
85
Nvars =0
@@ -140,6 +164,25 @@ function Reactor(domains::T,y0s::W,tspan::W2,interfaces::Z=Tuple(),ps::X=DiffEqB
140
164
jacy!(J::Q2,y::T,p::V,t::Q) where {Q2,T,Q,V} =jacobianyforwarddiff!(J,y,p,t,domains,interfaces,nothing)
141
165
jacp!(J::Q2,y::T,p::V,t::Q) where {Q2,T,Q,V} =jacobianpforwarddiff!(J,y,p,t,domains,interfaces,nothing)
142
166
167
+
psetupsundials(p::T1, t::T2, u::T3, du::T4, jok::Bool, jcurPtr::T5, gamma::T6) where {T1,T2,T3,T4,T5,T6} =_psetup(p, t, u, du, jok, jcurPtr, gamma, jacy!, W::SparseMatrixCSC{Float64, Int64}, preccache::Base.RefValue{IncompleteLU.ILUFactorization{Float64, Int64}}, tau::Float64)
precsjulia(W::T1,du::T2,u::T3,p::T4,t::T5,newW::T6,Plprev::T7,Prprev::T8,solverdata::T9) where {T1,T2,T3,T4,T5,T6,T7,T8,T9} =_precsjulia(W,du,u,p,t,newW,Plprev,Prprev,solverdata,tau)
170
+
171
+
# determine worst sparsity
172
+
y0length =length(y0)
173
+
J =spzeros(y0length,y0length)
174
+
jacy!(J,NaN*ones(y0length),p,0.0)
175
+
@. J.nzval =1.0
176
+
sparsity =1.0-length(J.nzval)/(y0length*y0length)
177
+
178
+
# preconditioner caches for Sundials solver
179
+
W =spzeros(y0length,y0length)
180
+
jacy!(W,y0,p,0.0)
181
+
@. W.nzval =-1.0*W.nzval
182
+
idxs =diagind(W)
183
+
@inbounds@views@. W[idxs] = W[idxs] +1
184
+
prectmp =ilu(W, τ = tau)
185
+
preccache =Ref(prectmp)
143
186
144
187
if forwardsensitivities
145
188
odefcn =ODEFunction(dydt;paramjac=jacp!)
@@ -152,9 +195,13 @@ function Reactor(domains::T,y0s::W,tspan::W2,interfaces::Z=Tuple(),ps::X=DiffEqB
0 commit comments