477
477
mutable struct AdaptiveRadauConstantCache{F, Tab, Tol, Dt, U, JType} < :
478
478
OrdinaryDiffEqConstantCache
479
479
uf:: F
480
- tab :: Tab
480
+ tabs :: Vector{ Tab}
481
481
κ:: Tol
482
482
ηold:: Tol
483
483
iter:: Int
@@ -486,6 +486,9 @@ mutable struct AdaptiveRadauConstantCache{F, Tab, Tol, Dt, U, JType} <:
486
486
W_γdt:: Dt
487
487
status:: NLStatus
488
488
J:: JType
489
+ num_stages:: Int
490
+ step:: Int
491
+ hist_iter:: Float64
489
492
end
490
493
491
494
function alg_cache (alg:: AdaptiveRadau , u, rate_prototype, :: Type{uEltypeNoUnits} ,
@@ -494,30 +497,24 @@ function alg_cache(alg::AdaptiveRadau, u, rate_prototype, ::Type{uEltypeNoUnits}
494
497
:: Val{false} ) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits}
495
498
uf = UDerivativeWrapper (f, t, p)
496
499
uToltype = constvalue (uBottomEltypeNoUnits)
497
- num_stages = alg. num_stages
498
-
499
- if (num_stages == 3 )
500
- tab = BigRadauIIA5Tableau (uToltype, constvalue (tTypeNoUnits))
501
- elseif (num_stages == 5 )
502
- tab = BigRadauIIA9Tableau (uToltype, constvalue (tTypeNoUnits))
503
- elseif (num_stages == 7 )
504
- tab = BigRadauIIA13Tableau (uToltype, constvalue (tTypeNoUnits))
505
- elseif iseven (num_stages) || num_stages < 3
506
- error (" num_stages must be odd and 3 or greater" )
507
- else
508
- tab = adaptiveRadauTableau (uToltype, constvalue (tTypeNoUnits), num_stages)
500
+ num_stages = alg. min_stages
501
+ max = alg. max_stages
502
+ tabs = [BigRadauIIA5Tableau (uToltype, constvalue (tTypeNoUnits)), BigRadauIIA9Tableau (uToltype, constvalue (tTypeNoUnits)), BigRadauIIA13Tableau (uToltype, constvalue (tTypeNoUnits))]
503
+
504
+ i = 9
505
+ while i <= alg. max_stages
506
+ push! (tabs, adaptiveRadauTableau (uToltype, constvalue (tTypeNoUnits), i))
507
+ i += 2
509
508
end
510
-
511
- cont = Vector {typeof(u)} (undef, num_stages)
512
- for i in 1 : num_stages
509
+ cont = Vector {typeof(u)} (undef, max)
510
+ for i in 1 : max
513
511
cont[i] = zero (u)
514
512
end
515
513
516
514
κ = alg. κ != = nothing ? convert (uToltype, alg. κ) : convert (uToltype, 1 // 100 )
517
515
J = false .* _vec (rate_prototype) .* _vec (rate_prototype)'
518
-
519
- AdaptiveRadauConstantCache (uf, tab, κ, one (uToltype), 10000 , cont, dt, dt,
520
- Convergence, J)
516
+ AdaptiveRadauConstantCache (uf, tabs, κ, one (uToltype), 10000 , cont, dt, dt,
517
+ Convergence, J, num_stages, 1 , 0.0 )
521
518
end
522
519
523
520
mutable struct AdaptiveRadauCache{uType, cuType, tType, uNoUnitsType, rateType, JType, W1Type, W2Type,
@@ -544,7 +541,7 @@ mutable struct AdaptiveRadauCache{uType, cuType, tType, uNoUnitsType, rateType,
544
541
W1:: W1Type # real
545
542
W2:: Vector{W2Type} # complex
546
543
uf:: UF
547
- tab :: Tab
544
+ tabs :: Vector{ Tab}
548
545
κ:: Tol
549
546
ηold:: Tol
550
547
iter:: Int
@@ -559,6 +556,9 @@ mutable struct AdaptiveRadauCache{uType, cuType, tType, uNoUnitsType, rateType,
559
556
W_γdt:: Dt
560
557
status:: NLStatus
561
558
step_limiter!:: StepLimiter
559
+ num_stages:: Int
560
+ step:: Int
561
+ hist_iter:: Float64
562
562
end
563
563
564
564
function alg_cache (alg:: AdaptiveRadau , u, rate_prototype, :: Type{uEltypeNoUnits} ,
@@ -567,62 +567,57 @@ function alg_cache(alg::AdaptiveRadau, u, rate_prototype, ::Type{uEltypeNoUnits}
567
567
:: Val{true} ) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits}
568
568
uf = UJacobianWrapper (f, t, p)
569
569
uToltype = constvalue (uBottomEltypeNoUnits)
570
- num_stages = alg. num_stages
571
-
572
- if (num_stages == 3 )
573
- tab = BigRadauIIA5Tableau (uToltype, constvalue (tTypeNoUnits))
574
- elseif (num_stages == 5 )
575
- tab = BigRadauIIA9Tableau (uToltype, constvalue (tTypeNoUnits))
576
- elseif (num_stages == 7 )
577
- tab = BigRadauIIA13Tableau (uToltype, constvalue (tTypeNoUnits))
578
- elseif iseven (num_stages) || num_stages < 3
579
- error (" num_stages must be odd and 3 or greater" )
580
- else
581
- tab = adaptiveRadauTableau (uToltype, constvalue (tTypeNoUnits), num_stages)
570
+
571
+ max = alg. max_stages
572
+ num_stages = alg. min_stages
573
+
574
+ tabs = [BigRadauIIA5Tableau (uToltype, constvalue (tTypeNoUnits)), BigRadauIIA9Tableau (uToltype, constvalue (tTypeNoUnits)), BigRadauIIA13Tableau (uToltype, constvalue (tTypeNoUnits))]
575
+ i = 9
576
+ while i <= max
577
+ push! (tabs, adaptiveRadauTableau (uToltype, constvalue (tTypeNoUnits), i))
578
+ i += 2
582
579
end
583
580
584
581
κ = alg. κ != = nothing ? convert (uToltype, alg. κ) : convert (uToltype, 1 // 100 )
585
582
586
- z = Vector {typeof(u)} (undef, num_stages )
587
- w = Vector {typeof(u)} (undef, num_stages )
588
- for i in 1 : num_stages
583
+ z = Vector {typeof(u)} (undef, max )
584
+ w = Vector {typeof(u)} (undef, max )
585
+ for i in 1 : max
589
586
z[i] = w[i] = zero (u)
590
587
end
591
588
592
- c_prime = Vector {typeof(t)} (undef, num_stages) # time stepping
589
+ c_prime = Vector {typeof(t)} (undef, max) # time stepping
590
+ for i in 1 : max
591
+ c_prime[i] = zero (t)
592
+ end
593
593
594
594
dw1 = zero (u)
595
595
ubuff = zero (u)
596
- dw2 = [similar (u, Complex{eltype (u)}) for _ in 1 : (num_stages - 1 ) ÷ 2 ]
596
+ dw2 = [similar (u, Complex{eltype (u)}) for _ in 1 : (max - 1 ) ÷ 2 ]
597
597
recursivefill! .(dw2, false )
598
- cubuff = [similar (u, Complex{eltype (u)}) for _ in 1 : (num_stages - 1 ) ÷ 2 ]
598
+ cubuff = [similar (u, Complex{eltype (u)}) for _ in 1 : (max - 1 ) ÷ 2 ]
599
599
recursivefill! .(cubuff, false )
600
- dw = Vector {typeof (u)} (undef, num_stages - 1 )
600
+ dw = [ zero (u) for i in 1 : max]
601
601
602
- cont = Vector {typeof(u)} (undef, num_stages)
603
- for i in 1 : num_stages
604
- cont[i] = zero (u)
605
- end
602
+ cont = [zero (u) for i in 1 : max]
606
603
607
- derivatives = Matrix {typeof(u)} (undef, num_stages, num_stages )
608
- for i in 1 : num_stages , j in 1 : num_stages
604
+ derivatives = Matrix {typeof(u)} (undef, max, max )
605
+ for i in 1 : max , j in 1 : max
609
606
derivatives[i, j] = zero (u)
610
607
end
611
608
612
609
fsalfirst = zero (rate_prototype)
613
- fw = Vector {typeof(rate_prototype)} (undef, num_stages)
614
- ks = Vector {typeof(rate_prototype)} (undef, num_stages)
615
- for i in 1 : num_stages
616
- ks[i] = fw[i] = zero (rate_prototype)
617
- end
610
+ fw = [zero (rate_prototype) for i in 1 : max]
611
+ ks = [zero (rate_prototype) for i in 1 : max]
612
+
618
613
k = ks[1 ]
619
614
620
615
J, W1 = build_J_W (alg, u, uprev, p, t, dt, f, uEltypeNoUnits, Val (true ))
621
616
if J isa AbstractSciMLOperator
622
617
error (" Non-concrete Jacobian not yet supported by AdaptiveRadau." )
623
618
end
624
619
625
- W2 = [similar (J, Complex{eltype (W1)}) for _ in 1 : (num_stages - 1 ) ÷ 2 ]
620
+ W2 = [similar (J, Complex{eltype (W1)}) for _ in 1 : (max - 1 ) ÷ 2 ]
626
621
recursivefill! .(W2, false )
627
622
628
623
du1 = zero (rate_prototype)
@@ -640,7 +635,7 @@ function alg_cache(alg::AdaptiveRadau, u, rate_prototype, ::Type{uEltypeNoUnits}
640
635
641
636
linsolve2 = [
642
637
init (LinearProblem (W2[i], _vec (cubuff[i]); u0 = _vec (dw2[i])), alg. linsolve, alias_A = true , alias_b = true ,
643
- assumptions = LinearSolve. OperatorAssumptions (true )) for i in 1 : (num_stages - 1 ) ÷ 2 ]
638
+ assumptions = LinearSolve. OperatorAssumptions (true )) for i in 1 : (max - 1 ) ÷ 2 ]
644
639
645
640
rtol = reltol isa Number ? reltol : zero (reltol)
646
641
atol = reltol isa Number ? reltol : zero (reltol)
@@ -649,9 +644,9 @@ function alg_cache(alg::AdaptiveRadau, u, rate_prototype, ::Type{uEltypeNoUnits}
649
644
z, w, c_prime, dw1, ubuff, dw2, cubuff, dw, cont, derivatives,
650
645
du1, fsalfirst, ks, k, fw,
651
646
J, W1, W2,
652
- uf, tab , κ, one (uToltype), 10000 , tmp,
647
+ uf, tabs , κ, one (uToltype), 10000 , tmp,
653
648
atmp, jac_config,
654
649
linsolve1, linsolve2, rtol, atol, dt, dt,
655
- Convergence, alg. step_limiter!)
650
+ Convergence, alg. step_limiter!, num_stages, 1 , 0.0 )
656
651
end
657
652
0 commit comments