477477mutable struct AdaptiveRadauConstantCache{F, Tab, Tol, Dt, U, JType} < :
478478 OrdinaryDiffEqConstantCache
479479 uf:: F
480- tab :: Tab
480+ tabs :: Vector{ Tab}
481481 κ:: Tol
482482 ηold:: Tol
483483 iter:: Int
@@ -486,6 +486,9 @@ mutable struct AdaptiveRadauConstantCache{F, Tab, Tol, Dt, U, JType} <:
486486 W_γdt:: Dt
487487 status:: NLStatus
488488 J:: JType
489+ num_stages:: Int
490+ step:: Int
491+ hist_iter:: Float64
489492end
490493
491494function alg_cache (alg:: AdaptiveRadau , u, rate_prototype, :: Type{uEltypeNoUnits} ,
@@ -494,30 +497,24 @@ function alg_cache(alg::AdaptiveRadau, u, rate_prototype, ::Type{uEltypeNoUnits}
494497 :: Val{false} ) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits}
495498 uf = UDerivativeWrapper (f, t, p)
496499 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
509508 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
513511 cont[i] = zero (u)
514512 end
515513
516514 κ = alg. κ != = nothing ? convert (uToltype, alg. κ) : convert (uToltype, 1 // 100 )
517515 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 )
521518end
522519
523520mutable struct AdaptiveRadauCache{uType, cuType, tType, uNoUnitsType, rateType, JType, W1Type, W2Type,
@@ -544,7 +541,7 @@ mutable struct AdaptiveRadauCache{uType, cuType, tType, uNoUnitsType, rateType,
544541 W1:: W1Type # real
545542 W2:: Vector{W2Type} # complex
546543 uf:: UF
547- tab :: Tab
544+ tabs :: Vector{ Tab}
548545 κ:: Tol
549546 ηold:: Tol
550547 iter:: Int
@@ -559,6 +556,9 @@ mutable struct AdaptiveRadauCache{uType, cuType, tType, uNoUnitsType, rateType,
559556 W_γdt:: Dt
560557 status:: NLStatus
561558 step_limiter!:: StepLimiter
559+ num_stages:: Int
560+ step:: Int
561+ hist_iter:: Float64
562562end
563563
564564function alg_cache (alg:: AdaptiveRadau , u, rate_prototype, :: Type{uEltypeNoUnits} ,
@@ -567,62 +567,57 @@ function alg_cache(alg::AdaptiveRadau, u, rate_prototype, ::Type{uEltypeNoUnits}
567567 :: Val{true} ) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits}
568568 uf = UJacobianWrapper (f, t, p)
569569 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
582579 end
583580
584581 κ = alg. κ != = nothing ? convert (uToltype, alg. κ) : convert (uToltype, 1 // 100 )
585582
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
589586 z[i] = w[i] = zero (u)
590587 end
591588
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
593593
594594 dw1 = zero (u)
595595 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 ]
597597 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 ]
599599 recursivefill! .(cubuff, false )
600- dw = Vector {typeof (u)} (undef, num_stages - 1 )
600+ dw = [ zero (u) for i in 1 : max]
601601
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]
606603
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
609606 derivatives[i, j] = zero (u)
610607 end
611608
612609 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+
618613 k = ks[1 ]
619614
620615 J, W1 = build_J_W (alg, u, uprev, p, t, dt, f, uEltypeNoUnits, Val (true ))
621616 if J isa AbstractSciMLOperator
622617 error (" Non-concrete Jacobian not yet supported by AdaptiveRadau." )
623618 end
624619
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 ]
626621 recursivefill! .(W2, false )
627622
628623 du1 = zero (rate_prototype)
@@ -640,7 +635,7 @@ function alg_cache(alg::AdaptiveRadau, u, rate_prototype, ::Type{uEltypeNoUnits}
640635
641636 linsolve2 = [
642637 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 ]
644639
645640 rtol = reltol isa Number ? reltol : zero (reltol)
646641 atol = reltol isa Number ? reltol : zero (reltol)
@@ -649,9 +644,9 @@ function alg_cache(alg::AdaptiveRadau, u, rate_prototype, ::Type{uEltypeNoUnits}
649644 z, w, c_prime, dw1, ubuff, dw2, cubuff, dw, cont, derivatives,
650645 du1, fsalfirst, ks, k, fw,
651646 J, W1, W2,
652- uf, tab , κ, one (uToltype), 10000 , tmp,
647+ uf, tabs , κ, one (uToltype), 10000 , tmp,
653648 atmp, jac_config,
654649 linsolve1, linsolve2, rtol, atol, dt, dt,
655- Convergence, alg. step_limiter!)
650+ Convergence, alg. step_limiter!, num_stages, 1 , 0.0 )
656651end
657652
0 commit comments