Skip to content

Commit 48d9375

Browse files
committed
add jacobianp! for ConstantPDomain and ParametrizedPDomain
1 parent ddd8ec5 commit 48d9375

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

src/Domain.jl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,6 +2232,46 @@ function jacobianp!(jacp::Q,y::U,p::W,t::Z,domain::D,interfaces::Q3,colorvec::Q2
22322232
end
22332233
end
22342234

2235+
function jacobianp!(jacp::Q,y::U,p::W,t::Z,domain::D,interfaces::Q3,colorvec::Q2=nothing) where {Q3<:AbstractArray,Q2,Q<:AbstractArray,U<:AbstractArray,W,Z<:Real,D<:Union{ConstantPDomain,ParametrizedPDomain}}
2236+
jacp.=0.0
2237+
ns,cs,T,P,V,C,N,mu,kfs,krevs,Hs,Us,Gs,diffs,Cvave,cpdivR = calcthermo(domain,y,t,p)
2238+
2239+
Nspcs = length(cs)
2240+
Nrxns = size(domain.rxnarray)[2]
2241+
2242+
dydt = zeros(size(y))
2243+
addreactionratecontributions!(dydt,domain.rxnarray,cs,kfs,krevs)
2244+
dydt .*= V
2245+
2246+
jacobianpnsderiv!(jacp,y,p,t,domain,domain.rxnarray,cs,T,V,kfs,krevs,Nspcs,Nrxns)
2247+
2248+
@fastmath Cpave = Cvave+R
2249+
@simd for i in 1:Nspcs
2250+
@views @fastmath @inbounds jacp[domain.indexes[3],i] = -(dot(Hs,jacp[domain.indexes[1]:domain.indexes[2],i])+dydt[i])/(N*Cpave) #divide by V to cancel ωV to ω
2251+
@views @fastmath @inbounds jacp[domain.indexes[4],i] = sum(jacp[domain.indexes[1]:domain.indexes[2],i])*R*T/P + jacp[domain.indexes[3],i]*V/T
2252+
end
2253+
2254+
@simd for i in Nspcs+1:Nspcs+Nrxns
2255+
@views @fastmath @inbounds jacp[domain.indexes[3],i] = -(dot(Hs,jacp[domain.indexes[1]:domain.indexes[2],i]))/(N*Cpave) #divide by V to cancel ωV to ω
2256+
@views @fastmath @inbounds jacp[domain.indexes[4],i] = sum(jacp[domain.indexes[1]:domain.indexes[2],i])*R*T/P + jacp[domain.indexes[3],i]*V/T
2257+
end
2258+
2259+
@simd for ind in domain.constantspeciesinds
2260+
@inbounds jacp[ind,:] .= 0.
2261+
end
2262+
2263+
@simd for inter in interfaces
2264+
if isa(inter,Inlet) && domain == inter.domain
2265+
flow = inter.F(t)
2266+
for i in 1:Nspcs
2267+
ddGidTdt = flow*(- ns[i]/N)/(N*Cpave)
2268+
jacp[domain.indexes[3],i] += ddGidTdt
2269+
jacp[domain.indexes[4],i] += ddGidTdt*V/T
2270+
end
2271+
end
2272+
end
2273+
end
2274+
22352275
function getreactionindices(ig::Q) where {Q<:AbstractPhase}
22362276
arr = zeros(Int64,(6,length(ig.reactions)))
22372277
for (i,rxn) in enumerate(ig.reactions)

0 commit comments

Comments
 (0)