@@ -497,6 +497,7 @@ mutable struct AdaptiveRadauConstantCache{F, Tab, Tol, Dt, U, JType} <:
497
497
num_stages:: Int
498
498
step:: Int
499
499
hist_iter:: Float64
500
+ index:: Int
500
501
end
501
502
502
503
function alg_cache (alg:: AdaptiveRadau , u, rate_prototype, :: Type{uEltypeNoUnits} ,
@@ -508,30 +509,32 @@ function alg_cache(alg::AdaptiveRadau, u, rate_prototype, ::Type{uEltypeNoUnits}
508
509
509
510
max_order = alg. max_order
510
511
min_order = alg. min_order
511
- max = (max_order - 1 ) ÷ 4 * 2 + 1
512
- min = (min_order - 1 ) ÷ 4 * 2 + 1
512
+ max_stages = (max_order - 1 ) ÷ 4 * 2 + 1
513
+ min_stages = (min_order - 1 ) ÷ 4 * 2 + 1
513
514
if (alg. min_order < 5 )
514
515
error (" min_order choice $min_order below 5 is not compatible with the algorithm" )
515
- elseif (max < min )
516
+ elseif (max_stages < min_stages )
516
517
error (" max_order $max_order is below min_order $min_order " )
517
518
end
518
- num_stages = min
519
+ num_stages = min_stages
519
520
520
521
tabs = [RadauIIATableau5 (uToltype, constvalue (tTypeNoUnits)), RadauIIATableau9 (uToltype, constvalue (tTypeNoUnits)), RadauIIATableau13 (uToltype, constvalue (tTypeNoUnits))]
521
- i = 9
522
- while i <= max
522
+ i = max (min_stages, 9 )
523
+ while i <= max_stages
523
524
push! (tabs, RadauIIATableau (uToltype, constvalue (tTypeNoUnits), i))
524
525
i += 2
525
526
end
526
- cont = Vector {typeof(u)} (undef, max )
527
- for i in 1 : max
527
+ cont = Vector {typeof(u)} (undef, max_stages )
528
+ for i in 1 : max_stages
528
529
cont[i] = zero (u)
529
530
end
530
531
532
+ index = min ((min_stages - 1 ) ÷ 2 , 4 )
533
+
531
534
κ = alg. κ != = nothing ? convert (uToltype, alg. κ) : convert (uToltype, 1 // 100 )
532
535
J = false .* _vec (rate_prototype) .* _vec (rate_prototype)'
533
536
AdaptiveRadauConstantCache (uf, tabs, κ, one (uToltype), 10000 , cont, dt, dt,
534
- Convergence, J, num_stages, 1 , 0.0 )
537
+ Convergence, J, num_stages, 1 , 0.0 , index )
535
538
end
536
539
537
540
mutable struct AdaptiveRadauCache{uType, cuType, tType, uNoUnitsType, rateType, JType, W1Type, W2Type,
@@ -578,6 +581,7 @@ mutable struct AdaptiveRadauCache{uType, cuType, tType, uNoUnitsType, rateType,
578
581
num_stages:: Int
579
582
step:: Int
580
583
hist_iter:: Float64
584
+ index:: Int
581
585
end
582
586
583
587
function alg_cache (alg:: AdaptiveRadau , u, rate_prototype, :: Type{uEltypeNoUnits} ,
@@ -589,56 +593,58 @@ function alg_cache(alg::AdaptiveRadau, u, rate_prototype, ::Type{uEltypeNoUnits}
589
593
590
594
max_order = alg. max_order
591
595
min_order = alg. min_order
592
- max = (max_order - 1 ) ÷ 4 * 2 + 1
593
- min = (min_order - 1 ) ÷ 4 * 2 + 1
596
+ max_stages = (max_order - 1 ) ÷ 4 * 2 + 1
597
+ min_stages = (min_order - 1 ) ÷ 4 * 2 + 1
594
598
if (alg. min_order < 5 )
595
599
error (" min_order choice $min_order below 5 is not compatible with the algorithm" )
596
- elseif (max < min )
600
+ elseif (max_stages < min_stages )
597
601
error (" max_order $max_order is below min_order $min_order " )
598
602
end
599
- num_stages = min
603
+ num_stages = min_stages
600
604
601
605
tabs = [RadauIIATableau5 (uToltype, constvalue (tTypeNoUnits)), RadauIIATableau9 (uToltype, constvalue (tTypeNoUnits)), RadauIIATableau13 (uToltype, constvalue (tTypeNoUnits))]
602
- i = 9
603
- while i <= max
606
+ i = max (min_stages, 9 )
607
+ while i <= max_stages
604
608
push! (tabs, RadauIIATableau (uToltype, constvalue (tTypeNoUnits), i))
605
609
i += 2
606
610
end
607
611
612
+ index = min ((min_stages - 1 ) ÷ 2 , 4 )
613
+
608
614
κ = alg. κ != = nothing ? convert (uToltype, alg. κ) : convert (uToltype, 1 // 100 )
609
615
610
- z = Vector {typeof(u)} (undef, max )
611
- w = Vector {typeof(u)} (undef, max )
612
- for i in 1 : max
616
+ z = Vector {typeof(u)} (undef, max_stages )
617
+ w = Vector {typeof(u)} (undef, max_stages )
618
+ for i in 1 : max_stages
613
619
z[i] = zero (u)
614
620
w[i] = zero (u)
615
621
end
616
622
617
- αdt = [zero (t) for i in 1 : max ]
618
- βdt = [zero (t) for i in 1 : max ]
619
- c_prime = Vector {typeof(t)} (undef, max ) # time stepping
620
- for i in 1 : max
623
+ αdt = [zero (t) for i in 1 : max_stages ]
624
+ βdt = [zero (t) for i in 1 : max_stages ]
625
+ c_prime = Vector {typeof(t)} (undef, max_stages ) # time stepping
626
+ for i in 1 : max_stages
621
627
c_prime[i] = zero (t)
622
628
end
623
629
624
630
dw1 = zero (u)
625
631
ubuff = zero (u)
626
- dw2 = [similar (u, Complex{eltype (u)}) for _ in 1 : (max - 1 ) ÷ 2 ]
632
+ dw2 = [similar (u, Complex{eltype (u)}) for _ in 1 : (max_stages - 1 ) ÷ 2 ]
627
633
recursivefill! .(dw2, false )
628
- cubuff = [similar (u, Complex{eltype (u)}) for _ in 1 : (max - 1 ) ÷ 2 ]
634
+ cubuff = [similar (u, Complex{eltype (u)}) for _ in 1 : (max_stages - 1 ) ÷ 2 ]
629
635
recursivefill! .(cubuff, false )
630
- dw = [zero (u) for i in 1 : max ]
636
+ dw = [zero (u) for i in 1 : max_stages ]
631
637
632
- cont = [zero (u) for i in 1 : max ]
638
+ cont = [zero (u) for i in 1 : max_stages ]
633
639
634
- derivatives = Matrix {typeof(u)} (undef, max, max )
635
- for i in 1 : max , j in 1 : max
640
+ derivatives = Matrix {typeof(u)} (undef, max_stages, max_stages )
641
+ for i in 1 : max_stages , j in 1 : max_stages
636
642
derivatives[i, j] = zero (u)
637
643
end
638
644
639
645
fsalfirst = zero (rate_prototype)
640
- fw = [zero (rate_prototype) for i in 1 : max ]
641
- ks = [zero (rate_prototype) for i in 1 : max ]
646
+ fw = [zero (rate_prototype) for i in 1 : max_stages ]
647
+ ks = [zero (rate_prototype) for i in 1 : max_stages ]
642
648
643
649
k = ks[1 ]
644
650
@@ -647,7 +653,7 @@ function alg_cache(alg::AdaptiveRadau, u, rate_prototype, ::Type{uEltypeNoUnits}
647
653
error (" Non-concrete Jacobian not yet supported by AdaptiveRadau." )
648
654
end
649
655
650
- W2 = [similar (J, Complex{eltype (W1)}) for _ in 1 : (max - 1 ) ÷ 2 ]
656
+ W2 = [similar (J, Complex{eltype (W1)}) for _ in 1 : (max_stages - 1 ) ÷ 2 ]
651
657
recursivefill! .(W2, false )
652
658
653
659
du1 = zero (rate_prototype)
@@ -665,7 +671,7 @@ function alg_cache(alg::AdaptiveRadau, u, rate_prototype, ::Type{uEltypeNoUnits}
665
671
666
672
linsolve2 = [
667
673
init (LinearProblem (W2[i], _vec (cubuff[i]); u0 = _vec (dw2[i])), alg. linsolve, alias_A = true , alias_b = true ,
668
- assumptions = LinearSolve. OperatorAssumptions (true )) for i in 1 : (max - 1 ) ÷ 2 ]
674
+ assumptions = LinearSolve. OperatorAssumptions (true )) for i in 1 : (max_stages - 1 ) ÷ 2 ]
669
675
670
676
rtol = reltol isa Number ? reltol : zero (reltol)
671
677
atol = reltol isa Number ? reltol : zero (reltol)
@@ -677,6 +683,6 @@ function alg_cache(alg::AdaptiveRadau, u, rate_prototype, ::Type{uEltypeNoUnits}
677
683
uf, tabs, κ, one (uToltype), 10000 , tmp,
678
684
atmp, jac_config,
679
685
linsolve1, linsolve2, rtol, atol, dt, dt,
680
- Convergence, alg. step_limiter!, num_stages, 1 , 0.0 )
686
+ Convergence, alg. step_limiter!, num_stages, 1 , 0.0 , index )
681
687
end
682
688
0 commit comments