@@ -27,10 +27,10 @@ tf = 100000.0
2727# generate ModelingToolkit ODEs
2828@timeit to "Parse Network" prnbng = loadrxnetwork(BNGNetwork(), joinpath(datadir, "bcr.net"))
2929show(to)
30- rn = prnbng.rn
30+ rn = complete( prnbng.rn)
3131obs = [eq.lhs for eq in observed(rn)]
3232
33- @timeit to "Create ODESys" osys = convert(ODESystem, rn)
33+ @timeit to "Create ODESys" osys = complete( convert(ODESystem, rn) )
3434show(to)
3535
3636tspan = (0.,tf)
@@ -56,12 +56,12 @@ As compiling the ODE derivative functions has in the past taken longer than
5656running a simulation, we first force compilation by evaluating these functions
5757one time.
5858```julia
59- u = ModelingToolkit.varmap_to_vars(nothing, species(rn); defaults=ModelingToolkit.defaults(rn))
59+ u = oprob.u0
6060du = copy(u)
61- p = ModelingToolkit.varmap_to_vars(nothing, parameters(rn); defaults=ModelingToolkit.defaults(rn))
61+ p = oprob.p
6262@timeit to "ODE rhs Eval1" oprob.f(du,u,p,0.)
63- @timeit to "ODE rhs Eval2" oprob .f(du,u,p,0.)
64- sparsejacprob.f(du,u,p,0. )
63+ @timeit to "ODE rhs spjac Eval1" sparsejacprob .f(du,u,p,0.)
64+ show(to )
6565```
6666
6767We also time the ODE rhs function with BenchmarkTools as it is more accurate
@@ -99,18 +99,6 @@ test_sol = TestSolution(sol);
9999default(legendfontsize=7,framestyle=:box,gridalpha=0.3,gridlinewidth=2.5)
100100```
101101
102- #### Declares a plotting helper function
103-
104- ```julia
105- function plot_settings(wp)
106- times = vcat(map(wp -> wp.times, wp.wps)...)
107- errors = vcat(map(wp -> wp.errors, wp.wps)...)
108- xlimit = 10 .^ (floor(log10(minimum(errors))), ceil(log10(maximum(errors))))
109- ylimit = 10 .^ (floor(log10(minimum(times))), ceil(log10(maximum(times))))
110- return xlimit,ylimit
111- end
112- ```
113-
114102#### Declare pre-conditioners
115103```julia
116104using IncompleteLU, LinearAlgebra
@@ -189,8 +177,7 @@ wp = WorkPrecisionSet([oprob,oprob_sparse,sparsejacprob],abstols,reltols,setups;
189177 saveat=tf/10000.,appxsol=[test_sol,test_sol,test_sol],maxiters=Int(1e6),numruns=1)
190178
191179names = ["lsoda" "CVODE_BDF" "CVODE_BDF (LapackDense)" "CVODE_BDF (GMRES)" "CVODE_BDF (GMRES, iLU)" "CVODE_BDF (KLU, sparse jac)"]
192- xlimit,ylimit = plot_settings(wp)
193- plot(wp;label=names,xlimit=xlimit,ylimit=ylimit)
180+ plot(wp;label=names)
194181```
195182
196183## Work-Precision Diagrams (various Julia solvers)
@@ -213,8 +200,7 @@ wp = WorkPrecisionSet(oprob,abstols,reltols,setups;error_estimate=:l2,
213200 saveat=tf/10000.,appxsol=test_sol,maxiters=Int(1e6),numruns=1)
214201
215202names = ["TRBDF2" "QNDF" "FBDF" "KenCarp4"]
216- xlimit,ylimit = plot_settings(wp)
217- plot(wp;label=names,xlimit=xlimit,ylimit=ylimit)
203+ plot(wp;label=names)
218204```
219205
220206#### Declare solvers (using GMRES linear solver).
@@ -235,8 +221,7 @@ wp = WorkPrecisionSet(oprob,abstols,reltols,setups;error_estimate=:l2,
235221 saveat=tf/10000.,appxsol=test_sol,maxiters=Int(1e6),numruns=1)
236222
237223names = ["TRBDF2 (GMRES)" "QNDF (GMRES)" "FBDF (GMRES)" "KenCarp4 (GMRES)"]
238- xlimit,ylimit = plot_settings(wp)
239- plot(wp;label=names,xlimit=xlimit,ylimit=ylimit)
224+ plot(wp;label=names)
240225```
241226
242227#### Declare solvers (using GMRES linear solver, with pre-conditioner).
@@ -257,8 +242,7 @@ wp = WorkPrecisionSet(sparsejacprob,abstols,reltols,setups;error_estimate=:l2,
257242 saveat=tf/10000.,appxsol=test_sol,maxiters=Int(1e6),numruns=1)
258243
259244names = ["TRBDF2 (GMRES, iLU)" "QNDF (GMRES, iLU)" "FBDF (GMRES, iLU)" "KenCarp4 (GMRES, iLU)"]
260- xlimit,ylimit = plot_settings(wp)
261- plot(wp;label=names,xlimit=xlimit,ylimit=ylimit)
245+ plot(wp;label=names)
262246```
263247
264248#### Declare solvers (using sparse jacobian)
@@ -282,8 +266,7 @@ wp = WorkPrecisionSet(sparsejacprob,abstols,reltols,setups;error_estimate=:l2,
282266 saveat=tf/10000.,appxsol=test_sol,maxiters=Int(1e6),numruns=1)
283267
284268names = ["TRBDF2 (KLU, sparse jac)" "QNDF (KLU, sparse jac)" "FBDF (KLU, sparse jac)" "KenCarp4 (KLU, sparse jac)"]
285- xlimit,ylimit = plot_settings(wp)
286- plot(wp;label=names,xlimit=xlimit,ylimit=ylimit)
269+ plot(wp;label=names)
287270```
288271
289272## Summary of results
@@ -312,9 +295,7 @@ wp = WorkPrecisionSet([oprob,oprob_sparse,sparsejacprob],abstols,reltols,setups;
312295names = ["CVODE_BDF (GMRES, iLU)" "QNDF (GMRES, iLU)" "FBDF (GMRES, iLU)" "QNDF (KLU, sparse jac)" "FBDF (KLU, sparse jac)" "KenCarp4 (KLU, sparse jac)"]
313296colors = [:green :deepskyblue1 :dodgerblue2 :royalblue2 :slateblue3 :lightskyblue]
314297markershapes = [:octagon :hexagon :rtriangle :pentagon :ltriangle :star5]
315- xlimit,ylimit = plot_settings(wp)
316- xlimit = xlimit .* [0.95,1/0.95]; ylimit = ylimit .* [0.95,1/0.95];
317- plot(wp;label=names,left_margin=10Plots.mm,right_margin=10Plots.mm,xlimit=xlimit,ylimit=ylimit,xticks=[1e-3,1e-2,1e-1,1e0,1e1,1e2,1e3],yticks=[1e0,1e1,1e2,1e3],color=colors,markershape=markershapes,legendfontsize=15,tickfontsize=15,guidefontsize=15, legend=:topright, lw=20, la=0.8, markersize=20,markerstrokealpha=1.0, markerstrokewidth=1.5, gridalpha=0.3, gridlinewidth=7.5,size=(1100,1000))
298+ plot(wp;label=names,left_margin=10Plots.mm,right_margin=10Plots.mm,xticks=[1e-3,1e-2,1e-1,1e0,1e1,1e2,1e3],yticks=[1e0,1e1,1e2,1e3],color=colors,markershape=markershapes,legendfontsize=15,tickfontsize=15,guidefontsize=15, legend=:topright, lw=20, la=0.8, markersize=20,markerstrokealpha=1.0, markerstrokewidth=1.5, gridalpha=0.3, gridlinewidth=7.5,size=(1100,1000))
318299```
319300
320301```julia, echo = false
0 commit comments