@@ -12,10 +12,10 @@ function recast! end
1212Integrate using OrdinaryDiffEq
1313"""
1414function integrate (tspan, df:: F , x0,
15- state, dstate, fout;
16- alg = OrdinaryDiffEq. DP5 (),
17- steady_state = false , tol = 1e-3 , save_everystep = false , saveat= tspan,
18- callback = nothing , kwargs... ) where {F}
15+ state, dstate, fout;
16+ alg = OrdinaryDiffEq. DP5 (),
17+ steady_state = false , tol = 1e-3 , save_everystep = false , saveat= tspan,
18+ callback = nothing , return_problem = false , kwargs... ) where {F}
1919
2020 function df_ (dx, x, p, t)
2121 recast! (state,x)
@@ -42,33 +42,37 @@ function integrate(tspan, df::F, x0,
4242 save_start = false ,
4343 tdir = first (tspan)< last (tspan) ? one (eltype (tspan)) : - one (eltype (tspan)))
4444
45- prob = OrdinaryDiffEq. ODEProblem {true} (df_, x0,(convert (tType, tspan[1 ]),convert (tType, tspan[end ])))
46-
47- if steady_state
48- affect! = function (integrator)
49- ! save_everystep && scb. affect! (integrator,true )
50- OrdinaryDiffEq. terminate! (integrator)
51- end
52- _cb = OrdinaryDiffEq. DiscreteCallback (
53- SteadyStateCondtion (copy (state),tol,state),
54- affect!;
55- save_positions = (false ,false ))
56- cb = OrdinaryDiffEq. CallbackSet (_cb,scb)
57- else
58- cb = scb
59- end
45+ prob = OrdinaryDiffEq. ODEProblem {true} (df_, x0,(convert (tType, tspan[1 ]),convert (tType, tspan[end ])))
46+
47+ if steady_state
48+ affect! = function (integrator)
49+ ! save_everystep && scb. affect! (integrator,true )
50+ OrdinaryDiffEq. terminate! (integrator)
51+ end
52+ _cb = OrdinaryDiffEq. DiscreteCallback (
53+ SteadyStateCondtion (copy (state),tol,state),
54+ affect!;
55+ save_positions = (false ,false ))
56+ cb = OrdinaryDiffEq. CallbackSet (_cb,scb)
57+ else
58+ cb = scb
59+ end
6060
6161 full_cb = OrdinaryDiffEq. CallbackSet (callback,cb)
6262
63- sol = OrdinaryDiffEq. solve (
64- prob,
65- alg;
66- reltol = 1.0e-6 ,
67- abstol = 1.0e-8 ,
68- save_everystep = false , save_start = false ,
69- save_end = false ,
70- callback= full_cb, kwargs... )
71- out. t,out. saveval
63+ if return_problem
64+ return Dict (" out" => out, " prob" => prob, " alg" => alg, " solve_kwargs" => (reltol= 1.0e-6 , abstol= 1.0e-8 , save_everystep= false , save_start= false , save_end= false , callback= full_cb, kwargs... ))
65+ else
66+ sol = OrdinaryDiffEq. solve (
67+ prob,
68+ alg;
69+ reltol= 1.0e-6 ,
70+ abstol= 1.0e-8 ,
71+ save_everystep= false , save_start= false ,
72+ save_end= false ,
73+ callback= full_cb, kwargs... )
74+ return out. t, out. saveval
75+ end
7276end
7377
7478function integrate (tspan, df, x0,
0 commit comments