Skip to content

Commit af33fd2

Browse files
authored
Merge pull request #3252 from oscardssmith/os/Refactor-linsolve
refactor Linsolve to match LinearSolve precs interface
2 parents 20b07b2 + f5b36b5 commit af33fd2

File tree

26 files changed

+298
-503
lines changed

26 files changed

+298
-503
lines changed

lib/OrdinaryDiffEqBDF/src/OrdinaryDiffEqBDF.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import OrdinaryDiffEqCore: alg_order, calculate_residuals!,
77
OrdinaryDiffEqMutableCache, OrdinaryDiffEqConstantCache,
88
OrdinaryDiffEqNewtonAdaptiveAlgorithm,
99
OrdinaryDiffEqNewtonAlgorithm,
10-
AbstractController, DEFAULT_PRECS,
10+
AbstractController,
1111
CompiledFloats, uses_uprev,
1212
alg_cache, _vec, _reshape, @cache,
1313
isfsal, full_cache,

lib/OrdinaryDiffEqBDF/src/algorithms.jl

Lines changed: 30 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ function BDF_docstring(
1111
1212
concrete_jac = nothing,
1313
linsolve = nothing,
14-
precs = DEFAULT_PRECS,
1514
""" * "\n" * extra_keyword_default
1615

1716
keyword_default_description = """
@@ -98,11 +97,10 @@ end
9897
step_limiter! = trivial_limiter!,
9998
"""
10099
)
101-
struct ABDF2{AD, F, F2, P, K, T, StepLimiter, CJ} <:
100+
struct ABDF2{AD, F, F2, K, T, StepLimiter, CJ} <:
102101
OrdinaryDiffEqNewtonAdaptiveAlgorithm
103102
linsolve::F
104103
nlsolve::F2
105-
precs::P
106104
κ::K
107105
tol::T
108106
smooth_est::Bool
@@ -115,18 +113,16 @@ end
115113
function ABDF2(;
116114
autodiff = AutoForwardDiff(),
117115
concrete_jac = nothing,
118-
κ = nothing, tol = nothing, linsolve = nothing, precs = DEFAULT_PRECS,
119-
nlsolve = NLNewton(),
116+
κ = nothing, tol = nothing, linsolve = nothing, nlsolve = NLNewton(),
120117
smooth_est = true, extrapolant = :linear,
121118
controller = :Standard, step_limiter! = trivial_limiter!
122119
)
123120
autodiff = _fixup_ad(autodiff)
124121

125122
return ABDF2(
126-
linsolve, nlsolve, precs, κ, tol,
123+
linsolve, nlsolve, κ, tol,
127124
smooth_est, extrapolant, controller, step_limiter!, autodiff,
128125
_unwrap_val(concrete_jac)
129-
130126
)
131127
end
132128

@@ -162,11 +158,10 @@ like `KenCarp4`, but instead using a multistep BDF approach",
162158
order,
163159
"""
164160
)
165-
struct SBDF{AD, F, F2, P, K, T, CJ} <:
161+
struct SBDF{AD, F, F2, K, T, CJ} <:
166162
OrdinaryDiffEqNewtonAlgorithm
167163
linsolve::F
168164
nlsolve::F2
169-
precs::P
170165
κ::K
171166
tol::T
172167
extrapolant::Symbol
@@ -179,7 +174,7 @@ end
179174
function SBDF(
180175
order; autodiff = AutoForwardDiff(),
181176
concrete_jac = nothing,
182-
linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), κ = nothing,
177+
linsolve = nothing, nlsolve = NLNewton(), κ = nothing,
183178
tol = nothing,
184179
extrapolant = :linear, ark = false
185180
)
@@ -188,7 +183,6 @@ function SBDF(
188183
return SBDF(
189184
linsolve,
190185
nlsolve,
191-
precs,
192186
κ,
193187
tol,
194188
extrapolant,
@@ -204,7 +198,7 @@ end
204198
function SBDF(;
205199
autodiff = AutoForwardDiff(),
206200
concrete_jac = nothing,
207-
linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), κ = nothing,
201+
linsolve = nothing, nlsolve = NLNewton(), κ = nothing,
208202
tol = nothing,
209203
extrapolant = :linear,
210204
order, ark = false
@@ -214,7 +208,6 @@ function SBDF(;
214208
return SBDF(
215209
linsolve,
216210
nlsolve,
217-
precs,
218211
κ,
219212
tol,
220213
extrapolant,
@@ -299,11 +292,10 @@ SBDF4(; kwargs...) = SBDF(4; kwargs...)
299292
step_limiter! = trivial_limiter!,
300293
"""
301294
)
302-
struct QNDF1{AD, F, F2, P, κType, StepLimiter, CJ} <:
295+
struct QNDF1{AD, F, F2, κType, StepLimiter, CJ} <:
303296
OrdinaryDiffEqNewtonAdaptiveAlgorithm
304297
linsolve::F
305298
nlsolve::F2
306-
precs::P
307299
extrapolant::Symbol
308300
kappa::κType
309301
controller::Symbol
@@ -315,7 +307,7 @@ end
315307
function QNDF1(;
316308
autodiff = AutoForwardDiff(),
317309
concrete_jac = nothing,
318-
linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(),
310+
linsolve = nothing, nlsolve = NLNewton(),
319311
extrapolant = :linear, kappa = -37 // 200,
320312
controller = :Standard, step_limiter! = trivial_limiter!
321313
)
@@ -324,7 +316,6 @@ function QNDF1(;
324316
return QNDF1(
325317
linsolve,
326318
nlsolve,
327-
precs,
328319
extrapolant,
329320
kappa,
330321
controller,
@@ -363,11 +354,10 @@ end
363354
step_limiter! = trivial_limiter!,
364355
"""
365356
)
366-
struct QNDF2{AD, F, F2, P, κType, StepLimiter, CJ} <:
357+
struct QNDF2{AD, F, F2, κType, StepLimiter, CJ} <:
367358
OrdinaryDiffEqNewtonAdaptiveAlgorithm
368359
linsolve::F
369360
nlsolve::F2
370-
precs::P
371361
extrapolant::Symbol
372362
kappa::κType
373363
controller::Symbol
@@ -379,7 +369,7 @@ end
379369
function QNDF2(;
380370
autodiff = AutoForwardDiff(),
381371
concrete_jac = nothing,
382-
linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(),
372+
linsolve = nothing, nlsolve = NLNewton(),
383373
extrapolant = :linear, kappa = -1 // 9,
384374
controller = :Standard, step_limiter! = trivial_limiter!
385375
)
@@ -388,7 +378,6 @@ function QNDF2(;
388378
return QNDF2(
389379
linsolve,
390380
nlsolve,
391-
precs,
392381
extrapolant,
393382
kappa,
394383
controller,
@@ -431,12 +420,11 @@ end
431420
step_limiter! = trivial_limiter!,
432421
"""
433422
)
434-
struct QNDF{MO, AD, F, F2, P, K, T, κType, StepLimiter, CJ} <:
423+
struct QNDF{MO, AD, F, F2, K, T, κType, StepLimiter, CJ} <:
435424
OrdinaryDiffEqNewtonAdaptiveAlgorithm
436425
max_order::Val{MO}
437426
linsolve::F
438427
nlsolve::F2
439-
precs::P
440428
κ::K
441429
tol::T
442430
extrapolant::Symbol
@@ -450,7 +438,7 @@ end
450438
function QNDF(;
451439
max_order::Val{MO} = Val{5}(),
452440
autodiff = AutoForwardDiff(), concrete_jac = nothing,
453-
linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), κ = nothing,
441+
linsolve = nothing, nlsolve = NLNewton(), κ = nothing,
454442
tol = nothing,
455443
extrapolant = :linear, kappa = (
456444
-37 // 200, -1 // 9, -823 // 10000, -83 // 2000, 0 // 1,
@@ -460,10 +448,9 @@ function QNDF(;
460448
autodiff = _fixup_ad(autodiff)
461449

462450
return QNDF(
463-
max_order, linsolve, nlsolve, precs, κ, tol,
451+
max_order, linsolve, nlsolve, κ, tol,
464452
extrapolant, kappa, controller, step_limiter!, autodiff,
465453
_unwrap_val(concrete_jac)
466-
467454
)
468455
end
469456

@@ -492,27 +479,25 @@ end
492479
extrapolant = :constant,
493480
"""
494481
)
495-
struct MEBDF2{AD, F, F2, P, CJ} <:
482+
struct MEBDF2{AD, F, F2, CJ} <:
496483
OrdinaryDiffEqNewtonAlgorithm
497484
linsolve::F
498485
nlsolve::F2
499-
precs::P
500486
extrapolant::Symbol
501487
autodiff::AD
502488
concrete_jac::CJ
503489
end
504490
function MEBDF2(;
505491
autodiff = AutoForwardDiff(),
506492
concrete_jac = nothing,
507-
linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(),
493+
linsolve = nothing, nlsolve = NLNewton(),
508494
extrapolant = :constant
509495
)
510496
autodiff = _fixup_ad(autodiff)
511497

512498
return MEBDF2(
513499
linsolve,
514500
nlsolve,
515-
precs,
516501
extrapolant,
517502
autodiff,
518503
_unwrap_val(concrete_jac)
@@ -563,12 +548,11 @@ Utilizes Shampine's accuracy-optimal kappa values as defaults (has a keyword arg
563548
stald_tiny = 1e-90,
564549
"""
565550
)
566-
struct FBDF{MO, AD, F, F2, P, K, T, StepLimiter, CJ} <:
551+
struct FBDF{MO, AD, F, F2, K, T, StepLimiter, CJ} <:
567552
OrdinaryDiffEqNewtonAdaptiveAlgorithm
568553
max_order::Val{MO}
569554
linsolve::F
570555
nlsolve::F2
571-
precs::P
572556
κ::K
573557
tol::T
574558
extrapolant::Symbol
@@ -588,7 +572,7 @@ end
588572
function FBDF(;
589573
max_order::Val{MO} = Val{5}(),
590574
autodiff = AutoForwardDiff(), concrete_jac = nothing,
591-
linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), κ = nothing,
575+
linsolve = nothing, nlsolve = NLNewton(), κ = nothing,
592576
tol = nothing,
593577
extrapolant = :linear, controller = :Standard, step_limiter! = trivial_limiter!,
594578
stald = true,
@@ -602,7 +586,7 @@ function FBDF(;
602586
autodiff = _fixup_ad(autodiff)
603587

604588
return FBDF(
605-
max_order, linsolve, nlsolve, precs, κ, tol, extrapolant,
589+
max_order, linsolve, nlsolve, κ, tol, extrapolant,
606590
controller, step_limiter!, autodiff,
607591
stald, Float64(stald_rrcut), Float64(stald_vrrtol), Float64(stald_vrrt2),
608592
Float64(stald_sqtol), Float64(stald_rrtol), Float64(stald_tiny),
@@ -706,10 +690,9 @@ It uses an apriori error estimator for adaptivity based on a finite differencing
706690
controller = :Standard,
707691
"""
708692
)
709-
struct DImplicitEuler{AD, F, F2, P, CJ} <: DAEAlgorithm
693+
struct DImplicitEuler{AD, F, F2, CJ} <: DAEAlgorithm
710694
linsolve::F
711695
nlsolve::F2
712-
precs::P
713696
extrapolant::Symbol
714697
controller::Symbol
715698
autodiff::AD
@@ -718,17 +701,16 @@ end
718701
function DImplicitEuler(;
719702
autodiff = AutoForwardDiff(),
720703
concrete_jac = nothing,
721-
linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(),
704+
linsolve = nothing, nlsolve = NLNewton(),
722705
extrapolant = :constant,
723706
controller = :Standard
724707
)
725708
autodiff = _fixup_ad(autodiff)
726709

727710
return DImplicitEuler(
728711
linsolve,
729-
nlsolve, precs, extrapolant, controller, autodiff,
712+
nlsolve, extrapolant, controller, autodiff,
730713
_unwrap_val(concrete_jac)
731-
732714
)
733715
end
734716

@@ -754,10 +736,9 @@ end
754736
controller = :Standard,
755737
"""
756738
)
757-
struct DABDF2{AD, F, F2, P, CJ} <: DAEAlgorithm
739+
struct DABDF2{AD, F, F2, CJ} <: DAEAlgorithm
758740
linsolve::F
759741
nlsolve::F2
760-
precs::P
761742
extrapolant::Symbol
762743
controller::Symbol
763744
autodiff::AD
@@ -766,32 +747,30 @@ end
766747
function DABDF2(;
767748
autodiff = AutoForwardDiff(),
768749
concrete_jac = nothing,
769-
linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(),
750+
linsolve = nothing, nlsolve = NLNewton(),
770751
extrapolant = :constant,
771752
controller = :Standard
772753
)
773754
autodiff = _fixup_ad(autodiff)
774755

775756
return DABDF2(
776757
linsolve,
777-
nlsolve, precs, extrapolant, controller, autodiff,
758+
nlsolve, extrapolant, controller, autodiff,
778759
_unwrap_val(concrete_jac)
779-
780760
)
781761
end
782762

783763
#=
784764
struct DBDF{AD, F, F2, P} <: DAEAlgorithm
785765
linsolve::F
786766
nlsolve::F2
787-
precs::P
788767
extrapolant::Symbol
789768
end
790769
791770
DBDF(;chunk_size=Val{0}(),autodiff=Val{true}(), concrete_jac = nothing,diff_type=Val{:forward},
792-
linsolve=nothing,precs = DEFAULT_PRECS,nlsolve=NLNewton(),extrapolant=:linear) =
793-
DBDF{_ad_chunksize_int(autodiff),_unwrap_val(autodiff),typeof(linsolve),typeof(nlsolve),typeof(precs),diff_type,true,_unwrap_val(concrete_jac)}(
794-
linsolve,nlsolve,precs,extrapolant)
771+
linsolve=nothing,nlsolve=NLNewton(),extrapolant=:linear) =
772+
DBDF{_ad_chunksize_int(autodiff),_unwrap_val(autodiff),typeof(linsolve),typeof(nlsolve),diff_type,true,_unwrap_val(concrete_jac)}(
773+
linsolve,nlsolve,extrapolant)
795774
=#
796775

797776
@doc BDF_docstring(
@@ -820,11 +799,10 @@ DBDF(;chunk_size=Val{0}(),autodiff=Val{true}(), concrete_jac = nothing,diff_type
820799
max_order::Val{MO} = Val{5}(),
821800
"""
822801
)
823-
struct DFBDF{MO, AD, F, F2, P, K, T, CJ} <: DAEAlgorithm
802+
struct DFBDF{MO, AD, F, F2, K, T, CJ} <: DAEAlgorithm
824803
max_order::Val{MO}
825804
linsolve::F
826805
nlsolve::F2
827-
precs::P
828806
κ::K
829807
tol::T
830808
extrapolant::Symbol
@@ -835,17 +813,16 @@ end
835813
function DFBDF(;
836814
max_order::Val{MO} = Val{5}(),
837815
autodiff = AutoForwardDiff(), concrete_jac = nothing,
838-
linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), κ = nothing,
816+
linsolve = nothing, nlsolve = NLNewton(), κ = nothing,
839817
tol = nothing,
840818
extrapolant = :linear, controller = :Standard
841819
) where {MO}
842820
autodiff = _fixup_ad(autodiff)
843821

844822
return DFBDF(
845-
max_order, linsolve, nlsolve, precs, κ, tol, extrapolant,
823+
max_order, linsolve, nlsolve, κ, tol, extrapolant,
846824
controller, autodiff,
847825
_unwrap_val(concrete_jac)
848-
849826
)
850827
end
851828

0 commit comments

Comments
 (0)