Skip to content

Commit 533de00

Browse files
Step 1: Make sure atmp is present when it should be.
1 parent 983dca4 commit 533de00

File tree

5 files changed

+87
-58
lines changed

5 files changed

+87
-58
lines changed

lib/OrdinaryDiffEqCore/src/integrators/controllers.jl

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ abstract type AbstractLegacyController <: AbstractController end
44
abstract type AbstractControllerCache end
55

66
"""
7-
setup_controller_cache(alg, controller::AbstractController)::AbstractControllerCache
7+
setup_controller_cache(alg, atmp, controller::AbstractController)::AbstractControllerCache
88
99
This function takes a controller together with the time stepping algorithm to
1010
construct and initialize the respective cache for the controller.
@@ -55,7 +55,7 @@ step_reject_controller!
5555

5656

5757
# The legacy controllers do not have this concept.
58-
setup_controller_cache(alg, controller::AbstractLegacyController) = controller
58+
setup_controller_cache(alg, atmp, controller::AbstractLegacyController) = controller
5959

6060
# checks whether the controller should accept a step based on the error estimate
6161
@inline function accept_step_controller(integrator, controller_or_cache::Union{<:AbstractLegacyController, <:AbstractControllerCache})
@@ -99,7 +99,7 @@ end
9999
struct DummyController <: AbstractController
100100
end
101101

102-
setup_controller_cache(alg, controller::DummyController) = controller
102+
setup_controller_cache(alg, atmp, controller::DummyController) = controller
103103

104104
@inline function accept_step_controller(integrator, controller::DummyController)
105105
return integrator.EEst <= 1
@@ -191,19 +191,21 @@ function NewIController(QT, alg; qmin = nothing, qmax = nothing, gamma = nothing
191191
)
192192
end
193193

194-
mutable struct IControllerCache{C, T} <: AbstractControllerCache
194+
mutable struct IControllerCache{C, T, UT} <: AbstractControllerCache
195195
controller::C
196196
q::T
197197
dtreject::T
198198
# I believe this should go here or in the algorithm cache, but not in the integrator itself.
199199
# EEst::T
200+
atmp::UT
200201
end
201202

202-
function setup_controller_cache(alg, controller::NewIController{T}) where T
203+
function setup_controller_cache(alg, atmp, controller::NewIController{T}) where T
203204
IControllerCache(
204205
controller,
205206
T(1),
206207
T(1 // 10^4), # TODO which value?
208+
atmp,
207209
)
208210
end
209211

@@ -356,23 +358,24 @@ function NewPIController(QT, alg; beta1 = nothing, beta2 = nothing, qmin = nothi
356358
)
357359
end
358360

359-
mutable struct PIControllerCache{T} <: AbstractControllerCache
361+
mutable struct PIControllerCache{T, UT} <: AbstractControllerCache
360362
controller::NewPIController{T}
361363
# Propsoed scaling factor for the time step length
362364
q::T
363365
# Cached εₙ₊₁^β₁
364366
q11::T
365367
# Previous EEst
366368
errold::T
369+
atmp::UT
367370
end
368371

369-
370-
function setup_controller_cache(alg, controller::NewPIController{T}) where T
372+
function setup_controller_cache(alg, atmp, controller::NewPIController{T}) where T
371373
PIControllerCache(
372374
controller,
373375
T(1),
374376
T(1),
375377
T(1 // 10^4),
378+
atmp,
376379
)
377380
end
378381

@@ -612,18 +615,20 @@ function Base.show(io::IO, controller::NewPIDController)
612615
")")
613616
end
614617

615-
mutable struct PIDControllerCache{T, Limiter} <: AbstractControllerCache
618+
mutable struct PIDControllerCache{T, Limiter, UT} <: AbstractControllerCache
616619
controller::NewPIDController{T, Limiter}
617620
err::MVector{3, T} # history of the error estimates
618621
dt_factor::T
622+
atmp::UT
619623
end
620624

621-
function setup_controller_cache(alg, controller::NewPIDController{QT}) where QT
625+
function setup_controller_cache(alg, atmp, controller::NewPIDController{QT}) where QT
622626
err = MVector{3, QT}(true, true, true)
623627
PIDControllerCache(
624628
controller,
625629
err,
626630
QT(1 // 10^4),
631+
atmp,
627632
)
628633
end
629634

@@ -829,21 +834,23 @@ function NewPredictiveController(QT, alg; qmin = nothing, qmax = nothing, gamma
829834
)
830835
end
831836

832-
mutable struct PredictiveControllerCache{T} <: AbstractControllerCache
837+
mutable struct PredictiveControllerCache{T, UT} <: AbstractControllerCache
833838
controller::NewPredictiveController{T}
834839
dtacc::T
835840
erracc::T
836841
qold::T
837842
q::T
843+
atmp::UT
838844
end
839845

840-
function setup_controller_cache(alg, controller::NewPredictiveController{T}) where T
846+
function setup_controller_cache(alg, atmp, controller::NewPredictiveController{T}) where T
841847
PredictiveControllerCache{T}(
842848
controller,
843849
T(1),
844850
T(1),
845851
T(1),
846-
T(1)
852+
T(1),
853+
atmp,
847854
)
848855
end
849856

@@ -909,13 +916,15 @@ struct CompositeController{T} <: AbstractController
909916
controllers::T
910917
end
911918

912-
struct CompositeControllerCache{T} <: AbstractControllerCache
919+
struct CompositeControllerCache{T, UT} <: AbstractControllerCache
913920
caches::T
921+
atmp::UT # This is just here for easy access
914922
end
915923

916-
function setup_controller_cache(alg::CompositeAlgorithm, cc::CompositeController)
924+
function setup_controller_cache(alg::CompositeAlgorithm, atmp, cc::CompositeController)
917925
CompositeControllerCache(
918-
map((alg, controller)->setup_controller_cache(alg, controller), alg.algs, cc.controllers)
926+
map((alg, controller)->setup_controller_cache(alg, atmp, controller), alg.algs, cc.controllers),
927+
atmp,
919928
)
920929
end
921930

lib/OrdinaryDiffEqCore/src/solve.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,13 @@ function SciMLBase.__init(
463463
qoldinit = hasfield(typeof(controller), :qoldinit) ? controller.qoldinit : (anyadaptive(alg) ? 1 // 10^4 : 0)
464464
end
465465

466-
controller_cache = setup_controller_cache(_alg, controller)
466+
467+
atmp = if hasfield(typeof(cache), :atmp)
468+
cache.atmp
469+
else
470+
nothing
471+
end
472+
controller_cache = setup_controller_cache(_alg, atmp, controller)
467473

468474
save_end_user = save_end
469475
save_end = save_end === nothing ?

lib/OrdinaryDiffEqExtrapolation/src/controllers.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,19 @@ function NewExtrapolationController(QT, alg; qmin = nothing, qmax = nothing, gam
2121
)
2222
end
2323

24-
mutable struct ExtrapolationControllerCache{QT} <: AbstractControllerCache
24+
mutable struct ExtrapolationControllerCache{QT, UT} <: AbstractControllerCache
2525
controller::NewExtrapolationController{QT}
2626
beta1::QT
2727
gamma::QT
28+
atmp::UT
2829
end
2930

30-
function setup_controller_cache(alg, controller::NewExtrapolationController{T}) where T
31-
ExtrapolationControllerCache{T}(
31+
function setup_controller_cache(alg, atmp, controller::NewExtrapolationController{T}) where T
32+
ExtrapolationControllerCache(
3233
controller,
3334
T(1),
34-
T(1)
35+
T(1),
36+
atmp,
3537
)
3638
end
3739

lib/OrdinaryDiffEqExtrapolation/src/extrapolation_caches.jl

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ end
124124
n_curr::Int # Storage for the current extrapolation order
125125
n_old::Int # Storage for the extrapolation order n_curr before perform_step! changes the latter
126126
sigma::Rational{Int} # Parameter for order selection
127-
res::uNoUnitsType # Storage for the scaled residual of u and utilde
128127

129128
#Stepsizing caches
130129
work::Array{QType, 1}
@@ -285,7 +284,6 @@ function alg_cache(alg::ImplicitEulerExtrapolation, u, rate_prototype,
285284
#Pr = Diagonal(_vec(weight)))
286285
end
287286

288-
res = uEltypeNoUnits.(zero(u))
289287
grad_config = build_grad_config(alg, f, tf, du1, t)
290288
jac_config = build_jac_config(alg, f, uf, du1, uprev, u, du1, du2)
291289
sequence = generate_sequence(constvalue(uBottomEltypeNoUnits), alg)
@@ -301,7 +299,7 @@ function alg_cache(alg::ImplicitEulerExtrapolation, u, rate_prototype,
301299
dtpropose, T, A, step_no,
302300
du1, du2, J, W, tf, uf, linsolve_tmps, linsolve,
303301
jac_config, grad_config, sequence, cc.stage_number,
304-
cc.Q, cc.n_curr, cc.n_old, cc.sigma, res, cc.work,
302+
cc.Q, cc.n_curr, cc.n_old, cc.sigma, cc.work,
305303
cc.dt_new, diff1, diff2)
306304
end
307305

@@ -942,7 +940,7 @@ end
942940
u_temp4::Array{uType, 1}
943941
tmp::uType # for get_tmp_cache()
944942
T::Array{uType, 1} # Storage for the internal discretisations obtained by the explicit midpoint rule
945-
res::uNoUnitsType # Storage for the scaled residual of u and utilde
943+
atmp::uNoUnitsType # Storage for the scaled residual of u and utilde
946944

947945
fsalfirst::rateType
948946
k::rateType
@@ -1026,7 +1024,7 @@ end
10261024
u_temp4::Array{uType, 1}
10271025
tmp::uType # for get_tmp_cache()
10281026
T::Array{uType, 1} # Storage for the internal discretisations obtained by the explicit midpoint rule
1029-
res::uNoUnitsType # Storage for the scaled residual of u and utilde
1027+
atmp::uNoUnitsType # Storage for the scaled residual of u and utilde
10301028

10311029
fsalfirst::rateType
10321030
k::rateType
@@ -1251,7 +1249,7 @@ end
12511249
u_temp4::Array{uType, 1}
12521250
tmp::uType # for get_tmp_cache()
12531251
T::Array{uType, 1} # Storage for the internal discretisations obtained by the explicit midpoint rule
1254-
res::uNoUnitsType # Storage for the scaled residual of u and utilde
1252+
atmp::uNoUnitsType # Storage for the scaled residual of u and utilde
12551253

12561254
fsalfirst::rateType
12571255
k::rateType
@@ -1394,7 +1392,7 @@ end
13941392
u_temp4::Array{uType, 1}
13951393
tmp::uType # for get_tmp_cache()
13961394
T::Array{uType, 1} # Storage for the internal discretisations obtained by the explicit midpoint rule
1397-
res::uNoUnitsType # Storage for the scaled residual of u and utilde
1395+
atmp::uNoUnitsType # Storage for the scaled residual of u and utilde
13981396

13991397
fsalfirst::rateType
14001398
k::rateType
@@ -1593,7 +1591,7 @@ end
15931591
u_temp4::Array{uType, 1}
15941592
tmp::uType # for get_tmp_cache()
15951593
T::Array{uType, 1} # Storage for the internal discretisations obtained by the explicit midpoint rule
1596-
res::uNoUnitsType # Storage for the scaled residual of u and utilde
1594+
atmp::uNoUnitsType # Storage for the scaled residual of u and utilde
15971595

15981596
fsalfirst::rateType
15991597
k::rateType

0 commit comments

Comments
 (0)