Skip to content

Commit cb87c1c

Browse files
Merge pull request #2390 from SciML/undef_fsal
Refactor ODEIntegrator to not allow undef fsal states
2 parents f43bcaf + 4856d99 commit cb87c1c

File tree

92 files changed

+524
-824
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+524
-824
lines changed

lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import OrdinaryDiffEqCore: OrdinaryDiffEqMutableCache, OrdinaryDiffEqConstantCac
77
OrdinaryDiffEqAdaptiveAlgorithm,
88
OrdinaryDiffEqAdamsVarOrderVarStepAlgorithm,
99
constvalue, calculate_residuals, calculate_residuals!,
10-
trivial_limiter!,
10+
trivial_limiter!, get_fsalfirstlast,
1111
full_cache
1212
import OrdinaryDiffEqLowOrderRK: BS3ConstantCache, BS3Cache, RK4ConstantCache, RK4Cache
1313
import RecursiveArrayTools: recursivefill!

lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_bashforth_moulton_caches.jl

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
@cache mutable struct AB3Cache{uType, rateType} <: OrdinaryDiffEqMutableCache
1+
abstract type ABMMutableCache <: OrdinaryDiffEqMutableCache end
2+
abstract type ABMVariableCoefficientMutableCache <: OrdinaryDiffEqMutableCache end
3+
get_fsalfirstlast(cache::ABMMutableCache,u) = (cache.fsalfirst, cache.k)
4+
get_fsalfirstlast(cache::ABMVariableCoefficientMutableCache,u) = (cache.fsalfirst, cache.k4)
5+
@cache mutable struct AB3Cache{uType, rateType} <: ABMMutableCache
26
u::uType
37
uprev::uType
48
fsalfirst::rateType
@@ -38,7 +42,7 @@ function alg_cache(alg::AB3, u, rate_prototype, ::Type{uEltypeNoUnits},
3842
AB3ConstantCache(k2, k3, 1)
3943
end
4044

41-
@cache mutable struct ABM32Cache{uType, rateType} <: OrdinaryDiffEqMutableCache
45+
@cache mutable struct ABM32Cache{uType, rateType} <: ABMMutableCache
4246
u::uType
4347
uprev::uType
4448
fsalfirst::rateType
@@ -78,7 +82,7 @@ function alg_cache(alg::ABM32, u, rate_prototype, ::Type{uEltypeNoUnits},
7882
ABM32ConstantCache(k2, k3, 1)
7983
end
8084

81-
@cache mutable struct AB4Cache{uType, rateType} <: OrdinaryDiffEqMutableCache
85+
@cache mutable struct AB4Cache{uType, rateType} <: ABMMutableCache
8286
u::uType
8387
uprev::uType
8488
fsalfirst::rateType
@@ -128,7 +132,7 @@ function alg_cache(alg::AB4, u, rate_prototype, ::Type{uEltypeNoUnits},
128132
AB4ConstantCache(k2, k3, k4, 1)
129133
end
130134

131-
@cache mutable struct ABM43Cache{uType, rateType} <: OrdinaryDiffEqMutableCache
135+
@cache mutable struct ABM43Cache{uType, rateType} <: ABMMutableCache
132136
u::uType
133137
uprev::uType
134138
fsalfirst::rateType
@@ -184,7 +188,7 @@ function alg_cache(alg::ABM43, u, rate_prototype, ::Type{uEltypeNoUnits},
184188
ABM43ConstantCache(k2, k3, k4, 1)
185189
end
186190

187-
@cache mutable struct AB5Cache{uType, rateType} <: OrdinaryDiffEqMutableCache
191+
@cache mutable struct AB5Cache{uType, rateType} <: ABMMutableCache
188192
u::uType
189193
uprev::uType
190194
fsalfirst::rateType
@@ -236,7 +240,7 @@ function alg_cache(alg::AB5, u, rate_prototype, ::Type{uEltypeNoUnits},
236240
AB5ConstantCache(k2, k3, k4, k5, 1)
237241
end
238242

239-
@cache mutable struct ABM54Cache{uType, rateType} <: OrdinaryDiffEqMutableCache
243+
@cache mutable struct ABM54Cache{uType, rateType} <: ABMMutableCache
240244
u::uType
241245
uprev::uType
242246
fsalfirst::rateType
@@ -312,7 +316,7 @@ end
312316

313317
@cache mutable struct VCAB3Cache{uType, rateType, TabType, bs3Type, tArrayType, cArrayType,
314318
uNoUnitsType, coefType, dtArrayType} <:
315-
OrdinaryDiffEqMutableCache
319+
ABMVariableCoefficientMutableCache
316320
u::uType
317321
uprev::uType
318322
fsalfirst::rateType
@@ -408,7 +412,7 @@ end
408412

409413
@cache mutable struct VCAB4Cache{uType, rateType, rk4cacheType, tArrayType, cArrayType,
410414
uNoUnitsType, coefType, dtArrayType} <:
411-
OrdinaryDiffEqMutableCache
415+
ABMVariableCoefficientMutableCache
412416
u::uType
413417
uprev::uType
414418
fsalfirst::rateType
@@ -504,7 +508,7 @@ end
504508

505509
@cache mutable struct VCAB5Cache{uType, rateType, rk4cacheType, tArrayType, cArrayType,
506510
uNoUnitsType, coefType, dtArrayType} <:
507-
OrdinaryDiffEqMutableCache
511+
ABMVariableCoefficientMutableCache
508512
u::uType
509513
uprev::uType
510514
fsalfirst::rateType
@@ -602,7 +606,7 @@ end
602606
@cache mutable struct VCABM3Cache{
603607
uType, rateType, TabType, bs3Type, tArrayType, cArrayType,
604608
uNoUnitsType, coefType, dtArrayType} <:
605-
OrdinaryDiffEqMutableCache
609+
ABMVariableCoefficientMutableCache
606610
u::uType
607611
uprev::uType
608612
fsalfirst::rateType
@@ -708,7 +712,7 @@ end
708712

709713
@cache mutable struct VCABM4Cache{uType, rateType, rk4cacheType, tArrayType, cArrayType,
710714
uNoUnitsType, coefType, dtArrayType} <:
711-
OrdinaryDiffEqMutableCache
715+
ABMVariableCoefficientMutableCache
712716
u::uType
713717
uprev::uType
714718
fsalfirst::rateType
@@ -813,7 +817,7 @@ end
813817

814818
@cache mutable struct VCABM5Cache{uType, rateType, rk4cacheType, tArrayType, cArrayType,
815819
uNoUnitsType, coefType, dtArrayType} <:
816-
OrdinaryDiffEqMutableCache
820+
ABMVariableCoefficientMutableCache
817821
u::uType
818822
uprev::uType
819823
fsalfirst::rateType
@@ -919,7 +923,7 @@ end
919923

920924
@cache mutable struct VCABMCache{uType, rateType, dtType, tArrayType, cArrayType,
921925
uNoUnitsType, coefType, dtArrayType} <:
922-
OrdinaryDiffEqMutableCache
926+
ABMVariableCoefficientMutableCache
923927
u::uType
924928
uprev::uType
925929
fsalfirst::rateType

lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_bashforth_moulton_perform_step.jl

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ function initialize!(integrator,
2424
ABM43Cache,
2525
ABM54Cache})
2626
@unpack fsalfirst, k = cache
27-
integrator.fsalfirst = fsalfirst
28-
integrator.fsallast = k
27+
2928
integrator.kshortsize = 2
3029
resize!(integrator.k, integrator.kshortsize)
3130
integrator.k[1] = integrator.fsalfirst
@@ -551,8 +550,7 @@ end
551550

552551
function initialize!(integrator, cache::VCAB3Cache)
553552
@unpack fsalfirst, k4 = cache
554-
integrator.fsalfirst = fsalfirst
555-
integrator.fsallast = k4
553+
556554
integrator.kshortsize = 2
557555
resize!(integrator.k, integrator.kshortsize)
558556
integrator.k[1] = integrator.fsalfirst
@@ -685,8 +683,7 @@ end
685683

686684
function initialize!(integrator, cache::VCAB4Cache)
687685
@unpack fsalfirst, k4 = cache
688-
integrator.fsalfirst = fsalfirst
689-
integrator.fsallast = k4
686+
690687
integrator.kshortsize = 2
691688
resize!(integrator.k, integrator.kshortsize)
692689
integrator.k[1] = integrator.fsalfirst
@@ -834,8 +831,7 @@ end
834831

835832
function initialize!(integrator, cache::VCAB5Cache)
836833
@unpack fsalfirst, k4 = cache
837-
integrator.fsalfirst = fsalfirst
838-
integrator.fsallast = k4
834+
839835
integrator.kshortsize = 2
840836
resize!(integrator.k, integrator.kshortsize)
841837
integrator.k[1] = integrator.fsalfirst
@@ -981,8 +977,7 @@ end
981977

982978
function initialize!(integrator, cache::VCABM3Cache)
983979
@unpack fsalfirst, k4 = cache
984-
integrator.fsalfirst = fsalfirst
985-
integrator.fsallast = k4
980+
986981
integrator.kshortsize = 2
987982
resize!(integrator.k, integrator.kshortsize)
988983
integrator.k[1] = integrator.fsalfirst
@@ -1125,8 +1120,7 @@ end
11251120

11261121
function initialize!(integrator, cache::VCABM4Cache)
11271122
@unpack fsalfirst, k4 = cache
1128-
integrator.fsalfirst = fsalfirst
1129-
integrator.fsallast = k4
1123+
11301124
integrator.kshortsize = 2
11311125
resize!(integrator.k, integrator.kshortsize)
11321126
integrator.k[1] = integrator.fsalfirst
@@ -1282,8 +1276,7 @@ end
12821276

12831277
function initialize!(integrator, cache::VCABM5Cache)
12841278
@unpack fsalfirst, k4 = cache
1285-
integrator.fsalfirst = fsalfirst
1286-
integrator.fsallast = k4
1279+
12871280
integrator.kshortsize = 2
12881281
resize!(integrator.k, integrator.kshortsize)
12891282
integrator.k[1] = integrator.fsalfirst
@@ -1459,8 +1452,7 @@ end
14591452

14601453
function initialize!(integrator, cache::VCABMCache)
14611454
@unpack fsalfirst, k4 = cache
1462-
integrator.fsalfirst = fsalfirst
1463-
integrator.fsallast = k4
1455+
14641456
integrator.kshortsize = 2
14651457
resize!(integrator.k, integrator.kshortsize)
14661458
integrator.k[1] = integrator.fsalfirst

lib/OrdinaryDiffEqBDF/src/OrdinaryDiffEqBDF.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import OrdinaryDiffEqCore: alg_order, calculate_residuals!,
1919
default_controller, stepsize_controller!,
2020
step_accept_controller!,
2121
step_reject_controller!, post_newton_controller!,
22-
u_modified!, DAEAlgorithm, _unwrap_val, DummyController
22+
u_modified!, DAEAlgorithm, _unwrap_val, DummyController,
23+
get_fsalfirstlast
2324
using OrdinaryDiffEqSDIRK: ImplicitEulerConstantCache, ImplicitEulerCache
2425

2526
using TruncatedStacktraces, MuladdMacro, MacroTools, FastBroadcast, RecursiveArrayTools

lib/OrdinaryDiffEqBDF/src/bdf_caches.jl

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
abstract type BDFMutableCache <: OrdinaryDiffEqMutableCache end
2+
get_fsalfirstlast(cache::BDFMutableCache,u) = (cache.fsalfirst, du_alias_or_new(cache.nlsolver, cache.fsalfirst))
3+
14
@cache mutable struct ABDF2ConstantCache{N, dtType, rate_prototype} <:
25
OrdinaryDiffEqConstantCache
36
nlsolver::N
@@ -22,7 +25,7 @@ function alg_cache(alg::ABDF2, u, rate_prototype, ::Type{uEltypeNoUnits},
2225
end
2326

2427
@cache mutable struct ABDF2Cache{uType, rateType, uNoUnitsType, N, dtType, StepLimiter} <:
25-
OrdinaryDiffEqMutableCache
28+
BDFMutableCache
2629
uₙ::uType
2730
uₙ₋₁::uType
2831
uₙ₋₂::uType
@@ -78,7 +81,7 @@ end
7881
du₂::rateType
7982
end
8083

81-
@cache mutable struct SBDFCache{uType, rateType, N} <: OrdinaryDiffEqMutableCache
84+
@cache mutable struct SBDFCache{uType, rateType, N} <: BDFMutableCache
8285
cnt::Int
8386
ark::Bool
8487
u::uType
@@ -164,7 +167,7 @@ end
164167
end
165168

166169
@cache mutable struct QNDF1Cache{uType, rateType, coefType, coefType1, coefType2,
167-
uNoUnitsType, N, dtType, StepLimiter} <: OrdinaryDiffEqMutableCache
170+
uNoUnitsType, N, dtType, StepLimiter} <: BDFMutableCache
168171
uprev2::uType
169172
fsalfirst::rateType
170173
D::coefType1
@@ -252,7 +255,7 @@ end
252255
end
253256

254257
@cache mutable struct QNDF2Cache{uType, rateType, coefType, coefType1, coefType2,
255-
uNoUnitsType, N, dtType, StepLimiter} <: OrdinaryDiffEqMutableCache
258+
uNoUnitsType, N, dtType, StepLimiter} <: BDFMutableCache
256259
uprev2::uType
257260
uprev3::uType
258261
fsalfirst::rateType
@@ -383,7 +386,7 @@ end
383386

384387
@cache mutable struct QNDFCache{MO, UType, RUType, rateType, N, coefType, dtType, EEstType,
385388
gammaType, uType, uNoUnitsType, StepLimiter} <:
386-
OrdinaryDiffEqMutableCache
389+
BDFMutableCache
387390
fsalfirst::rateType
388391
dd::uType
389392
utilde::uType
@@ -462,7 +465,7 @@ function alg_cache(alg::QNDF{MO}, u, rate_prototype, ::Type{uEltypeNoUnits},
462465
end
463466

464467
@cache mutable struct MEBDF2Cache{uType, rateType, uNoUnitsType, N} <:
465-
OrdinaryDiffEqMutableCache
468+
BDFMutableCache
466469
u::uType
467470
uprev::uType
468471
uprev2::uType
@@ -574,7 +577,7 @@ end
574577
@cache mutable struct FBDFCache{
575578
MO, N, rateType, uNoUnitsType, tsType, tType, uType, uuType,
576579
coeffType, EEstType, rType, wType, StepLimiter} <:
577-
OrdinaryDiffEqMutableCache
580+
BDFMutableCache
578581
fsalfirst::rateType
579582
nlsolver::N
580583
ts::tsType

lib/OrdinaryDiffEqBDF/src/bdf_perform_step.jl

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ end
8686

8787
function initialize!(integrator, cache::ABDF2Cache)
8888
integrator.kshortsize = 2
89-
integrator.fsalfirst = cache.fsalfirst
90-
integrator.fsallast = du_alias_or_new(cache.nlsolver, integrator.fsalfirst)
89+
9190
resize!(integrator.k, integrator.kshortsize)
9291
integrator.k[1] = integrator.fsalfirst
9392
integrator.k[2] = integrator.fsallast
@@ -255,8 +254,7 @@ function initialize!(integrator, cache::SBDFCache)
255254
@unpack uprev, p, t = integrator
256255
@unpack f1, f2 = integrator.f
257256
integrator.kshortsize = 2
258-
integrator.fsalfirst = cache.fsalfirst
259-
integrator.fsallast = du_alias_or_new(cache.nlsolver, integrator.fsalfirst)
257+
260258
resize!(integrator.k, integrator.kshortsize)
261259
integrator.k[1] = integrator.fsalfirst
262260
integrator.k[2] = integrator.fsallast
@@ -412,8 +410,7 @@ end
412410

413411
function initialize!(integrator, cache::QNDF1Cache)
414412
integrator.kshortsize = 2
415-
integrator.fsalfirst = cache.fsalfirst
416-
integrator.fsallast = du_alias_or_new(cache.nlsolver, integrator.fsalfirst)
413+
417414
resize!(integrator.k, integrator.kshortsize)
418415
integrator.k[1] = integrator.fsalfirst
419416
integrator.k[2] = integrator.fsallast
@@ -608,8 +605,7 @@ end
608605

609606
function initialize!(integrator, cache::QNDF2Cache)
610607
integrator.kshortsize = 2
611-
integrator.fsalfirst = cache.fsalfirst
612-
integrator.fsallast = du_alias_or_new(cache.nlsolver, integrator.fsalfirst)
608+
613609
resize!(integrator.k, integrator.kshortsize)
614610
integrator.k[1] = integrator.fsalfirst
615611
integrator.k[2] = integrator.fsallast
@@ -833,8 +829,7 @@ end
833829

834830
function initialize!(integrator, cache::QNDFCache)
835831
integrator.kshortsize = 2
836-
integrator.fsalfirst = cache.fsalfirst
837-
integrator.fsallast = du_alias_or_new(cache.nlsolver, integrator.fsalfirst)
832+
838833
resize!(integrator.k, integrator.kshortsize)
839834
integrator.k[1] = integrator.fsalfirst
840835
integrator.k[2] = integrator.fsallast
@@ -1010,8 +1005,7 @@ end
10101005

10111006
function initialize!(integrator, cache::MEBDF2Cache)
10121007
integrator.kshortsize = 2
1013-
integrator.fsalfirst = cache.fsalfirst
1014-
integrator.fsallast = du_alias_or_new(cache.nlsolver, integrator.fsalfirst)
1008+
10151009
resize!(integrator.k, integrator.kshortsize)
10161010
integrator.k[1] = integrator.fsalfirst
10171011
integrator.k[2] = integrator.fsallast
@@ -1218,8 +1212,7 @@ end
12181212

12191213
function initialize!(integrator, cache::FBDFCache)
12201214
integrator.kshortsize = 2
1221-
integrator.fsalfirst = cache.fsalfirst
1222-
integrator.fsallast = du_alias_or_new(cache.nlsolver, integrator.fsalfirst)
1215+
12231216
resize!(integrator.k, integrator.kshortsize)
12241217
integrator.k[1] = integrator.fsalfirst
12251218
integrator.k[2] = integrator.fsallast

lib/OrdinaryDiffEqBDF/src/dae_caches.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
abstract type DAEBDFMutableCache <: OrdinaryDiffEqMutableCache end
2+
get_fsalfirstlast(cache::DAEBDFMutableCache,u) = (cache.fsalfirst, du_alias_or_new(cache.nlsolver, cache.fsalfirst))
3+
14
@cache mutable struct DImplicitEulerCache{uType, rateType, uNoUnitsType, N} <:
2-
OrdinaryDiffEqMutableCache
5+
DAEBDFMutableCache
36
u::uType
47
uprev::uType
58
uprev2::uType
@@ -9,6 +12,9 @@
912
nlsolver::N
1013
end
1114

15+
# Not FSAL
16+
get_fsalfirstlast(cache::DImplicitEulerCache,u) = (u,u)
17+
1218
mutable struct DImplicitEulerConstantCache{N} <: OrdinaryDiffEqConstantCache
1319
nlsolver::N
1420
end
@@ -68,7 +74,7 @@ function alg_cache(alg::DABDF2, du, u, res_prototype, rate_prototype,
6874
end
6975

7076
@cache mutable struct DABDF2Cache{uType, rateType, uNoUnitsType, N, dtType} <:
71-
OrdinaryDiffEqMutableCache
77+
DAEBDFMutableCache
7278
uₙ::uType
7379
uₙ₋₁::uType
7480
uₙ₋₂::uType
@@ -171,7 +177,7 @@ end
171177

172178
@cache mutable struct DFBDFCache{MO, N, rateType, uNoUnitsType, tsType, tType, uType,
173179
uuType, coeffType, EEstType, rType, wType} <:
174-
OrdinaryDiffEqMutableCache
180+
DAEBDFMutableCache
175181
fsalfirst::rateType
176182
nlsolver::N
177183
ts::tsType

0 commit comments

Comments
 (0)