Skip to content

Commit 58f1b41

Browse files
committed
add test for adjoint and forward sensitivities for ConstantVDomain (rate coefficients not constant)
1 parent 7195855 commit 58f1b41

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

src/TestReactors.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,24 @@ y = sol(t);
116116
ja=jacobiany(y,p,t,domain,[],nothing);
117117
j = jacobianyforwarddiff(y,p,t,domain,[],nothing);
118118
@test all((abs.(ja.-j) .> 1e-4.*abs.(j).+1e-16).==false)
119+
120+
#sensitivities
121+
react = Reactor(domain,y0,(0.0,0.02),p=p) #Create the reactor object
122+
sol = solve(react.ode,CVODE_BDF(),abstol=1e-20,reltol=1e-12); #solve the ode associated with the reactor
123+
sim = Simulation(sol,domain)
124+
dps = getadjointsensitivities(sim,"H2",CVODE_BDF();sensealg=InterpolatingAdjoint(autojacvec=ReverseDiffVJP(false)),abstol=1e-16,reltol=1e-6)
125+
react2 = Reactor(domain,y0,(0.0,0.02);p=p,forwardsensitivities=true)
126+
sol2 = solve(react2.ode,CVODE_BDF(),abstol=1e-16,reltol=1e-6); #solve the ode associated with the reactor
127+
sim2 = Simulation(sol2,domain)
128+
129+
x,dp = extract_local_sensitivities(sol2,0.02);
130+
ind = findfirst(isequal("H2"),sim2.names)
131+
dpvs = [v[ind] for v in dp]
132+
dpvs[length(domain.phase.species)+1:end] .*= domain.p[length(domain.phase.species)+1:end]
133+
dpvs ./= sol2(0.02)[ind]
134+
rerr = (dpvs .- dps')./dpvs
135+
rerr = [isinf(x) ? 0.0 : x for x in rerr]
136+
@test all((abs.(rerr) .> 2e-1).==false)
119137
end;
120138

121139
#Constant P adiabatic Ideal Gas

0 commit comments

Comments
 (0)