Skip to content

add overrides_adaptive #2449

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions lib/OrdinaryDiffEqBDF/src/bdf_perform_step.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ end
integrator.fsallast = f(uₙ, p, t + dtₙ)
OrdinaryDiffEqCore.increment_nf!(integrator.stats, 1)

if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
tmp = integrator.fsallast - (1 + dtₙ / dtₙ₋₁) * integrator.fsalfirst +
(dtₙ / dtₙ₋₁) * cache.fsalfirstprev
est = (dtₙ₋₁ + dtₙ) / 6 * tmp
Expand Down Expand Up @@ -151,7 +151,7 @@ end

f(integrator.fsallast, uₙ, p, t + dtₙ)
OrdinaryDiffEqCore.increment_nf!(integrator.stats, 1)
if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
btilde0 = (dtₙ₋₁ + dtₙ) * 1 // 6
btilde1 = 1 + dtₙ / dtₙ₋₁
btilde2 = dtₙ / dtₙ₋₁
Expand Down Expand Up @@ -382,7 +382,7 @@ function perform_step!(integrator, cache::QNDF1ConstantCache, repeat_step = fals
u = nlsolve!(nlsolver, integrator, cache, repeat_step)

nlsolvefail(nlsolver) && return
if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
if integrator.success_iter == 0
integrator.EEst = one(integrator.EEst)
else
Expand Down Expand Up @@ -471,7 +471,7 @@ function perform_step!(integrator, cache::QNDF1Cache, repeat_step = false)

step_limiter!(u, integrator, p, t + dt)

if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
if integrator.success_iter == 0
integrator.EEst = one(integrator.EEst)
else
Expand Down Expand Up @@ -567,7 +567,7 @@ function perform_step!(integrator, cache::QNDF2ConstantCache, repeat_step = fals
u = nlsolve!(nlsolver, integrator, cache, repeat_step)
nlsolvefail(nlsolver) && return

if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
if integrator.success_iter == 0
integrator.EEst = one(integrator.EEst)
elseif integrator.success_iter == 1
Expand Down Expand Up @@ -681,7 +681,7 @@ function perform_step!(integrator, cache::QNDF2Cache, repeat_step = false)

step_limiter!(u, integrator, p, t + dt)

if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
if integrator.success_iter == 0
integrator.EEst = one(integrator.EEst)
elseif integrator.success_iter == 1
Expand Down Expand Up @@ -791,7 +791,7 @@ function perform_step!(integrator, cache::QNDFConstantCache{max_order},
dd = u - u₀
update_D!(D, dd, k)

if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
@unpack abstol, reltol, internalnorm = integrator.opts
if cache.consfailcnt > 1 && mass_matrix !== I
# if we get repeated failure and mass_matrix !== I it's likely that
Expand Down Expand Up @@ -913,7 +913,7 @@ function perform_step!(integrator, cache::QNDFCache{max_order},

step_limiter!(u, integrator, p, t + dt)

if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
@unpack abstol, reltol, internalnorm = integrator.opts
if cache.consfailcnt > 1 && mass_matrix !== I
# if we get repeated failure and mass_matrix !== I it's likely that
Expand Down Expand Up @@ -1151,7 +1151,7 @@ function perform_step!(integrator, cache::FBDFConstantCache{max_order},
end
lte *= terkp1

if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
for i in 1:(k + 1)
ts_tmp[i + 1] = ts[i]
end
Expand Down Expand Up @@ -1292,7 +1292,7 @@ function perform_step!(integrator, cache::FBDFCache{max_order},
lte -= bdf_coeffs[k, j] * r[j]
end
@.. broadcast=false terk_tmp=lte * terkp1_tmp
if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
@unpack abstol, reltol, internalnorm = integrator.opts
for i in 1:(k + 1)
ts_tmp[i + 1] = ts[i]
Expand Down
4 changes: 3 additions & 1 deletion lib/OrdinaryDiffEqCore/src/integrators/controllers.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
abstract type AbstractController end
using OrdinaryDiffEqCore

abstract type AbstractController end
overrides_adaptive(::AbstractController) = false

@inline function stepsize_controller!(integrator, alg)
stepsize_controller!(integrator, integrator.opts.controller, alg)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/OrdinaryDiffEqExplicitRK/src/explicit_rk_perform_step.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ end
integrator.eigen_est = integrator.opts.internalnorm(n, t)
end

if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
utilde = αEEst[1] .* kk[1]
for i in 2:stages
utilde = utilde + αEEst[i] * kk[i]
Expand Down Expand Up @@ -223,7 +223,7 @@ end
integrator.eigen_est = integrator.opts.internalnorm(norm(utilde, Inf), t)
end

if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
runtime_split_EEst!(tmp, αEEst, utilde, kk, dt, stages)
calculate_residuals!(atmp, tmp, uprev, u,
integrator.opts.abstol, integrator.opts.reltol,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,7 @@ function perform_step!(integrator, cache::Exprb32ConstantCache, repeat_step = fa
w2 = phiv(dt, A, F2, 3; m = min(alg.m, size(A, 1)),
opnorm = integrator.opts.internalopnorm, iop = alg.iop)
u = uprev + dt * (w1[:, 2] - 2w1[:, 4] + 2w2[:, 4])
if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
# error estimator for the imbedded method
utilde = 2dt * (-w1[:, 4] + w2[:, 4])
atmp = calculate_residuals(utilde, uprev, u, integrator.opts.abstol,
Expand Down Expand Up @@ -1436,7 +1436,7 @@ function perform_step!(integrator, cache::Exprb32Cache, repeat_step = false)
axpy!(dt, @view(w1[:, 2]), u)
axpy!(-2dt, @view(w1[:, 4]), u)
axpy!(2dt, @view(w2[:, 4]), u)
if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
# error estimator for the imbedded method
@views @.. broadcast=false utilde=(2 * dt) * (-w1[:, 4] + w2[:, 4])
calculate_residuals!(tmp, utilde, uprev, u, integrator.opts.abstol,
Expand Down Expand Up @@ -1476,7 +1476,7 @@ function perform_step!(integrator, cache::Exprb43ConstantCache, repeat_step = fa
u = uprev +
dt * (w1[:, 2] - 14w1[:, 4] + 36w1[:, 5] + 16w2[:, 4] - 48w2[:, 5] - 2w3[:, 4] +
12w3[:, 5])
if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
# error estimator for the imbedded method
utilde = dt * (36w1[:, 5] - 48w2[:, 5] + 12w3[:, 5])
atmp = calculate_residuals(utilde, uprev, u, integrator.opts.abstol,
Expand Down Expand Up @@ -1527,7 +1527,7 @@ function perform_step!(integrator, cache::Exprb43Cache, repeat_step = false)
@views @.. broadcast=false rtmp=w1[:, 2] - 14w1[:, 4] + 36w1[:, 5] + 16w2[:, 4] -
48w2[:, 5] - 2w3[:, 4] + 12w3[:, 5]
@muladd @.. broadcast=false u=uprev + dt * rtmp
if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
@views @.. broadcast=false rtmp=36w1[:, 5] - 48w2[:, 5] + 12w3[:, 5]
@.. broadcast=false utilde=dt * rtmp
calculate_residuals!(tmp, utilde, uprev, u, integrator.opts.abstol,
Expand Down
52 changes: 26 additions & 26 deletions lib/OrdinaryDiffEqExtrapolation/src/extrapolation_perform_step.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function perform_step!(integrator, cache::AitkenNevilleCache, repeat_step = fals
end
end

if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
minimum_work = Inf
if isone(cache.step_no)
range_start = 2
Expand Down Expand Up @@ -196,7 +196,7 @@ function perform_step!(integrator, cache::AitkenNevilleConstantCache, repeat_ste
end
end

if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller) || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
minimum_work = Inf
if isone(cache.step_no)
range_start = 2
Expand Down Expand Up @@ -271,7 +271,7 @@ function perform_step!(integrator, cache::ImplicitEulerExtrapolationCache,

@unpack sequence = cache

if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
# Set up the order window
# alg.min_order + 1 ≦ n_curr ≦ alg.max_order - 1 is enforced by step_*_controller!
if !(alg.min_order + 1 <= n_curr <= alg.max_order - 1)
Expand Down Expand Up @@ -418,7 +418,7 @@ function perform_step!(integrator, cache::ImplicitEulerExtrapolationCache,
end
end

if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
# Compute all information relating to an extrapolation order ≦ win_min
for i in (win_min - 1):win_min
@.. broadcast=false integrator.u=T[i + 1, i + 1]
Expand Down Expand Up @@ -528,7 +528,7 @@ function perform_step!(integrator, cache::ImplicitEulerExtrapolationConstantCach
@unpack dtpropose, T, n_curr, work, A, tf, uf = cache
@unpack sequence, stage_number = cache

if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
# Set up the order window
# alg.min_order + 1 ≦ n_curr ≦ alg.max_order - 1 is enforced by step_*_controller!
if !(alg.min_order + 1 <= n_curr <= alg.max_order - 1)
Expand Down Expand Up @@ -637,7 +637,7 @@ function perform_step!(integrator, cache::ImplicitEulerExtrapolationConstantCach

integrator.dt = dt

if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
# Compute all information relating to an extrapolation order ≦ win_min
for i in (win_min - 1):win_min
u = T[i + 1, i + 1]
Expand Down Expand Up @@ -747,7 +747,7 @@ function perform_step!(integrator, cache::ExtrapolationMidpointDeuflhardCache,
fill!(cache.Q, zero(eltype(cache.Q)))
tol = integrator.opts.internalnorm(integrator.opts.reltol, t) # Used by the convergence monitor

if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
# Set up the order window
win_min = max(alg.min_order, n_curr - 1)
win_max = min(alg.max_order, n_curr + 1)
Expand Down Expand Up @@ -840,7 +840,7 @@ function perform_step!(integrator, cache::ExtrapolationMidpointDeuflhardCache,
integrator.stats.nf += nevals
end

if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
# Compute all information relating to an extrapolation order ≦ win_min
for i in (alg.min_order):n_curr

Expand Down Expand Up @@ -968,7 +968,7 @@ function perform_step!(integrator, cache::ExtrapolationMidpointDeuflhardConstant
fill!(cache.Q, zero(eltype(cache.Q)))

# Start computation
if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
# Set up the order window
win_min = max(alg.min_order, n_curr - 1)
win_max = min(alg.max_order, n_curr + 1)
Expand Down Expand Up @@ -1051,7 +1051,7 @@ function perform_step!(integrator, cache::ExtrapolationMidpointDeuflhardConstant
integrator.stats.nf += nevals
end

if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
# Compute all information relating to an extrapolation order ≦ win_min
for i in (alg.min_order):n_curr
u = eltype(uprev).(extrapolation_scalars[i + 1]) *
Expand Down Expand Up @@ -1158,7 +1158,7 @@ function perform_step!(integrator, cache::ImplicitDeuflhardExtrapolationCache,

fill!(cache.Q, zero(eltype(cache.Q)))

if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
# Set up the order window
win_min = max(alg.min_order, n_curr - 1)
win_max = min(alg.max_order, n_curr + 1)
Expand Down Expand Up @@ -1416,7 +1416,7 @@ function perform_step!(integrator, cache::ImplicitDeuflhardExtrapolationCache,
return
end

if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
# Compute all information relating to an extrapolation order ≦ win_min
for i in (alg.min_order):n_curr

Expand Down Expand Up @@ -1564,7 +1564,7 @@ function perform_step!(integrator, cache::ImplicitDeuflhardExtrapolationConstant
fill!(cache.Q, zero(eltype(cache.Q)))

# Start computation
if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
# Set up the order window
win_min = max(alg.min_order, n_curr - 1)
win_max = min(alg.max_order, n_curr + 1)
Expand Down Expand Up @@ -1712,7 +1712,7 @@ function perform_step!(integrator, cache::ImplicitDeuflhardExtrapolationConstant
return
end

if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
# Compute all information relating to an extrapolation order ≦ win_min
for i in (alg.min_order):n_curr
u = eltype(uprev).(extrapolation_scalars[i + 1]) *
Expand Down Expand Up @@ -1826,7 +1826,7 @@ function perform_step!(integrator, cache::ExtrapolationMidpointHairerWannerCache

fill!(cache.Q, zero(eltype(cache.Q)))

if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
# Set up the order window
# alg.min_order + 1 ≦ n_curr ≦ alg.max_order - 1 is enforced by step_*_controller!
if !(alg.min_order + 1 <= n_curr <= alg.max_order - 1)
Expand Down Expand Up @@ -1924,7 +1924,7 @@ function perform_step!(integrator, cache::ExtrapolationMidpointHairerWannerCache
integrator.stats.nf += nevals
end

if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
# Compute all information relating to an extrapolation order ≦ win_min
for i in (win_min - 1):win_min

Expand Down Expand Up @@ -2051,7 +2051,7 @@ function perform_step!(integrator, cache::ExtrapolationMidpointHairerWannerConst
T = fill(zero(uprev), alg.max_order + 1) # Storage for the internal discretisations obtained by the explicit midpoint rule
fill!(cache.Q, zero(eltype(cache.Q)))

if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
# Set up the order window
# alg.min_order + 1 ≦ n_curr ≦ alg.max_order - 1 is enforced by step_*_controller!
if !(alg.min_order + 1 <= n_curr <= alg.max_order - 1)
Expand Down Expand Up @@ -2136,7 +2136,7 @@ function perform_step!(integrator, cache::ExtrapolationMidpointHairerWannerConst
nevals = cache.stage_number[n_curr + 1] - 1
integrator.stats.nf += nevals
end
if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
# Compute all information relating to an extrapolation order ≦ win_min
for i in (win_min - 1):win_min
u = eltype(uprev).(extrapolation_scalars[i + 1]) *
Expand Down Expand Up @@ -2246,7 +2246,7 @@ function perform_step!(integrator, cache::ImplicitHairerWannerExtrapolationConst
T = fill(zero(uprev), alg.max_order + 1) # Storage for the internal discretisations obtained by the explicit midpoint rule
fill!(cache.Q, zero(eltype(cache.Q)))

if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
# Set up the order window
# alg.min_order + 1 ≦ n_curr ≦ alg.max_order - 1 is enforced by step_*_controller!
if !(alg.min_order + 1 <= n_curr <= alg.max_order - 1)
Expand Down Expand Up @@ -2409,7 +2409,7 @@ function perform_step!(integrator, cache::ImplicitHairerWannerExtrapolationConst
return
end

if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
# Compute all information relating to an extrapolation order ≦ win_min
for i in (win_min - 1):win_min
u = eltype(uprev).(extrapolation_scalars[i + 1]) *
Expand Down Expand Up @@ -2527,7 +2527,7 @@ function perform_step!(integrator, cache::ImplicitHairerWannerExtrapolationCache

fill!(cache.Q, zero(eltype(cache.Q)))

if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
# Set up the order window
# alg.min_order + 1 ≦ n_curr ≦ alg.max_order - 1 is enforced by step_*_controller!
if !(alg.min_order + 1 <= n_curr <= alg.max_order - 1)
Expand Down Expand Up @@ -2787,7 +2787,7 @@ function perform_step!(integrator, cache::ImplicitHairerWannerExtrapolationCache
return
end

if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
# Compute all information relating to an extrapolation order ≦ win_min
for i in (win_min - 1):win_min

Expand Down Expand Up @@ -2952,7 +2952,7 @@ function perform_step!(integrator,
T = fill(zero(uprev), alg.max_order + 1) # Storage for the internal discretisations obtained by the explicit midpoint rule
fill!(cache.Q, zero(eltype(cache.Q)))

if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
# Set up the order window
# alg.min_order + 1 ≦ n_curr ≦ alg.max_order - 1 is enforced by step_*_controller!
if !(alg.min_order + 1 <= n_curr <= alg.max_order - 1)
Expand Down Expand Up @@ -3109,7 +3109,7 @@ function perform_step!(integrator,
return
end

if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
# Compute all information relating to an extrapolation order ≦ win_min
for i in (win_min - 1):win_min
u = eltype(uprev).(extrapolation_scalars[i + 1]) *
Expand Down Expand Up @@ -3226,7 +3226,7 @@ function perform_step!(integrator, cache::ImplicitEulerBarycentricExtrapolationC

fill!(cache.Q, zero(eltype(cache.Q)))

if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
# Set up the order window
# alg.min_order + 1 ≦ n_curr ≦ alg.max_order - 1 is enforced by step_*_controller!
if !(alg.min_order + 1 <= n_curr <= alg.max_order - 1)
Expand Down Expand Up @@ -3500,7 +3500,7 @@ function perform_step!(integrator, cache::ImplicitEulerBarycentricExtrapolationC
return
end

if integrator.opts.adaptive
if integrator.opts.adaptive || OrdinaryDiffEqCore.overrides_adaptive(integrator.opts.controller)
# Compute all information relating to an extrapolation order ≦ win_min
for i in (win_min - 1):win_min

Expand Down
Loading
Loading