From 5534a3e02f82bc48a93bc8617e33e5c07f7de314 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Duez?= <42682941+Theozeud@users.noreply.github.com> Date: Sun, 14 Jul 2024 14:26:10 +0200 Subject: [PATCH 1/8] add Nothing Controller --- src/integrators/controllers.jl | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/integrators/controllers.jl b/src/integrators/controllers.jl index 416a6ea99d..092a063965 100644 --- a/src/integrators/controllers.jl +++ b/src/integrators/controllers.jl @@ -1,6 +1,10 @@ abstract type AbstractController end using OrdinaryDiffEq +@inline function accept_step_controller(integrator, ::AbstractController) + return integrator.EEst <= 1 +end + @inline function stepsize_controller!(integrator, alg) stepsize_controller!(integrator, integrator.opts.controller, alg) end @@ -23,6 +27,31 @@ reset_alg_dependent_opts!(controller::AbstractController, alg1, alg2) = nothing DiffEqBase.reinit!(integrator::ODEIntegrator, controller::AbstractController) = nothing +# Standard integral (I) step size controller +""" + NothingController() + +This Controller exists to match the interface when one does not want to use a controller, +basically if you want to keep a fixed time step. +""" +struct NothingController <: AbstractController +end + +@inline function stepsize_controller!(integrator, controller::IController, alg) + nothing +end + +@inline function accept_step_controller(integrator, ::NothingController) + return true +end + +function step_accept_controller!(integrator, ::NothingController, alg, q) + integrator.dt +end + +function step_reject_controller!(integrator, ::NothingController, alg) +end + # Standard integral (I) step size controller """ IController() @@ -308,11 +337,6 @@ end return dt_factor end -# checks whether the controller should accept a step based on the error estimate -@inline function accept_step_controller(integrator, controller::AbstractController) - return integrator.EEst <= 1 -end - @inline function accept_step_controller(integrator, controller::PIDController) return integrator.qold >= controller.accept_safety end From 46959ebe241942c265592a7d9ad9aab06d7419a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Duez?= <42682941+Theozeud@users.noreply.github.com> Date: Sun, 14 Jul 2024 14:26:29 +0200 Subject: [PATCH 2/8] remove loop for intergator.opts.adaptive --- src/integrators/integrator_utils.jl | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/src/integrators/integrator_utils.jl b/src/integrators/integrator_utils.jl index a3f45f456a..a5da642eb7 100644 --- a/src/integrators/integrator_utils.jl +++ b/src/integrators/integrator_utils.jl @@ -222,7 +222,7 @@ function _loopfooter!(integrator) end integrator.last_stepfail = true integrator.accept_step = false - elseif integrator.opts.adaptive + else q = stepsize_controller!(integrator, integrator.alg) integrator.isout = integrator.opts.isoutofdomain(integrator.u, integrator.p, ttmp) integrator.accept_step = (!integrator.isout && @@ -255,24 +255,6 @@ function _loopfooter!(integrator) else # Reject integrator.stats.nreject += 1 end - elseif !integrator.opts.adaptive #Not adaptive - integrator.stats.naccept += 1 - integrator.tprev = integrator.t - integrator.t = if has_tstop(integrator) - tstop = integrator.tdir * first_tstop(integrator) - if abs(ttmp - tstop) < - 100eps(float(integrator.t / oneunit(integrator.t))) * oneunit(integrator.t) - tstop - else - ttmp - end - else - ttmp - end - integrator.last_stepfail = false - integrator.accept_step = true - integrator.dtpropose = integrator.dt - handle_callbacks!(integrator) end if integrator.opts.progress && integrator.iter % integrator.opts.progress_steps == 0 t1, t2 = integrator.sol.prob.tspan From cc8aee86729b7020c5d93544cd0e6b2e5ba6cf61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Duez?= <42682941+Theozeud@users.noreply.github.com> Date: Sun, 14 Jul 2024 14:26:51 +0200 Subject: [PATCH 3/8] change init of controller depending on adaptive option --- src/solve.jl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/solve.jl b/src/solve.jl index 65ddb3fdd1..5aa8caadce 100644 --- a/src/solve.jl +++ b/src/solve.jl @@ -363,8 +363,12 @@ function DiffEqBase.__init( Base.depwarn(message, :solve) end - if controller === nothing - controller = default_controller(_alg, cache, qoldinit, beta1, beta2) + if controller === nothing + if adaptive + controller = default_controller(_alg, cache, qoldinit, beta1, beta2) + else + controller = NothingController() + end end save_end_user = save_end From ff64b872f64008a38761f5a7bda54e70bb7843f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Duez?= <42682941+Theozeud@users.noreply.github.com> Date: Sun, 14 Jul 2024 14:27:44 +0200 Subject: [PATCH 4/8] fix typo --- src/integrators/controllers.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/integrators/controllers.jl b/src/integrators/controllers.jl index 092a063965..5964617fea 100644 --- a/src/integrators/controllers.jl +++ b/src/integrators/controllers.jl @@ -37,7 +37,7 @@ basically if you want to keep a fixed time step. struct NothingController <: AbstractController end -@inline function stepsize_controller!(integrator, controller::IController, alg) +@inline function stepsize_controller!(integrator, controller::NothingController, alg) nothing end From 65c6a78aee9f0cc045804d8f712c684a0770aa88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Duez?= <42682941+Theozeud@users.noreply.github.com> Date: Sun, 14 Jul 2024 15:14:20 +0200 Subject: [PATCH 5/8] formatter --- .../src/OrdinaryDiffEqDefault.jl | 6 ++++-- lib/OrdinaryDiffEqDefault/src/default_alg.jl | 4 ++-- lib/OrdinaryDiffEqVerner/src/alg_utils.jl | 2 +- lib/OrdinaryDiffEqVerner/src/algorithms.jl | 2 +- lib/OrdinaryDiffEqVerner/src/controllers.jl | 2 +- lib/OrdinaryDiffEqVerner/src/interp_func.jl | 2 +- lib/OrdinaryDiffEqVerner/src/interpolants.jl | 14 +++++++------- src/integrators/controllers.jl | 2 +- src/solve.jl | 2 +- 9 files changed, 19 insertions(+), 17 deletions(-) diff --git a/lib/OrdinaryDiffEqDefault/src/OrdinaryDiffEqDefault.jl b/lib/OrdinaryDiffEqDefault/src/OrdinaryDiffEqDefault.jl index ae485281ef..0c09b330b0 100644 --- a/lib/OrdinaryDiffEqDefault/src/OrdinaryDiffEqDefault.jl +++ b/lib/OrdinaryDiffEqDefault/src/OrdinaryDiffEqDefault.jl @@ -1,8 +1,10 @@ module OrdinaryDiffEqDefault using OrdinaryDiffEq: Vern7, Vern8, Vern9, Vern6, Tsit5, Rosenbrock23, Rodas5P, FBDF, - alg_stability_size, beta2_default, beta1_default, AutoSwitchCache, ODEIntegrator, - CompositeAlgorithm, OrdinaryDiffEqAlgorithm, OrdinaryDiffEqMutableCache, AutoAlgSwitch + alg_stability_size, beta2_default, beta1_default, AutoSwitchCache, + ODEIntegrator, + CompositeAlgorithm, OrdinaryDiffEqAlgorithm, + OrdinaryDiffEqMutableCache, AutoAlgSwitch import OrdinaryDiffEq: is_mass_matrix_alg, default_autoswitch import LinearSolve using LinearAlgebra: I, isdiag diff --git a/lib/OrdinaryDiffEqDefault/src/default_alg.jl b/lib/OrdinaryDiffEqDefault/src/default_alg.jl index 9b396d9096..0faed75a0b 100644 --- a/lib/OrdinaryDiffEqDefault/src/default_alg.jl +++ b/lib/OrdinaryDiffEqDefault/src/default_alg.jl @@ -116,6 +116,6 @@ end # hack for the default alg function is_mass_matrix_alg(alg::CompositeAlgorithm{ - <:Any, <:Tuple{Tsit5, Vern7, Rosenbrock23, Rodas5P, FBDF, FBDF}}) + <:Any, <:Tuple{Tsit5, Vern7, Rosenbrock23, Rodas5P, FBDF, FBDF}}) true -end \ No newline at end of file +end diff --git a/lib/OrdinaryDiffEqVerner/src/alg_utils.jl b/lib/OrdinaryDiffEqVerner/src/alg_utils.jl index 2f3a8e6db6..b210d3b8c9 100644 --- a/lib/OrdinaryDiffEqVerner/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqVerner/src/alg_utils.jl @@ -10,4 +10,4 @@ alg_order(alg::Vern9) = 9 alg_stability_size(alg::Vern6) = 4.8553 alg_stability_size(alg::Vern7) = 4.6400 alg_stability_size(alg::Vern8) = 5.8641 -alg_stability_size(alg::Vern9) = 4.4762 \ No newline at end of file +alg_stability_size(alg::Vern9) = 4.4762 diff --git a/lib/OrdinaryDiffEqVerner/src/algorithms.jl b/lib/OrdinaryDiffEqVerner/src/algorithms.jl index 5396373f4a..7786b94e22 100644 --- a/lib/OrdinaryDiffEqVerner/src/algorithms.jl +++ b/lib/OrdinaryDiffEqVerner/src/algorithms.jl @@ -116,4 +116,4 @@ end AutoVern6(alg; lazy = true, kwargs...) = AutoAlgSwitch(Vern6(lazy = lazy), alg; kwargs...) AutoVern7(alg; lazy = true, kwargs...) = AutoAlgSwitch(Vern7(lazy = lazy), alg; kwargs...) AutoVern8(alg; lazy = true, kwargs...) = AutoAlgSwitch(Vern8(lazy = lazy), alg; kwargs...) -AutoVern9(alg; lazy = true, kwargs...) = AutoAlgSwitch(Vern9(lazy = lazy), alg; kwargs...) \ No newline at end of file +AutoVern9(alg; lazy = true, kwargs...) = AutoAlgSwitch(Vern9(lazy = lazy), alg; kwargs...) diff --git a/lib/OrdinaryDiffEqVerner/src/controllers.jl b/lib/OrdinaryDiffEqVerner/src/controllers.jl index a3ed7318d2..e61ba34b6c 100644 --- a/lib/OrdinaryDiffEqVerner/src/controllers.jl +++ b/lib/OrdinaryDiffEqVerner/src/controllers.jl @@ -5,4 +5,4 @@ end @inline function accept_step_controller(integrator, controller::PIDController) return integrator.qold >= controller.accept_safety -end \ No newline at end of file +end diff --git a/lib/OrdinaryDiffEqVerner/src/interp_func.jl b/lib/OrdinaryDiffEqVerner/src/interp_func.jl index 4301446c06..5df0533fec 100644 --- a/lib/OrdinaryDiffEqVerner/src/interp_func.jl +++ b/lib/OrdinaryDiffEqVerner/src/interp_func.jl @@ -28,4 +28,4 @@ function DiffEqBase.interp_summary(::Type{cacheType}, Union{Vern9Cache, Vern9ConstantCache }} dense ? "specialized 9th order lazy interpolation" : "1st order linear" -end \ No newline at end of file +end diff --git a/lib/OrdinaryDiffEqVerner/src/interpolants.jl b/lib/OrdinaryDiffEqVerner/src/interpolants.jl index 05c75f8755..5c1d62db70 100644 --- a/lib/OrdinaryDiffEqVerner/src/interpolants.jl +++ b/lib/OrdinaryDiffEqVerner/src/interpolants.jl @@ -6,15 +6,15 @@ RK_WITH_SPECIAL_INTERPOLATIONS = Union{ } function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::RK_WITH_SPECIAL_INTERPOLATIONS, - idxs, T::Type{Val{D}}, differential_vars) where {D} -throw(DerivativeOrderNotPossibleError()) + cache::RK_WITH_SPECIAL_INTERPOLATIONS, + idxs, T::Type{Val{D}}, differential_vars) where {D} + throw(DerivativeOrderNotPossibleError()) end function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::RK_WITH_SPECIAL_INTERPOLATIONS, - idxs, T::Type{Val{D}}, differential_vars) where {D} -throw(DerivativeOrderNotPossibleError()) + cache::RK_WITH_SPECIAL_INTERPOLATIONS, + idxs, T::Type{Val{D}}, differential_vars) where {D} + throw(DerivativeOrderNotPossibleError()) end ## Vern6 @@ -1040,4 +1040,4 @@ end k[18][idxs] * b24Θdiff + k[19][idxs] * b25Θdiff + k[20][idxs] * b26Θdiff) * invdt3 out -end \ No newline at end of file +end diff --git a/src/integrators/controllers.jl b/src/integrators/controllers.jl index 5964617fea..88f8fb0526 100644 --- a/src/integrators/controllers.jl +++ b/src/integrators/controllers.jl @@ -32,7 +32,7 @@ DiffEqBase.reinit!(integrator::ODEIntegrator, controller::AbstractController) = NothingController() This Controller exists to match the interface when one does not want to use a controller, -basically if you want to keep a fixed time step. +basically if you want to keep a fixed time step. """ struct NothingController <: AbstractController end diff --git a/src/solve.jl b/src/solve.jl index 5aa8caadce..17e5733b23 100644 --- a/src/solve.jl +++ b/src/solve.jl @@ -363,7 +363,7 @@ function DiffEqBase.__init( Base.depwarn(message, :solve) end - if controller === nothing + if controller === nothing if adaptive controller = default_controller(_alg, cache, qoldinit, beta1, beta2) else From 97a4d6ea6a7ee60906c62fb8680dac0292171fbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Duez?= <42682941+Theozeud@users.noreply.github.com> Date: Mon, 15 Jul 2024 14:40:22 +0200 Subject: [PATCH 6/8] Update src/integrators/controllers.jl Co-authored-by: Hendrik Ranocha --- src/integrators/controllers.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/integrators/controllers.jl b/src/integrators/controllers.jl index 88f8fb0526..59c8d788b1 100644 --- a/src/integrators/controllers.jl +++ b/src/integrators/controllers.jl @@ -27,7 +27,6 @@ reset_alg_dependent_opts!(controller::AbstractController, alg1, alg2) = nothing DiffEqBase.reinit!(integrator::ODEIntegrator, controller::AbstractController) = nothing -# Standard integral (I) step size controller """ NothingController() From c8f8d9ce45144355a1b02d8dfebba29c93eafd00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Duez?= <42682941+Theozeud@users.noreply.github.com> Date: Mon, 15 Jul 2024 14:46:02 +0200 Subject: [PATCH 7/8] Change name NothingController -> NonAdaptativeController --- src/integrators/controllers.jl | 12 ++++++------ src/solve.jl | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/integrators/controllers.jl b/src/integrators/controllers.jl index 59c8d788b1..8f7f6d0790 100644 --- a/src/integrators/controllers.jl +++ b/src/integrators/controllers.jl @@ -28,27 +28,27 @@ reset_alg_dependent_opts!(controller::AbstractController, alg1, alg2) = nothing DiffEqBase.reinit!(integrator::ODEIntegrator, controller::AbstractController) = nothing """ - NothingController() + NonAdaptiveController() This Controller exists to match the interface when one does not want to use a controller, basically if you want to keep a fixed time step. """ -struct NothingController <: AbstractController +struct NonAdaptiveController <: AbstractController end -@inline function stepsize_controller!(integrator, controller::NothingController, alg) +@inline function stepsize_controller!(integrator, controller::NonAdaptiveController, alg) nothing end -@inline function accept_step_controller(integrator, ::NothingController) +@inline function accept_step_controller(integrator, ::NonAdaptiveController) return true end -function step_accept_controller!(integrator, ::NothingController, alg, q) +function step_accept_controller!(integrator, ::NonAdaptiveController, alg, q) integrator.dt end -function step_reject_controller!(integrator, ::NothingController, alg) +function step_reject_controller!(integrator, ::NonAdaptiveController, alg) end # Standard integral (I) step size controller diff --git a/src/solve.jl b/src/solve.jl index 17e5733b23..558f74722f 100644 --- a/src/solve.jl +++ b/src/solve.jl @@ -367,7 +367,7 @@ function DiffEqBase.__init( if adaptive controller = default_controller(_alg, cache, qoldinit, beta1, beta2) else - controller = NothingController() + controller = NonAdaptiveController() end end From 8300cbd9f9708c951c8b485a760c11d75b7dda9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Duez?= <42682941+Theozeud@users.noreply.github.com> Date: Mon, 15 Jul 2024 17:20:50 +0200 Subject: [PATCH 8/8] Update controllers.jl --- src/integrators/controllers.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/integrators/controllers.jl b/src/integrators/controllers.jl index 8f7f6d0790..a55aef4c02 100644 --- a/src/integrators/controllers.jl +++ b/src/integrators/controllers.jl @@ -36,7 +36,7 @@ basically if you want to keep a fixed time step. struct NonAdaptiveController <: AbstractController end -@inline function stepsize_controller!(integrator, controller::NonAdaptiveController, alg) +@inline function stepsize_controller!(integrator, ::NonAdaptiveController, alg) nothing end