Skip to content

Commit 96157b4

Browse files
committed
Add test for ConstantTPDomain reactor with interfaces
1 parent 923783c commit 96157b4

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

src/TestReactors.jl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,46 @@ rerr = [isinf(x) ? 0.0 : x for x in rerr]
124124
@test all((abs.(rerr) .> 1e-1).==false)
125125
end;
126126

127+
#Constant T and P Ideal Gas
128+
@testset "Test constant T and P reactor with interfaces simulation" begin
129+
#Define the phase (how species thermodynamic and kinetic properties calculated)
130+
initialconds = Dict(["T"=>1000.0,"P"=>1e5,"H2"=>0.67,"O2"=>0.33]) #Set simulation Initial Temp and Pressure
131+
domain,y0,p = ConstantTPDomain(phase=ig,initialconds=initialconds) #Define the domain (encodes how system thermodynamic properties calculated)
132+
133+
interfaces = [Inlet(domain,Dict{String,Float64}("H2"=>0.67,"O2"=>0.33,"T"=>1000.0,"P"=>1e5),x->0.001),
134+
Outlet(domain,x->0.001)]
135+
136+
react = Reactor(domain,y0,(0.0,150.11094),interfaces;p=p) #Create the reactor object
137+
sol = solve(react.ode,CVODE_BDF(),abstol=1e-20,reltol=1e-12); #solve the ode associated with the reactor
138+
sim = Simulation(sol,domain,interfaces);
139+
140+
#analytic jacobian vs. ForwardDiff jacobian
141+
t = 20.44002454;
142+
y = sol(t)
143+
ja = jacobiany(y,p,t,domain,interfaces,nothing);
144+
j = jacobianyforwarddiff(y,p,t,domain,interfaces,nothing);
145+
@test all((abs.(ja.-j) .> 1e-4.*abs.(j).+1e-16).==false)
146+
147+
jpa = jacobianp(y,p,t,domain,interfaces,nothing);
148+
jp = jacobianpforwarddiff(y,p,t,domain,interfaces,nothing);
149+
@test all((abs.(jpa.-jp) .> 1e-4.*abs.(jp).+1e-16).==false)
150+
151+
#sensitivities
152+
dps = getadjointsensitivities(sim,"H2",CVODE_BDF(linear_solver=:GMRES);sensealg=InterpolatingAdjoint(autojacvec=ReverseDiffVJP(true)),abstol=1e-16,reltol=1e-6)
153+
react2 = Reactor(domain,y0,(0.0,150.11094),interfaces;p=p,forwardsensitivities=true)
154+
sol2 = solve(react2.ode,CVODE_BDF(linear_solver=:GMRES),abstol=1e-21,reltol=1e-7); #solve the ode associated with the reactor
155+
sim2 = Simulation(sol2,domain,interfaces)
156+
157+
x,dp = extract_local_sensitivities(sol2,150.11094);
158+
ind = findfirst(isequal("H2"),sim2.names)
159+
dpvs = [v[ind] for v in dp]
160+
dpvs[length(domain.phase.species)+1:end] .*= domain.p[length(domain.phase.species)+1:end]
161+
dpvs ./= sol2(150.11094)[ind]
162+
rerr = (dpvs .- dps')./dpvs
163+
rerr = [isinf(x) ? 0.0 : x for x in rerr]
164+
@test all((abs.(rerr) .> 1e-1).==false)
165+
end;
166+
127167
#Constant V adiabatic Ideal Gas
128168
#uses superminimal.yml mechanism
129169
@testset "Constant volume adiabatic reactor simulation" begin

0 commit comments

Comments
 (0)