|
6 | 6 | "metadata": {}, |
7 | 7 | "outputs": [], |
8 | 8 | "source": [ |
9 | | - "using DifferentialEquations\n", |
| 9 | + "using DiffEqBase\n", |
| 10 | + "using Sundials\n", |
| 11 | + "using DiffEqSensitivity\n", |
10 | 12 | "using PyPlot\n", |
11 | 13 | "using ReactionMechanismSimulator" |
12 | 14 | ] |
|
38 | 40 | "source": [ |
39 | 41 | "ig = IdealGas(spcs,rxns,name=\"gas\"); #Define the phase (how species thermodynamic and kinetic properties calculated)\n", |
40 | 42 | "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)" |
42 | 44 | ] |
43 | 45 | }, |
44 | 46 | { |
|
47 | 49 | "metadata": {}, |
48 | 50 | "outputs": [], |
49 | 51 | "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" |
51 | 53 | ] |
52 | 54 | }, |
53 | 55 | { |
|
58 | 60 | }, |
59 | 61 | "outputs": [], |
60 | 62 | "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" |
62 | 64 | ] |
63 | 65 | }, |
64 | 66 | { |
|
85 | 87 | "metadata": {}, |
86 | 88 | "outputs": [], |
87 | 89 | "source": [ |
88 | | - "plotmaxratesensitivity(bsol,\"H2\")" |
| 90 | + "plotrops(bsol,\"OH\",tol=0.01)" |
89 | 91 | ] |
90 | 92 | }, |
91 | 93 | { |
|
94 | 96 | "metadata": {}, |
95 | 97 | "outputs": [], |
96 | 98 | "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)" |
98 | 101 | ] |
99 | 102 | }, |
100 | 103 | { |
|
103 | 106 | "metadata": {}, |
104 | 107 | "outputs": [], |
105 | 108 | "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\")" |
107 | 149 | ] |
108 | 150 | }, |
109 | 151 | { |
|
120 | 162 | "lastKernelId": null |
121 | 163 | }, |
122 | 164 | "kernelspec": { |
123 | | - "display_name": "Julia 1.1.0", |
| 165 | + "display_name": "Julia 1.3.0", |
124 | 166 | "language": "julia", |
125 | | - "name": "julia-1.1" |
| 167 | + "name": "julia-1.3" |
126 | 168 | }, |
127 | 169 | "language_info": { |
128 | 170 | "file_extension": ".jl", |
129 | 171 | "mimetype": "application/julia", |
130 | 172 | "name": "julia", |
131 | | - "version": "1.1.0" |
| 173 | + "version": "1.3.0" |
132 | 174 | } |
133 | 175 | }, |
134 | 176 | "nbformat": 4, |
|
0 commit comments