Skip to content

Commit b110683

Browse files
committed
add sensitivity examples in ConstantTPH2Combustion.ipynb
1 parent 462a29c commit b110683

1 file changed

Lines changed: 52 additions & 10 deletions

File tree

iJulia/ConstantTPH2Combustion.ipynb

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"metadata": {},
77
"outputs": [],
88
"source": [
9-
"using DifferentialEquations\n",
9+
"using DiffEqBase\n",
10+
"using Sundials\n",
11+
"using DiffEqSensitivity\n",
1012
"using PyPlot\n",
1113
"using ReactionMechanismSimulator"
1214
]
@@ -38,7 +40,7 @@
3840
"source": [
3941
"ig = IdealGas(spcs,rxns,name=\"gas\"); #Define the phase (how species thermodynamic and kinetic properties calculated)\n",
4042
"initialconds = Dict([\"T\"=>1000.0,\"P\"=>1e5,\"H2\"=>0.67,\"O2\"=>0.33]); #Set simulation Initial Temp and Pressure\n",
41-
"domain,y0 = ConstantTPDomain(phase=ig,initialconds=initialconds;sensitivity=true); #Define the domain (encodes how system thermodynamic properties calculated)"
43+
"domain,y0,p = ConstantTPDomain(phase=ig,initialconds=initialconds); #Define the domain (encodes how system thermodynamic properties calculated)"
4244
]
4345
},
4446
{
@@ -47,7 +49,7 @@
4749
"metadata": {},
4850
"outputs": [],
4951
"source": [
50-
"react = Reactor(domain,y0,(0.0,150.1)); #Create the reactor object"
52+
"react = Reactor(domain,y0,(0.0,150.1);p=p); #Create the reactor object"
5153
]
5254
},
5355
{
@@ -58,7 +60,7 @@
5860
},
5961
"outputs": [],
6062
"source": [
61-
"sol = solve(react.ode,DifferentialEquations.CVODE_BDF(),abstol=1e-20,reltol=1e-12); #solve the ode associated with the reactor"
63+
"sol = solve(react.ode,CVODE_BDF(),abstol=1e-20,reltol=1e-12); #solve the ode associated with the reactor"
6264
]
6365
},
6466
{
@@ -85,7 +87,7 @@
8587
"metadata": {},
8688
"outputs": [],
8789
"source": [
88-
"plotmaxratesensitivity(bsol,\"H2\")"
90+
"plotrops(bsol,\"OH\",tol=0.01)"
8991
]
9092
},
9193
{
@@ -94,7 +96,8 @@
9496
"metadata": {},
9597
"outputs": [],
9698
"source": [
97-
"plotmaxthermosensitivity(bsol,\"H2\")"
99+
"#Adjoint Sensitivities\n",
100+
"dps = getadjointsensitivities(bsol,\"H2\",CVODE_BDF();sensealg=InterpolatingAdjoint(autojacvec=ReverseDiffVJP(true)),abstol=1e-8,reltol=1e-6)"
98101
]
99102
},
100103
{
@@ -103,7 +106,46 @@
103106
"metadata": {},
104107
"outputs": [],
105108
"source": [
106-
"plotrops(bsol,\"OH\",tol=0.01)"
109+
"plotthermoadjointsensitivities(bsol,\"H2\",dps)"
110+
]
111+
},
112+
{
113+
"cell_type": "code",
114+
"execution_count": null,
115+
"metadata": {},
116+
"outputs": [],
117+
"source": [
118+
"plotrateadjointsensitivities(bsol,\"H2\",dps)"
119+
]
120+
},
121+
{
122+
"cell_type": "code",
123+
"execution_count": null,
124+
"metadata": {},
125+
"outputs": [],
126+
"source": [
127+
"#Forward Sensitivities\n",
128+
"react2 = Reactor(domain,y0,(0.0,150.1);p=p,forwardsensitivities=true);\n",
129+
"sol2 = solve(react2.ode,CVODE_BDF(),abstol=1e-20,reltol=1e-6);\n",
130+
"bsol2 = Simulation(sol,domain);"
131+
]
132+
},
133+
{
134+
"cell_type": "code",
135+
"execution_count": null,
136+
"metadata": {},
137+
"outputs": [],
138+
"source": [
139+
"plotmaxthermoforwardsensitivity(bsol2,\"H2\")"
140+
]
141+
},
142+
{
143+
"cell_type": "code",
144+
"execution_count": null,
145+
"metadata": {},
146+
"outputs": [],
147+
"source": [
148+
"plotmaxrateforwardsensitivity(bsol2,\"H2\")"
107149
]
108150
},
109151
{
@@ -120,15 +162,15 @@
120162
"lastKernelId": null
121163
},
122164
"kernelspec": {
123-
"display_name": "Julia 1.1.0",
165+
"display_name": "Julia 1.3.0",
124166
"language": "julia",
125-
"name": "julia-1.1"
167+
"name": "julia-1.3"
126168
},
127169
"language_info": {
128170
"file_extension": ".jl",
129171
"mimetype": "application/julia",
130172
"name": "julia",
131-
"version": "1.1.0"
173+
"version": "1.3.0"
132174
}
133175
},
134176
"nbformat": 4,

0 commit comments

Comments
 (0)