From 3917a262daf6e90b60429fbd56935c8a90f9587b Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Tue, 30 Jul 2024 19:52:33 +0530 Subject: [PATCH 001/133] Added High Order and Low Order RK methods --- lib/OrdinaryDiffEqHighOrderRK/Project.toml | 4 + .../src/OrdinaryDiffEqHighOrderRK.jl | 21 + .../src/alg_utils.jl | 12 + .../src/algorithms.jl | 61 ++ .../src}/high_order_rk_addsteps.jl | 2 +- .../src}/high_order_rk_caches.jl | 2 +- .../src}/high_order_rk_perform_step.jl | 2 +- .../src}/high_order_rk_tableaus.jl | 2 +- lib/OrdinaryDiffEqLowOrderRK/Project.toml | 4 + .../src/OrdinaryDiffEqLowOrderRK.jl | 29 + lib/OrdinaryDiffEqLowOrderRK/src/alg_utils.jl | 49 ++ .../src/algorithms.jl | 628 +++++++++++------- .../src/fixed_timestep_perform_step.jl | 487 ++++++++++++++ .../src/interp_func.jl | 37 ++ .../src}/low_order_rk_addsteps.jl | 2 +- .../src}/low_order_rk_caches.jl | 2 +- .../src}/low_order_rk_perform_step.jl | 2 +- .../src}/low_order_rk_tableaus.jl | 2 +- .../src}/split_perform_step.jl | 2 +- .../test}/owrenzen_tests.jl | 2 +- lib/OrdinaryDiffEqLowOrderRK/test/runtests.jl | 3 + src/OrdinaryDiffEq.jl | 31 +- src/alg_utils.jl | 37 +- src/algorithms.jl | 228 +------ src/interp_func.jl | 38 -- .../fixed_timestep_perform_step.jl | 490 +------------- test/runtests.jl | 5 +- 27 files changed, 1135 insertions(+), 1049 deletions(-) create mode 100644 lib/OrdinaryDiffEqHighOrderRK/Project.toml create mode 100644 lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl create mode 100644 lib/OrdinaryDiffEqHighOrderRK/src/alg_utils.jl create mode 100644 lib/OrdinaryDiffEqHighOrderRK/src/algorithms.jl rename {src/dense => lib/OrdinaryDiffEqHighOrderRK/src}/high_order_rk_addsteps.jl (99%) rename {src/caches => lib/OrdinaryDiffEqHighOrderRK/src}/high_order_rk_caches.jl (99%) rename {src/perform_step => lib/OrdinaryDiffEqHighOrderRK/src}/high_order_rk_perform_step.jl (99%) rename {src/tableaus => lib/OrdinaryDiffEqHighOrderRK/src}/high_order_rk_tableaus.jl (99%) create mode 100644 lib/OrdinaryDiffEqLowOrderRK/Project.toml create mode 100644 lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl create mode 100644 lib/OrdinaryDiffEqLowOrderRK/src/alg_utils.jl rename src/algorithms/explicit_rk.jl => lib/OrdinaryDiffEqLowOrderRK/src/algorithms.jl (67%) create mode 100644 lib/OrdinaryDiffEqLowOrderRK/src/fixed_timestep_perform_step.jl create mode 100644 lib/OrdinaryDiffEqLowOrderRK/src/interp_func.jl rename {src/dense => lib/OrdinaryDiffEqLowOrderRK/src}/low_order_rk_addsteps.jl (99%) rename {src/caches => lib/OrdinaryDiffEqLowOrderRK/src}/low_order_rk_caches.jl (99%) rename {src/perform_step => lib/OrdinaryDiffEqLowOrderRK/src}/low_order_rk_perform_step.jl (99%) rename {src/tableaus => lib/OrdinaryDiffEqLowOrderRK/src}/low_order_rk_tableaus.jl (99%) rename {src/perform_step => lib/OrdinaryDiffEqLowOrderRK/src}/split_perform_step.jl (99%) rename {test/algconvergence => lib/OrdinaryDiffEqLowOrderRK/test}/owrenzen_tests.jl (97%) create mode 100644 lib/OrdinaryDiffEqLowOrderRK/test/runtests.jl diff --git a/lib/OrdinaryDiffEqHighOrderRK/Project.toml b/lib/OrdinaryDiffEqHighOrderRK/Project.toml new file mode 100644 index 0000000000..a7081d102b --- /dev/null +++ b/lib/OrdinaryDiffEqHighOrderRK/Project.toml @@ -0,0 +1,4 @@ +name = "OrdinaryDiffEqHighOrderRK" +uuid = "d28bc4f8-55e1-4f49-af69-84c1a99f0f58" +authors = ["ParamThakkar123 "] +version = "0.1.0" diff --git a/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl b/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl new file mode 100644 index 0000000000..222ec57605 --- /dev/null +++ b/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl @@ -0,0 +1,21 @@ +module OrdinaryDiffEqHighOrderRK + +import OrdinaryDiffEq: alg_order, qmax_default, qmin_default, beta2_default, beta1_default, + explicit_rk_docstring, OrdinaryDiffEqAdaptiveAlgorithm, trivial_limiter!, + _ode_addsteps!, @unpack, @cache, OrdinaryDiffEqMutableCache, constvalue, + alg_cache, uses_uprev, initialize!, perform_step!, OrdinaryDiffEqConstantCache, + calculate_residuals!, calculate_residuals +import Static: False +import MuladdMacro: @muladd +import FastBroadcast: @.. + +include("algorithms.jl") +include("alg_utils.jl") +include("high_order_rk_caches.jl") +include("high_order_rk_tableaus.jl") +include("high_order_rk_addsteps.jl") +include("high_order_rk_perform_step.jl") + +export TanYam7, DP8, PFRK87, TsitPap8 + +end diff --git a/lib/OrdinaryDiffEqHighOrderRK/src/alg_utils.jl b/lib/OrdinaryDiffEqHighOrderRK/src/alg_utils.jl new file mode 100644 index 0000000000..6cab08f623 --- /dev/null +++ b/lib/OrdinaryDiffEqHighOrderRK/src/alg_utils.jl @@ -0,0 +1,12 @@ +alg_order(alg::TanYam7) = 7 +alg_order(alg::DP8) = 8 +alg_order(alg::TsitPap8) = 8 +alg_order(alg::PFRK87) = 8 + +qmin_default(alg::DP8) = 1 // 3 + +qmax_default(alg::DP8) = 6 + +beta2_default(alg::DP8) = 0 // 1 + +beta1_default(alg::DP8, beta2) = typeof(beta2)(1 // alg_order(alg)) - beta2 / 5 \ No newline at end of file diff --git a/lib/OrdinaryDiffEqHighOrderRK/src/algorithms.jl b/lib/OrdinaryDiffEqHighOrderRK/src/algorithms.jl new file mode 100644 index 0000000000..be111f65c2 --- /dev/null +++ b/lib/OrdinaryDiffEqHighOrderRK/src/algorithms.jl @@ -0,0 +1,61 @@ +@doc explicit_rk_docstring( + "Tanaka-Yamashita 7 Runge-Kutta method. (7th order interpolant).", + "TanYam7", + references = "Tanaka M., Muramatsu S., Yamashita S., (1992), On the Optimization of Some Nine-Stage + Seventh-order Runge-Kutta Method, Information Processing Society of Japan, + 33 (12), pp. 1512-1526.") +Base.@kwdef struct TanYam7{StageLimiter, StepLimiter, Thread} <: + OrdinaryDiffEqAdaptiveAlgorithm + stage_limiter!::StageLimiter = trivial_limiter! + step_limiter!::StepLimiter = trivial_limiter! + thread::Thread = False() +end +# for backwards compatibility +function TanYam7(stage_limiter!, step_limiter! = trivial_limiter!) + TanYam7(stage_limiter!, step_limiter!, False()) +end + +@doc explicit_rk_docstring( + "Hairer's 8/5/3 adaption of the Dormand-Prince Runge-Kutta method. (7th order interpolant).", + "DP8", + references = "E. Hairer, S.P. Norsett, G. Wanner, (1993) Solving Ordinary Differential Equations I. + Nonstiff Problems. 2nd Edition. Springer Series in Computational Mathematics, + Springer-Verlag.") +Base.@kwdef struct DP8{StageLimiter, StepLimiter, Thread} <: OrdinaryDiffEqAdaptiveAlgorithm + stage_limiter!::StageLimiter = trivial_limiter! + step_limiter!::StepLimiter = trivial_limiter! + thread::Thread = False() +end +# for backwards compatibility +function DP8(stage_limiter!, step_limiter! = trivial_limiter!) + DP8(stage_limiter!, step_limiter!, False()) +end + +@doc explicit_rk_docstring("Phase-fitted Runge-Kutta of 8th order.", "PFRK87", + extra_keyword_description = """- `omega`: a periodicity phase estimate, + when accurate this method results in zero numerical dissipation. + """, + extra_keyword_default = "omega = 0.0") +Base.@kwdef struct PFRK87{StageLimiter, StepLimiter, Thread, T} <: + OrdinaryDiffEqAdaptiveAlgorithm + stage_limiter!::StageLimiter = trivial_limiter! + step_limiter!::StepLimiter = trivial_limiter! + thread::Thread = False() + omega::T = 0.0 +end +# for backwards compatibility +function PFRK87(stage_limiter!, step_limiter! = trivial_limiter!; omega = 0.0) + PFRK87(stage_limiter!, step_limiter!, False(), omega) +end + +@doc explicit_rk_docstring("Tsitouras-Papakostas 8/7 Runge-Kutta method.", "TsitPap8") +Base.@kwdef struct TsitPap8{StageLimiter, StepLimiter, Thread} <: + OrdinaryDiffEqAdaptiveAlgorithm + stage_limiter!::StageLimiter = trivial_limiter! + step_limiter!::StepLimiter = trivial_limiter! + thread::Thread = False() +end +# for backwards compatibility +function TsitPap8(stage_limiter!, step_limiter! = trivial_limiter!) + TsitPap8(stage_limiter!, step_limiter!, False()) +end \ No newline at end of file diff --git a/src/dense/high_order_rk_addsteps.jl b/lib/OrdinaryDiffEqHighOrderRK/src/high_order_rk_addsteps.jl similarity index 99% rename from src/dense/high_order_rk_addsteps.jl rename to lib/OrdinaryDiffEqHighOrderRK/src/high_order_rk_addsteps.jl index 69d14ef78c..5e1447fb24 100644 --- a/src/dense/high_order_rk_addsteps.jl +++ b/lib/OrdinaryDiffEqHighOrderRK/src/high_order_rk_addsteps.jl @@ -256,4 +256,4 @@ end end end end -=# +=# \ No newline at end of file diff --git a/src/caches/high_order_rk_caches.jl b/lib/OrdinaryDiffEqHighOrderRK/src/high_order_rk_caches.jl similarity index 99% rename from src/caches/high_order_rk_caches.jl rename to lib/OrdinaryDiffEqHighOrderRK/src/high_order_rk_caches.jl index bfb55ef511..678ee8416f 100644 --- a/src/caches/high_order_rk_caches.jl +++ b/lib/OrdinaryDiffEqHighOrderRK/src/high_order_rk_caches.jl @@ -262,4 +262,4 @@ function alg_cache(alg::PFRK87, u, rate_prototype, ::Type{uEltypeNoUnits}, dt, reltol, p, calck, ::Val{false}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits} PFRK87ConstantCache(constvalue(uBottomEltypeNoUnits), constvalue(tTypeNoUnits)) -end +end \ No newline at end of file diff --git a/src/perform_step/high_order_rk_perform_step.jl b/lib/OrdinaryDiffEqHighOrderRK/src/high_order_rk_perform_step.jl similarity index 99% rename from src/perform_step/high_order_rk_perform_step.jl rename to lib/OrdinaryDiffEqHighOrderRK/src/high_order_rk_perform_step.jl index 62e6025575..9873cc8cbf 100644 --- a/src/perform_step/high_order_rk_perform_step.jl +++ b/lib/OrdinaryDiffEqHighOrderRK/src/high_order_rk_perform_step.jl @@ -1150,4 +1150,4 @@ end f(k, u, p, t + dt) integrator.stats.nf += 1 return nothing -end +end \ No newline at end of file diff --git a/src/tableaus/high_order_rk_tableaus.jl b/lib/OrdinaryDiffEqHighOrderRK/src/high_order_rk_tableaus.jl similarity index 99% rename from src/tableaus/high_order_rk_tableaus.jl rename to lib/OrdinaryDiffEqHighOrderRK/src/high_order_rk_tableaus.jl index 1e03a14aac..8ca15f91de 100644 --- a/src/tableaus/high_order_rk_tableaus.jl +++ b/lib/OrdinaryDiffEqHighOrderRK/src/high_order_rk_tableaus.jl @@ -1403,4 +1403,4 @@ function PFRK87ConstantCache(T1::Type, T2::Type) α1211, α1311, β1, β6, β7, β8, β9, β10, β11, β12, β13, β1tilde, β6tilde, β7tilde, β8tilde, β9tilde, β10tilde, β11tilde, β12tilde, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13) -end +end \ No newline at end of file diff --git a/lib/OrdinaryDiffEqLowOrderRK/Project.toml b/lib/OrdinaryDiffEqLowOrderRK/Project.toml new file mode 100644 index 0000000000..ca4f29622c --- /dev/null +++ b/lib/OrdinaryDiffEqLowOrderRK/Project.toml @@ -0,0 +1,4 @@ +name = "OrdinaryDiffEqLowOrderRK" +uuid = "1344f307-1e59-4825-a18e-ace9aa3fa4c6" +authors = ["ParamThakkar123 "] +version = "0.1.0" diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl new file mode 100644 index 0000000000..428bcf023b --- /dev/null +++ b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl @@ -0,0 +1,29 @@ +module OrdinaryDiffEqLowOrderRK + +import OrdinaryDiffEq: alg_order, isfsal, beta2_default, beta1_default, alg_stability_size, + ssp_coefficient, OrdinaryDiffEqAlgorithm, OrdinaryDiffEqExponentialAlgorithm, + explicit_rk_docstring, trivial_limiter!, OrdinaryDiffEqAdaptiveAlgorithm, + unwrap_alg, @unpack, initialize!, perform_step!, calculate_residuals, + calculate_residuals!, _ode_addsteps!, @OnDemandTableauExtract, constvalue, + OrdinaryDiffEqMutableCache, uses_uprev, OrdinaryDiffEqConstantCache +import DiffEqBase: @tight_loop_macros +import MuladdMacro: @muladd +import FastBroadcast: @.. + +include("algorithms.jl") +include("alg_utils.jl") +include("low_order_rk_caches.jl") +include("low_order_rk_tableaus.jl") +include("interp_func.jl") +include("low_order_rk_perform_step.jl") +include("low_order_rk_addsteps.jl") +include("split_perform_step.jl") +include("fixed_timestep_perform_step.jl") + +export Euler, SplitEuler, Heun, Ralston, Midpoint, RK4, + BS3, OwrenZen3, OwrenZen4, OwrenZen5, BS5, Tsit5, + DP5, Anas5, RKO65, FRK65, RKM, MSRK5, MSRK6, + PSRK4p7q6, PSRK3p5q4, PSRK3p6q5, Stepanov5, SIR54, + Alshina2, Alshina3, Alshina6 + +end \ No newline at end of file diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/alg_utils.jl b/lib/OrdinaryDiffEqLowOrderRK/src/alg_utils.jl new file mode 100644 index 0000000000..5a0b66acc9 --- /dev/null +++ b/lib/OrdinaryDiffEqLowOrderRK/src/alg_utils.jl @@ -0,0 +1,49 @@ +alg_order(alg::Euler) = 1 +alg_order(alg::SplitEuler) = 1 +alg_order(alg::Heun) = 2 +alg_order(alg::Ralston) = 2 +alg_order(alg::Midpoint) = 2 +alg_order(alg::BS3) = 3 +alg_order(alg::OwrenZen3) = 3 +alg_order(alg::BS5) = 5 +alg_order(alg::OwrenZen4) = 4 +alg_order(alg::OwrenZen5) = 5 +alg_order(alg::Tsit5) = 5 +alg_order(alg::DP5) = 5 +alg_order(alg::Anas5) = 5 +alg_order(alg::RKO65) = 5 +alg_order(alg::FRK65) = 6 +alg_order(alg::RK4) = 4 +alg_order(alg::RKM) = 4 +alg_order(alg::MSRK5) = 5 +alg_order(alg::MSRK6) = 6 +alg_order(alg::PSRK4p7q6) = 4 +alg_order(alg::PSRK3p6q5) = 3 +alg_order(alg::PSRK3p5q4) = 3 +alg_order(alg::Stepanov5) = 5 +alg_order(alg::SIR54) = 5 +alg_order(alg::Alshina2) = 2 +alg_order(alg::Alshina3) = 3 +alg_order(alg::Alshina6) = 6 + +isfsal(alg::FRK65) = true +isfsal(alg::RKO65) = false +isfsal(alg::PSRK3p5q4) = false +isfsal(alg::PSRK3p6q5) = false +isfsal(alg::PSRK4p7q6) = false + +beta2_default(alg::DP5) = 4 // 100 + +beta1_default(alg::DP5, beta2) = typeof(beta2)(1 // alg_order(alg)) - 3beta2 / 4 + +alg_stability_size(alg::Tsit5) = 3.5068 +alg_stability_size(alg::DP5) = 3.3066 + +ssp_coefficient(alg::Euler) = 1 + +function DiffEqBase.prepare_alg( + alg::SplitEuler, + u0::AbstractArray, + p, prob) + alg +end \ No newline at end of file diff --git a/src/algorithms/explicit_rk.jl b/lib/OrdinaryDiffEqLowOrderRK/src/algorithms.jl similarity index 67% rename from src/algorithms/explicit_rk.jl rename to lib/OrdinaryDiffEqLowOrderRK/src/algorithms.jl index 5fe7fde93e..b90b379d7c 100644 --- a/src/algorithms/explicit_rk.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/algorithms.jl @@ -6,6 +6,14 @@ function Base.show(io::IO, alg::OrdinaryDiffEqAlgorithm) print(io, ")") end +""" +Euler - The canonical forward Euler method. Fixed timestep only. +""" +struct Euler <: OrdinaryDiffEqAlgorithm end + +struct SplitEuler <: + OrdinaryDiffEqExponentialAlgorithm{0, false, Val{:forward}, Val{true}, nothing} end + @doc explicit_rk_docstring( "The second order Heun's method. Uses embedded Euler method for adaptivity.", "Heun") @@ -71,150 +79,28 @@ function RK4(stage_limiter!, step_limiter! = trivial_limiter!) RK4(stage_limiter!, step_limiter!, False()) end -@doc explicit_rk_docstring("TBD", "RKM") -Base.@kwdef struct RKM{StageLimiter, StepLimiter, Thread} <: OrdinaryDiffEqAlgorithm - stage_limiter!::StageLimiter = trivial_limiter! - step_limiter!::StepLimiter = trivial_limiter! - thread::Thread = False() -end -# for backwards compatibility -function RKM(stage_limiter!, step_limiter! = trivial_limiter!) - RKM(stage_limiter!, step_limiter!, False()) -end - -@doc explicit_rk_docstring("4-stage Pseudo-Symplectic Explicit RK method.", "3p5q(4)", - references = "@article{Aubry1998, - author = {A. Aubry and P. Chartier}, - journal = {BIT Numer. Math.}, - title = {Pseudo-symplectic {R}unge-{K}utta methods}, - year = {1998}, - }, - @article{Capuano2017, - title = {Explicit {R}unge–{K}utta schemes for incompressible flow with improved energy-conservation properties}, - journal = {J. Comput. Phys.}, - year = {2017}, - author = {F. Capuano and G. Coppola and L. Rández and L. {de Luca}},}") -Base.@kwdef struct PSRK3p5q4{StageLimiter, StepLimiter, Thread} <: OrdinaryDiffEqAlgorithm - stage_limiter!::StageLimiter = trivial_limiter! - step_limiter!::StepLimiter = trivial_limiter! - thread::Thread = False() -end - -@doc explicit_rk_docstring("5-stage Pseudo-Symplectic Explicit RK method.", "3p6q(5)", - references = "@article{Aubry1998, - author = {A. Aubry and P. Chartier}, - journal = {BIT Numer. Math.}, - title = {Pseudo-symplectic {R}unge-{K}utta methods}, - year = {1998}, - }, - @article{Capuano2017, - title = {Explicit {R}unge–{K}utta schemes for incompressible flow with improved energy-conservation properties}, - journal = {J. Comput. Phys.}, - year = {2017}, - author = {F. Capuano and G. Coppola and L. Rández and L. {de Luca}},}") -Base.@kwdef struct PSRK3p6q5{StageLimiter, StepLimiter, Thread} <: OrdinaryDiffEqAlgorithm - stage_limiter!::StageLimiter = trivial_limiter! - step_limiter!::StepLimiter = trivial_limiter! - thread::Thread = False() -end - -@doc explicit_rk_docstring("6-stage Pseudo-Symplectic Explicit RK method.", "4p7q(6)", - references = "@article{Aubry1998, - author = {A. Aubry and P. Chartier}, - journal = {BIT Numer. Math.}, - title = {Pseudo-symplectic {R}unge-{K}utta methods}, - volume = {38}, - PAGES = {439-461}, - year = {1998}, - }, - @article{Capuano2017, - title = {Explicit {R}unge–{K}utta schemes for incompressible flow with improved energy-conservation properties}, - journal = {J. Comput. Phys.}, - volume = {328}, - pages = {86-94}, - year = {2017}, - issn = {0021-9991}, - doi = {https://doi.org/10.1016/j.jcp.2016.10.040}, - author = {F. Capuano and G. Coppola and L. Rández and L. {de Luca}},}") -Base.@kwdef struct PSRK4p7q6{StageLimiter, StepLimiter, Thread} <: OrdinaryDiffEqAlgorithm - stage_limiter!::StageLimiter = trivial_limiter! - step_limiter!::StepLimiter = trivial_limiter! - thread::Thread = False() -end - -@doc explicit_rk_docstring("5th order Explicit RK method.", "MSRK5", - references = "Misha Stepanov - https://arxiv.org/pdf/2202.08443.pdf : Figure 3.") -Base.@kwdef struct MSRK5{StageLimiter, StepLimiter, Thread} <: OrdinaryDiffEqAlgorithm - stage_limiter!::StageLimiter = trivial_limiter! - step_limiter!::StepLimiter = trivial_limiter! - thread::Thread = False() -end -# for backwards compatibility -function MSRK5(stage_limiter!, step_limiter! = trivial_limiter!) - MSRK5(stage_limiter!, step_limiter!, False()) -end - -@doc explicit_rk_docstring("6th order Explicit RK method.", "MSRK6", - references = "Misha Stepanov - https://arxiv.org/pdf/2202.08443.pdf : Table4") -Base.@kwdef struct MSRK6{StageLimiter, StepLimiter, Thread} <: OrdinaryDiffEqAlgorithm - stage_limiter!::StageLimiter = trivial_limiter! - step_limiter!::StepLimiter = trivial_limiter! - thread::Thread = False() -end -# for backwards compatibility -function MSRK6(stage_limiter!, step_limiter! = trivial_limiter!) - MSRK6(stage_limiter!, step_limiter!, False()) -end - -@doc explicit_rk_docstring("5th order Explicit RK method.", - "Stepanov5", - references = "@article{Stepanov2021Embedded5, - title={Embedded (4, 5) pairs of explicit 7-stage Runge–Kutta methods with FSAL property}, - author={Misha Stepanov}, - journal={Calcolo}, - year={2021}, - volume={59} +@doc explicit_rk_docstring( + "A third-order, four-stage explicit FSAL Runge-Kutta method with embedded error +estimator of Bogacki and Shampine.", + "BS3", + references = "@article{bogacki19893, + title={A 3 (2) pair of Runge-Kutta formulas}, + author={Bogacki, Przemyslaw and Shampine, Lawrence F}, + journal={Applied Mathematics Letters}, + volume={2}, + number={4}, + pages={321--325}, + year={1989}, + publisher={Elsevier} }") -Base.@kwdef struct Stepanov5{StageLimiter, StepLimiter, Thread} <: - OrdinaryDiffEqAdaptiveAlgorithm - stage_limiter!::StageLimiter = trivial_limiter! - step_limiter!::StepLimiter = trivial_limiter! - thread::Thread = False() -end -# for backwards compatibility -function Stepanov5(stage_limiter!, step_limiter! = trivial_limiter!) - Stepanov5(stage_limiter!, step_limiter!, False()) -end - -@doc explicit_rk_docstring("4th order Runge-Kutta method designed for periodic problems.", - "Anas5", - extra_keyword_description = """- `w`: a periodicity estimate, which when accurate the method becomes 5th order - (and is otherwise 4th order with less error for better estimates). - """, - extra_keyword_default = "w = 1") -Base.@kwdef struct Anas5{StageLimiter, StepLimiter, Thread, T} <: OrdinaryDiffEqAlgorithm - stage_limiter!::StageLimiter = trivial_limiter! - step_limiter!::StepLimiter = trivial_limiter! - thread::Thread = False() - w::T = 1 -end -# for backwards compatibility -function Anas5(stage_limiter!, step_limiter! = trivial_limiter!; w = 1) - Anas5(stage_limiter!, step_limiter!, False(), w) -end - -@doc explicit_rk_docstring("5th order Explicit RK method.", "RKO5", - references = "Tsitouras, Ch. \"Explicit Runge–Kutta methods for starting integration of - Lane–Emden problem.\" Applied Mathematics and Computation 354 (2019): 353-364. - doi: https://doi.org/10.1016/j.amc.2019.02.047") -Base.@kwdef struct RKO65{StageLimiter, StepLimiter, Thread} <: OrdinaryDiffEqAlgorithm +Base.@kwdef struct BS3{StageLimiter, StepLimiter, Thread} <: OrdinaryDiffEqAdaptiveAlgorithm stage_limiter!::StageLimiter = trivial_limiter! step_limiter!::StepLimiter = trivial_limiter! thread::Thread = False() end # for backwards compatibility -function RKO65(stage_limiter!, step_limiter! = trivial_limiter!) - RKO65(stage_limiter!, step_limiter!, False()) +function BS3(stage_limiter!, step_limiter! = trivial_limiter!) + BS3(stage_limiter!, step_limiter!, False()) end @doc explicit_rk_docstring( @@ -290,50 +176,30 @@ function OwrenZen5(stage_limiter!, step_limiter! = trivial_limiter!) end @doc explicit_rk_docstring( - "A third-order, four-stage explicit FSAL Runge-Kutta method with embedded error -estimator of Bogacki and Shampine.", - "BS3", - references = "@article{bogacki19893, - title={A 3 (2) pair of Runge-Kutta formulas}, - author={Bogacki, Przemyslaw and Shampine, Lawrence F}, - journal={Applied Mathematics Letters}, - volume={2}, - number={4}, - pages={321--325}, - year={1989}, - publisher={Elsevier} - }") -Base.@kwdef struct BS3{StageLimiter, StepLimiter, Thread} <: OrdinaryDiffEqAdaptiveAlgorithm - stage_limiter!::StageLimiter = trivial_limiter! - step_limiter!::StepLimiter = trivial_limiter! - thread::Thread = False() -end -# for backwards compatibility -function BS3(stage_limiter!, step_limiter! = trivial_limiter!) - BS3(stage_limiter!, step_limiter!, False()) -end - -@doc explicit_rk_docstring( - "Dormand-Prince's 5/4 Runge-Kutta method. (free 4th order interpolant).", - "DP5", - references = "@article{dormand1980family, - title={A family of embedded Runge-Kutta formulae}, - author={Dormand, John R and Prince, Peter J}, - journal={Journal of computational and applied mathematics}, - volume={6}, - number={1}, - pages={19--26}, - year={1980}, + "Bogacki-Shampine 5/4 Runge-Kutta method. (lazy 5th order interpolant).", + "BS5", + references = "@article{bogacki1996efficient, + title={An efficient runge-kutta (4, 5) pair}, + author={Bogacki, P and Shampine, Lawrence F}, + journal={Computers \\& Mathematics with Applications}, + volume={32}, + number={6}, + pages={15--28}, + year={1996}, publisher={Elsevier} - }") -Base.@kwdef struct DP5{StageLimiter, StepLimiter, Thread} <: OrdinaryDiffEqAdaptiveAlgorithm + }", + extra_keyword_description = """- `lazy`: determines if the lazy interpolant is used. + """, + extra_keyword_default = "lazy = true") +Base.@kwdef struct BS5{StageLimiter, StepLimiter, Thread} <: OrdinaryDiffEqAdaptiveAlgorithm stage_limiter!::StageLimiter = trivial_limiter! step_limiter!::StepLimiter = trivial_limiter! thread::Thread = False() + lazy::Bool = true end # for backwards compatibility -function DP5(stage_limiter!, step_limiter! = trivial_limiter!) - DP5(stage_limiter!, step_limiter!, False()) +function BS5(stage_limiter!, step_limiter! = trivial_limiter!; lazy = true) + BS5(stage_limiter!, step_limiter!, False(), lazy) end @doc explicit_rk_docstring( @@ -362,48 +228,57 @@ function Tsit5(stage_limiter!, step_limiter! = trivial_limiter!) end @doc explicit_rk_docstring( - "Hairer's 8/5/3 adaption of the Dormand-Prince Runge-Kutta method. (7th order interpolant).", - "DP8", - references = "E. Hairer, S.P. Norsett, G. Wanner, (1993) Solving Ordinary Differential Equations I. - Nonstiff Problems. 2nd Edition. Springer Series in Computational Mathematics, - Springer-Verlag.") -Base.@kwdef struct DP8{StageLimiter, StepLimiter, Thread} <: OrdinaryDiffEqAdaptiveAlgorithm + "Dormand-Prince's 5/4 Runge-Kutta method. (free 4th order interpolant).", + "DP5", + references = "@article{dormand1980family, + title={A family of embedded Runge-Kutta formulae}, + author={Dormand, John R and Prince, Peter J}, + journal={Journal of computational and applied mathematics}, + volume={6}, + number={1}, + pages={19--26}, + year={1980}, + publisher={Elsevier} + }") +Base.@kwdef struct DP5{StageLimiter, StepLimiter, Thread} <: OrdinaryDiffEqAdaptiveAlgorithm stage_limiter!::StageLimiter = trivial_limiter! step_limiter!::StepLimiter = trivial_limiter! thread::Thread = False() end # for backwards compatibility -function DP8(stage_limiter!, step_limiter! = trivial_limiter!) - DP8(stage_limiter!, step_limiter!, False()) +function DP5(stage_limiter!, step_limiter! = trivial_limiter!) + DP5(stage_limiter!, step_limiter!, False()) end -@doc explicit_rk_docstring( - "Tanaka-Yamashita 7 Runge-Kutta method. (7th order interpolant).", - "TanYam7", - references = "Tanaka M., Muramatsu S., Yamashita S., (1992), On the Optimization of Some Nine-Stage - Seventh-order Runge-Kutta Method, Information Processing Society of Japan, - 33 (12), pp. 1512-1526.") -Base.@kwdef struct TanYam7{StageLimiter, StepLimiter, Thread} <: - OrdinaryDiffEqAdaptiveAlgorithm +@doc explicit_rk_docstring("4th order Runge-Kutta method designed for periodic problems.", + "Anas5", + extra_keyword_description = """- `w`: a periodicity estimate, which when accurate the method becomes 5th order + (and is otherwise 4th order with less error for better estimates). + """, + extra_keyword_default = "w = 1") +Base.@kwdef struct Anas5{StageLimiter, StepLimiter, Thread, T} <: OrdinaryDiffEqAlgorithm stage_limiter!::StageLimiter = trivial_limiter! step_limiter!::StepLimiter = trivial_limiter! thread::Thread = False() + w::T = 1 end # for backwards compatibility -function TanYam7(stage_limiter!, step_limiter! = trivial_limiter!) - TanYam7(stage_limiter!, step_limiter!, False()) +function Anas5(stage_limiter!, step_limiter! = trivial_limiter!; w = 1) + Anas5(stage_limiter!, step_limiter!, False(), w) end -@doc explicit_rk_docstring("Tsitouras-Papakostas 8/7 Runge-Kutta method.", "TsitPap8") -Base.@kwdef struct TsitPap8{StageLimiter, StepLimiter, Thread} <: - OrdinaryDiffEqAdaptiveAlgorithm +@doc explicit_rk_docstring("5th order Explicit RK method.", "RKO5", + references = "Tsitouras, Ch. \"Explicit Runge–Kutta methods for starting integration of + Lane–Emden problem.\" Applied Mathematics and Computation 354 (2019): 353-364. + doi: https://doi.org/10.1016/j.amc.2019.02.047") +Base.@kwdef struct RKO65{StageLimiter, StepLimiter, Thread} <: OrdinaryDiffEqAlgorithm stage_limiter!::StageLimiter = trivial_limiter! step_limiter!::StepLimiter = trivial_limiter! thread::Thread = False() end # for backwards compatibility -function TsitPap8(stage_limiter!, step_limiter! = trivial_limiter!) - TsitPap8(stage_limiter!, step_limiter!, False()) +function RKO65(stage_limiter!, step_limiter! = trivial_limiter!) + RKO65(stage_limiter!, step_limiter!, False()) end @doc explicit_rk_docstring("Zero Dissipation Runge-Kutta of 6th order.", "FRK65", @@ -424,51 +299,342 @@ function FRK65(stage_limiter!, step_limiter! = trivial_limiter!; omega = 0.0) FRK65(stage_limiter!, step_limiter!, False(), omega) end -@doc explicit_rk_docstring("Phase-fitted Runge-Kutta of 8th order.", "PFRK87", - extra_keyword_description = """- `omega`: a periodicity phase estimate, - when accurate this method results in zero numerical dissipation. - """, - extra_keyword_default = "omega = 0.0") -Base.@kwdef struct PFRK87{StageLimiter, StepLimiter, Thread, T} <: - OrdinaryDiffEqAdaptiveAlgorithm +@doc explicit_rk_docstring("TBD", "RKM") +Base.@kwdef struct RKM{StageLimiter, StepLimiter, Thread} <: OrdinaryDiffEqAlgorithm stage_limiter!::StageLimiter = trivial_limiter! step_limiter!::StepLimiter = trivial_limiter! thread::Thread = False() - omega::T = 0.0 end # for backwards compatibility -function PFRK87(stage_limiter!, step_limiter! = trivial_limiter!; omega = 0.0) - PFRK87(stage_limiter!, step_limiter!, False(), omega) +function RKM(stage_limiter!, step_limiter! = trivial_limiter!) + RKM(stage_limiter!, step_limiter!, False()) end -@doc explicit_rk_docstring( - "Bogacki-Shampine 5/4 Runge-Kutta method. (lazy 5th order interpolant).", - "BS5", - references = "@article{bogacki1996efficient, - title={An efficient runge-kutta (4, 5) pair}, - author={Bogacki, P and Shampine, Lawrence F}, - journal={Computers \\& Mathematics with Applications}, - volume={32}, - number={6}, - pages={15--28}, - year={1996}, - publisher={Elsevier} - }", - extra_keyword_description = """- `lazy`: determines if the lazy interpolant is used. - """, - extra_keyword_default = "lazy = true") -Base.@kwdef struct BS5{StageLimiter, StepLimiter, Thread} <: OrdinaryDiffEqAdaptiveAlgorithm +@doc explicit_rk_docstring("5th order Explicit RK method.", "MSRK5", + references = "Misha Stepanov - https://arxiv.org/pdf/2202.08443.pdf : Figure 3.") +Base.@kwdef struct MSRK5{StageLimiter, StepLimiter, Thread} <: OrdinaryDiffEqAlgorithm stage_limiter!::StageLimiter = trivial_limiter! step_limiter!::StepLimiter = trivial_limiter! thread::Thread = False() - lazy::Bool = true end # for backwards compatibility -function BS5(stage_limiter!, step_limiter! = trivial_limiter!; lazy = true) - BS5(stage_limiter!, step_limiter!, False(), lazy) +function MSRK5(stage_limiter!, step_limiter! = trivial_limiter!) + MSRK5(stage_limiter!, step_limiter!, False()) +end + +@doc explicit_rk_docstring("6th order Explicit RK method.", "MSRK6", + references = "Misha Stepanov - https://arxiv.org/pdf/2202.08443.pdf : Table4") +Base.@kwdef struct MSRK6{StageLimiter, StepLimiter, Thread} <: OrdinaryDiffEqAlgorithm + stage_limiter!::StageLimiter = trivial_limiter! + step_limiter!::StepLimiter = trivial_limiter! + thread::Thread = False() +end +# for backwards compatibility +function MSRK6(stage_limiter!, step_limiter! = trivial_limiter!) + MSRK6(stage_limiter!, step_limiter!, False()) +end + +@doc explicit_rk_docstring("6-stage Pseudo-Symplectic Explicit RK method.", "4p7q(6)", + references = "@article{Aubry1998, + author = {A. Aubry and P. Chartier}, + journal = {BIT Numer. Math.}, + title = {Pseudo-symplectic {R}unge-{K}utta methods}, + volume = {38}, + PAGES = {439-461}, + year = {1998}, + }, + @article{Capuano2017, + title = {Explicit {R}unge–{K}utta schemes for incompressible flow with improved energy-conservation properties}, + journal = {J. Comput. Phys.}, + volume = {328}, + pages = {86-94}, + year = {2017}, + issn = {0021-9991}, + doi = {https://doi.org/10.1016/j.jcp.2016.10.040}, + author = {F. Capuano and G. Coppola and L. Rández and L. {de Luca}},}") +Base.@kwdef struct PSRK4p7q6{StageLimiter, StepLimiter, Thread} <: OrdinaryDiffEqAlgorithm + stage_limiter!::StageLimiter = trivial_limiter! + step_limiter!::StepLimiter = trivial_limiter! + thread::Thread = False() end +@doc explicit_rk_docstring("4-stage Pseudo-Symplectic Explicit RK method.", "3p5q(4)", + references = "@article{Aubry1998, + author = {A. Aubry and P. Chartier}, + journal = {BIT Numer. Math.}, + title = {Pseudo-symplectic {R}unge-{K}utta methods}, + year = {1998}, + }, + @article{Capuano2017, + title = {Explicit {R}unge–{K}utta schemes for incompressible flow with improved energy-conservation properties}, + journal = {J. Comput. Phys.}, + year = {2017}, + author = {F. Capuano and G. Coppola and L. Rández and L. {de Luca}},}") +Base.@kwdef struct PSRK3p5q4{StageLimiter, StepLimiter, Thread} <: OrdinaryDiffEqAlgorithm + stage_limiter!::StageLimiter = trivial_limiter! + step_limiter!::StepLimiter = trivial_limiter! + thread::Thread = False() +end + +@doc explicit_rk_docstring("5-stage Pseudo-Symplectic Explicit RK method.", "3p6q(5)", + references = "@article{Aubry1998, + author = {A. Aubry and P. Chartier}, + journal = {BIT Numer. Math.}, + title = {Pseudo-symplectic {R}unge-{K}utta methods}, + year = {1998}, + }, + @article{Capuano2017, + title = {Explicit {R}unge–{K}utta schemes for incompressible flow with improved energy-conservation properties}, + journal = {J. Comput. Phys.}, + year = {2017}, + author = {F. Capuano and G. Coppola and L. Rández and L. {de Luca}},}") +Base.@kwdef struct PSRK3p6q5{StageLimiter, StepLimiter, Thread} <: OrdinaryDiffEqAlgorithm + stage_limiter!::StageLimiter = trivial_limiter! + step_limiter!::StepLimiter = trivial_limiter! + thread::Thread = False() +end + +@doc explicit_rk_docstring("5th order Explicit RK method.", + "Stepanov5", + references = "@article{Stepanov2021Embedded5, + title={Embedded (4, 5) pairs of explicit 7-stage Runge–Kutta methods with FSAL property}, + author={Misha Stepanov}, + journal={Calcolo}, + year={2021}, + volume={59} + }") +Base.@kwdef struct Stepanov5{StageLimiter, StepLimiter, Thread} <: + OrdinaryDiffEqAdaptiveAlgorithm + stage_limiter!::StageLimiter = trivial_limiter! + step_limiter!::StepLimiter = trivial_limiter! + thread::Thread = False() +end +# for backwards compatibility +function Stepanov5(stage_limiter!, step_limiter! = trivial_limiter!) + Stepanov5(stage_limiter!, step_limiter!, False()) +end + +@inline trivial_limiter!(u, integrator, p, t) = nothing """ -Euler - The canonical forward Euler method. Fixed timestep only. + SIR54(; stage_limiter! = OrdinaryDiffEq.trivial_limiter!, + step_limiter! = OrdinaryDiffEq.trivial_limiter!, + thread = OrdinaryDiffEq.False()) + +5th order Explicit RK method suited for SIR-type epidemic models. + +Like SSPRK methods, this method also takes optional arguments `stage_limiter!` +and `step_limiter!`, where `stage_limiter!` and `step_limiter!` are functions +of the form `limiter!(u, integrator, p, t)`. + +The argument `thread` determines whether internal broadcasting on +appropriate CPU arrays should be serial (`thread = OrdinaryDiffEq.False()`, +default) or use multiple threads (`thread = OrdinaryDiffEq.True()`) when +Julia is started with multiple threads. + +## Reference + +@article{Kovalnogov2020RungeKuttaPS, +title={Runge–Kutta pairs suited for SIR‐type epidemic models}, +author={Vladislav N. Kovalnogov and Theodore E. Simos and Ch. Tsitouras}, +journal={Mathematical Methods in the Applied Sciences}, +year={2020}, +volume={44}, +pages={5210 - 5216} +} +""" +struct SIR54{StageLimiter, StepLimiter, Thread} <: OrdinaryDiffEqAdaptiveAlgorithm + stage_limiter!::StageLimiter + step_limiter!::StepLimiter + thread::Thread +end + +function SIR54(; stage_limiter! = trivial_limiter!, step_limiter! = trivial_limiter!, + thread = False()) + SIR54{typeof(stage_limiter!), typeof(step_limiter!), typeof(thread)}(stage_limiter!, + step_limiter!, + thread) +end + +# for backwards compatibility +function SIR54(stage_limiter!, step_limiter! = trivial_limiter!) + SIR54{typeof(stage_limiter!), typeof(step_limiter!), False}(stage_limiter!, + step_limiter!, + False()) +end + +function Base.show(io::IO, alg::SIR54) + print(io, "SIR54(stage_limiter! = ", alg.stage_limiter!, + ", step_limiter! = ", alg.step_limiter!, + ", thread = ", alg.thread, ")") +end + +""" + Alshina2(; stage_limiter! = OrdinaryDiffEq.trivial_limiter!, + step_limiter! = OrdinaryDiffEq.trivial_limiter!, + thread = OrdinaryDiffEq.False()) + +2nd order, 2-stage Explicit Runge-Kutta Method with optimal parameters. + +Like SSPRK methods, this method also takes optional arguments `stage_limiter!` +and `step_limiter!`, where `stage_limiter!` and `step_limiter!` are functions +of the form `limiter!(u, integrator, p, t)`. + +The argument `thread` determines whether internal broadcasting on +appropriate CPU arrays should be serial (`thread = OrdinaryDiffEq.False()`, +default) or use multiple threads (`thread = OrdinaryDiffEq.True()`) when +Julia is started with multiple threads. + +## Reference + +@article{Alshina2008, +doi = {10.1134/s0965542508030068}, +url = {https://doi.org/10.1134/s0965542508030068}, +year = {2008}, +month = mar, +publisher = {Pleiades Publishing Ltd}, +volume = {48}, +number = {3}, +pages = {395--405}, +author = {E. A. Alshina and E. M. Zaks and N. N. Kalitkin}, +title = {Optimal first- to sixth-order accurate Runge-Kutta schemes}, +journal = {Computational Mathematics and Mathematical Physics} +} +""" +struct Alshina2{StageLimiter, StepLimiter, Thread} <: OrdinaryDiffEqAdaptiveAlgorithm + stage_limiter!::StageLimiter + step_limiter!::StepLimiter + thread::Thread +end + +function Alshina2(; stage_limiter! = trivial_limiter!, step_limiter! = trivial_limiter!, + thread = False()) + Alshina2{typeof(stage_limiter!), typeof(step_limiter!), typeof(thread)}(stage_limiter!, + step_limiter!, + thread) +end + +function Alshina2(stage_limiter!, step_limiter! = trivial_limiter!) + Alshina2{typeof(stage_limiter!), typeof(step_limiter!), False}(stage_limiter!, + step_limiter!, + False()) +end + +function Base.show(io::IO, alg::Alshina2) + print(io, "Alshina2(stage_limiter! = ", alg.stage_limiter!, + ", step_limiter! = ", alg.step_limiter!, + ", thread = ", alg.thread, ")") +end + """ -struct Euler <: OrdinaryDiffEqAlgorithm end \ No newline at end of file + Alshina3(; stage_limiter! = OrdinaryDiffEq.trivial_limiter!, + step_limiter! = OrdinaryDiffEq.trivial_limiter!, + thread = OrdinaryDiffEq.False()) + +3rd order, 3-stage Explicit Runge-Kutta Method with optimal parameters. + +Like SSPRK methods, this method also takes optional arguments `stage_limiter!` +and `step_limiter!`, where `stage_limiter!` and `step_limiter!` are functions +of the form `limiter!(u, integrator, p, t)`. + +The argument `thread` determines whether internal broadcasting on +appropriate CPU arrays should be serial (`thread = OrdinaryDiffEq.False()`, +default) or use multiple threads (`thread = OrdinaryDiffEq.True()`) when +Julia is started with multiple threads. + +## Reference + +@article{Alshina2008, +doi = {10.1134/s0965542508030068}, +url = {https://doi.org/10.1134/s0965542508030068}, +year = {2008}, +month = mar, +publisher = {Pleiades Publishing Ltd}, +volume = {48}, +number = {3}, +pages = {395--405}, +author = {E. A. Alshina and E. M. Zaks and N. N. Kalitkin}, +title = {Optimal first- to sixth-order accurate Runge-Kutta schemes}, +journal = {Computational Mathematics and Mathematical Physics} +} +""" +struct Alshina3{StageLimiter, StepLimiter, Thread} <: OrdinaryDiffEqAdaptiveAlgorithm + stage_limiter!::StageLimiter + step_limiter!::StepLimiter + thread::Thread +end + +function Alshina3(; stage_limiter! = trivial_limiter!, step_limiter! = trivial_limiter!, + thread = False()) + Alshina3{typeof(stage_limiter!), typeof(step_limiter!), typeof(thread)}(stage_limiter!, + step_limiter!, + thread) +end + +function Alshina3(stage_limiter!, step_limiter! = trivial_limiter!) + Alshina3{typeof(stage_limiter!), typeof(step_limiter!), False}(stage_limiter!, + step_limiter!, + False()) +end + +function Base.show(io::IO, alg::Alshina3) + print(io, "Alshina3(stage_limiter! = ", alg.stage_limiter!, + ", step_limiter! = ", alg.step_limiter!, + ", thread = ", alg.thread, ")") +end + +""" + Alshina6(; stage_limiter! = OrdinaryDiffEq.trivial_limiter!, + step_limiter! = OrdinaryDiffEq.trivial_limiter!, + thread = OrdinaryDiffEq.False()) + +6th order, 7-stage Explicit Runge-Kutta Method with optimal parameters. + +Like SSPRK methods, this method also takes optional arguments `stage_limiter!` +and `step_limiter!`, where `stage_limiter!` and `step_limiter!` are functions +of the form `limiter!(u, integrator, p, t)`. + +The argument `thread` determines whether internal broadcasting on +appropriate CPU arrays should be serial (`thread = OrdinaryDiffEq.False()`, +default) or use multiple threads (`thread = OrdinaryDiffEq.True()`) when +Julia is started with multiple threads. + +## Reference + +@article{Alshina2008, +doi = {10.1134/s0965542508030068}, +url = {https://doi.org/10.1134/s0965542508030068}, +year = {2008}, +month = mar, +publisher = {Pleiades Publishing Ltd}, +volume = {48}, +number = {3}, +pages = {395--405}, +author = {E. A. Alshina and E. M. Zaks and N. N. Kalitkin}, +title = {Optimal first- to sixth-order accurate Runge-Kutta schemes}, +journal = {Computational Mathematics and Mathematical Physics} +} +""" +struct Alshina6{StageLimiter, StepLimiter, Thread} <: OrdinaryDiffEqAlgorithm + stage_limiter!::StageLimiter + step_limiter!::StepLimiter + thread::Thread +end + +function Alshina6(; stage_limiter! = trivial_limiter!, step_limiter! = trivial_limiter!, + thread = False()) + Alshina6{typeof(stage_limiter!), typeof(step_limiter!), typeof(thread)}(stage_limiter!, + step_limiter!, + thread) +end + +function Alshina6(stage_limiter!, step_limiter! = trivial_limiter!) + Alshina6{typeof(stage_limiter!), typeof(step_limiter!), False}(stage_limiter!, + step_limiter!, + False()) +end + +function Base.show(io::IO, alg::Alshina6) + print(io, "Alshina6(stage_limiter! = ", alg.stage_limiter!, + ", step_limiter! = ", alg.step_limiter!, + ", thread = ", alg.thread, ")") +end \ No newline at end of file diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/fixed_timestep_perform_step.jl b/lib/OrdinaryDiffEqLowOrderRK/src/fixed_timestep_perform_step.jl new file mode 100644 index 0000000000..c46a3f1992 --- /dev/null +++ b/lib/OrdinaryDiffEqLowOrderRK/src/fixed_timestep_perform_step.jl @@ -0,0 +1,487 @@ +function initialize!(integrator, cache::EulerConstantCache) + integrator.kshortsize = 2 + integrator.k = typeof(integrator.k)(undef, integrator.kshortsize) + integrator.fsalfirst = integrator.f(integrator.uprev, integrator.p, integrator.t) # Pre-start fsal + integrator.stats.nf += 1 + + # Avoid undefined entries if k is an array of arrays + integrator.fsallast = zero(integrator.fsalfirst) + integrator.k[1] = integrator.fsalfirst + integrator.k[2] = integrator.fsallast +end + +function perform_step!(integrator, cache::EulerConstantCache, repeat_step = false) + @unpack t, dt, uprev, f, p = integrator + @muladd u = @.. broadcast=false uprev+dt * integrator.fsalfirst + k = f(u, p, t + dt) # For the interpolation, needs k at the updated point + integrator.stats.nf += 1 + integrator.fsallast = k + integrator.k[1] = integrator.fsalfirst + integrator.k[2] = integrator.fsallast + integrator.u = u +end + +function initialize!(integrator, cache::EulerCache) + integrator.kshortsize = 2 + @unpack k, fsalfirst = cache + integrator.fsalfirst = fsalfirst + integrator.fsallast = k + resize!(integrator.k, integrator.kshortsize) + integrator.k[1] = integrator.fsalfirst + integrator.k[2] = integrator.fsallast + integrator.f(integrator.fsalfirst, integrator.uprev, integrator.p, integrator.t) # For the interpolation, needs k at the updated point + integrator.stats.nf += 1 +end + +function perform_step!(integrator, cache::EulerCache, repeat_step = false) + @unpack t, dt, uprev, u, f, p = integrator + @muladd @.. broadcast=false u=uprev + dt * integrator.fsalfirst + f(integrator.fsallast, u, p, t + dt) # For the interpolation, needs k at the updated point + integrator.stats.nf += 1 +end + +function initialize!(integrator, cache::Union{HeunConstantCache, RalstonConstantCache}) + integrator.kshortsize = 2 + integrator.k = typeof(integrator.k)(undef, integrator.kshortsize) + integrator.fsalfirst = integrator.f(integrator.uprev, integrator.p, integrator.t) # Pre-start fsal + integrator.stats.nf += 1 + + # Avoid undefined entries if k is an array of arrays + integrator.fsallast = zero(integrator.fsalfirst) + integrator.k[1] = integrator.fsalfirst + integrator.k[2] = integrator.fsallast +end + +@muladd function perform_step!(integrator, + cache::Union{HeunConstantCache, RalstonConstantCache}, + repeat_step = false) +@unpack t, dt, uprev, u, f, p, fsalfirst = integrator + +# precalculations +if cache isa HeunConstantCache + a₁ = dt + a₂ = dt / 2 +else # Ralston + a₁ = 2 * dt / 3 + a₂ = dt / 4 + a₃ = 3 * a₂ +end + +tmp = @.. broadcast=false uprev+a₁ * fsalfirst +k2 = f(tmp, p, t + a₁) +integrator.stats.nf += 1 + +if cache isa HeunConstantCache + u = @.. broadcast=false uprev+a₂ * (fsalfirst + k2) +else + u = @.. broadcast=false uprev+a₂*fsalfirst+a₃*k2 +end + +if integrator.opts.adaptive + if cache isa HeunConstantCache + tmp = @.. broadcast=false a₂*(k2 - fsalfirst) + else + tmp = @.. broadcast=false a₃*(k2 - fsalfirst) + end + + atmp = calculate_residuals(tmp, uprev, u, integrator.opts.abstol, + integrator.opts.reltol, integrator.opts.internalnorm, t) + integrator.EEst = integrator.opts.internalnorm(atmp, t) +end +k = f(u, p, t + dt) +integrator.stats.nf += 1 +integrator.fsallast = k +integrator.k[1] = integrator.fsalfirst +integrator.k[2] = integrator.fsallast +integrator.u = u +end + +function initialize!(integrator, cache::Union{HeunCache, RalstonCache}) + integrator.kshortsize = 2 + @unpack k, fsalfirst = cache + integrator.fsalfirst = fsalfirst + integrator.fsallast = k + resize!(integrator.k, integrator.kshortsize) + integrator.k[1] = integrator.fsalfirst + integrator.k[2] = integrator.fsallast + integrator.f(integrator.fsalfirst, integrator.uprev, integrator.p, integrator.t) # For the interpolation, needs k at the updated point + integrator.stats.nf += 1 +end + +@muladd function perform_step!(integrator, cache::Union{HeunCache, RalstonCache}, + repeat_step = false) + @unpack t, dt, uprev, u, f, p = integrator + @unpack fsalfirst, k, tmp, atmp, stage_limiter!, step_limiter!, thread = cache + + # precalculations + if cache isa HeunCache + a₁ = dt + a₂ = dt / 2 + else # Ralston + a₁ = 2 * dt / 3 + a₂ = dt / 4 + a₃ = 3 * a₂ + end + + @.. broadcast=false thread=thread tmp=uprev + a₁ * fsalfirst + stage_limiter!(tmp, integrator, p, t + a₁) + f(k, tmp, p, t + a₁) + integrator.stats.nf += 1 + + if cache isa HeunCache + @.. broadcast=false thread=thread u=uprev + a₂ * (fsalfirst + k) + stage_limiter!(u, integrator, p, t + dt) + step_limiter!(u, integrator, p, t + dt) + else + @.. broadcast=false thread=thread u=uprev + a₂ * fsalfirst + a₃ * k + stage_limiter!(u, integrator, p, t + dt) + step_limiter!(u, integrator, p, t + dt) + end + + if integrator.opts.adaptive + if cache isa HeunCache + @.. broadcast=false thread=thread tmp=a₂ * (k - fsalfirst) + else + @.. broadcast=false thread=thread tmp=a₃ * (k - fsalfirst) + end + + calculate_residuals!(atmp, tmp, uprev, u, integrator.opts.abstol, + integrator.opts.reltol, integrator.opts.internalnorm, t, + thread) + integrator.EEst = integrator.opts.internalnorm(atmp, t) + end + f(integrator.fsallast, u, p, t + dt) # For the interpolation, needs k at the updated point + integrator.stats.nf += 1 +end + +function initialize!(integrator, cache::MidpointConstantCache) + integrator.fsalfirst = integrator.f(integrator.uprev, integrator.p, integrator.t) # Pre-start fsal + integrator.stats.nf += 1 + integrator.kshortsize = 2 + integrator.k = typeof(integrator.k)(undef, integrator.kshortsize) + + # Avoid undefined entries if k is an array of arrays + integrator.fsallast = zero(integrator.fsalfirst) + integrator.k[1] = integrator.fsalfirst + integrator.k[2] = integrator.fsallast +end + +@muladd function perform_step!(integrator, cache::MidpointConstantCache, + repeat_step = false) + @unpack t, dt, uprev, u, f, p = integrator + halfdt = dt / 2 + tmp = @.. broadcast=false uprev+halfdt * integrator.fsalfirst + k = f(tmp, p, t + halfdt) + integrator.stats.nf += 1 + u = @.. broadcast=false uprev+dt * k + integrator.fsallast = f(u, p, t + dt) # For interpolation, then FSAL'd + integrator.stats.nf += 1 + if integrator.opts.adaptive + utilde = @.. broadcast=false dt*(integrator.fsalfirst - k) + atmp = calculate_residuals(utilde, uprev, u, integrator.opts.abstol, + integrator.opts.reltol, integrator.opts.internalnorm, t) + integrator.EEst = integrator.opts.internalnorm(atmp, t) + end + integrator.k[1] = integrator.fsalfirst + integrator.k[2] = integrator.fsallast + integrator.u = u +end + +function initialize!(integrator, cache::MidpointCache) + @unpack k, fsalfirst = cache + integrator.fsalfirst = fsalfirst + integrator.fsallast = k + integrator.kshortsize = 2 + resize!(integrator.k, integrator.kshortsize) + integrator.k[1] = integrator.fsalfirst + integrator.k[2] = integrator.fsallast + integrator.f(integrator.fsalfirst, integrator.uprev, integrator.p, integrator.t) # FSAL for interpolation + integrator.stats.nf += 1 +end + +@muladd function perform_step!(integrator, cache::MidpointCache, repeat_step = false) + @unpack t, dt, uprev, u, f, p = integrator + @unpack tmp, k, fsalfirst, atmp, stage_limiter!, step_limiter!, thread = cache + halfdt = dt / 2 + @.. broadcast=false thread=thread tmp=uprev + halfdt * fsalfirst + stage_limiter!(k, tmp, p, t + halfdt) + f(k, tmp, p, t + halfdt) + integrator.stats.nf += 1 + @.. broadcast=false thread=thread u=uprev + dt * k + stage_limiter!(u, integrator, p, t + dt) + step_limiter!(u, integrator, p, t + dt) + if integrator.opts.adaptive + @.. broadcast=false thread=thread tmp=dt * (fsalfirst - k) + calculate_residuals!(atmp, tmp, uprev, u, integrator.opts.abstol, + integrator.opts.reltol, integrator.opts.internalnorm, t, + thread) + integrator.EEst = integrator.opts.internalnorm(atmp, t) + end + f(k, u, p, t + dt) + integrator.stats.nf += 1 +end + +function initialize!(integrator, cache::RK4ConstantCache) + integrator.fsalfirst = integrator.f(integrator.uprev, integrator.p, integrator.t) # Pre-start fsal + integrator.stats.nf += 1 + integrator.kshortsize = 2 + integrator.k = typeof(integrator.k)(undef, integrator.kshortsize) + + # Avoid undefined entries if k is an array of arrays + integrator.fsallast = zero(integrator.fsalfirst) + integrator.k[1] = integrator.fsalfirst + integrator.k[2] = integrator.fsallast +end + +@muladd function perform_step!(integrator, cache::RK4ConstantCache, repeat_step = false) + @unpack t, dt, uprev, u, f, p = integrator + halfdt = dt / 2 + k₁ = integrator.fsalfirst + ttmp = t + halfdt + k₂ = f(uprev + halfdt * k₁, p, ttmp) + k₃ = f(uprev + halfdt * k₂, p, ttmp) + k₄ = f(uprev + dt * k₃, p, t + dt) + u = uprev + (dt / 6) * (2 * (k₂ + k₃) + (k₁ + k₄)) + integrator.fsallast = f(u, p, t + dt) + integrator.stats.nf += 4 + if integrator.opts.adaptive + # Shampine Solving ODEs and DDEs with Residual Control Estimate + k₅ = integrator.fsallast + + # one(t) so that types are correct but unitless + σ₁ = one(t) * (1 // 2) - sqrt(one(t) * 3) / 6 + σ₂ = one(t) * (1 // 2) + sqrt(one(t) * 3) / 6 + p1 = (1 - σ₁) * uprev + σ₁ * u + + σ₁ * (σ₁ - 1) * ((1 - 2σ₁) * (u - uprev) + (σ₁ - 1) * dt * k₁ + σ₁ * dt * k₅) + p2 = (1 - σ₂) * uprev + σ₂ * u + + σ₂ * (σ₂ - 1) * ((1 - 2σ₂) * (u - uprev) + (σ₂ - 1) * dt * k₁ + σ₂ * dt * k₅) + pprime1 = k₁ + + σ₁ * (-4 * dt * k₁ - 2 * dt * k₅ - 6 * uprev + + σ₁ * (3 * dt * k₁ + 3 * dt * k₅ + 6 * uprev - 6 * u) + 6 * u) / dt + pprime2 = k₁ + + σ₂ * (-4 * dt * k₁ - 2 * dt * k₅ - 6 * uprev + + σ₂ * (3 * dt * k₁ + 3 * dt * k₅ + 6 * uprev - 6 * u) + 6 * u) / dt + e1 = integrator.opts.internalnorm( + calculate_residuals(dt * (f(p1, p, t + σ₁ * dt) - + pprime1), uprev, u, + integrator.opts.abstol, + integrator.opts.reltol, + integrator.opts.internalnorm, + t), + t) + e2 = integrator.opts.internalnorm( + calculate_residuals(dt * (f(p2, p, t + σ₂ * dt) - + pprime2), uprev, u, + integrator.opts.abstol, + integrator.opts.reltol, + integrator.opts.internalnorm, + t), + t) + integrator.stats.nf += 2 + integrator.EEst = convert(typeof(one(t)), 2.1342) * max(e1, e2) + end + integrator.k[1] = integrator.fsalfirst + integrator.k[2] = integrator.fsallast + integrator.u = u +end + +function initialize!(integrator, cache::RK4Cache) + @unpack tmp, fsalfirst, k₂, k₃, k₄, k = cache + integrator.fsalfirst = fsalfirst + integrator.fsallast = k + integrator.kshortsize = 2 + resize!(integrator.k, integrator.kshortsize) + integrator.k[1] = integrator.fsalfirst + integrator.k[2] = integrator.fsallast + integrator.f(integrator.fsalfirst, integrator.uprev, integrator.p, integrator.t) # pre-start FSAL + integrator.stats.nf += 1 +end + +@muladd function perform_step!(integrator, cache::RK4Cache, repeat_step = false) + @unpack t, dt, uprev, u, f, p = integrator + @unpack tmp, fsalfirst, k₂, k₃, k₄, k, atmp, stage_limiter!, step_limiter!, thread = cache + k₁ = fsalfirst + halfdt = dt / 2 + ttmp = t + halfdt + @.. broadcast=false thread=thread tmp=uprev + halfdt * k₁ + stage_limiter!(tmp, integrator, p, ttmp) + f(k₂, tmp, p, ttmp) + @.. broadcast=false thread=thread tmp=uprev + halfdt * k₂ + stage_limiter!(tmp, integrator, p, ttmp) + f(k₃, tmp, p, ttmp) + @.. broadcast=false thread=thread tmp=uprev + dt * k₃ + stage_limiter!(tmp, integrator, p, t + dt) + f(k₄, tmp, p, t + dt) + @.. broadcast=false thread=thread u=uprev + (dt / 6) * (2 * (k₂ + k₃) + (k₁ + k₄)) + stage_limiter!(u, integrator, p, t + dt) + step_limiter!(u, integrator, p, t + dt) + f(k, u, p, t + dt) + integrator.stats.nf += 4 + if integrator.opts.adaptive + # Shampine Solving ODEs and DDEs with Residual Control Estimate + k₅ = k + _p = k₂ + pprime = k₃ # Alias some cache arrays + # one(t) so that types are correct but unitless + σ₁ = one(t) * (1 // 2) - sqrt(one(t) * 3) / 6 + σ₂ = one(t) * (1 // 2) + sqrt(one(t) * 3) / 6 + @.. broadcast=false thread=thread tmp=(1 - σ₁) * uprev + σ₁ * u + + σ₁ * (σ₁ - 1) * + ((1 - 2σ₁) * (u - uprev) + + (σ₁ - 1) * dt * k₁ + + σ₁ * dt * k₅) + @.. broadcast=false thread=thread pprime=k₁ + + σ₁ * + (-4 * dt * k₁ - 2 * dt * k₅ - 6 * uprev + + σ₁ * + (3 * dt * k₁ + 3 * dt * k₅ + 6 * uprev - + 6 * u) + + 6 * u) / dt + f(_p, tmp, p, t + σ₁ * dt) + @.. broadcast=false thread=thread tmp=dt * (_p - pprime) + calculate_residuals!(atmp, tmp, uprev, u, integrator.opts.abstol, + integrator.opts.reltol, integrator.opts.internalnorm, t, + thread) + e1 = integrator.opts.internalnorm(atmp, t) + @.. broadcast=false thread=thread tmp=(1 - σ₂) * uprev + σ₂ * u + + σ₂ * (σ₂ - 1) * + ((1 - 2σ₂) * (u - uprev) + + (σ₂ - 1) * dt * k₁ + + σ₂ * dt * k₅) + @.. broadcast=false thread=thread pprime=k₁ + + σ₂ * + (-4 * dt * k₁ - 2 * dt * k₅ - 6 * uprev + + σ₂ * + (3 * dt * k₁ + 3 * dt * k₅ + 6 * uprev - + 6 * u) + + 6 * u) / dt + f(_p, tmp, p, t + σ₂ * dt) + @.. broadcast=false thread=thread tmp=dt * (_p - pprime) + calculate_residuals!(atmp, tmp, uprev, u, integrator.opts.abstol, + integrator.opts.reltol, integrator.opts.internalnorm, t, + thread) + e2 = integrator.opts.internalnorm(atmp, t) + integrator.EEst = convert(typeof(one(t)), 2.1342) * max(e1, e2) + integrator.stats.nf += 2 + end +end + +function initialize!(integrator, cache::Anas5ConstantCache) + integrator.kshortsize = 7 + integrator.k = typeof(integrator.k)(undef, integrator.kshortsize) + integrator.fsalfirst = integrator.f(integrator.uprev, integrator.p, integrator.t) # Pre-start fsal + integrator.stats.nf += 1 + + # Avoid undefined entries if k is an array of arrays + integrator.fsallast = zero(integrator.fsalfirst) + integrator.k[1] = integrator.fsalfirst + @inbounds for i in 2:(integrator.kshortsize - 1) + integrator.k[i] = zero(integrator.fsalfirst) + end + integrator.k[integrator.kshortsize] = integrator.fsallast +end + +@muladd function perform_step!(integrator, cache::Anas5ConstantCache, repeat_step = false) + @unpack t, dt, uprev, u, f, p = integrator + @unpack a21, a31, a32, a41, a42, a43, a51, a52, a53, a54, a61, a62, a63, a64, c2, c3, c4, c5, c6, b1, b3, b4, b5, b6 = cache + ## Note that c1 and b2 were 0. + alg = unwrap_alg(integrator, false) + w = alg.w + v = w * dt + ## Formula by Z.A. Anastassi, see the Anas5 caches in tableaus/low_order_rk_tableaus.jl for the full citation. + a65 = (-8000 // 1071) * + (-a43 * (v^5) + 6 * tan(v) * (v^4) + 24 * (v^3) - 72 * tan(v) * (v^2) - 144 * v + + 144 * tan(v)) / ((v^5) * (a43 * tan(v) * v + 12 - 10 * a43)) + a61 += (-119 // 200) * a65 + a63 += (189 // 100) * a65 + a64 += (-459 // 200) * a65 + k1 = integrator.fsalfirst + k2 = f(uprev + dt * a21 * k1, p, t + c2 * dt) + k3 = f(uprev + dt * (a31 * k1 + a32 * k2), p, t + c3 * dt) + k4 = f(uprev + dt * (a41 * k1 + a42 * k2 + 2 * k3), p, t + c4 * dt) + k5 = f(uprev + dt * (a51 * k1 + a52 * k2 + a53 * k3 + a54 * k4), p, t + c5 * dt) + k6 = f(uprev + dt * (a61 * k1 + a62 * k2 + a63 * k3 + a64 * k4 + a65 * k5), p, + t + c6 * dt) + u = uprev + dt * (b1 * k1 + b3 * k3 + b4 * k4 + b5 * k5 + b6 * k6) + k7 = f(u, p, t + dt) + integrator.fsallast = k7 + integrator.stats.nf += 6 + integrator.k[1] = k1 + integrator.k[2] = k2 + integrator.k[3] = k3 + integrator.k[4] = k4 + integrator.k[5] = k5 + integrator.k[6] = k6 + integrator.k[7] = k7 + integrator.u = u +end + +function initialize!(integrator, cache::Anas5Cache) + integrator.kshortsize = 7 + resize!(integrator.k, integrator.kshortsize) + integrator.k[1] = cache.k1 + integrator.k[2] = cache.k2 + integrator.k[3] = cache.k3 + integrator.k[4] = cache.k4 + integrator.k[5] = cache.k5 + integrator.k[6] = cache.k6 + integrator.k[7] = cache.k7 + integrator.fsalfirst = cache.k1 + integrator.fsallast = cache.k7 # setup pointers + integrator.f(integrator.fsalfirst, integrator.uprev, integrator.p, integrator.t) # Pre-start fsal + integrator.stats.nf += 1 +end + +@muladd function perform_step!(integrator, cache::Anas5Cache, repeat_step = false) + @unpack t, dt, uprev, u, f, p = integrator + uidx = eachindex(integrator.uprev) + @unpack k1, k2, k3, k4, k5, k6, k7, utilde, tmp, atmp, stage_limiter!, step_limiter!, thread = cache + @unpack a21, a31, a32, a41, a42, a43, a51, a52, a53, a54, a61, a62, a63, a64, c2, c3, c4, c5, c6, b1, b3, b4, b5, b6 = cache.tab + alg = unwrap_alg(integrator, false) + w = alg.w + v = w * dt + ## Formula by Z.A. Anastassi, see the Anas5 caches in tableaus/low_order_rk_tableaus.jl for the full citation. + a65 = (-8000 // 1071) * + (-a43 * (v^5) + 6 * tan(v) * (v^4) + 24 * (v^3) - 72 * tan(v) * (v^2) - 144 * v + + 144 * tan(v)) / ((v^5) * (a43 * tan(v) * v + 12 - 10 * a43)) + a61 += (-119 // 200) * a65 + a63 += (189 // 100) * a65 + a64 += (-459 // 200) * a65 + @tight_loop_macros for i in uidx + @inbounds tmp[i] = uprev[i] + a21 * k1[i] + end + stage_limiter!(tmp, integrator, p, t + c2 * dt) + f(k2, tmp, p, t + c2 * dt) + @tight_loop_macros for i in uidx + @inbounds tmp[i] = uprev[i] + dt * (a31 * k1[i] + a32 * k2[i]) + end + stage_limiter!(tmp, integrator, p, t + c3 * dt) + f(k3, tmp, p, t + c3 * dt) + @tight_loop_macros for i in uidx + @inbounds tmp[i] = uprev[i] + dt * (a41 * k1[i] + a42 * k2[i] + 2 * k3[i]) + end + stage_limiter!(tmp, integrator, p, t + c4 * dt) + f(k4, tmp, p, t + c4 * dt) + @tight_loop_macros for i in uidx + @inbounds tmp[i] = uprev[i] + + dt * (a51 * k1[i] + a52 * k2[i] + a53 * k3[i] + a54 * k4[i]) + end + stage_limiter!(tmp, integrator, p, t + c5 * dt) + f(k5, tmp, p, t + c5 * dt) + @tight_loop_macros for i in uidx + @inbounds tmp[i] = uprev[i] + + dt * (a61 * k1[i] + a62 * k2[i] + a63 * k3[i] + a64 * k4[i] + + a65 * k5[i]) + end + stage_limiter!(tmp, integrator, p, t + c6 * dt) + f(k6, tmp, p, t + c6 * dt) + @tight_loop_macros for i in uidx + @inbounds u[i] = uprev[i] + + dt * + (b1 * k1[i] + b3 * k3[i] + b4 * k4[i] + b5 * k5[i] + b6 * k6[i]) + end + stage_limiter!(tmp, integrator, p, t + dt) + step_limiter!(u, integrator, p, t + dt) + f(k7, u, p, t + dt) + integrator.stats.nf += 6 +end \ No newline at end of file diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/interp_func.jl b/lib/OrdinaryDiffEqLowOrderRK/src/interp_func.jl new file mode 100644 index 0000000000..97835d2747 --- /dev/null +++ b/lib/OrdinaryDiffEqLowOrderRK/src/interp_func.jl @@ -0,0 +1,37 @@ +function DiffEqBase.interp_summary(::Type{cacheType}, + dense::Bool) where { + cacheType <: Union{OwrenZen3Cache, + OwrenZen3ConstantCache}} + dense ? "specialized 3rd order \"free\" interpolation" : "1st order linear" +end +function DiffEqBase.interp_summary(::Type{cacheType}, + dense::Bool) where { + cacheType <: Union{OwrenZen4Cache, + OwrenZen4ConstantCache}} + dense ? "specialized 4th order \"free\" interpolation" : "1st order linear" +end +function DiffEqBase.interp_summary(::Type{cacheType}, + dense::Bool) where { + cacheType <: Union{OwrenZen5Cache, + OwrenZen5ConstantCache}} + dense ? "specialized 5th order \"free\" interpolation" : "1st order linear" +end +function DiffEqBase.interp_summary(::Type{cacheType}, + dense::Bool) where { + cacheType <: + Union{Tsit5Cache, Tsit5ConstantCache +}} + dense ? "specialized 4th order \"free\" interpolation" : "1st order linear" +end +function DiffEqBase.interp_summary(::Type{cacheType}, + dense::Bool) where { + cacheType <: + Union{BS5ConstantCache, BS5Cache}} + dense ? "specialized 5th order lazy interpolation" : "1st order linear" +end +function DiffEqBase.interp_summary(::Type{cacheType}, + dense::Bool) where { + cacheType <: + Union{DP8ConstantCache, DP8Cache}} + dense ? "specialized 7th order interpolation" : "1st order linear" +end \ No newline at end of file diff --git a/src/dense/low_order_rk_addsteps.jl b/lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_addsteps.jl similarity index 99% rename from src/dense/low_order_rk_addsteps.jl rename to lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_addsteps.jl index 9e609808b1..1d919b2f0f 100644 --- a/src/dense/low_order_rk_addsteps.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_addsteps.jl @@ -712,4 +712,4 @@ Called to add the extra k9, k10, k11 steps for the Order 5 interpolation when ne end nothing end -=# +=# \ No newline at end of file diff --git a/src/caches/low_order_rk_caches.jl b/lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_caches.jl similarity index 99% rename from src/caches/low_order_rk_caches.jl rename to lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_caches.jl index 0da22a8f41..c62610cdb3 100644 --- a/src/caches/low_order_rk_caches.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_caches.jl @@ -1534,4 +1534,4 @@ function alg_cache(alg::Alshina6, u, rate_prototype, ::Type{uEltypeNoUnits}, tab = Alshina6ConstantCache(constvalue(uBottomEltypeNoUnits), constvalue(tTypeNoUnits)) Alshina6Cache(u, uprev, k1, k2, k3, k4, k5, k6, k7, tmp, tab, alg.stage_limiter!, alg.step_limiter!, alg.thread) -end +end \ No newline at end of file diff --git a/src/perform_step/low_order_rk_perform_step.jl b/lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_perform_step.jl similarity index 99% rename from src/perform_step/low_order_rk_perform_step.jl rename to lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_perform_step.jl index 8b8a0f63dd..1cd465607d 100644 --- a/src/perform_step/low_order_rk_perform_step.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_perform_step.jl @@ -2323,4 +2323,4 @@ function perform_step!(integrator, cache::Alshina6Cache, repeat_step = false) integrator.stats.nf += 7 integrator.fsallast = k7 return nothing -end +end \ No newline at end of file diff --git a/src/tableaus/low_order_rk_tableaus.jl b/lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_tableaus.jl similarity index 99% rename from src/tableaus/low_order_rk_tableaus.jl rename to lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_tableaus.jl index 0dde8ad263..4e9e0069a0 100644 --- a/src/tableaus/low_order_rk_tableaus.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_tableaus.jl @@ -2183,4 +2183,4 @@ function Alshina6ConstantCache(T, T2) Alshina6ConstantCache(a21, a31, a32, a41, a42, a43, a51, a52, a53, a54, a61, a62, a63, a64, a65, a71, a72, a73, a74, a75, a76, b1, b5, b6, b7, c2, c3, c4, c5, c6, c7) -end +end \ No newline at end of file diff --git a/src/perform_step/split_perform_step.jl b/lib/OrdinaryDiffEqLowOrderRK/src/split_perform_step.jl similarity index 99% rename from src/perform_step/split_perform_step.jl rename to lib/OrdinaryDiffEqLowOrderRK/src/split_perform_step.jl index 80f7a906d7..aaa9a13783 100644 --- a/src/perform_step/split_perform_step.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/split_perform_step.jl @@ -47,4 +47,4 @@ end integrator.stats.nf2 += 1 integrator.stats.nf += 1 integrator.fsallast .+= cache.tmp -end +end \ No newline at end of file diff --git a/test/algconvergence/owrenzen_tests.jl b/lib/OrdinaryDiffEqLowOrderRK/test/owrenzen_tests.jl similarity index 97% rename from test/algconvergence/owrenzen_tests.jl rename to lib/OrdinaryDiffEqLowOrderRK/test/owrenzen_tests.jl index 35d4a5b3a9..96b6cb57d7 100644 --- a/test/algconvergence/owrenzen_tests.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/test/owrenzen_tests.jl @@ -40,4 +40,4 @@ sim = test_convergence(dts, prob, OwrenZen4(), dense_errors = true) @test sim.𝒪est[:L2]≈4 atol=testTol sim = test_convergence(dts, prob, OwrenZen5(), dense_errors = true) @test sim.𝒪est[:final]≈5 atol=testTol -@test sim.𝒪est[:L2]≈5 atol=testTol +@test sim.𝒪est[:L2]≈5 atol=testTol \ No newline at end of file diff --git a/lib/OrdinaryDiffEqLowOrderRK/test/runtests.jl b/lib/OrdinaryDiffEqLowOrderRK/test/runtests.jl new file mode 100644 index 0000000000..d1e01c5703 --- /dev/null +++ b/lib/OrdinaryDiffEqLowOrderRK/test/runtests.jl @@ -0,0 +1,3 @@ +using SafeTestsets + +@time @safetestset "Extrapolation Tests" include("owrenzen_tests.jl") \ No newline at end of file diff --git a/src/OrdinaryDiffEq.jl b/src/OrdinaryDiffEq.jl index 5fc4650ac4..4ef0121120 100644 --- a/src/OrdinaryDiffEq.jl +++ b/src/OrdinaryDiffEq.jl @@ -150,16 +150,12 @@ include("nlsolve/newton.jl") include("generic_rosenbrock.jl") include("caches/basic_caches.jl") -include("caches/low_order_rk_caches.jl") -include("caches/high_order_rk_caches.jl") include("caches/linear_caches.jl") include("caches/linear_nonlinear_caches.jl") include("caches/rosenbrock_caches.jl") include("caches/adams_bashforth_moulton_caches.jl") include("caches/nordsieck_caches.jl") -include("tableaus/low_order_rk_tableaus.jl") -include("tableaus/high_order_rk_tableaus.jl") include("tableaus/rosenbrock_tableaus.jl") include("integrators/type.jl") @@ -171,12 +167,9 @@ include("initialize_dae.jl") include("wrappers.jl") include("perform_step/fixed_timestep_perform_step.jl") -include("perform_step/split_perform_step.jl") include("perform_step/linear_perform_step.jl") include("perform_step/exponential_rk_perform_step.jl") include("perform_step/explicit_rk_perform_step.jl") -include("perform_step/low_order_rk_perform_step.jl") -include("perform_step/high_order_rk_perform_step.jl") include("perform_step/rosenbrock_perform_step.jl") include("perform_step/composite_perform_step.jl") include("perform_step/adams_bashforth_moulton_perform_step.jl") @@ -186,8 +179,6 @@ include("dense/generic_dense.jl") include("dense/interpolants.jl") include("dense/rosenbrock_interpolants.jl") include("dense/stiff_addsteps.jl") -include("dense/low_order_rk_addsteps.jl") -include("dense/high_order_rk_addsteps.jl") include("derivative_utils.jl") include("nordsieck_utils.jl") @@ -293,6 +284,18 @@ include("../lib/OrdinaryDiffEqPRK/src/OrdinaryDiffEqPRK.jl") using ..OrdinaryDiffEqPRK export KuttaPRK2p5 +include("../lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl") +using ..OrdinaryDiffEqHighOrderRK +export TanYam7, DP8, PFRK87, TsitPap8 + +include("../lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl") +using ..OrdinaryDiffEqLowOrderRK +export Euler, SplitEuler, Heun, Ralston, Midpoint, RK4, + BS3, OwrenZen3, OwrenZen4, OwrenZen5, BS5, Tsit5, + DP5, Anas5, RKO65, FRK65, RKM, MSRK5, MSRK6, + PSRK4p7q6, PSRK3p5q4, PSRK3p6q5, Stepanov5, SIR54, + Alshina2, Alshina3, Alshina6 + PrecompileTools.@compile_workload begin function lorenz(du, u, p, t) du[1] = 10.0(u[2] - u[1]) @@ -421,11 +424,7 @@ export constructDormandPrince # Reexport the Alg Types -export FunctionMap, Euler, Heun, Ralston, Midpoint, RK4, ExplicitRK, OwrenZen3, OwrenZen4, - OwrenZen5, - BS3, BS5, DP5, Tsit5, DP8, TanYam7, TsitPap8, CompositeAlgorithm, Anas5, RKO65, - FRK65, PFRK87, - RKM, MSRK5, MSRK6, Stepanov5, SIR54, PSRK4p7q6, PSRK3p6q5, PSRK3p5q4 +export FunctionMap, ExplicitRK, CompositeAlgorithm export MagnusMidpoint, LinearExponential, MagnusLeapfrog, LieEuler, CayleyEuler, MagnusGauss4, MagnusNC6, MagnusGL6, MagnusGL8, MagnusNC8, MagnusGL4, @@ -444,8 +443,6 @@ export LawsonEuler, NorsettEuler, ETD1, ETDRK2, ETDRK3, ETDRK4, HochOst4, Exp4, export SHLDDRK52, SHLDDRK_2N -export SplitEuler - export AB3, AB4, AB5, ABM32, ABM43, ABM54 export VCAB3, VCAB4, VCAB5, VCABM3, VCABM4, VCABM5 @@ -456,8 +453,6 @@ export CNAB2, CNLF2 export AN5, JVODE, JVODE_Adams, JVODE_BDF -export Alshina2, Alshina3, Alshina6 - export AutoSwitch, AutoTsit5, AutoDP5, AutoVern6, AutoVern7, AutoVern8, AutoVern9 diff --git a/src/alg_utils.jl b/src/alg_utils.jl index 2fc29bddf5..c0f5489ae6 100644 --- a/src/alg_utils.jl +++ b/src/alg_utils.jl @@ -40,8 +40,6 @@ isfsal(alg::Rodas42) = false isfsal(alg::Rodas4P) = false isfsal(alg::Rodas4P2) = false # Pseudo Non-FSAL -isfsal(alg::RKO65) = false -isfsal(alg::FRK65) = true #isfsal(alg::RKM) = false isfsal(alg::PSRK3p5q4) = false @@ -169,11 +167,9 @@ function qmin_default(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm}) isadaptive(alg) ? 1 // 5 : 0 end qmin_default(alg::CompositeAlgorithm) = maximum(qmin_default.(alg.algs)) -qmin_default(alg::DP8) = 1 // 3 qmax_default(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm}) = 10 qmax_default(alg::CompositeAlgorithm) = minimum(qmax_default.(alg.algs)) -qmax_default(alg::DP8) = 6 function has_chunksize(alg::OrdinaryDiffEqAlgorithm) return alg isa Union{OrdinaryDiffEqExponentialAlgorithm, @@ -247,7 +243,7 @@ end # Linear Exponential doesn't have any of the AD stuff function DiffEqBase.prepare_alg( - alg::Union{ETD2, SplitEuler, LinearExponential, + alg::Union{ETD2, LinearExponential, OrdinaryDiffEqLinearExponentialAlgorithm}, u0::AbstractArray, p, prob) @@ -374,9 +370,6 @@ function get_current_adaptive_order(alg::CompositeAlgorithm, cache) end alg_order(alg::FunctionMap) = 0 -alg_order(alg::Euler) = 1 -alg_order(alg::Heun) = 2 -alg_order(alg::Ralston) = 2 alg_order(alg::LawsonEuler) = 1 alg_order(alg::NorsettEuler) = 1 alg_order(alg::LieEuler) = 1 @@ -392,20 +385,12 @@ alg_order(alg::EPIRK5s3) = 5 alg_order(alg::EPIRK5P1) = 5 alg_order(alg::EPIRK5P2) = 5 alg_order(alg::EXPRB53s3) = 5 -alg_order(alg::SplitEuler) = 1 alg_order(alg::ETD2) = 2 alg_order(alg::Exprb32) = 3 alg_order(alg::Exprb43) = 4 -alg_order(alg::Anas5) = 5 -alg_order(alg::RKO65) = 5 -alg_order(alg::FRK65) = 6 -alg_order(alg::Midpoint) = 2 - -alg_order(alg::RK4) = 4 -alg_order(alg::RKM) = 4 alg_order(alg::ExplicitRK) = alg.tableau.order -alg_order(alg::MSRK5) = 5 + alg_order(alg::MSRK6) = 6 alg_order(alg::Stepanov5) = 5 alg_order(alg::SIR54) = 5 @@ -413,16 +398,6 @@ alg_order(alg::PSRK4p7q6) = 4 alg_order(alg::PSRK3p6q5) = 3 alg_order(alg::PSRK3p5q4) = 3 -alg_order(alg::BS3) = 3 -alg_order(alg::BS5) = 5 -alg_order(alg::OwrenZen3) = 3 -alg_order(alg::OwrenZen4) = 4 -alg_order(alg::OwrenZen5) = 5 -alg_order(alg::DP5) = 5 -alg_order(alg::Tsit5) = 5 -alg_order(alg::DP8) = 8 -alg_order(alg::TanYam7) = 7 -alg_order(alg::TsitPap8) = 8 alg_order(alg::RKMK2) = 2 alg_order(alg::RKMK4) = 4 alg_order(alg::LieRK4) = 4 @@ -439,7 +414,6 @@ alg_order(alg::MagnusGL4) = 4 alg_order(alg::MagnusAdapt4) = 4 alg_order(alg::LinearExponential) = 1 alg_order(alg::MagnusLeapfrog) = 2 -alg_order(alg::PFRK87) = 8 alg_order(alg::ROS2) = 2 alg_order(alg::ROS2PR) = 2 @@ -556,15 +530,11 @@ function beta2_default(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm}) isadaptive(alg) ? 2 // (5alg_order(alg)) : 0 end beta2_default(alg::FunctionMap) = 0 -beta2_default(alg::DP8) = 0 // 1 -beta2_default(alg::DP5) = 4 // 100 function beta1_default(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm}, beta2) isadaptive(alg) ? 7 // (10alg_order(alg)) : 0 end beta1_default(alg::FunctionMap, beta2) = 0 -beta1_default(alg::DP8, beta2) = typeof(beta2)(1 // alg_order(alg)) - beta2 / 5 -beta1_default(alg::DP5, beta2) = typeof(beta2)(1 // alg_order(alg)) - 3beta2 / 4 function gamma_default(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm}) isadaptive(alg) ? 9 // 10 : 0 @@ -590,15 +560,12 @@ end # SSP coefficients ssp_coefficient(alg) = error("$alg is not a strong stability preserving method.") -ssp_coefficient(alg::Euler) = 1 # We shouldn't do this probably. #ssp_coefficient(alg::ImplicitEuler) = Inf # stability regions alg_stability_size(alg::ExplicitRK) = alg.tableau.stability_size -alg_stability_size(alg::DP5) = 3.3066 -alg_stability_size(alg::Tsit5) = 3.5068 alg_can_repeat_jac(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm}) = false alg_can_repeat_jac(alg::OrdinaryDiffEqNewtonAdaptiveAlgorithm) = true diff --git a/src/algorithms.jl b/src/algorithms.jl index f2affbef07..6cf380a214 100644 --- a/src/algorithms.jl +++ b/src/algorithms.jl @@ -80,231 +80,6 @@ ExplicitRK(; tableau = ODE_DEFAULT_TABLEAU) = ExplicitRK(tableau) TruncatedStacktraces.@truncate_stacktrace ExplicitRK -@inline trivial_limiter!(u, integrator, p, t) = nothing -""" - SIR54(; stage_limiter! = OrdinaryDiffEq.trivial_limiter!, - step_limiter! = OrdinaryDiffEq.trivial_limiter!, - thread = OrdinaryDiffEq.False()) - -5th order Explicit RK method suited for SIR-type epidemic models. - -Like SSPRK methods, this method also takes optional arguments `stage_limiter!` -and `step_limiter!`, where `stage_limiter!` and `step_limiter!` are functions -of the form `limiter!(u, integrator, p, t)`. - -The argument `thread` determines whether internal broadcasting on -appropriate CPU arrays should be serial (`thread = OrdinaryDiffEq.False()`, -default) or use multiple threads (`thread = OrdinaryDiffEq.True()`) when -Julia is started with multiple threads. - -## Reference - -@article{Kovalnogov2020RungeKuttaPS, -title={Runge–Kutta pairs suited for SIR‐type epidemic models}, -author={Vladislav N. Kovalnogov and Theodore E. Simos and Ch. Tsitouras}, -journal={Mathematical Methods in the Applied Sciences}, -year={2020}, -volume={44}, -pages={5210 - 5216} -} -""" -struct SIR54{StageLimiter, StepLimiter, Thread} <: OrdinaryDiffEqAdaptiveAlgorithm - stage_limiter!::StageLimiter - step_limiter!::StepLimiter - thread::Thread -end - -function SIR54(; stage_limiter! = trivial_limiter!, step_limiter! = trivial_limiter!, - thread = False()) - SIR54{typeof(stage_limiter!), typeof(step_limiter!), typeof(thread)}(stage_limiter!, - step_limiter!, - thread) -end - -# for backwards compatibility -function SIR54(stage_limiter!, step_limiter! = trivial_limiter!) - SIR54{typeof(stage_limiter!), typeof(step_limiter!), False}(stage_limiter!, - step_limiter!, - False()) -end - -function Base.show(io::IO, alg::SIR54) - print(io, "SIR54(stage_limiter! = ", alg.stage_limiter!, - ", step_limiter! = ", alg.step_limiter!, - ", thread = ", alg.thread, ")") -end - -""" - Alshina2(; stage_limiter! = OrdinaryDiffEq.trivial_limiter!, - step_limiter! = OrdinaryDiffEq.trivial_limiter!, - thread = OrdinaryDiffEq.False()) - -2nd order, 2-stage Explicit Runge-Kutta Method with optimal parameters. - -Like SSPRK methods, this method also takes optional arguments `stage_limiter!` -and `step_limiter!`, where `stage_limiter!` and `step_limiter!` are functions -of the form `limiter!(u, integrator, p, t)`. - -The argument `thread` determines whether internal broadcasting on -appropriate CPU arrays should be serial (`thread = OrdinaryDiffEq.False()`, -default) or use multiple threads (`thread = OrdinaryDiffEq.True()`) when -Julia is started with multiple threads. - -## Reference - -@article{Alshina2008, -doi = {10.1134/s0965542508030068}, -url = {https://doi.org/10.1134/s0965542508030068}, -year = {2008}, -month = mar, -publisher = {Pleiades Publishing Ltd}, -volume = {48}, -number = {3}, -pages = {395--405}, -author = {E. A. Alshina and E. M. Zaks and N. N. Kalitkin}, -title = {Optimal first- to sixth-order accurate Runge-Kutta schemes}, -journal = {Computational Mathematics and Mathematical Physics} -} -""" -struct Alshina2{StageLimiter, StepLimiter, Thread} <: OrdinaryDiffEqAdaptiveAlgorithm - stage_limiter!::StageLimiter - step_limiter!::StepLimiter - thread::Thread -end - -function Alshina2(; stage_limiter! = trivial_limiter!, step_limiter! = trivial_limiter!, - thread = False()) - Alshina2{typeof(stage_limiter!), typeof(step_limiter!), typeof(thread)}(stage_limiter!, - step_limiter!, - thread) -end - -function Alshina2(stage_limiter!, step_limiter! = trivial_limiter!) - Alshina2{typeof(stage_limiter!), typeof(step_limiter!), False}(stage_limiter!, - step_limiter!, - False()) -end - -function Base.show(io::IO, alg::Alshina2) - print(io, "Alshina2(stage_limiter! = ", alg.stage_limiter!, - ", step_limiter! = ", alg.step_limiter!, - ", thread = ", alg.thread, ")") -end - -""" - Alshina3(; stage_limiter! = OrdinaryDiffEq.trivial_limiter!, - step_limiter! = OrdinaryDiffEq.trivial_limiter!, - thread = OrdinaryDiffEq.False()) - -3rd order, 3-stage Explicit Runge-Kutta Method with optimal parameters. - -Like SSPRK methods, this method also takes optional arguments `stage_limiter!` -and `step_limiter!`, where `stage_limiter!` and `step_limiter!` are functions -of the form `limiter!(u, integrator, p, t)`. - -The argument `thread` determines whether internal broadcasting on -appropriate CPU arrays should be serial (`thread = OrdinaryDiffEq.False()`, -default) or use multiple threads (`thread = OrdinaryDiffEq.True()`) when -Julia is started with multiple threads. - -## Reference - -@article{Alshina2008, -doi = {10.1134/s0965542508030068}, -url = {https://doi.org/10.1134/s0965542508030068}, -year = {2008}, -month = mar, -publisher = {Pleiades Publishing Ltd}, -volume = {48}, -number = {3}, -pages = {395--405}, -author = {E. A. Alshina and E. M. Zaks and N. N. Kalitkin}, -title = {Optimal first- to sixth-order accurate Runge-Kutta schemes}, -journal = {Computational Mathematics and Mathematical Physics} -} -""" -struct Alshina3{StageLimiter, StepLimiter, Thread} <: OrdinaryDiffEqAdaptiveAlgorithm - stage_limiter!::StageLimiter - step_limiter!::StepLimiter - thread::Thread -end - -function Alshina3(; stage_limiter! = trivial_limiter!, step_limiter! = trivial_limiter!, - thread = False()) - Alshina3{typeof(stage_limiter!), typeof(step_limiter!), typeof(thread)}(stage_limiter!, - step_limiter!, - thread) -end - -function Alshina3(stage_limiter!, step_limiter! = trivial_limiter!) - Alshina3{typeof(stage_limiter!), typeof(step_limiter!), False}(stage_limiter!, - step_limiter!, - False()) -end - -function Base.show(io::IO, alg::Alshina3) - print(io, "Alshina3(stage_limiter! = ", alg.stage_limiter!, - ", step_limiter! = ", alg.step_limiter!, - ", thread = ", alg.thread, ")") -end - -""" - Alshina6(; stage_limiter! = OrdinaryDiffEq.trivial_limiter!, - step_limiter! = OrdinaryDiffEq.trivial_limiter!, - thread = OrdinaryDiffEq.False()) - -6th order, 7-stage Explicit Runge-Kutta Method with optimal parameters. - -Like SSPRK methods, this method also takes optional arguments `stage_limiter!` -and `step_limiter!`, where `stage_limiter!` and `step_limiter!` are functions -of the form `limiter!(u, integrator, p, t)`. - -The argument `thread` determines whether internal broadcasting on -appropriate CPU arrays should be serial (`thread = OrdinaryDiffEq.False()`, -default) or use multiple threads (`thread = OrdinaryDiffEq.True()`) when -Julia is started with multiple threads. - -## Reference - -@article{Alshina2008, -doi = {10.1134/s0965542508030068}, -url = {https://doi.org/10.1134/s0965542508030068}, -year = {2008}, -month = mar, -publisher = {Pleiades Publishing Ltd}, -volume = {48}, -number = {3}, -pages = {395--405}, -author = {E. A. Alshina and E. M. Zaks and N. N. Kalitkin}, -title = {Optimal first- to sixth-order accurate Runge-Kutta schemes}, -journal = {Computational Mathematics and Mathematical Physics} -} -""" -struct Alshina6{StageLimiter, StepLimiter, Thread} <: OrdinaryDiffEqAlgorithm - stage_limiter!::StageLimiter - step_limiter!::StepLimiter - thread::Thread -end - -function Alshina6(; stage_limiter! = trivial_limiter!, step_limiter! = trivial_limiter!, - thread = False()) - Alshina6{typeof(stage_limiter!), typeof(step_limiter!), typeof(thread)}(stage_limiter!, - step_limiter!, - thread) -end - -function Alshina6(stage_limiter!, step_limiter! = trivial_limiter!) - Alshina6{typeof(stage_limiter!), typeof(step_limiter!), False}(stage_limiter!, - step_limiter!, - False()) -end - -function Base.show(io::IO, alg::Alshina6) - print(io, "Alshina6(stage_limiter! = ", alg.stage_limiter!, - ", step_limiter! = ", alg.step_limiter!, - ", thread = ", alg.thread, ")") -end - ################################################################################ # Adams Bashforth and Adams moulton methods @@ -818,8 +593,7 @@ for Alg in [:Exp4, :EPIRK4s3A, :EPIRK4s3B, :EPIRK5s3, :EXPRB53s3, :EPIRK5P1, :EP iop) end end -struct SplitEuler <: - OrdinaryDiffEqExponentialAlgorithm{0, false, Val{:forward}, Val{true}, nothing} end + """ ETD2: Exponential Runge-Kutta Method Second order Exponential Time Differencing method (in development). diff --git a/src/interp_func.jl b/src/interp_func.jl index b1c364c734..a3a916de18 100644 --- a/src/interp_func.jl +++ b/src/interp_func.jl @@ -71,44 +71,6 @@ function DiffEqBase.interp_summary(::Type{cacheType}, dense ? "specialized 4rd order \"free\" stiffness-aware interpolation" : "1st order linear" end - -function DiffEqBase.interp_summary(::Type{cacheType}, - dense::Bool) where { - cacheType <: Union{OwrenZen3Cache, - OwrenZen3ConstantCache}} - dense ? "specialized 3rd order \"free\" interpolation" : "1st order linear" -end -function DiffEqBase.interp_summary(::Type{cacheType}, - dense::Bool) where { - cacheType <: Union{OwrenZen4Cache, - OwrenZen4ConstantCache}} - dense ? "specialized 4th order \"free\" interpolation" : "1st order linear" -end -function DiffEqBase.interp_summary(::Type{cacheType}, - dense::Bool) where { - cacheType <: Union{OwrenZen5Cache, - OwrenZen5ConstantCache}} - dense ? "specialized 5th order \"free\" interpolation" : "1st order linear" -end -function DiffEqBase.interp_summary(::Type{cacheType}, - dense::Bool) where { - cacheType <: - Union{Tsit5Cache, Tsit5ConstantCache -}} - dense ? "specialized 4th order \"free\" interpolation" : "1st order linear" -end -function DiffEqBase.interp_summary(::Type{cacheType}, - dense::Bool) where { - cacheType <: - Union{BS5ConstantCache, BS5Cache}} - dense ? "specialized 5th order lazy interpolation" : "1st order linear" -end -function DiffEqBase.interp_summary(::Type{cacheType}, - dense::Bool) where { - cacheType <: - Union{DP8ConstantCache, DP8Cache}} - dense ? "specialized 7th order interpolation" : "1st order linear" -end function DiffEqBase.interp_summary(::Type{cacheType}, dense::Bool) where {cacheType} dense ? "3rd order Hermite" : "1st order linear" end diff --git a/src/perform_step/fixed_timestep_perform_step.jl b/src/perform_step/fixed_timestep_perform_step.jl index 643ce748f8..2923459c72 100644 --- a/src/perform_step/fixed_timestep_perform_step.jl +++ b/src/perform_step/fixed_timestep_perform_step.jl @@ -40,492 +40,4 @@ function perform_step!(integrator, cache::FunctionMapCache, repeat_step = false) end integrator.stats.nf += 1 end -end - -function initialize!(integrator, cache::EulerConstantCache) - integrator.kshortsize = 2 - integrator.k = typeof(integrator.k)(undef, integrator.kshortsize) - integrator.fsalfirst = integrator.f(integrator.uprev, integrator.p, integrator.t) # Pre-start fsal - integrator.stats.nf += 1 - - # Avoid undefined entries if k is an array of arrays - integrator.fsallast = zero(integrator.fsalfirst) - integrator.k[1] = integrator.fsalfirst - integrator.k[2] = integrator.fsallast -end - -function perform_step!(integrator, cache::EulerConstantCache, repeat_step = false) - @unpack t, dt, uprev, f, p = integrator - @muladd u = @.. broadcast=false uprev+dt * integrator.fsalfirst - k = f(u, p, t + dt) # For the interpolation, needs k at the updated point - integrator.stats.nf += 1 - integrator.fsallast = k - integrator.k[1] = integrator.fsalfirst - integrator.k[2] = integrator.fsallast - integrator.u = u -end - -function initialize!(integrator, cache::EulerCache) - integrator.kshortsize = 2 - @unpack k, fsalfirst = cache - integrator.fsalfirst = fsalfirst - integrator.fsallast = k - resize!(integrator.k, integrator.kshortsize) - integrator.k[1] = integrator.fsalfirst - integrator.k[2] = integrator.fsallast - integrator.f(integrator.fsalfirst, integrator.uprev, integrator.p, integrator.t) # For the interpolation, needs k at the updated point - integrator.stats.nf += 1 -end - -function perform_step!(integrator, cache::EulerCache, repeat_step = false) - @unpack t, dt, uprev, u, f, p = integrator - @muladd @.. broadcast=false u=uprev + dt * integrator.fsalfirst - f(integrator.fsallast, u, p, t + dt) # For the interpolation, needs k at the updated point - integrator.stats.nf += 1 -end - -function initialize!(integrator, cache::Union{HeunConstantCache, RalstonConstantCache}) - integrator.kshortsize = 2 - integrator.k = typeof(integrator.k)(undef, integrator.kshortsize) - integrator.fsalfirst = integrator.f(integrator.uprev, integrator.p, integrator.t) # Pre-start fsal - integrator.stats.nf += 1 - - # Avoid undefined entries if k is an array of arrays - integrator.fsallast = zero(integrator.fsalfirst) - integrator.k[1] = integrator.fsalfirst - integrator.k[2] = integrator.fsallast -end - -@muladd function perform_step!(integrator, - cache::Union{HeunConstantCache, RalstonConstantCache}, - repeat_step = false) - @unpack t, dt, uprev, u, f, p, fsalfirst = integrator - - # precalculations - if cache isa HeunConstantCache - a₁ = dt - a₂ = dt / 2 - else # Ralston - a₁ = 2 * dt / 3 - a₂ = dt / 4 - a₃ = 3 * a₂ - end - - tmp = @.. broadcast=false uprev+a₁ * fsalfirst - k2 = f(tmp, p, t + a₁) - integrator.stats.nf += 1 - - if cache isa HeunConstantCache - u = @.. broadcast=false uprev+a₂ * (fsalfirst + k2) - else - u = @.. broadcast=false uprev+a₂*fsalfirst+a₃*k2 - end - - if integrator.opts.adaptive - if cache isa HeunConstantCache - tmp = @.. broadcast=false a₂*(k2 - fsalfirst) - else - tmp = @.. broadcast=false a₃*(k2 - fsalfirst) - end - - atmp = calculate_residuals(tmp, uprev, u, integrator.opts.abstol, - integrator.opts.reltol, integrator.opts.internalnorm, t) - integrator.EEst = integrator.opts.internalnorm(atmp, t) - end - k = f(u, p, t + dt) - integrator.stats.nf += 1 - integrator.fsallast = k - integrator.k[1] = integrator.fsalfirst - integrator.k[2] = integrator.fsallast - integrator.u = u -end - -function initialize!(integrator, cache::Union{HeunCache, RalstonCache}) - integrator.kshortsize = 2 - @unpack k, fsalfirst = cache - integrator.fsalfirst = fsalfirst - integrator.fsallast = k - resize!(integrator.k, integrator.kshortsize) - integrator.k[1] = integrator.fsalfirst - integrator.k[2] = integrator.fsallast - integrator.f(integrator.fsalfirst, integrator.uprev, integrator.p, integrator.t) # For the interpolation, needs k at the updated point - integrator.stats.nf += 1 -end - -@muladd function perform_step!(integrator, cache::Union{HeunCache, RalstonCache}, - repeat_step = false) - @unpack t, dt, uprev, u, f, p = integrator - @unpack fsalfirst, k, tmp, atmp, stage_limiter!, step_limiter!, thread = cache - - # precalculations - if cache isa HeunCache - a₁ = dt - a₂ = dt / 2 - else # Ralston - a₁ = 2 * dt / 3 - a₂ = dt / 4 - a₃ = 3 * a₂ - end - - @.. broadcast=false thread=thread tmp=uprev + a₁ * fsalfirst - stage_limiter!(tmp, integrator, p, t + a₁) - f(k, tmp, p, t + a₁) - integrator.stats.nf += 1 - - if cache isa HeunCache - @.. broadcast=false thread=thread u=uprev + a₂ * (fsalfirst + k) - stage_limiter!(u, integrator, p, t + dt) - step_limiter!(u, integrator, p, t + dt) - else - @.. broadcast=false thread=thread u=uprev + a₂ * fsalfirst + a₃ * k - stage_limiter!(u, integrator, p, t + dt) - step_limiter!(u, integrator, p, t + dt) - end - - if integrator.opts.adaptive - if cache isa HeunCache - @.. broadcast=false thread=thread tmp=a₂ * (k - fsalfirst) - else - @.. broadcast=false thread=thread tmp=a₃ * (k - fsalfirst) - end - - calculate_residuals!(atmp, tmp, uprev, u, integrator.opts.abstol, - integrator.opts.reltol, integrator.opts.internalnorm, t, - thread) - integrator.EEst = integrator.opts.internalnorm(atmp, t) - end - f(integrator.fsallast, u, p, t + dt) # For the interpolation, needs k at the updated point - integrator.stats.nf += 1 -end - -function initialize!(integrator, cache::MidpointConstantCache) - integrator.fsalfirst = integrator.f(integrator.uprev, integrator.p, integrator.t) # Pre-start fsal - integrator.stats.nf += 1 - integrator.kshortsize = 2 - integrator.k = typeof(integrator.k)(undef, integrator.kshortsize) - - # Avoid undefined entries if k is an array of arrays - integrator.fsallast = zero(integrator.fsalfirst) - integrator.k[1] = integrator.fsalfirst - integrator.k[2] = integrator.fsallast -end - -@muladd function perform_step!(integrator, cache::MidpointConstantCache, - repeat_step = false) - @unpack t, dt, uprev, u, f, p = integrator - halfdt = dt / 2 - tmp = @.. broadcast=false uprev+halfdt * integrator.fsalfirst - k = f(tmp, p, t + halfdt) - integrator.stats.nf += 1 - u = @.. broadcast=false uprev+dt * k - integrator.fsallast = f(u, p, t + dt) # For interpolation, then FSAL'd - integrator.stats.nf += 1 - if integrator.opts.adaptive - utilde = @.. broadcast=false dt*(integrator.fsalfirst - k) - atmp = calculate_residuals(utilde, uprev, u, integrator.opts.abstol, - integrator.opts.reltol, integrator.opts.internalnorm, t) - integrator.EEst = integrator.opts.internalnorm(atmp, t) - end - integrator.k[1] = integrator.fsalfirst - integrator.k[2] = integrator.fsallast - integrator.u = u -end - -function initialize!(integrator, cache::MidpointCache) - @unpack k, fsalfirst = cache - integrator.fsalfirst = fsalfirst - integrator.fsallast = k - integrator.kshortsize = 2 - resize!(integrator.k, integrator.kshortsize) - integrator.k[1] = integrator.fsalfirst - integrator.k[2] = integrator.fsallast - integrator.f(integrator.fsalfirst, integrator.uprev, integrator.p, integrator.t) # FSAL for interpolation - integrator.stats.nf += 1 -end - -@muladd function perform_step!(integrator, cache::MidpointCache, repeat_step = false) - @unpack t, dt, uprev, u, f, p = integrator - @unpack tmp, k, fsalfirst, atmp, stage_limiter!, step_limiter!, thread = cache - halfdt = dt / 2 - @.. broadcast=false thread=thread tmp=uprev + halfdt * fsalfirst - stage_limiter!(k, tmp, p, t + halfdt) - f(k, tmp, p, t + halfdt) - integrator.stats.nf += 1 - @.. broadcast=false thread=thread u=uprev + dt * k - stage_limiter!(u, integrator, p, t + dt) - step_limiter!(u, integrator, p, t + dt) - if integrator.opts.adaptive - @.. broadcast=false thread=thread tmp=dt * (fsalfirst - k) - calculate_residuals!(atmp, tmp, uprev, u, integrator.opts.abstol, - integrator.opts.reltol, integrator.opts.internalnorm, t, - thread) - integrator.EEst = integrator.opts.internalnorm(atmp, t) - end - f(k, u, p, t + dt) - integrator.stats.nf += 1 -end - -function initialize!(integrator, cache::RK4ConstantCache) - integrator.fsalfirst = integrator.f(integrator.uprev, integrator.p, integrator.t) # Pre-start fsal - integrator.stats.nf += 1 - integrator.kshortsize = 2 - integrator.k = typeof(integrator.k)(undef, integrator.kshortsize) - - # Avoid undefined entries if k is an array of arrays - integrator.fsallast = zero(integrator.fsalfirst) - integrator.k[1] = integrator.fsalfirst - integrator.k[2] = integrator.fsallast -end - -@muladd function perform_step!(integrator, cache::RK4ConstantCache, repeat_step = false) - @unpack t, dt, uprev, u, f, p = integrator - halfdt = dt / 2 - k₁ = integrator.fsalfirst - ttmp = t + halfdt - k₂ = f(uprev + halfdt * k₁, p, ttmp) - k₃ = f(uprev + halfdt * k₂, p, ttmp) - k₄ = f(uprev + dt * k₃, p, t + dt) - u = uprev + (dt / 6) * (2 * (k₂ + k₃) + (k₁ + k₄)) - integrator.fsallast = f(u, p, t + dt) - integrator.stats.nf += 4 - if integrator.opts.adaptive - # Shampine Solving ODEs and DDEs with Residual Control Estimate - k₅ = integrator.fsallast - - # one(t) so that types are correct but unitless - σ₁ = one(t) * (1 // 2) - sqrt(one(t) * 3) / 6 - σ₂ = one(t) * (1 // 2) + sqrt(one(t) * 3) / 6 - p1 = (1 - σ₁) * uprev + σ₁ * u + - σ₁ * (σ₁ - 1) * ((1 - 2σ₁) * (u - uprev) + (σ₁ - 1) * dt * k₁ + σ₁ * dt * k₅) - p2 = (1 - σ₂) * uprev + σ₂ * u + - σ₂ * (σ₂ - 1) * ((1 - 2σ₂) * (u - uprev) + (σ₂ - 1) * dt * k₁ + σ₂ * dt * k₅) - pprime1 = k₁ + - σ₁ * (-4 * dt * k₁ - 2 * dt * k₅ - 6 * uprev + - σ₁ * (3 * dt * k₁ + 3 * dt * k₅ + 6 * uprev - 6 * u) + 6 * u) / dt - pprime2 = k₁ + - σ₂ * (-4 * dt * k₁ - 2 * dt * k₅ - 6 * uprev + - σ₂ * (3 * dt * k₁ + 3 * dt * k₅ + 6 * uprev - 6 * u) + 6 * u) / dt - e1 = integrator.opts.internalnorm( - calculate_residuals(dt * (f(p1, p, t + σ₁ * dt) - - pprime1), uprev, u, - integrator.opts.abstol, - integrator.opts.reltol, - integrator.opts.internalnorm, - t), - t) - e2 = integrator.opts.internalnorm( - calculate_residuals(dt * (f(p2, p, t + σ₂ * dt) - - pprime2), uprev, u, - integrator.opts.abstol, - integrator.opts.reltol, - integrator.opts.internalnorm, - t), - t) - integrator.stats.nf += 2 - integrator.EEst = convert(typeof(one(t)), 2.1342) * max(e1, e2) - end - integrator.k[1] = integrator.fsalfirst - integrator.k[2] = integrator.fsallast - integrator.u = u -end - -function initialize!(integrator, cache::RK4Cache) - @unpack tmp, fsalfirst, k₂, k₃, k₄, k = cache - integrator.fsalfirst = fsalfirst - integrator.fsallast = k - integrator.kshortsize = 2 - resize!(integrator.k, integrator.kshortsize) - integrator.k[1] = integrator.fsalfirst - integrator.k[2] = integrator.fsallast - integrator.f(integrator.fsalfirst, integrator.uprev, integrator.p, integrator.t) # pre-start FSAL - integrator.stats.nf += 1 -end - -@muladd function perform_step!(integrator, cache::RK4Cache, repeat_step = false) - @unpack t, dt, uprev, u, f, p = integrator - @unpack tmp, fsalfirst, k₂, k₃, k₄, k, atmp, stage_limiter!, step_limiter!, thread = cache - k₁ = fsalfirst - halfdt = dt / 2 - ttmp = t + halfdt - @.. broadcast=false thread=thread tmp=uprev + halfdt * k₁ - stage_limiter!(tmp, integrator, p, ttmp) - f(k₂, tmp, p, ttmp) - @.. broadcast=false thread=thread tmp=uprev + halfdt * k₂ - stage_limiter!(tmp, integrator, p, ttmp) - f(k₃, tmp, p, ttmp) - @.. broadcast=false thread=thread tmp=uprev + dt * k₃ - stage_limiter!(tmp, integrator, p, t + dt) - f(k₄, tmp, p, t + dt) - @.. broadcast=false thread=thread u=uprev + (dt / 6) * (2 * (k₂ + k₃) + (k₁ + k₄)) - stage_limiter!(u, integrator, p, t + dt) - step_limiter!(u, integrator, p, t + dt) - f(k, u, p, t + dt) - integrator.stats.nf += 4 - if integrator.opts.adaptive - # Shampine Solving ODEs and DDEs with Residual Control Estimate - k₅ = k - _p = k₂ - pprime = k₃ # Alias some cache arrays - # one(t) so that types are correct but unitless - σ₁ = one(t) * (1 // 2) - sqrt(one(t) * 3) / 6 - σ₂ = one(t) * (1 // 2) + sqrt(one(t) * 3) / 6 - @.. broadcast=false thread=thread tmp=(1 - σ₁) * uprev + σ₁ * u + - σ₁ * (σ₁ - 1) * - ((1 - 2σ₁) * (u - uprev) + - (σ₁ - 1) * dt * k₁ + - σ₁ * dt * k₅) - @.. broadcast=false thread=thread pprime=k₁ + - σ₁ * - (-4 * dt * k₁ - 2 * dt * k₅ - 6 * uprev + - σ₁ * - (3 * dt * k₁ + 3 * dt * k₅ + 6 * uprev - - 6 * u) + - 6 * u) / dt - f(_p, tmp, p, t + σ₁ * dt) - @.. broadcast=false thread=thread tmp=dt * (_p - pprime) - calculate_residuals!(atmp, tmp, uprev, u, integrator.opts.abstol, - integrator.opts.reltol, integrator.opts.internalnorm, t, - thread) - e1 = integrator.opts.internalnorm(atmp, t) - @.. broadcast=false thread=thread tmp=(1 - σ₂) * uprev + σ₂ * u + - σ₂ * (σ₂ - 1) * - ((1 - 2σ₂) * (u - uprev) + - (σ₂ - 1) * dt * k₁ + - σ₂ * dt * k₅) - @.. broadcast=false thread=thread pprime=k₁ + - σ₂ * - (-4 * dt * k₁ - 2 * dt * k₅ - 6 * uprev + - σ₂ * - (3 * dt * k₁ + 3 * dt * k₅ + 6 * uprev - - 6 * u) + - 6 * u) / dt - f(_p, tmp, p, t + σ₂ * dt) - @.. broadcast=false thread=thread tmp=dt * (_p - pprime) - calculate_residuals!(atmp, tmp, uprev, u, integrator.opts.abstol, - integrator.opts.reltol, integrator.opts.internalnorm, t, - thread) - e2 = integrator.opts.internalnorm(atmp, t) - integrator.EEst = convert(typeof(one(t)), 2.1342) * max(e1, e2) - integrator.stats.nf += 2 - end -end - -function initialize!(integrator, cache::Anas5ConstantCache) - integrator.kshortsize = 7 - integrator.k = typeof(integrator.k)(undef, integrator.kshortsize) - integrator.fsalfirst = integrator.f(integrator.uprev, integrator.p, integrator.t) # Pre-start fsal - integrator.stats.nf += 1 - - # Avoid undefined entries if k is an array of arrays - integrator.fsallast = zero(integrator.fsalfirst) - integrator.k[1] = integrator.fsalfirst - @inbounds for i in 2:(integrator.kshortsize - 1) - integrator.k[i] = zero(integrator.fsalfirst) - end - integrator.k[integrator.kshortsize] = integrator.fsallast -end - -@muladd function perform_step!(integrator, cache::Anas5ConstantCache, repeat_step = false) - @unpack t, dt, uprev, u, f, p = integrator - @unpack a21, a31, a32, a41, a42, a43, a51, a52, a53, a54, a61, a62, a63, a64, c2, c3, c4, c5, c6, b1, b3, b4, b5, b6 = cache - ## Note that c1 and b2 were 0. - alg = unwrap_alg(integrator, false) - w = alg.w - v = w * dt - ## Formula by Z.A. Anastassi, see the Anas5 caches in tableaus/low_order_rk_tableaus.jl for the full citation. - a65 = (-8000 // 1071) * - (-a43 * (v^5) + 6 * tan(v) * (v^4) + 24 * (v^3) - 72 * tan(v) * (v^2) - 144 * v + - 144 * tan(v)) / ((v^5) * (a43 * tan(v) * v + 12 - 10 * a43)) - a61 += (-119 // 200) * a65 - a63 += (189 // 100) * a65 - a64 += (-459 // 200) * a65 - k1 = integrator.fsalfirst - k2 = f(uprev + dt * a21 * k1, p, t + c2 * dt) - k3 = f(uprev + dt * (a31 * k1 + a32 * k2), p, t + c3 * dt) - k4 = f(uprev + dt * (a41 * k1 + a42 * k2 + 2 * k3), p, t + c4 * dt) - k5 = f(uprev + dt * (a51 * k1 + a52 * k2 + a53 * k3 + a54 * k4), p, t + c5 * dt) - k6 = f(uprev + dt * (a61 * k1 + a62 * k2 + a63 * k3 + a64 * k4 + a65 * k5), p, - t + c6 * dt) - u = uprev + dt * (b1 * k1 + b3 * k3 + b4 * k4 + b5 * k5 + b6 * k6) - k7 = f(u, p, t + dt) - integrator.fsallast = k7 - integrator.stats.nf += 6 - integrator.k[1] = k1 - integrator.k[2] = k2 - integrator.k[3] = k3 - integrator.k[4] = k4 - integrator.k[5] = k5 - integrator.k[6] = k6 - integrator.k[7] = k7 - integrator.u = u -end - -function initialize!(integrator, cache::Anas5Cache) - integrator.kshortsize = 7 - resize!(integrator.k, integrator.kshortsize) - integrator.k[1] = cache.k1 - integrator.k[2] = cache.k2 - integrator.k[3] = cache.k3 - integrator.k[4] = cache.k4 - integrator.k[5] = cache.k5 - integrator.k[6] = cache.k6 - integrator.k[7] = cache.k7 - integrator.fsalfirst = cache.k1 - integrator.fsallast = cache.k7 # setup pointers - integrator.f(integrator.fsalfirst, integrator.uprev, integrator.p, integrator.t) # Pre-start fsal - integrator.stats.nf += 1 -end - -@muladd function perform_step!(integrator, cache::Anas5Cache, repeat_step = false) - @unpack t, dt, uprev, u, f, p = integrator - uidx = eachindex(integrator.uprev) - @unpack k1, k2, k3, k4, k5, k6, k7, utilde, tmp, atmp, stage_limiter!, step_limiter!, thread = cache - @unpack a21, a31, a32, a41, a42, a43, a51, a52, a53, a54, a61, a62, a63, a64, c2, c3, c4, c5, c6, b1, b3, b4, b5, b6 = cache.tab - alg = unwrap_alg(integrator, false) - w = alg.w - v = w * dt - ## Formula by Z.A. Anastassi, see the Anas5 caches in tableaus/low_order_rk_tableaus.jl for the full citation. - a65 = (-8000 // 1071) * - (-a43 * (v^5) + 6 * tan(v) * (v^4) + 24 * (v^3) - 72 * tan(v) * (v^2) - 144 * v + - 144 * tan(v)) / ((v^5) * (a43 * tan(v) * v + 12 - 10 * a43)) - a61 += (-119 // 200) * a65 - a63 += (189 // 100) * a65 - a64 += (-459 // 200) * a65 - @tight_loop_macros for i in uidx - @inbounds tmp[i] = uprev[i] + a21 * k1[i] - end - stage_limiter!(tmp, integrator, p, t + c2 * dt) - f(k2, tmp, p, t + c2 * dt) - @tight_loop_macros for i in uidx - @inbounds tmp[i] = uprev[i] + dt * (a31 * k1[i] + a32 * k2[i]) - end - stage_limiter!(tmp, integrator, p, t + c3 * dt) - f(k3, tmp, p, t + c3 * dt) - @tight_loop_macros for i in uidx - @inbounds tmp[i] = uprev[i] + dt * (a41 * k1[i] + a42 * k2[i] + 2 * k3[i]) - end - stage_limiter!(tmp, integrator, p, t + c4 * dt) - f(k4, tmp, p, t + c4 * dt) - @tight_loop_macros for i in uidx - @inbounds tmp[i] = uprev[i] + - dt * (a51 * k1[i] + a52 * k2[i] + a53 * k3[i] + a54 * k4[i]) - end - stage_limiter!(tmp, integrator, p, t + c5 * dt) - f(k5, tmp, p, t + c5 * dt) - @tight_loop_macros for i in uidx - @inbounds tmp[i] = uprev[i] + - dt * (a61 * k1[i] + a62 * k2[i] + a63 * k3[i] + a64 * k4[i] + - a65 * k5[i]) - end - stage_limiter!(tmp, integrator, p, t + c6 * dt) - f(k6, tmp, p, t + c6 * dt) - @tight_loop_macros for i in uidx - @inbounds u[i] = uprev[i] + - dt * - (b1 * k1[i] + b3 * k3[i] + b4 * k4[i] + b5 * k5[i] + b6 * k6[i]) - end - stage_limiter!(tmp, integrator, p, t + dt) - step_limiter!(u, integrator, p, t + dt) - f(k7, u, p, t + dt) - integrator.stats.nf += 6 -end +end \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index f5eed7559e..4f8d03c059 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -212,7 +212,6 @@ end end if !is_APPVEYOR && GROUP == "AlgConvergence_II" - @time @safetestset "OwrenZen Tests" include("algconvergence/owrenzen_tests.jl") @time @safetestset "Runge-Kutta-Chebyshev Tests" include("../lib/OrdinaryDiffEqStabilizedRK/test/rkc_tests.jl") end @@ -224,6 +223,10 @@ end @time @safetestset "Linear-Nonlinear Krylov Methods Tests" include("algconvergence/linear_nonlinear_krylov_tests.jl") end + if !is_APPVEYOR && GROUP == "OwrenZen" + @time @safetestset "OwrenZen Tests" include("../lib/OrdinaryDiffEqLowOrderRK/test/owrenzen_tests.jl") + end + if !is_APPVEYOR && GROUP == "FIRK" @time @safetestset "FIRK Tests" include("../lib/OrdinaryDiffEqFIRK/src/OrdinaryDiffEqFIRK.jl") end From e7b8f53a425548d8a2d62a82c6e2557b1647437f Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Tue, 30 Jul 2024 19:57:04 +0530 Subject: [PATCH 002/133] Changes --- lib/OrdinaryDiffEqHighOrderRK/Project.toml | 20 ++++++++++++++++++- .../src/OrdinaryDiffEqHighOrderRK.jl | 1 + lib/OrdinaryDiffEqLowOrderRK/Project.toml | 20 ++++++++++++++++++- .../src/OrdinaryDiffEqLowOrderRK.jl | 1 + 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/lib/OrdinaryDiffEqHighOrderRK/Project.toml b/lib/OrdinaryDiffEqHighOrderRK/Project.toml index a7081d102b..679f7d6cf7 100644 --- a/lib/OrdinaryDiffEqHighOrderRK/Project.toml +++ b/lib/OrdinaryDiffEqHighOrderRK/Project.toml @@ -1,4 +1,22 @@ name = "OrdinaryDiffEqHighOrderRK" uuid = "d28bc4f8-55e1-4f49-af69-84c1a99f0f58" authors = ["ParamThakkar123 "] -version = "0.1.0" +version = "1.0.0" + +[deps] +OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" +MuladdMacro = "46d2c3a1-f734-5fdb-9937-b9b9aeba4221" +RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd" +FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898" + +[compat] +julia = "1.10" + +[extras] +DiffEqDevTools = "f3b72e0c-5b89-59e1-b016-84e28bfd966d" +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" +SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[targets] +test = ["DiffEqDevTools", "Random", "SafeTestsets", "Test"] \ No newline at end of file diff --git a/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl b/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl index 222ec57605..0639bcd45b 100644 --- a/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl +++ b/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl @@ -8,6 +8,7 @@ import OrdinaryDiffEq: alg_order, qmax_default, qmin_default, beta2_default, bet import Static: False import MuladdMacro: @muladd import FastBroadcast: @.. +import RecursiveArrayTools: recursivefill! include("algorithms.jl") include("alg_utils.jl") diff --git a/lib/OrdinaryDiffEqLowOrderRK/Project.toml b/lib/OrdinaryDiffEqLowOrderRK/Project.toml index ca4f29622c..8e436a3ea2 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/Project.toml +++ b/lib/OrdinaryDiffEqLowOrderRK/Project.toml @@ -1,4 +1,22 @@ name = "OrdinaryDiffEqLowOrderRK" uuid = "1344f307-1e59-4825-a18e-ace9aa3fa4c6" authors = ["ParamThakkar123 "] -version = "0.1.0" +version = "1.0.0" + +[deps] +OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" +MuladdMacro = "46d2c3a1-f734-5fdb-9937-b9b9aeba4221" +RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd" +FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898" + +[compat] +julia = "1.10" + +[extras] +DiffEqDevTools = "f3b72e0c-5b89-59e1-b016-84e28bfd966d" +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" +SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[targets] +test = ["DiffEqDevTools", "Random", "SafeTestsets", "Test"] \ No newline at end of file diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl index 428bcf023b..33fa3a34ca 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl @@ -9,6 +9,7 @@ import OrdinaryDiffEq: alg_order, isfsal, beta2_default, beta1_default, alg_stab import DiffEqBase: @tight_loop_macros import MuladdMacro: @muladd import FastBroadcast: @.. +import RecursiveArrayTools: recursivefill! include("algorithms.jl") include("alg_utils.jl") From 2ad688fc030b350d3391187caf1cd6b75ee9d67e Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Tue, 30 Jul 2024 19:59:24 +0530 Subject: [PATCH 003/133] Changes --- src/OrdinaryDiffEq.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/OrdinaryDiffEq.jl b/src/OrdinaryDiffEq.jl index 4ef0121120..a0a9572676 100644 --- a/src/OrdinaryDiffEq.jl +++ b/src/OrdinaryDiffEq.jl @@ -136,7 +136,6 @@ include("doc_utils.jl") include("misc_utils.jl") include("algorithms.jl") -include("algorithms/explicit_rk.jl") include("composite_algs.jl") include("alg_utils.jl") From 5d7759a3940bee8efd9896f044d4883a115e2033 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Tue, 30 Jul 2024 10:32:59 -0400 Subject: [PATCH 004/133] Update lib/OrdinaryDiffEqLowOrderRK/test/runtests.jl --- lib/OrdinaryDiffEqLowOrderRK/test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqLowOrderRK/test/runtests.jl b/lib/OrdinaryDiffEqLowOrderRK/test/runtests.jl index d1e01c5703..8a24eb8c0f 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/test/runtests.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/test/runtests.jl @@ -1,3 +1,3 @@ using SafeTestsets -@time @safetestset "Extrapolation Tests" include("owrenzen_tests.jl") \ No newline at end of file +@time @safetestset "OwrenZen Tests" include("owrenzen_tests.jl") \ No newline at end of file From 235027d38c8af5aa60c898cfb1d646478b29547e Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Tue, 30 Jul 2024 20:03:02 +0530 Subject: [PATCH 005/133] Fixes --- src/alg_utils.jl | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/alg_utils.jl b/src/alg_utils.jl index c0f5489ae6..452dc44794 100644 --- a/src/alg_utils.jl +++ b/src/alg_utils.jl @@ -42,10 +42,6 @@ isfsal(alg::Rodas4P2) = false # Pseudo Non-FSAL #isfsal(alg::RKM) = false -isfsal(alg::PSRK3p5q4) = false -isfsal(alg::PSRK3p6q5) = false -isfsal(alg::PSRK4p7q6) = false - isfirk(alg) = false get_current_isfsal(alg, cache) = isfsal(alg) @@ -391,13 +387,6 @@ alg_order(alg::Exprb43) = 4 alg_order(alg::ExplicitRK) = alg.tableau.order -alg_order(alg::MSRK6) = 6 -alg_order(alg::Stepanov5) = 5 -alg_order(alg::SIR54) = 5 -alg_order(alg::PSRK4p7q6) = 4 -alg_order(alg::PSRK3p6q5) = 3 -alg_order(alg::PSRK3p5q4) = 3 - alg_order(alg::RKMK2) = 2 alg_order(alg::RKMK4) = 4 alg_order(alg::LieRK4) = 4 From 0e74476fbe9cec5bac864db28d93bc520698d5fe Mon Sep 17 00:00:00 2001 From: Param Thakkar <128291516+ParamThakkar123@users.noreply.github.com> Date: Tue, 30 Jul 2024 20:04:36 +0530 Subject: [PATCH 006/133] Update test/runtests.jl Co-authored-by: Christopher Rackauckas --- test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 4f8d03c059..0c7baef7e6 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -223,7 +223,7 @@ end @time @safetestset "Linear-Nonlinear Krylov Methods Tests" include("algconvergence/linear_nonlinear_krylov_tests.jl") end - if !is_APPVEYOR && GROUP == "OwrenZen" + if !is_APPVEYOR && GROUP == "LowOrderRK" @time @safetestset "OwrenZen Tests" include("../lib/OrdinaryDiffEqLowOrderRK/test/owrenzen_tests.jl") end From e852f013b9bbb93a83e60e03cfbb68faea11b26b Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Tue, 30 Jul 2024 21:34:42 +0530 Subject: [PATCH 007/133] OrdinaryDiffEqTsit5 added --- lib/OrdinaryDiffEqHighOrderRK/Project.toml | 1 + .../src/algorithms.jl | 24 +- .../src/high_order_rk_perform_step.jl | 774 +++++++++--------- lib/OrdinaryDiffEqLowOrderRK/Project.toml | 1 + .../src/OrdinaryDiffEqLowOrderRK.jl | 3 +- lib/OrdinaryDiffEqLowOrderRK/src/alg_utils.jl | 2 - .../src/algorithms.jl | 25 - .../src/interp_func.jl | 7 - .../src/low_order_rk_addsteps.jl | 107 --- .../src/low_order_rk_caches.jl | 50 -- .../src/low_order_rk_perform_step.jl | 126 --- .../src/low_order_rk_tableaus.jl | 258 ------ lib/OrdinaryDiffEqTsit5/Project.toml | 23 + .../src/OrdinaryDiffEqTsit.jl | 19 + lib/OrdinaryDiffEqTsit5/src/alg_utils.jl | 3 + lib/OrdinaryDiffEqTsit5/src/algorithms.jl | 24 + lib/OrdinaryDiffEqTsit5/src/interp_func.jl | 7 + lib/OrdinaryDiffEqTsit5/src/tsit_caches.jl | 49 ++ .../src/tsit_perform_step.jl | 232 ++++++ lib/OrdinaryDiffEqTsit5/src/tsit_tableaus.jl | 257 ++++++ src/alg_utils.jl | 5 - 21 files changed, 1017 insertions(+), 980 deletions(-) create mode 100644 lib/OrdinaryDiffEqTsit5/Project.toml create mode 100644 lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit.jl create mode 100644 lib/OrdinaryDiffEqTsit5/src/alg_utils.jl create mode 100644 lib/OrdinaryDiffEqTsit5/src/algorithms.jl create mode 100644 lib/OrdinaryDiffEqTsit5/src/interp_func.jl create mode 100644 lib/OrdinaryDiffEqTsit5/src/tsit_caches.jl create mode 100644 lib/OrdinaryDiffEqTsit5/src/tsit_perform_step.jl create mode 100644 lib/OrdinaryDiffEqTsit5/src/tsit_tableaus.jl diff --git a/lib/OrdinaryDiffEqHighOrderRK/Project.toml b/lib/OrdinaryDiffEqHighOrderRK/Project.toml index 679f7d6cf7..2a3cee12e9 100644 --- a/lib/OrdinaryDiffEqHighOrderRK/Project.toml +++ b/lib/OrdinaryDiffEqHighOrderRK/Project.toml @@ -8,6 +8,7 @@ OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" MuladdMacro = "46d2c3a1-f734-5fdb-9937-b9b9aeba4221" RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd" FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898" +Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3" [compat] julia = "1.10" diff --git a/lib/OrdinaryDiffEqHighOrderRK/src/algorithms.jl b/lib/OrdinaryDiffEqHighOrderRK/src/algorithms.jl index be111f65c2..1ca8852765 100644 --- a/lib/OrdinaryDiffEqHighOrderRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqHighOrderRK/src/algorithms.jl @@ -15,6 +15,18 @@ function TanYam7(stage_limiter!, step_limiter! = trivial_limiter!) TanYam7(stage_limiter!, step_limiter!, False()) end +@doc explicit_rk_docstring("Tsitouras-Papakostas 8/7 Runge-Kutta method.", "TsitPap8") +Base.@kwdef struct TsitPap8{StageLimiter, StepLimiter, Thread} <: + OrdinaryDiffEqAdaptiveAlgorithm + stage_limiter!::StageLimiter = trivial_limiter! + step_limiter!::StepLimiter = trivial_limiter! + thread::Thread = False() +end +# for backwards compatibility +function TsitPap8(stage_limiter!, step_limiter! = trivial_limiter!) + TsitPap8(stage_limiter!, step_limiter!, False()) +end + @doc explicit_rk_docstring( "Hairer's 8/5/3 adaption of the Dormand-Prince Runge-Kutta method. (7th order interpolant).", "DP8", @@ -46,16 +58,4 @@ end # for backwards compatibility function PFRK87(stage_limiter!, step_limiter! = trivial_limiter!; omega = 0.0) PFRK87(stage_limiter!, step_limiter!, False(), omega) -end - -@doc explicit_rk_docstring("Tsitouras-Papakostas 8/7 Runge-Kutta method.", "TsitPap8") -Base.@kwdef struct TsitPap8{StageLimiter, StepLimiter, Thread} <: - OrdinaryDiffEqAdaptiveAlgorithm - stage_limiter!::StageLimiter = trivial_limiter! - step_limiter!::StepLimiter = trivial_limiter! - thread::Thread = False() -end -# for backwards compatibility -function TsitPap8(stage_limiter!, step_limiter! = trivial_limiter!) - TsitPap8(stage_limiter!, step_limiter!, False()) end \ No newline at end of file diff --git a/lib/OrdinaryDiffEqHighOrderRK/src/high_order_rk_perform_step.jl b/lib/OrdinaryDiffEqHighOrderRK/src/high_order_rk_perform_step.jl index 9873cc8cbf..dbcda2a369 100644 --- a/lib/OrdinaryDiffEqHighOrderRK/src/high_order_rk_perform_step.jl +++ b/lib/OrdinaryDiffEqHighOrderRK/src/high_order_rk_perform_step.jl @@ -196,53 +196,84 @@ end end =# -function initialize!(integrator, cache::DP8ConstantCache) - integrator.kshortsize = 7 - integrator.k = typeof(integrator.k)(undef, integrator.kshortsize) - integrator.fsalfirst = integrator.f(integrator.uprev, integrator.p, integrator.t) # Pre-start fsal - integrator.stats.nf += 1 +function initialize!(integrator, cache::TsitPap8ConstantCache) + integrator.fsalfirst = integrator.f(integrator.uprev, integrator.p, integrator.t) # Pre-start fsal + integrator.stats.nf += 1 + integrator.kshortsize = 2 + integrator.k = typeof(integrator.k)(undef, integrator.kshortsize) - # Avoid undefined entries if k is an array of arrays - integrator.fsallast = zero(integrator.fsalfirst) - @inbounds for i in eachindex(integrator.k) - integrator.k[i] = zero(integrator.fsalfirst) - end + # Avoid undefined entries if k is an array of arrays + integrator.fsallast = zero(integrator.fsalfirst) + integrator.k[1] = integrator.fsalfirst + integrator.k[2] = integrator.fsallast end -@muladd function perform_step!(integrator, cache::DP8ConstantCache, repeat_step = false) +#= +@muladd function perform_step!(integrator, cache::TsitPap8ConstantCache, repeat_step=false) + @unpack t,dt,uprev,u,f,p = integrator + @unpack c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,a0201,a0301,a0302,a0401,a0403,a0501,a0503,a0504,a0601,a0604,a0605,a0701,a0704,a0705,a0706,a0801,a0804,a0805,a0806,a0807,a0901,a0904,a0905,a0906,a0907,a0908,a1001,a1004,a1005,a1006,a1007,a1008,a1009,a1101,a1104,a1105,a1106,a1107,a1108,a1109,a1110,a1201,a1204,a1205,a1206,a1207,a1208,a1209,a1210,a1211,a1301,a1304,a1305,a1306,a1307,a1308,a1309,a1310,b1,b6,b7,b8,b9,b10,b11,b12,btilde1,btilde6,btilde7,btilde8,btilde9,btilde10,btilde11,btilde12,btilde13 = cache + k1 = integrator.fsalfirst + a = dt*a0201 + k2 = f(t + c1*dt, @.. broadcast=false uprev+a*k1) + k3 = f(t + c2*dt, @.. broadcast=false uprev+dt*(a0301*k1+a0302*k2)) + k4 = f(t + c3*dt, @.. broadcast=false uprev+dt*(a0401*k1 +a0403*k3)) + k5 = f(t + c4*dt, @.. broadcast=false uprev+dt*(a0501*k1 +a0503*k3+a0504*k4)) + k6 = f(t + c5*dt, @.. broadcast=false uprev+dt*(a0601*k1 +a0604*k4+a0605*k5)) + k7 = f(t + c6*dt, @.. broadcast=false uprev+dt*(a0701*k1 +a0704*k4+a0705*k5+a0706*k6)) + k8 = f(t + c7*dt, @.. broadcast=false uprev+dt*(a0801*k1 +a0804*k4+a0805*k5+a0806*k6+a0807*k7)) + k9 = f(t + c8*dt, @.. broadcast=false uprev+dt*(a0901*k1 +a0904*k4+a0905*k5+a0906*k6+a0907*k7+a0908*k8)) + k10 =f(t + c9*dt, @.. broadcast=false uprev+dt*(a1001*k1 +a1004*k4+a1005*k5+a1006*k6+a1007*k7+a1008*k8+a1009*k9)) + k11= f(t + c10*dt, @.. broadcast=false uprev+dt*(a1101*k1 +a1104*k4+a1105*k5+a1106*k6+a1107*k7+a1108*k8+a1109*k9+a1110*k10)) + k12= f(t+dt, @.. broadcast=false uprev+dt*(a1201*k1 +a1204*k4+a1205*k5+a1206*k6+a1207*k7+a1208*k8+a1209*k9+a1210*k10+a1211*k11)) + k13= f(t+dt, @.. broadcast=false uprev+dt*(a1301*k1 +a1304*k4+a1305*k5+a1306*k6+a1307*k7+a1308*k8+a1309*k9+a1310*k10)) + u = @.. broadcast=false uprev + dt*(b1*k1+b6*k6+b7*k7+b8*k8+b9*k9+b10*k10+b11*k11+b12*k12) + if integrator.opts.adaptive + utilde = @.. broadcast=false dt*(btilde1*k1 + btilde6*k6 + btilde7*k7 + btilde8*k8 + btilde9*k9 + btilde10*k10 + btilde11*k11 + btilde12*k12 + btilde13*k13) + atmp = calculate_residuals(utilde, uprev, u, integrator.opts.abstol, integrator.opts.reltol,integrator.opts.internalnorm,t) + integrator.EEst = integrator.opts.internalnorm(atmp,t) + end + integrator.fsallast = f(u, p, t+dt) + integrator.k[1] = integrator.fsalfirst + integrator.k[2] = integrator.fsallast + integrator.u = u +end +=# + +@muladd function perform_step!(integrator, cache::TsitPap8ConstantCache, + repeat_step = false) @unpack t, dt, uprev, u, f, p = integrator - @unpack c7, c8, c9, c10, c11, c6, c5, c4, c3, c2, b1, b6, b7, b8, b9, b10, b11, b12, btilde1, btilde6, btilde7, btilde8, btilde9, btilde10, btilde11, btilde12, er1, er6, er7, er8, er9, er10, er11, er12, a0201, a0301, a0302, a0401, a0403, a0501, a0503, a0504, a0601, a0604, a0605, a0701, a0704, a0705, a0706, a0801, a0804, a0805, a0806, a0807, a0901, a0904, a0905, a0906, a0907, a0908, a1001, a1004, a1005, a1006, a1007, a1008, a1009, a1101, a1104, a1105, a1106, a1107, a1108, a1109, a1110, a1201, a1204, a1205, a1206, a1207, a1208, a1209, a1210, a1211 = cache + @unpack c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, a0201, a0301, a0302, a0401, a0403, a0501, a0503, a0504, a0601, a0604, a0605, a0701, a0704, a0705, a0706, a0801, a0804, a0805, a0806, a0807, a0901, a0904, a0905, a0906, a0907, a0908, a1001, a1004, a1005, a1006, a1007, a1008, a1009, a1101, a1104, a1105, a1106, a1107, a1108, a1109, a1110, a1201, a1204, a1205, a1206, a1207, a1208, a1209, a1210, a1211, a1301, a1304, a1305, a1306, a1307, a1308, a1309, a1310, b1, b6, b7, b8, b9, b10, b11, b12, btilde1, btilde6, btilde7, btilde8, btilde9, btilde10, btilde11, btilde12, btilde13 = cache k1 = integrator.fsalfirst a = dt * a0201 - k2 = f(uprev + a * k1, p, t + c2 * dt) - k3 = f(uprev + dt * (a0301 * k1 + a0302 * k2), p, t + c3 * dt) - k4 = f(uprev + dt * (a0401 * k1 + a0403 * k3), p, t + c4 * dt) - k5 = f(uprev + dt * (a0501 * k1 + a0503 * k3 + a0504 * k4), p, t + c5 * dt) - k6 = f(uprev + dt * (a0601 * k1 + a0604 * k4 + a0605 * k5), p, t + c6 * dt) - k7 = f(uprev + dt * (a0701 * k1 + a0704 * k4 + a0705 * k5 + a0706 * k6), p, t + c7 * dt) + k2 = f(uprev + a * k1, p, t + c1 * dt) + k3 = f(uprev + dt * (a0301 * k1 + a0302 * k2), p, t + c2 * dt) + k4 = f(uprev + dt * (a0401 * k1 + a0403 * k3), p, t + c3 * dt) + k5 = f(uprev + dt * (a0501 * k1 + a0503 * k3 + a0504 * k4), p, t + c4 * dt) + k6 = f(uprev + dt * (a0601 * k1 + a0604 * k4 + a0605 * k5), p, t + c5 * dt) + k7 = f(uprev + dt * (a0701 * k1 + a0704 * k4 + a0705 * k5 + a0706 * k6), p, t + c6 * dt) k8 = f( uprev + dt * (a0801 * k1 + a0804 * k4 + a0805 * k5 + a0806 * k6 + a0807 * k7), p, - t + c8 * dt) + t + c7 * dt) k9 = f( uprev + dt * (a0901 * k1 + a0904 * k4 + a0905 * k5 + a0906 * k6 + a0907 * k7 + a0908 * k8), p, - t + c9 * dt) + t + c8 * dt) k10 = f( uprev + dt * (a1001 * k1 + a1004 * k4 + a1005 * k5 + a1006 * k6 + a1007 * k7 + a1008 * k8 + a1009 * k9), p, - t + c10 * dt) + t + c9 * dt) k11 = f( uprev + dt * (a1101 * k1 + a1104 * k4 + a1105 * k5 + a1106 * k6 + a1107 * k7 + a1108 * k8 + a1109 * k9 + a1110 * k10), p, - t + c11 * dt) + t + c10 * dt) k12 = f( uprev + dt * @@ -250,147 +281,97 @@ end a1209 * k9 + a1210 * k10 + a1211 * k11), p, t + dt) - integrator.stats.nf += 11 - kupdate = b1 * k1 + b6 * k6 + b7 * k7 + b8 * k8 + b9 * k9 + b10 * k10 + b11 * k11 + - b12 * k12 - u = uprev + dt * kupdate + k13 = f( + uprev + + dt * + (a1301 * k1 + a1304 * k4 + a1305 * k5 + a1306 * k6 + a1307 * k7 + a1308 * k8 + + a1309 * k9 + a1310 * k10), + p, + t + dt) + integrator.stats.nf += 12 + u = uprev + + dt * (b1 * k1 + b6 * k6 + b7 * k7 + b8 * k8 + b9 * k9 + b10 * k10 + b11 * k11 + + b12 * k12) if integrator.opts.adaptive - utilde = dt * (k1 * er1 + k6 * er6 + k7 * er7 + k8 * er8 + k9 * er9 + k10 * er10 + - k11 * er11 + k12 * er12) - atmp = calculate_residuals(utilde, uprev, u, integrator.opts.abstol, - integrator.opts.reltol, integrator.opts.internalnorm, t) - err5 = integrator.opts.internalnorm(atmp, t) # Order 5 utilde = dt * (btilde1 * k1 + btilde6 * k6 + btilde7 * k7 + btilde8 * k8 + btilde9 * k9 + - btilde10 * k10 + btilde11 * k11 + btilde12 * k12) + btilde10 * k10 + btilde11 * k11 + btilde12 * k12 + btilde13 * k13) atmp = calculate_residuals(utilde, uprev, u, integrator.opts.abstol, integrator.opts.reltol, integrator.opts.internalnorm, t) - err3 = integrator.opts.internalnorm(atmp, t) # Order 3 - err52 = err5 * err5 - if err5 ≈ 0 && err3 ≈ 0 - integrator.EEst = zero(integrator.EEst) - else - integrator.EEst = err52 / sqrt(err52 + 0.01 * err3 * err3) - end + integrator.EEst = integrator.opts.internalnorm(atmp, t) end - k13 = f(u, p, t + dt) + integrator.fsallast = f(u, p, t + dt) integrator.stats.nf += 1 - integrator.fsallast = k13 - if integrator.opts.calck - @unpack c14, c15, c16, a1401, a1407, a1408, a1409, a1410, a1411, a1412, a1413, a1501, a1506, a1507, a1508, a1511, a1512, a1513, a1514, a1601, a1606, a1607, a1608, a1609, a1613, a1614, a1615 = cache - @unpack d401, d406, d407, d408, d409, d410, d411, d412, d413, d414, d415, d416, d501, d506, d507, d508, d509, d510, d511, d512, d513, d514, d515, d516, d601, d606, d607, d608, d609, d610, d611, d612, d613, d614, d615, d616, d701, d706, d707, d708, d709, d710, d711, d712, d713, d714, d715, d716 = cache - k14 = f( - uprev + - dt * (a1401 * k1 + a1407 * k7 + a1408 * k8 + a1409 * k9 + a1410 * k10 + - a1411 * k11 + a1412 * k12 + a1413 * k13), - p, - t + c14 * dt) - k15 = f( - uprev + - dt * (a1501 * k1 + a1506 * k6 + a1507 * k7 + a1508 * k8 + a1511 * k11 + - a1512 * k12 + a1513 * k13 + a1514 * k14), - p, - t + c15 * dt) - k16 = f( - uprev + - dt * (a1601 * k1 + a1606 * k6 + a1607 * k7 + a1608 * k8 + a1609 * k9 + - a1613 * k13 + a1614 * k14 + a1615 * k15), - p, - t + c16 * dt) - integrator.stats.nf += 3 - udiff = kupdate - integrator.k[1] = udiff - bspl = k1 - udiff - integrator.k[2] = bspl - integrator.k[3] = udiff - k13 - bspl - integrator.k[4] = d401 * k1 + d406 * k6 + d407 * k7 + d408 * k8 + d409 * k9 + - d410 * k10 + d411 * k11 + d412 * k12 + d413 * k13 + d414 * k14 + - d415 * k15 + d416 * k16 - integrator.k[5] = d501 * k1 + d506 * k6 + d507 * k7 + d508 * k8 + d509 * k9 + - d510 * k10 + d511 * k11 + d512 * k12 + d513 * k13 + d514 * k14 + - d515 * k15 + d516 * k16 - integrator.k[6] = d601 * k1 + d606 * k6 + d607 * k7 + d608 * k8 + d609 * k9 + - d610 * k10 + d611 * k11 + d612 * k12 + d613 * k13 + d614 * k14 + - d615 * k15 + d616 * k16 - integrator.k[7] = d701 * k1 + d706 * k6 + d707 * k7 + d708 * k8 + d709 * k9 + - d710 * k10 + d711 * k11 + d712 * k12 + d713 * k13 + d714 * k14 + - d715 * k15 + d716 * k16 - end + integrator.k[1] = integrator.fsalfirst + integrator.k[2] = integrator.fsallast integrator.u = u end -function initialize!(integrator, cache::DP8Cache) - integrator.kshortsize = 7 +function initialize!(integrator, cache::TsitPap8Cache) + integrator.fsalfirst = cache.fsalfirst + integrator.fsallast = cache.k + integrator.kshortsize = 2 resize!(integrator.k, integrator.kshortsize) - integrator.k .= [ - cache.udiff, - cache.bspl, - cache.dense_tmp3, - cache.dense_tmp4, - cache.dense_tmp5, - cache.dense_tmp6, - cache.dense_tmp7 - ] - integrator.fsalfirst = cache.k1 - integrator.fsallast = cache.k13 + integrator.k[1] = integrator.fsalfirst + integrator.k[2] = integrator.fsallast integrator.f(integrator.fsalfirst, integrator.uprev, integrator.p, integrator.t) # Pre-start fsal integrator.stats.nf += 1 end -@muladd function perform_step!(integrator, cache::DP8Cache, repeat_step = false) +@muladd function perform_step!(integrator, cache::TsitPap8Cache, repeat_step = false) @unpack t, dt, uprev, u, f, p = integrator - uidx = eachindex(integrator.uprev) - @unpack c7, c8, c9, c10, c11, c6, c5, c4, c3, c2, b1, b6, b7, b8, b9, b10, b11, b12, btilde1, btilde6, btilde7, btilde8, btilde9, btilde10, btilde11, btilde12, er1, er6, er7, er8, er9, er10, er11, er12, a0201, a0301, a0302, a0401, a0403, a0501, a0503, a0504, a0601, a0604, a0605, a0701, a0704, a0705, a0706, a0801, a0804, a0805, a0806, a0807, a0901, a0904, a0905, a0906, a0907, a0908, a1001, a1004, a1005, a1006, a1007, a1008, a1009, a1101, a1104, a1105, a1106, a1107, a1108, a1109, a1110, a1201, a1204, a1205, a1206, a1207, a1208, a1209, a1210, a1211 = cache.tab - @unpack k1, k2, k3, k4, k5, k6, k7, k8, k9, k10, k11, k12, k13, k14, k15, k16, udiff, bspl, dense_tmp3, dense_tmp4, dense_tmp5, dense_tmp6, dense_tmp7, kupdate, utilde, tmp, atmp, stage_limiter!, step_limiter!, thread = cache + @unpack c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, a0201, a0301, a0302, a0401, a0403, a0501, a0503, a0504, a0601, a0604, a0605, a0701, a0704, a0705, a0706, a0801, a0804, a0805, a0806, a0807, a0901, a0904, a0905, a0906, a0907, a0908, a1001, a1004, a1005, a1006, a1007, a1008, a1009, a1101, a1104, a1105, a1106, a1107, a1108, a1109, a1110, a1201, a1204, a1205, a1206, a1207, a1208, a1209, a1210, a1211, a1301, a1304, a1305, a1306, a1307, a1308, a1309, a1310, b1, b6, b7, b8, b9, b10, b11, b12, btilde1, btilde6, btilde7, btilde8, btilde9, btilde10, btilde11, btilde12, btilde13 = cache.tab + @unpack k2, k3, k4, k5, k6, k7, k8, k9, k10, k11, k12, k13, utilde, tmp, atmp, k, stage_limiter!, step_limiter!, thread = cache + k1 = cache.fsalfirst f(k1, uprev, p, t) a = dt * a0201 @.. broadcast=false thread=thread tmp=uprev + a * k1 - stage_limiter!(tmp, integrator, p, t + c2 * dt) - f(k2, tmp, p, t + c2 * dt) + stage_limiter!(tmp, integrator, p, t + c1 * dt) + f(k2, tmp, p, t + c1 * dt) @.. broadcast=false thread=thread tmp=uprev + dt * (a0301 * k1 + a0302 * k2) - stage_limiter!(tmp, integrator, p, t + c3 * dt) - f(k3, tmp, p, t + c3 * dt) + stage_limiter!(tmp, integrator, p, t + c2 * dt) + f(k3, tmp, p, t + c2 * dt) @.. broadcast=false thread=thread tmp=uprev + dt * (a0401 * k1 + a0403 * k3) - stage_limiter!(tmp, integrator, p, t + c4 * dt) - f(k4, tmp, p, t + c4 * dt) + stage_limiter!(tmp, integrator, p, t + c3 * dt) + f(k4, tmp, p, t + c3 * dt) @.. broadcast=false thread=thread tmp=uprev + dt * (a0501 * k1 + a0503 * k3 + a0504 * k4) - stage_limiter!(tmp, integrator, p, t + c5 * dt) - f(k5, tmp, p, t + c5 * dt) + stage_limiter!(tmp, integrator, p, t + c4 * dt) + f(k5, tmp, p, t + c4 * dt) @.. broadcast=false thread=thread tmp=uprev + dt * (a0601 * k1 + a0604 * k4 + a0605 * k5) - stage_limiter!(tmp, integrator, p, t + c6 * dt) - f(k6, tmp, p, t + c6 * dt) + stage_limiter!(tmp, integrator, p, t + c5 * dt) + f(k6, tmp, p, t + c5 * dt) @.. broadcast=false thread=thread tmp=uprev + dt * (a0701 * k1 + a0704 * k4 + a0705 * k5 + a0706 * k6) - stage_limiter!(tmp, integrator, p, t + c7 * dt) - f(k7, tmp, p, t + c7 * dt) + stage_limiter!(tmp, integrator, p, t + c6 * dt) + f(k7, tmp, p, t + c6 * dt) @.. broadcast=false thread=thread tmp=uprev + dt * (a0801 * k1 + a0804 * k4 + a0805 * k5 + a0806 * k6 + a0807 * k7) - stage_limiter!(tmp, integrator, p, t + c8 * dt) - f(k8, tmp, p, t + c8 * dt) + stage_limiter!(tmp, integrator, p, t + c7 * dt) + f(k8, tmp, p, t + c7 * dt) @.. broadcast=false thread=thread tmp=uprev + dt * (a0901 * k1 + a0904 * k4 + a0905 * k5 + a0906 * k6 + a0907 * k7 + a0908 * k8) - stage_limiter!(tmp, integrator, p, t + c9 * dt) - f(k9, tmp, p, t + c9 * dt) + stage_limiter!(tmp, integrator, p, t + c8 * dt) + f(k9, tmp, p, t + c8 * dt) @.. broadcast=false thread=thread tmp=uprev + dt * (a1001 * k1 + a1004 * k4 + a1005 * k5 + a1006 * k6 + a1007 * k7 + a1008 * k8 + a1009 * k9) - stage_limiter!(tmp, integrator, p, t + c10 * dt) - f(k10, tmp, p, t + c10 * dt) + stage_limiter!(tmp, integrator, p, t + c9 * dt) + f(k10, tmp, p, t + c9 * dt) @.. broadcast=false thread=thread tmp=uprev + dt * (a1101 * k1 + a1104 * k4 + a1105 * k5 + a1106 * k6 + a1107 * k7 + a1108 * k8 + a1109 * k9 + a1110 * k10) - stage_limiter!(tmp, integrator, p, t + c11 * dt) - f(k11, tmp, p, t + c11 * dt) + stage_limiter!(tmp, integrator, p, t + c10 * dt) + f(k11, tmp, p, t + c10 * dt) @.. broadcast=false thread=thread tmp=uprev + dt * (a1201 * k1 + a1204 * k4 + a1205 * k5 + a1206 * k6 + @@ -399,280 +380,158 @@ end a1211 * k11) stage_limiter!(tmp, integrator, p, t + dt) f(k12, tmp, p, t + dt) - @.. broadcast=false thread=thread kupdate=b1 * k1 + b6 * k6 + b7 * k7 + b8 * k8 + - b9 * k9 + - b10 * k10 + b11 * k11 + b12 * k12 - @.. broadcast=false thread=thread u=uprev + dt * kupdate + @.. broadcast=false thread=thread tmp=uprev + + dt * (a1301 * k1 + a1304 * k4 + a1305 * k5 + + a1306 * k6 + + a1307 * k7 + a1308 * k8 + a1309 * k9 + + a1310 * k10) + stage_limiter!(tmp, integrator, p, t + dt) + f(k13, tmp, p, t + dt) + @.. broadcast=false thread=thread u=uprev + + dt * + (b1 * k1 + b6 * k6 + b7 * k7 + b8 * k8 + b9 * k9 + + b10 * k10 + + b11 * k11 + b12 * k12) stage_limiter!(u, integrator, p, t + dt) step_limiter!(u, integrator, p, t + dt) - integrator.stats.nf += 12 + integrator.stats.nf += 13 if integrator.opts.adaptive - @.. broadcast=false thread=thread utilde=dt * - (k1 * er1 + k6 * er6 + k7 * er7 + - k8 * er8 + k9 * er9 + - k10 * er10 + k11 * er11 + k12 * er12) - calculate_residuals!(atmp, utilde, uprev, u, integrator.opts.abstol, - integrator.opts.reltol, integrator.opts.internalnorm, t, - thread) - err5 = integrator.opts.internalnorm(atmp, t) # Order 5 @.. broadcast=false thread=thread utilde=dt * (btilde1 * k1 + btilde6 * k6 + btilde7 * k7 + btilde8 * k8 + btilde9 * k9 + btilde10 * k10 + - btilde11 * k11 + btilde12 * k12) + btilde11 * k11 + btilde12 * k12 + + btilde13 * k13) calculate_residuals!(atmp, utilde, uprev, u, integrator.opts.abstol, integrator.opts.reltol, integrator.opts.internalnorm, t, thread) - err3 = integrator.opts.internalnorm(atmp, t) # Order 3 - err52 = err5 * err5 - if err5 ≈ 0 && err3 ≈ 0 - integrator.EEst = zero(integrator.EEst) - else - integrator.EEst = err52 / sqrt(err52 + 0.01 * err3 * err3) - end + integrator.EEst = integrator.opts.internalnorm(atmp, t) end - f(k13, u, p, t + dt) + f(k, u, p, t + dt) integrator.stats.nf += 1 - if integrator.opts.calck - @unpack c14, c15, c16, a1401, a1407, a1408, a1409, a1410, a1411, a1412, a1413, a1501, a1506, a1507, a1508, a1511, a1512, a1513, a1514, a1601, a1606, a1607, a1608, a1609, a1613, a1614, a1615 = cache.tab - @unpack d401, d406, d407, d408, d409, d410, d411, d412, d413, d414, d415, d416, d501, d506, d507, d508, d509, d510, d511, d512, d513, d514, d515, d516, d601, d606, d607, d608, d609, d610, d611, d612, d613, d614, d615, d616, d701, d706, d707, d708, d709, d710, d711, d712, d713, d714, d715, d716 = cache.tab - @.. broadcast=false thread=thread tmp=uprev + - dt * (a1401 * k1 + a1407 * k7 + a1408 * k8 + - a1409 * k9 + - a1410 * k10 + a1411 * k11 + a1412 * k12 + - a1413 * k13) - f(k14, tmp, p, t + c14 * dt) - @.. broadcast=false thread=thread tmp=uprev + - dt * (a1501 * k1 + a1506 * k6 + a1507 * k7 + - a1508 * k8 + - a1511 * k11 + a1512 * k12 + a1513 * k13 + - a1514 * k14) - f(k15, tmp, p, t + c15 * dt) - @.. broadcast=false thread=thread tmp=uprev + - dt * (a1601 * k1 + a1606 * k6 + a1607 * k7 + - a1608 * k8 + - a1609 * k9 + a1613 * k13 + a1614 * k14 + - a1615 * k15) - f(k16, tmp, p, t + c16 * dt) - integrator.stats.nf += 3 - @.. broadcast=false thread=thread udiff=kupdate - @.. broadcast=false thread=thread bspl=k1 - udiff - @.. broadcast=false thread=thread integrator.k[3]=udiff - k13 - bspl - @.. broadcast=false thread=thread integrator.k[4]=d401 * k1 + d406 * k6 + - d407 * k7 + d408 * k8 + - d409 * k9 + d410 * k10 + - d411 * k11 + - d412 * k12 + d413 * k13 + - d414 * k14 + - d415 * k15 + d416 * k16 - @.. broadcast=false thread=thread integrator.k[5]=d501 * k1 + d506 * k6 + - d507 * k7 + d508 * k8 + - d509 * k9 + d510 * k10 + - d511 * k11 + - d512 * k12 + d513 * k13 + - d514 * k14 + - d515 * k15 + d516 * k16 - @.. broadcast=false thread=thread integrator.k[6]=d601 * k1 + d606 * k6 + - d607 * k7 + d608 * k8 + - d609 * k9 + d610 * k10 + - d611 * k11 + - d612 * k12 + d613 * k13 + - d614 * k14 + - d615 * k15 + d616 * k16 - @.. broadcast=false thread=thread integrator.k[7]=d701 * k1 + d706 * k6 + - d707 * k7 + d708 * k8 + - d709 * k9 + d710 * k10 + - d711 * k11 + - d712 * k12 + d713 * k13 + - d714 * k14 + - d715 * k15 + d716 * k16 - end + return nothing end #= -@muladd function perform_step!(integrator, cache::DP8Cache, repeat_step=false) +@muladd function perform_step!(integrator, cache::TsitPap8Cache, repeat_step=false) @unpack t,dt,uprev,u,f,p = integrator uidx = eachindex(integrator.uprev) - @unpack c7,c8,c9,c10,c11,c6,c5,c4,c3,c2,b1,b6,b7,b8,b9,b10,b11,b12,btilde1,btilde6,btilde7,btilde8,btilde9,btilde10,btilde11,btilde12,er1,er6,er7,er8,er9,er10,er11,er12,a0201,a0301,a0302,a0401,a0403,a0501,a0503,a0504,a0601,a0604,a0605,a0701,a0704,a0705,a0706,a0801,a0804,a0805,a0806,a0807,a0901,a0904,a0905,a0906,a0907,a0908,a1001,a1004,a1005,a1006,a1007,a1008,a1009,a1101,a1104,a1105,a1106,a1107,a1108,a1109,a1110,a1201,a1204,a1205,a1206,a1207,a1208,a1209,a1210,a1211 = cache.tab - @unpack k1,k2,k3,k4,k5,k6,k7,k8,k9,k10,k11,k12,k13,k14,k15,k16,udiff,bspl,dense_tmp3,dense_tmp4,dense_tmp5,dense_tmp6,dense_tmp7,kupdate,utilde,tmp,atmp = cache + @unpack c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,a0201,a0301,a0302,a0401,a0403,a0501,a0503,a0504,a0601,a0604,a0605,a0701,a0704,a0705,a0706,a0801,a0804,a0805,a0806,a0807,a0901,a0904,a0905,a0906,a0907,a0908,a1001,a1004,a1005,a1006,a1007,a1008,a1009,a1101,a1104,a1105,a1106,a1107,a1108,a1109,a1110,a1201,a1204,a1205,a1206,a1207,a1208,a1209,a1210,a1211,a1301,a1304,a1305,a1306,a1307,a1308,a1309,a1310,b1,b6,b7,b8,b9,b10,b11,b12,btilde1,btilde6,btilde7,btilde8,btilde9,btilde10,btilde11,btilde12,btilde13 = cache.tab + @unpack k2,k3,k4,k5,k6,k7,k8,k9,k10,k11,k12,k13,utilde,tmp,atmp,k = cache + k1 = cache.fsalfirst f(k1, uprev, p, t) a = dt*a0201 @tight_loop_macros for i in uidx @inbounds tmp[i] = uprev[i]+a*k1[i] end - f(k2, tmp, p, t + c2*dt) + f(k2, tmp, p, t + c1*dt) @tight_loop_macros for i in uidx @inbounds tmp[i] = uprev[i]+dt*(a0301*k1[i]+a0302*k2[i]) end - f(k3, tmp, p, t + c3*dt) + f(k3, tmp, p, t + c2*dt) @tight_loop_macros for i in uidx @inbounds tmp[i] = uprev[i]+dt*(a0401*k1[i]+a0403*k3[i]) end - f(k4, tmp, p, t + c4*dt) + f(k4, tmp, p, t + c3*dt) @tight_loop_macros for i in uidx @inbounds tmp[i] = uprev[i]+dt*(a0501*k1[i]+a0503*k3[i]+a0504*k4[i]) end - f(k5, tmp, p, t + c5*dt) + f(k5, tmp, p, t + c4*dt) @tight_loop_macros for i in uidx @inbounds tmp[i] = uprev[i]+dt*(a0601*k1[i]+a0604*k4[i]+a0605*k5[i]) end - f(k6, tmp, p, t + c6*dt) + f(k6, tmp, p, t + c5*dt) @tight_loop_macros for i in uidx @inbounds tmp[i] = uprev[i]+dt*(a0701*k1[i]+a0704*k4[i]+a0705*k5[i]+a0706*k6[i]) end - f(k7, tmp, p, t + c7*dt) + f(k7, tmp, p, t + c6*dt) @tight_loop_macros for i in uidx @inbounds tmp[i] = uprev[i]+dt*(a0801*k1[i]+a0804*k4[i]+a0805*k5[i]+a0806*k6[i]+a0807*k7[i]) end - f(k8, tmp, p, t + c8*dt) + f(k8, tmp, p, t + c7*dt) @tight_loop_macros for i in uidx @inbounds tmp[i] = uprev[i]+dt*(a0901*k1[i]+a0904*k4[i]+a0905*k5[i]+a0906*k6[i]+a0907*k7[i]+a0908*k8[i]) end - f(k9, tmp, p, t + c9*dt) + f(k9, tmp, p, t + c8*dt) @tight_loop_macros for i in uidx @inbounds tmp[i] = uprev[i]+dt*(a1001*k1[i]+a1004*k4[i]+a1005*k5[i]+a1006*k6[i]+a1007*k7[i]+a1008*k8[i]+a1009*k9[i]) end - f(k10, tmp, p, t + c10*dt) + f(k10, tmp, p, t + c9*dt) @tight_loop_macros for i in uidx @inbounds tmp[i] = uprev[i]+dt*(a1101*k1[i]+a1104*k4[i]+a1105*k5[i]+a1106*k6[i]+a1107*k7[i]+a1108*k8[i]+a1109*k9[i]+a1110*k10[i]) end - f(k11, tmp, p, t + c11*dt) + f(k11, tmp, p, t + c10*dt) @tight_loop_macros for i in uidx @inbounds tmp[i] = uprev[i]+dt*(a1201*k1[i]+a1204*k4[i]+a1205*k5[i]+a1206*k6[i]+a1207*k7[i]+a1208*k8[i]+a1209*k9[i]+a1210*k10[i]+a1211*k11[i]) end f(k12, tmp, p, t+dt) @tight_loop_macros for i in uidx - @inbounds kupdate[i] = b1*k1[i]+b6*k6[i]+b7*k7[i]+b8*k8[i]+b9*k9[i]+b10*k10[i]+b11*k11[i]+b12*k12[i] - @inbounds u[i] = uprev[i] + dt*kupdate[i] + @inbounds tmp[i] = uprev[i]+dt*(a1301*k1[i]+a1304*k4[i]+a1305*k5[i]+a1306*k6[i]+a1307*k7[i]+a1308*k8[i]+a1309*k9[i]+a1310*k10[i]) end - integrator.stats.nf += 12 + f(k13, tmp, p, t+dt) + @tight_loop_macros for i in uidx + @inbounds u[i] = uprev[i] + dt*(b1*k1[i]+b6*k6[i]+b7*k7[i]+b8*k8[i]+b9*k9[i]+b10*k10[i]+b11*k11[i]+b12*k12[i]) + end + integrator.stats.nf += 13 if integrator.opts.adaptive @tight_loop_macros for i in uidx - @inbounds utilde[i] = dt*(k1[i]*er1 + k6[i]*er6 + k7[i]*er7 + k8[i]*er8 + k9[i]*er9 + k10[i]*er10 + k11[i]*er11 + k12[i]*er12) - end - calculate_residuals!(atmp, utilde, uprev, u, integrator.opts.abstol, integrator.opts.reltol,integrator.opts.internalnorm,t) - err5 = integrator.opts.internalnorm(atmp,t) # Order 5 - @tight_loop_macros for i in uidx - @inbounds utilde[i]= dt*(btilde1*k1[i] + btilde6*k6[i] + btilde7*k7[i] + btilde8*k8[i] + btilde9*k9[i] + btilde10*k10[i] + btilde11*k11[i] + btilde12*k12[i]) + @inbounds utilde[i] = dt*(btilde1*k1[i] + btilde6*k6[i] + btilde7*k7[i] + btilde8*k8[i] + btilde9*k9[i] + btilde10*k10[i] + btilde11*k11[i] + btilde12*k12[i] + btilde13*k13[i]) end calculate_residuals!(atmp, utilde, uprev, u, integrator.opts.abstol, integrator.opts.reltol,integrator.opts.internalnorm,t) - err3 = integrator.opts.internalnorm(atmp,t) # Order 3 - err52 = err5*err5 - if err5 ≈ 0 && err3 ≈ 0 - integrator.EEst = zero(integrator.EEst) - else - integrator.EEst = err52/sqrt(err52 + 0.01*err3*err3) - end + integrator.EEst = integrator.opts.internalnorm(atmp,t) end - f(k13, u, p, t+dt) + f(k, u, p, t+dt) integrator.stats.nf += 1 - if integrator.opts.calck - @unpack c14,c15,c16,a1401,a1407,a1408,a1409,a1410,a1411,a1412,a1413,a1501,a1506,a1507,a1508,a1511,a1512,a1513,a1514,a1601,a1606,a1607,a1608,a1609,a1613,a1614,a1615 = cache.tab - @unpack d401,d406,d407,d408,d409,d410,d411,d412,d413,d414,d415,d416,d501,d506,d507,d508,d509,d510,d511,d512,d513,d514,d515,d516,d601,d606,d607,d608,d609,d610,d611,d612,d613,d614,d615,d616,d701,d706,d707,d708,d709,d710,d711,d712,d713,d714,d715,d716 = cache.tab - @tight_loop_macros for i in uidx - @inbounds tmp[i] = uprev[i]+dt*(a1401*k1[i]+a1407*k7[i]+a1408*k8[i]+a1409*k9[i]+a1410*k10[i]+a1411*k11[i]+a1412*k12[i]+a1413*k13[i]) - end - f(k14, tmp, p, t + c14*dt) - @tight_loop_macros for i in uidx - @inbounds tmp[i] = uprev[i]+dt*(a1501*k1[i]+a1506*k6[i]+a1507*k7[i]+a1508*k8[i]+a1511*k11[i]+a1512*k12[i]+a1513*k13[i]+a1514*k14[i]) - end - f(k15, tmp, p, t + c15*dt) - @tight_loop_macros for i in uidx - @inbounds tmp[i] = uprev[i]+dt*(a1601*k1[i]+a1606*k6[i]+a1607*k7[i]+a1608*k8[i]+a1609*k9[i]+a1613*k13[i]+a1614*k14[i]+a1615*k15[i]) - end - f(k16, tmp, p, t + c16*dt) - integrator.stats.nf += 3 - @tight_loop_macros for i in uidx - @inbounds udiff[i]= kupdate[i] - @inbounds bspl[i] = k1[i] - udiff[i] - @inbounds integrator.k[3][i] = udiff[i] - k13[i] - bspl[i] - @inbounds integrator.k[4][i] = d401*k1[i]+d406*k6[i]+d407*k7[i]+d408*k8[i]+d409*k9[i]+d410*k10[i]+d411*k11[i]+d412*k12[i]+d413*k13[i]+d414*k14[i]+d415*k15[i]+d416*k16[i] - @inbounds integrator.k[5][i] = d501*k1[i]+d506*k6[i]+d507*k7[i]+d508*k8[i]+d509*k9[i]+d510*k10[i]+d511*k11[i]+d512*k12[i]+d513*k13[i]+d514*k14[i]+d515*k15[i]+d516*k16[i] - @inbounds integrator.k[6][i] = d601*k1[i]+d606*k6[i]+d607*k7[i]+d608*k8[i]+d609*k9[i]+d610*k10[i]+d611*k11[i]+d612*k12[i]+d613*k13[i]+d614*k14[i]+d615*k15[i]+d616*k16[i] - @inbounds integrator.k[7][i] = d701*k1[i]+d706*k6[i]+d707*k7[i]+d708*k8[i]+d709*k9[i]+d710*k10[i]+d711*k11[i]+d712*k12[i]+d713*k13[i]+d714*k14[i]+d715*k15[i]+d716*k16[i] - end - end end =# -function initialize!(integrator, cache::TsitPap8ConstantCache) +function initialize!(integrator, cache::DP8ConstantCache) + integrator.kshortsize = 7 + integrator.k = typeof(integrator.k)(undef, integrator.kshortsize) integrator.fsalfirst = integrator.f(integrator.uprev, integrator.p, integrator.t) # Pre-start fsal integrator.stats.nf += 1 - integrator.kshortsize = 2 - integrator.k = typeof(integrator.k)(undef, integrator.kshortsize) # Avoid undefined entries if k is an array of arrays integrator.fsallast = zero(integrator.fsalfirst) - integrator.k[1] = integrator.fsalfirst - integrator.k[2] = integrator.fsallast -end - -#= -@muladd function perform_step!(integrator, cache::TsitPap8ConstantCache, repeat_step=false) - @unpack t,dt,uprev,u,f,p = integrator - @unpack c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,a0201,a0301,a0302,a0401,a0403,a0501,a0503,a0504,a0601,a0604,a0605,a0701,a0704,a0705,a0706,a0801,a0804,a0805,a0806,a0807,a0901,a0904,a0905,a0906,a0907,a0908,a1001,a1004,a1005,a1006,a1007,a1008,a1009,a1101,a1104,a1105,a1106,a1107,a1108,a1109,a1110,a1201,a1204,a1205,a1206,a1207,a1208,a1209,a1210,a1211,a1301,a1304,a1305,a1306,a1307,a1308,a1309,a1310,b1,b6,b7,b8,b9,b10,b11,b12,btilde1,btilde6,btilde7,btilde8,btilde9,btilde10,btilde11,btilde12,btilde13 = cache - k1 = integrator.fsalfirst - a = dt*a0201 - k2 = f(t + c1*dt, @.. broadcast=false uprev+a*k1) - k3 = f(t + c2*dt, @.. broadcast=false uprev+dt*(a0301*k1+a0302*k2)) - k4 = f(t + c3*dt, @.. broadcast=false uprev+dt*(a0401*k1 +a0403*k3)) - k5 = f(t + c4*dt, @.. broadcast=false uprev+dt*(a0501*k1 +a0503*k3+a0504*k4)) - k6 = f(t + c5*dt, @.. broadcast=false uprev+dt*(a0601*k1 +a0604*k4+a0605*k5)) - k7 = f(t + c6*dt, @.. broadcast=false uprev+dt*(a0701*k1 +a0704*k4+a0705*k5+a0706*k6)) - k8 = f(t + c7*dt, @.. broadcast=false uprev+dt*(a0801*k1 +a0804*k4+a0805*k5+a0806*k6+a0807*k7)) - k9 = f(t + c8*dt, @.. broadcast=false uprev+dt*(a0901*k1 +a0904*k4+a0905*k5+a0906*k6+a0907*k7+a0908*k8)) - k10 =f(t + c9*dt, @.. broadcast=false uprev+dt*(a1001*k1 +a1004*k4+a1005*k5+a1006*k6+a1007*k7+a1008*k8+a1009*k9)) - k11= f(t + c10*dt, @.. broadcast=false uprev+dt*(a1101*k1 +a1104*k4+a1105*k5+a1106*k6+a1107*k7+a1108*k8+a1109*k9+a1110*k10)) - k12= f(t+dt, @.. broadcast=false uprev+dt*(a1201*k1 +a1204*k4+a1205*k5+a1206*k6+a1207*k7+a1208*k8+a1209*k9+a1210*k10+a1211*k11)) - k13= f(t+dt, @.. broadcast=false uprev+dt*(a1301*k1 +a1304*k4+a1305*k5+a1306*k6+a1307*k7+a1308*k8+a1309*k9+a1310*k10)) - u = @.. broadcast=false uprev + dt*(b1*k1+b6*k6+b7*k7+b8*k8+b9*k9+b10*k10+b11*k11+b12*k12) - if integrator.opts.adaptive - utilde = @.. broadcast=false dt*(btilde1*k1 + btilde6*k6 + btilde7*k7 + btilde8*k8 + btilde9*k9 + btilde10*k10 + btilde11*k11 + btilde12*k12 + btilde13*k13) - atmp = calculate_residuals(utilde, uprev, u, integrator.opts.abstol, integrator.opts.reltol,integrator.opts.internalnorm,t) - integrator.EEst = integrator.opts.internalnorm(atmp,t) - end - integrator.fsallast = f(u, p, t+dt) - integrator.k[1] = integrator.fsalfirst - integrator.k[2] = integrator.fsallast - integrator.u = u + @inbounds for i in eachindex(integrator.k) + integrator.k[i] = zero(integrator.fsalfirst) + end end -=# -@muladd function perform_step!(integrator, cache::TsitPap8ConstantCache, - repeat_step = false) +@muladd function perform_step!(integrator, cache::DP8ConstantCache, repeat_step = false) @unpack t, dt, uprev, u, f, p = integrator - @unpack c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, a0201, a0301, a0302, a0401, a0403, a0501, a0503, a0504, a0601, a0604, a0605, a0701, a0704, a0705, a0706, a0801, a0804, a0805, a0806, a0807, a0901, a0904, a0905, a0906, a0907, a0908, a1001, a1004, a1005, a1006, a1007, a1008, a1009, a1101, a1104, a1105, a1106, a1107, a1108, a1109, a1110, a1201, a1204, a1205, a1206, a1207, a1208, a1209, a1210, a1211, a1301, a1304, a1305, a1306, a1307, a1308, a1309, a1310, b1, b6, b7, b8, b9, b10, b11, b12, btilde1, btilde6, btilde7, btilde8, btilde9, btilde10, btilde11, btilde12, btilde13 = cache + @unpack c7, c8, c9, c10, c11, c6, c5, c4, c3, c2, b1, b6, b7, b8, b9, b10, b11, b12, btilde1, btilde6, btilde7, btilde8, btilde9, btilde10, btilde11, btilde12, er1, er6, er7, er8, er9, er10, er11, er12, a0201, a0301, a0302, a0401, a0403, a0501, a0503, a0504, a0601, a0604, a0605, a0701, a0704, a0705, a0706, a0801, a0804, a0805, a0806, a0807, a0901, a0904, a0905, a0906, a0907, a0908, a1001, a1004, a1005, a1006, a1007, a1008, a1009, a1101, a1104, a1105, a1106, a1107, a1108, a1109, a1110, a1201, a1204, a1205, a1206, a1207, a1208, a1209, a1210, a1211 = cache k1 = integrator.fsalfirst a = dt * a0201 - k2 = f(uprev + a * k1, p, t + c1 * dt) - k3 = f(uprev + dt * (a0301 * k1 + a0302 * k2), p, t + c2 * dt) - k4 = f(uprev + dt * (a0401 * k1 + a0403 * k3), p, t + c3 * dt) - k5 = f(uprev + dt * (a0501 * k1 + a0503 * k3 + a0504 * k4), p, t + c4 * dt) - k6 = f(uprev + dt * (a0601 * k1 + a0604 * k4 + a0605 * k5), p, t + c5 * dt) - k7 = f(uprev + dt * (a0701 * k1 + a0704 * k4 + a0705 * k5 + a0706 * k6), p, t + c6 * dt) + k2 = f(uprev + a * k1, p, t + c2 * dt) + k3 = f(uprev + dt * (a0301 * k1 + a0302 * k2), p, t + c3 * dt) + k4 = f(uprev + dt * (a0401 * k1 + a0403 * k3), p, t + c4 * dt) + k5 = f(uprev + dt * (a0501 * k1 + a0503 * k3 + a0504 * k4), p, t + c5 * dt) + k6 = f(uprev + dt * (a0601 * k1 + a0604 * k4 + a0605 * k5), p, t + c6 * dt) + k7 = f(uprev + dt * (a0701 * k1 + a0704 * k4 + a0705 * k5 + a0706 * k6), p, t + c7 * dt) k8 = f( uprev + dt * (a0801 * k1 + a0804 * k4 + a0805 * k5 + a0806 * k6 + a0807 * k7), p, - t + c7 * dt) + t + c8 * dt) k9 = f( uprev + dt * (a0901 * k1 + a0904 * k4 + a0905 * k5 + a0906 * k6 + a0907 * k7 + a0908 * k8), p, - t + c8 * dt) + t + c9 * dt) k10 = f( uprev + dt * (a1001 * k1 + a1004 * k4 + a1005 * k5 + a1006 * k6 + a1007 * k7 + a1008 * k8 + a1009 * k9), p, - t + c9 * dt) + t + c10 * dt) k11 = f( uprev + dt * (a1101 * k1 + a1104 * k4 + a1105 * k5 + a1106 * k6 + a1107 * k7 + a1108 * k8 + a1109 * k9 + a1110 * k10), p, - t + c10 * dt) + t + c11 * dt) k12 = f( uprev + dt * @@ -680,97 +539,147 @@ end a1209 * k9 + a1210 * k10 + a1211 * k11), p, t + dt) - k13 = f( - uprev + - dt * - (a1301 * k1 + a1304 * k4 + a1305 * k5 + a1306 * k6 + a1307 * k7 + a1308 * k8 + - a1309 * k9 + a1310 * k10), - p, - t + dt) - integrator.stats.nf += 12 - u = uprev + - dt * (b1 * k1 + b6 * k6 + b7 * k7 + b8 * k8 + b9 * k9 + b10 * k10 + b11 * k11 + - b12 * k12) + integrator.stats.nf += 11 + kupdate = b1 * k1 + b6 * k6 + b7 * k7 + b8 * k8 + b9 * k9 + b10 * k10 + b11 * k11 + + b12 * k12 + u = uprev + dt * kupdate if integrator.opts.adaptive + utilde = dt * (k1 * er1 + k6 * er6 + k7 * er7 + k8 * er8 + k9 * er9 + k10 * er10 + + k11 * er11 + k12 * er12) + atmp = calculate_residuals(utilde, uprev, u, integrator.opts.abstol, + integrator.opts.reltol, integrator.opts.internalnorm, t) + err5 = integrator.opts.internalnorm(atmp, t) # Order 5 utilde = dt * (btilde1 * k1 + btilde6 * k6 + btilde7 * k7 + btilde8 * k8 + btilde9 * k9 + - btilde10 * k10 + btilde11 * k11 + btilde12 * k12 + btilde13 * k13) + btilde10 * k10 + btilde11 * k11 + btilde12 * k12) atmp = calculate_residuals(utilde, uprev, u, integrator.opts.abstol, integrator.opts.reltol, integrator.opts.internalnorm, t) - integrator.EEst = integrator.opts.internalnorm(atmp, t) + err3 = integrator.opts.internalnorm(atmp, t) # Order 3 + err52 = err5 * err5 + if err5 ≈ 0 && err3 ≈ 0 + integrator.EEst = zero(integrator.EEst) + else + integrator.EEst = err52 / sqrt(err52 + 0.01 * err3 * err3) + end + end + k13 = f(u, p, t + dt) + integrator.stats.nf += 1 + integrator.fsallast = k13 + if integrator.opts.calck + @unpack c14, c15, c16, a1401, a1407, a1408, a1409, a1410, a1411, a1412, a1413, a1501, a1506, a1507, a1508, a1511, a1512, a1513, a1514, a1601, a1606, a1607, a1608, a1609, a1613, a1614, a1615 = cache + @unpack d401, d406, d407, d408, d409, d410, d411, d412, d413, d414, d415, d416, d501, d506, d507, d508, d509, d510, d511, d512, d513, d514, d515, d516, d601, d606, d607, d608, d609, d610, d611, d612, d613, d614, d615, d616, d701, d706, d707, d708, d709, d710, d711, d712, d713, d714, d715, d716 = cache + k14 = f( + uprev + + dt * (a1401 * k1 + a1407 * k7 + a1408 * k8 + a1409 * k9 + a1410 * k10 + + a1411 * k11 + a1412 * k12 + a1413 * k13), + p, + t + c14 * dt) + k15 = f( + uprev + + dt * (a1501 * k1 + a1506 * k6 + a1507 * k7 + a1508 * k8 + a1511 * k11 + + a1512 * k12 + a1513 * k13 + a1514 * k14), + p, + t + c15 * dt) + k16 = f( + uprev + + dt * (a1601 * k1 + a1606 * k6 + a1607 * k7 + a1608 * k8 + a1609 * k9 + + a1613 * k13 + a1614 * k14 + a1615 * k15), + p, + t + c16 * dt) + integrator.stats.nf += 3 + udiff = kupdate + integrator.k[1] = udiff + bspl = k1 - udiff + integrator.k[2] = bspl + integrator.k[3] = udiff - k13 - bspl + integrator.k[4] = d401 * k1 + d406 * k6 + d407 * k7 + d408 * k8 + d409 * k9 + + d410 * k10 + d411 * k11 + d412 * k12 + d413 * k13 + d414 * k14 + + d415 * k15 + d416 * k16 + integrator.k[5] = d501 * k1 + d506 * k6 + d507 * k7 + d508 * k8 + d509 * k9 + + d510 * k10 + d511 * k11 + d512 * k12 + d513 * k13 + d514 * k14 + + d515 * k15 + d516 * k16 + integrator.k[6] = d601 * k1 + d606 * k6 + d607 * k7 + d608 * k8 + d609 * k9 + + d610 * k10 + d611 * k11 + d612 * k12 + d613 * k13 + d614 * k14 + + d615 * k15 + d616 * k16 + integrator.k[7] = d701 * k1 + d706 * k6 + d707 * k7 + d708 * k8 + d709 * k9 + + d710 * k10 + d711 * k11 + d712 * k12 + d713 * k13 + d714 * k14 + + d715 * k15 + d716 * k16 end - integrator.fsallast = f(u, p, t + dt) - integrator.stats.nf += 1 - integrator.k[1] = integrator.fsalfirst - integrator.k[2] = integrator.fsallast integrator.u = u end -function initialize!(integrator, cache::TsitPap8Cache) - integrator.fsalfirst = cache.fsalfirst - integrator.fsallast = cache.k - integrator.kshortsize = 2 +function initialize!(integrator, cache::DP8Cache) + integrator.kshortsize = 7 resize!(integrator.k, integrator.kshortsize) - integrator.k[1] = integrator.fsalfirst - integrator.k[2] = integrator.fsallast + integrator.k .= [ + cache.udiff, + cache.bspl, + cache.dense_tmp3, + cache.dense_tmp4, + cache.dense_tmp5, + cache.dense_tmp6, + cache.dense_tmp7 + ] + integrator.fsalfirst = cache.k1 + integrator.fsallast = cache.k13 integrator.f(integrator.fsalfirst, integrator.uprev, integrator.p, integrator.t) # Pre-start fsal integrator.stats.nf += 1 end -@muladd function perform_step!(integrator, cache::TsitPap8Cache, repeat_step = false) +@muladd function perform_step!(integrator, cache::DP8Cache, repeat_step = false) @unpack t, dt, uprev, u, f, p = integrator - @unpack c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, a0201, a0301, a0302, a0401, a0403, a0501, a0503, a0504, a0601, a0604, a0605, a0701, a0704, a0705, a0706, a0801, a0804, a0805, a0806, a0807, a0901, a0904, a0905, a0906, a0907, a0908, a1001, a1004, a1005, a1006, a1007, a1008, a1009, a1101, a1104, a1105, a1106, a1107, a1108, a1109, a1110, a1201, a1204, a1205, a1206, a1207, a1208, a1209, a1210, a1211, a1301, a1304, a1305, a1306, a1307, a1308, a1309, a1310, b1, b6, b7, b8, b9, b10, b11, b12, btilde1, btilde6, btilde7, btilde8, btilde9, btilde10, btilde11, btilde12, btilde13 = cache.tab - @unpack k2, k3, k4, k5, k6, k7, k8, k9, k10, k11, k12, k13, utilde, tmp, atmp, k, stage_limiter!, step_limiter!, thread = cache - k1 = cache.fsalfirst + uidx = eachindex(integrator.uprev) + @unpack c7, c8, c9, c10, c11, c6, c5, c4, c3, c2, b1, b6, b7, b8, b9, b10, b11, b12, btilde1, btilde6, btilde7, btilde8, btilde9, btilde10, btilde11, btilde12, er1, er6, er7, er8, er9, er10, er11, er12, a0201, a0301, a0302, a0401, a0403, a0501, a0503, a0504, a0601, a0604, a0605, a0701, a0704, a0705, a0706, a0801, a0804, a0805, a0806, a0807, a0901, a0904, a0905, a0906, a0907, a0908, a1001, a1004, a1005, a1006, a1007, a1008, a1009, a1101, a1104, a1105, a1106, a1107, a1108, a1109, a1110, a1201, a1204, a1205, a1206, a1207, a1208, a1209, a1210, a1211 = cache.tab + @unpack k1, k2, k3, k4, k5, k6, k7, k8, k9, k10, k11, k12, k13, k14, k15, k16, udiff, bspl, dense_tmp3, dense_tmp4, dense_tmp5, dense_tmp6, dense_tmp7, kupdate, utilde, tmp, atmp, stage_limiter!, step_limiter!, thread = cache f(k1, uprev, p, t) a = dt * a0201 @.. broadcast=false thread=thread tmp=uprev + a * k1 - stage_limiter!(tmp, integrator, p, t + c1 * dt) - f(k2, tmp, p, t + c1 * dt) - @.. broadcast=false thread=thread tmp=uprev + dt * (a0301 * k1 + a0302 * k2) stage_limiter!(tmp, integrator, p, t + c2 * dt) - f(k3, tmp, p, t + c2 * dt) - @.. broadcast=false thread=thread tmp=uprev + dt * (a0401 * k1 + a0403 * k3) + f(k2, tmp, p, t + c2 * dt) + @.. broadcast=false thread=thread tmp=uprev + dt * (a0301 * k1 + a0302 * k2) stage_limiter!(tmp, integrator, p, t + c3 * dt) - f(k4, tmp, p, t + c3 * dt) + f(k3, tmp, p, t + c3 * dt) + @.. broadcast=false thread=thread tmp=uprev + dt * (a0401 * k1 + a0403 * k3) + stage_limiter!(tmp, integrator, p, t + c4 * dt) + f(k4, tmp, p, t + c4 * dt) @.. broadcast=false thread=thread tmp=uprev + dt * (a0501 * k1 + a0503 * k3 + a0504 * k4) - stage_limiter!(tmp, integrator, p, t + c4 * dt) - f(k5, tmp, p, t + c4 * dt) + stage_limiter!(tmp, integrator, p, t + c5 * dt) + f(k5, tmp, p, t + c5 * dt) @.. broadcast=false thread=thread tmp=uprev + dt * (a0601 * k1 + a0604 * k4 + a0605 * k5) - stage_limiter!(tmp, integrator, p, t + c5 * dt) - f(k6, tmp, p, t + c5 * dt) + stage_limiter!(tmp, integrator, p, t + c6 * dt) + f(k6, tmp, p, t + c6 * dt) @.. broadcast=false thread=thread tmp=uprev + dt * (a0701 * k1 + a0704 * k4 + a0705 * k5 + a0706 * k6) - stage_limiter!(tmp, integrator, p, t + c6 * dt) - f(k7, tmp, p, t + c6 * dt) + stage_limiter!(tmp, integrator, p, t + c7 * dt) + f(k7, tmp, p, t + c7 * dt) @.. broadcast=false thread=thread tmp=uprev + dt * (a0801 * k1 + a0804 * k4 + a0805 * k5 + a0806 * k6 + a0807 * k7) - stage_limiter!(tmp, integrator, p, t + c7 * dt) - f(k8, tmp, p, t + c7 * dt) + stage_limiter!(tmp, integrator, p, t + c8 * dt) + f(k8, tmp, p, t + c8 * dt) @.. broadcast=false thread=thread tmp=uprev + dt * (a0901 * k1 + a0904 * k4 + a0905 * k5 + a0906 * k6 + a0907 * k7 + a0908 * k8) - stage_limiter!(tmp, integrator, p, t + c8 * dt) - f(k9, tmp, p, t + c8 * dt) + stage_limiter!(tmp, integrator, p, t + c9 * dt) + f(k9, tmp, p, t + c9 * dt) @.. broadcast=false thread=thread tmp=uprev + dt * (a1001 * k1 + a1004 * k4 + a1005 * k5 + a1006 * k6 + a1007 * k7 + a1008 * k8 + a1009 * k9) - stage_limiter!(tmp, integrator, p, t + c9 * dt) - f(k10, tmp, p, t + c9 * dt) + stage_limiter!(tmp, integrator, p, t + c10 * dt) + f(k10, tmp, p, t + c10 * dt) @.. broadcast=false thread=thread tmp=uprev + dt * (a1101 * k1 + a1104 * k4 + a1105 * k5 + a1106 * k6 + a1107 * k7 + a1108 * k8 + a1109 * k9 + a1110 * k10) - stage_limiter!(tmp, integrator, p, t + c10 * dt) - f(k11, tmp, p, t + c10 * dt) + stage_limiter!(tmp, integrator, p, t + c11 * dt) + f(k11, tmp, p, t + c11 * dt) @.. broadcast=false thread=thread tmp=uprev + dt * (a1201 * k1 + a1204 * k4 + a1205 * k5 + a1206 * k6 + @@ -779,108 +688,199 @@ end a1211 * k11) stage_limiter!(tmp, integrator, p, t + dt) f(k12, tmp, p, t + dt) - @.. broadcast=false thread=thread tmp=uprev + - dt * (a1301 * k1 + a1304 * k4 + a1305 * k5 + - a1306 * k6 + - a1307 * k7 + a1308 * k8 + a1309 * k9 + - a1310 * k10) - stage_limiter!(tmp, integrator, p, t + dt) - f(k13, tmp, p, t + dt) - @.. broadcast=false thread=thread u=uprev + - dt * - (b1 * k1 + b6 * k6 + b7 * k7 + b8 * k8 + b9 * k9 + - b10 * k10 + - b11 * k11 + b12 * k12) + @.. broadcast=false thread=thread kupdate=b1 * k1 + b6 * k6 + b7 * k7 + b8 * k8 + + b9 * k9 + + b10 * k10 + b11 * k11 + b12 * k12 + @.. broadcast=false thread=thread u=uprev + dt * kupdate stage_limiter!(u, integrator, p, t + dt) step_limiter!(u, integrator, p, t + dt) - integrator.stats.nf += 13 + integrator.stats.nf += 12 if integrator.opts.adaptive + @.. broadcast=false thread=thread utilde=dt * + (k1 * er1 + k6 * er6 + k7 * er7 + + k8 * er8 + k9 * er9 + + k10 * er10 + k11 * er11 + k12 * er12) + calculate_residuals!(atmp, utilde, uprev, u, integrator.opts.abstol, + integrator.opts.reltol, integrator.opts.internalnorm, t, + thread) + err5 = integrator.opts.internalnorm(atmp, t) # Order 5 @.. broadcast=false thread=thread utilde=dt * (btilde1 * k1 + btilde6 * k6 + btilde7 * k7 + btilde8 * k8 + btilde9 * k9 + btilde10 * k10 + - btilde11 * k11 + btilde12 * k12 + - btilde13 * k13) + btilde11 * k11 + btilde12 * k12) calculate_residuals!(atmp, utilde, uprev, u, integrator.opts.abstol, integrator.opts.reltol, integrator.opts.internalnorm, t, thread) - integrator.EEst = integrator.opts.internalnorm(atmp, t) + err3 = integrator.opts.internalnorm(atmp, t) # Order 3 + err52 = err5 * err5 + if err5 ≈ 0 && err3 ≈ 0 + integrator.EEst = zero(integrator.EEst) + else + integrator.EEst = err52 / sqrt(err52 + 0.01 * err3 * err3) + end end - f(k, u, p, t + dt) + f(k13, u, p, t + dt) integrator.stats.nf += 1 - return nothing + if integrator.opts.calck + @unpack c14, c15, c16, a1401, a1407, a1408, a1409, a1410, a1411, a1412, a1413, a1501, a1506, a1507, a1508, a1511, a1512, a1513, a1514, a1601, a1606, a1607, a1608, a1609, a1613, a1614, a1615 = cache.tab + @unpack d401, d406, d407, d408, d409, d410, d411, d412, d413, d414, d415, d416, d501, d506, d507, d508, d509, d510, d511, d512, d513, d514, d515, d516, d601, d606, d607, d608, d609, d610, d611, d612, d613, d614, d615, d616, d701, d706, d707, d708, d709, d710, d711, d712, d713, d714, d715, d716 = cache.tab + @.. broadcast=false thread=thread tmp=uprev + + dt * (a1401 * k1 + a1407 * k7 + a1408 * k8 + + a1409 * k9 + + a1410 * k10 + a1411 * k11 + a1412 * k12 + + a1413 * k13) + f(k14, tmp, p, t + c14 * dt) + @.. broadcast=false thread=thread tmp=uprev + + dt * (a1501 * k1 + a1506 * k6 + a1507 * k7 + + a1508 * k8 + + a1511 * k11 + a1512 * k12 + a1513 * k13 + + a1514 * k14) + f(k15, tmp, p, t + c15 * dt) + @.. broadcast=false thread=thread tmp=uprev + + dt * (a1601 * k1 + a1606 * k6 + a1607 * k7 + + a1608 * k8 + + a1609 * k9 + a1613 * k13 + a1614 * k14 + + a1615 * k15) + f(k16, tmp, p, t + c16 * dt) + integrator.stats.nf += 3 + @.. broadcast=false thread=thread udiff=kupdate + @.. broadcast=false thread=thread bspl=k1 - udiff + @.. broadcast=false thread=thread integrator.k[3]=udiff - k13 - bspl + @.. broadcast=false thread=thread integrator.k[4]=d401 * k1 + d406 * k6 + + d407 * k7 + d408 * k8 + + d409 * k9 + d410 * k10 + + d411 * k11 + + d412 * k12 + d413 * k13 + + d414 * k14 + + d415 * k15 + d416 * k16 + @.. broadcast=false thread=thread integrator.k[5]=d501 * k1 + d506 * k6 + + d507 * k7 + d508 * k8 + + d509 * k9 + d510 * k10 + + d511 * k11 + + d512 * k12 + d513 * k13 + + d514 * k14 + + d515 * k15 + d516 * k16 + @.. broadcast=false thread=thread integrator.k[6]=d601 * k1 + d606 * k6 + + d607 * k7 + d608 * k8 + + d609 * k9 + d610 * k10 + + d611 * k11 + + d612 * k12 + d613 * k13 + + d614 * k14 + + d615 * k15 + d616 * k16 + @.. broadcast=false thread=thread integrator.k[7]=d701 * k1 + d706 * k6 + + d707 * k7 + d708 * k8 + + d709 * k9 + d710 * k10 + + d711 * k11 + + d712 * k12 + d713 * k13 + + d714 * k14 + + d715 * k15 + d716 * k16 + end end #= -@muladd function perform_step!(integrator, cache::TsitPap8Cache, repeat_step=false) +@muladd function perform_step!(integrator, cache::DP8Cache, repeat_step=false) @unpack t,dt,uprev,u,f,p = integrator uidx = eachindex(integrator.uprev) - @unpack c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,a0201,a0301,a0302,a0401,a0403,a0501,a0503,a0504,a0601,a0604,a0605,a0701,a0704,a0705,a0706,a0801,a0804,a0805,a0806,a0807,a0901,a0904,a0905,a0906,a0907,a0908,a1001,a1004,a1005,a1006,a1007,a1008,a1009,a1101,a1104,a1105,a1106,a1107,a1108,a1109,a1110,a1201,a1204,a1205,a1206,a1207,a1208,a1209,a1210,a1211,a1301,a1304,a1305,a1306,a1307,a1308,a1309,a1310,b1,b6,b7,b8,b9,b10,b11,b12,btilde1,btilde6,btilde7,btilde8,btilde9,btilde10,btilde11,btilde12,btilde13 = cache.tab - @unpack k2,k3,k4,k5,k6,k7,k8,k9,k10,k11,k12,k13,utilde,tmp,atmp,k = cache - k1 = cache.fsalfirst + @unpack c7,c8,c9,c10,c11,c6,c5,c4,c3,c2,b1,b6,b7,b8,b9,b10,b11,b12,btilde1,btilde6,btilde7,btilde8,btilde9,btilde10,btilde11,btilde12,er1,er6,er7,er8,er9,er10,er11,er12,a0201,a0301,a0302,a0401,a0403,a0501,a0503,a0504,a0601,a0604,a0605,a0701,a0704,a0705,a0706,a0801,a0804,a0805,a0806,a0807,a0901,a0904,a0905,a0906,a0907,a0908,a1001,a1004,a1005,a1006,a1007,a1008,a1009,a1101,a1104,a1105,a1106,a1107,a1108,a1109,a1110,a1201,a1204,a1205,a1206,a1207,a1208,a1209,a1210,a1211 = cache.tab + @unpack k1,k2,k3,k4,k5,k6,k7,k8,k9,k10,k11,k12,k13,k14,k15,k16,udiff,bspl,dense_tmp3,dense_tmp4,dense_tmp5,dense_tmp6,dense_tmp7,kupdate,utilde,tmp,atmp = cache f(k1, uprev, p, t) a = dt*a0201 @tight_loop_macros for i in uidx @inbounds tmp[i] = uprev[i]+a*k1[i] end - f(k2, tmp, p, t + c1*dt) + f(k2, tmp, p, t + c2*dt) @tight_loop_macros for i in uidx @inbounds tmp[i] = uprev[i]+dt*(a0301*k1[i]+a0302*k2[i]) end - f(k3, tmp, p, t + c2*dt) + f(k3, tmp, p, t + c3*dt) @tight_loop_macros for i in uidx @inbounds tmp[i] = uprev[i]+dt*(a0401*k1[i]+a0403*k3[i]) end - f(k4, tmp, p, t + c3*dt) + f(k4, tmp, p, t + c4*dt) @tight_loop_macros for i in uidx @inbounds tmp[i] = uprev[i]+dt*(a0501*k1[i]+a0503*k3[i]+a0504*k4[i]) end - f(k5, tmp, p, t + c4*dt) + f(k5, tmp, p, t + c5*dt) @tight_loop_macros for i in uidx @inbounds tmp[i] = uprev[i]+dt*(a0601*k1[i]+a0604*k4[i]+a0605*k5[i]) end - f(k6, tmp, p, t + c5*dt) + f(k6, tmp, p, t + c6*dt) @tight_loop_macros for i in uidx @inbounds tmp[i] = uprev[i]+dt*(a0701*k1[i]+a0704*k4[i]+a0705*k5[i]+a0706*k6[i]) end - f(k7, tmp, p, t + c6*dt) + f(k7, tmp, p, t + c7*dt) @tight_loop_macros for i in uidx @inbounds tmp[i] = uprev[i]+dt*(a0801*k1[i]+a0804*k4[i]+a0805*k5[i]+a0806*k6[i]+a0807*k7[i]) end - f(k8, tmp, p, t + c7*dt) + f(k8, tmp, p, t + c8*dt) @tight_loop_macros for i in uidx @inbounds tmp[i] = uprev[i]+dt*(a0901*k1[i]+a0904*k4[i]+a0905*k5[i]+a0906*k6[i]+a0907*k7[i]+a0908*k8[i]) end - f(k9, tmp, p, t + c8*dt) + f(k9, tmp, p, t + c9*dt) @tight_loop_macros for i in uidx @inbounds tmp[i] = uprev[i]+dt*(a1001*k1[i]+a1004*k4[i]+a1005*k5[i]+a1006*k6[i]+a1007*k7[i]+a1008*k8[i]+a1009*k9[i]) end - f(k10, tmp, p, t + c9*dt) + f(k10, tmp, p, t + c10*dt) @tight_loop_macros for i in uidx @inbounds tmp[i] = uprev[i]+dt*(a1101*k1[i]+a1104*k4[i]+a1105*k5[i]+a1106*k6[i]+a1107*k7[i]+a1108*k8[i]+a1109*k9[i]+a1110*k10[i]) end - f(k11, tmp, p, t + c10*dt) + f(k11, tmp, p, t + c11*dt) @tight_loop_macros for i in uidx @inbounds tmp[i] = uprev[i]+dt*(a1201*k1[i]+a1204*k4[i]+a1205*k5[i]+a1206*k6[i]+a1207*k7[i]+a1208*k8[i]+a1209*k9[i]+a1210*k10[i]+a1211*k11[i]) end f(k12, tmp, p, t+dt) @tight_loop_macros for i in uidx - @inbounds tmp[i] = uprev[i]+dt*(a1301*k1[i]+a1304*k4[i]+a1305*k5[i]+a1306*k6[i]+a1307*k7[i]+a1308*k8[i]+a1309*k9[i]+a1310*k10[i]) - end - f(k13, tmp, p, t+dt) - @tight_loop_macros for i in uidx - @inbounds u[i] = uprev[i] + dt*(b1*k1[i]+b6*k6[i]+b7*k7[i]+b8*k8[i]+b9*k9[i]+b10*k10[i]+b11*k11[i]+b12*k12[i]) + @inbounds kupdate[i] = b1*k1[i]+b6*k6[i]+b7*k7[i]+b8*k8[i]+b9*k9[i]+b10*k10[i]+b11*k11[i]+b12*k12[i] + @inbounds u[i] = uprev[i] + dt*kupdate[i] end - integrator.stats.nf += 13 + integrator.stats.nf += 12 if integrator.opts.adaptive @tight_loop_macros for i in uidx - @inbounds utilde[i] = dt*(btilde1*k1[i] + btilde6*k6[i] + btilde7*k7[i] + btilde8*k8[i] + btilde9*k9[i] + btilde10*k10[i] + btilde11*k11[i] + btilde12*k12[i] + btilde13*k13[i]) + @inbounds utilde[i] = dt*(k1[i]*er1 + k6[i]*er6 + k7[i]*er7 + k8[i]*er8 + k9[i]*er9 + k10[i]*er10 + k11[i]*er11 + k12[i]*er12) end calculate_residuals!(atmp, utilde, uprev, u, integrator.opts.abstol, integrator.opts.reltol,integrator.opts.internalnorm,t) - integrator.EEst = integrator.opts.internalnorm(atmp,t) + err5 = integrator.opts.internalnorm(atmp,t) # Order 5 + @tight_loop_macros for i in uidx + @inbounds utilde[i]= dt*(btilde1*k1[i] + btilde6*k6[i] + btilde7*k7[i] + btilde8*k8[i] + btilde9*k9[i] + btilde10*k10[i] + btilde11*k11[i] + btilde12*k12[i]) + end + calculate_residuals!(atmp, utilde, uprev, u, integrator.opts.abstol, integrator.opts.reltol,integrator.opts.internalnorm,t) + err3 = integrator.opts.internalnorm(atmp,t) # Order 3 + err52 = err5*err5 + if err5 ≈ 0 && err3 ≈ 0 + integrator.EEst = zero(integrator.EEst) + else + integrator.EEst = err52/sqrt(err52 + 0.01*err3*err3) + end end - f(k, u, p, t+dt) + f(k13, u, p, t+dt) integrator.stats.nf += 1 + if integrator.opts.calck + @unpack c14,c15,c16,a1401,a1407,a1408,a1409,a1410,a1411,a1412,a1413,a1501,a1506,a1507,a1508,a1511,a1512,a1513,a1514,a1601,a1606,a1607,a1608,a1609,a1613,a1614,a1615 = cache.tab + @unpack d401,d406,d407,d408,d409,d410,d411,d412,d413,d414,d415,d416,d501,d506,d507,d508,d509,d510,d511,d512,d513,d514,d515,d516,d601,d606,d607,d608,d609,d610,d611,d612,d613,d614,d615,d616,d701,d706,d707,d708,d709,d710,d711,d712,d713,d714,d715,d716 = cache.tab + @tight_loop_macros for i in uidx + @inbounds tmp[i] = uprev[i]+dt*(a1401*k1[i]+a1407*k7[i]+a1408*k8[i]+a1409*k9[i]+a1410*k10[i]+a1411*k11[i]+a1412*k12[i]+a1413*k13[i]) + end + f(k14, tmp, p, t + c14*dt) + @tight_loop_macros for i in uidx + @inbounds tmp[i] = uprev[i]+dt*(a1501*k1[i]+a1506*k6[i]+a1507*k7[i]+a1508*k8[i]+a1511*k11[i]+a1512*k12[i]+a1513*k13[i]+a1514*k14[i]) + end + f(k15, tmp, p, t + c15*dt) + @tight_loop_macros for i in uidx + @inbounds tmp[i] = uprev[i]+dt*(a1601*k1[i]+a1606*k6[i]+a1607*k7[i]+a1608*k8[i]+a1609*k9[i]+a1613*k13[i]+a1614*k14[i]+a1615*k15[i]) + end + f(k16, tmp, p, t + c16*dt) + integrator.stats.nf += 3 + @tight_loop_macros for i in uidx + @inbounds udiff[i]= kupdate[i] + @inbounds bspl[i] = k1[i] - udiff[i] + @inbounds integrator.k[3][i] = udiff[i] - k13[i] - bspl[i] + @inbounds integrator.k[4][i] = d401*k1[i]+d406*k6[i]+d407*k7[i]+d408*k8[i]+d409*k9[i]+d410*k10[i]+d411*k11[i]+d412*k12[i]+d413*k13[i]+d414*k14[i]+d415*k15[i]+d416*k16[i] + @inbounds integrator.k[5][i] = d501*k1[i]+d506*k6[i]+d507*k7[i]+d508*k8[i]+d509*k9[i]+d510*k10[i]+d511*k11[i]+d512*k12[i]+d513*k13[i]+d514*k14[i]+d515*k15[i]+d516*k16[i] + @inbounds integrator.k[6][i] = d601*k1[i]+d606*k6[i]+d607*k7[i]+d608*k8[i]+d609*k9[i]+d610*k10[i]+d611*k11[i]+d612*k12[i]+d613*k13[i]+d614*k14[i]+d615*k15[i]+d616*k16[i] + @inbounds integrator.k[7][i] = d701*k1[i]+d706*k6[i]+d707*k7[i]+d708*k8[i]+d709*k9[i]+d710*k10[i]+d711*k11[i]+d712*k12[i]+d713*k13[i]+d714*k14[i]+d715*k15[i]+d716*k16[i] + end + end end =# diff --git a/lib/OrdinaryDiffEqLowOrderRK/Project.toml b/lib/OrdinaryDiffEqLowOrderRK/Project.toml index 8e436a3ea2..b95f383c78 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/Project.toml +++ b/lib/OrdinaryDiffEqLowOrderRK/Project.toml @@ -8,6 +8,7 @@ OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" MuladdMacro = "46d2c3a1-f734-5fdb-9937-b9b9aeba4221" RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd" FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898" +Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3" [compat] julia = "1.10" diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl index 33fa3a34ca..f0a5522f0c 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl @@ -10,6 +10,7 @@ import DiffEqBase: @tight_loop_macros import MuladdMacro: @muladd import FastBroadcast: @.. import RecursiveArrayTools: recursivefill! +import Static: False include("algorithms.jl") include("alg_utils.jl") @@ -22,7 +23,7 @@ include("split_perform_step.jl") include("fixed_timestep_perform_step.jl") export Euler, SplitEuler, Heun, Ralston, Midpoint, RK4, - BS3, OwrenZen3, OwrenZen4, OwrenZen5, BS5, Tsit5, + BS3, OwrenZen3, OwrenZen4, OwrenZen5, BS5, DP5, Anas5, RKO65, FRK65, RKM, MSRK5, MSRK6, PSRK4p7q6, PSRK3p5q4, PSRK3p6q5, Stepanov5, SIR54, Alshina2, Alshina3, Alshina6 diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/alg_utils.jl b/lib/OrdinaryDiffEqLowOrderRK/src/alg_utils.jl index 5a0b66acc9..f9c206588e 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/alg_utils.jl @@ -8,7 +8,6 @@ alg_order(alg::OwrenZen3) = 3 alg_order(alg::BS5) = 5 alg_order(alg::OwrenZen4) = 4 alg_order(alg::OwrenZen5) = 5 -alg_order(alg::Tsit5) = 5 alg_order(alg::DP5) = 5 alg_order(alg::Anas5) = 5 alg_order(alg::RKO65) = 5 @@ -36,7 +35,6 @@ beta2_default(alg::DP5) = 4 // 100 beta1_default(alg::DP5, beta2) = typeof(beta2)(1 // alg_order(alg)) - 3beta2 / 4 -alg_stability_size(alg::Tsit5) = 3.5068 alg_stability_size(alg::DP5) = 3.3066 ssp_coefficient(alg::Euler) = 1 diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/algorithms.jl b/lib/OrdinaryDiffEqLowOrderRK/src/algorithms.jl index b90b379d7c..8eaeed7d66 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/algorithms.jl @@ -202,31 +202,6 @@ function BS5(stage_limiter!, step_limiter! = trivial_limiter!; lazy = true) BS5(stage_limiter!, step_limiter!, False(), lazy) end -@doc explicit_rk_docstring( - "A fifth-order explicit Runge-Kutta method with embedded error -estimator of Tsitouras. Free 4th order interpolant.", "Tsit5", - references = "@article{tsitouras2011runge, - title={Runge--Kutta pairs of order 5 (4) satisfying only the first column simplifying assumption}, - author={Tsitouras, Ch}, - journal={Computers \\& Mathematics with Applications}, - volume={62}, - number={2}, - pages={770--775}, - year={2011}, - publisher={Elsevier} - }") -Base.@kwdef struct Tsit5{StageLimiter, StepLimiter, Thread} <: - OrdinaryDiffEqAdaptiveAlgorithm - stage_limiter!::StageLimiter = trivial_limiter! - step_limiter!::StepLimiter = trivial_limiter! - thread::Thread = False() -end -TruncatedStacktraces.@truncate_stacktrace Tsit5 3 -# for backwards compatibility -function Tsit5(stage_limiter!, step_limiter! = trivial_limiter!) - Tsit5(stage_limiter!, step_limiter!, False()) -end - @doc explicit_rk_docstring( "Dormand-Prince's 5/4 Runge-Kutta method. (free 4th order interpolant).", "DP5", diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/interp_func.jl b/lib/OrdinaryDiffEqLowOrderRK/src/interp_func.jl index 97835d2747..8a5c3e26e0 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/interp_func.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/interp_func.jl @@ -16,13 +16,6 @@ function DiffEqBase.interp_summary(::Type{cacheType}, OwrenZen5ConstantCache}} dense ? "specialized 5th order \"free\" interpolation" : "1st order linear" end -function DiffEqBase.interp_summary(::Type{cacheType}, - dense::Bool) where { - cacheType <: - Union{Tsit5Cache, Tsit5ConstantCache -}} - dense ? "specialized 4th order \"free\" interpolation" : "1st order linear" -end function DiffEqBase.interp_summary(::Type{cacheType}, dense::Bool) where { cacheType <: diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_addsteps.jl b/lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_addsteps.jl index 1d919b2f0f..95a7c53ae2 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_addsteps.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_addsteps.jl @@ -123,41 +123,6 @@ end nothing end -@muladd function _ode_addsteps!(k, t, uprev, u, dt, f, p, cache::Tsit5Cache, - always_calc_begin = false, allow_calc_end = true, - force_calc_end = false) - if length(k) < 7 || always_calc_begin - T = constvalue(recursive_unitless_bottom_eltype(u)) - T2 = constvalue(typeof(one(t))) - @OnDemandTableauExtract Tsit5ConstantCacheActual T T2 - @unpack k1, k2, k3, k4, k5, k6, k7, tmp = cache - @.. broadcast=false tmp=uprev + dt * (a21 * k1) - f(k2, tmp, p, t + c1 * dt) - @.. broadcast=false tmp=uprev + dt * (a31 * k1 + a32 * k2) - f(k3, tmp, p, t + c2 * dt) - @.. broadcast=false tmp=uprev + dt * (a41 * k1 + a42 * k2 + a43 * k3) - f(k4, tmp, p, t + c3 * dt) - @.. broadcast=false tmp=uprev + dt * (a51 * k1 + a52 * k2 + a53 * k3 + a54 * k4) - f(k5, tmp, p, t + c4 * dt) - @.. broadcast=false tmp=uprev + - dt * (a61 * k1 + a62 * k2 + a63 * k3 + a64 * k4 + a65 * k5) - f(k6, tmp, p, t + dt) - @.. broadcast=false tmp=uprev + - dt * - (a71 * k1 + a72 * k2 + a73 * k3 + a74 * k4 + a75 * k5 + - a76 * k6) - f(k7, tmp, p, t + dt) - copyat_or_push!(k, 1, k1) - copyat_or_push!(k, 2, k2) - copyat_or_push!(k, 3, k3) - copyat_or_push!(k, 4, k4) - copyat_or_push!(k, 5, k5) - copyat_or_push!(k, 6, k6) - copyat_or_push!(k, 7, k7) - end - nothing -end - """ An Efficient Runge-Kutta (4,5) Pair by P.Bogacki and L.F.Shampine Computers and Mathematics with Applications, Vol. 32, No. 6, 1996, pages 15 to 28 @@ -498,78 +463,6 @@ end end =# -@muladd function _ode_addsteps!(k, t, uprev, u, dt, f, p, cache::Tsit5ConstantCache, - always_calc_begin = false, allow_calc_end = true, - force_calc_end = false) - if length(k) < 7 || always_calc_begin - T = constvalue(recursive_unitless_bottom_eltype(u)) - T2 = constvalue(typeof(one(t))) - @OnDemandTableauExtract Tsit5ConstantCacheActual T T2 - copyat_or_push!(k, 1, f(uprev, p, t)) - copyat_or_push!(k, 2, f(uprev + dt * (a21 * k[1]), p, t + c1 * dt)) - copyat_or_push!(k, 3, f(uprev + dt * (a31 * k[1] + a32 * k[2]), p, t + c2 * dt)) - copyat_or_push!(k, 4, - f(uprev + dt * (a41 * k[1] + a42 * k[2] + a43 * k[3]), p, - t + c3 * dt)) - copyat_or_push!(k, 5, - f(uprev + dt * (a51 * k[1] + a52 * k[2] + a53 * k[3] + a54 * k[4]), - p, t + c4 * dt)) - copyat_or_push!(k, 6, - f( - uprev + - dt * - (a61 * k[1] + a62 * k[2] + a63 * k[3] + a64 * k[4] + a65 * k[5]), - p, t + dt)) - utmp = uprev + - dt * - (a71 * k[1] + a72 * k[2] + a73 * k[3] + a74 * k[4] + a75 * k[5] + a76 * k[6]) - copyat_or_push!(k, 7, f(utmp, p, t + dt)) - end - nothing -end - -#= -@muladd function _ode_addsteps!(k,t,uprev,u,dt,f,p,cache::Tsit5Cache,always_calc_begin = false,allow_calc_end = true,force_calc_end = false) - if length(k)<7 || always_calc_begin - @unpack c1,c2,c3,c4,c5,c6,a21,a31,a32,a41,a42,a43,a51,a52,a53,a54,a61,a62,a63,a64,a65,a71,a72,a73,a74,a75,a76 = cache.tab - @unpack k1,k2,k3,k4,k5,k6,k7,tmp = cache - uidx = eachindex(uprev) - @tight_loop_macros for i in uidx - @inbounds tmp[i] = uprev[i]+dt*(a21*k1[i]) - end - f(k2,tmp,p,t+c1*dt) - @tight_loop_macros for i in uidx - @inbounds tmp[i] = uprev[i]+dt*(a31*k1[i]+a32*k2[i]) - end - f(k3,tmp,p,t+c2*dt) - @tight_loop_macros for i in uidx - @inbounds tmp[i] = uprev[i]+dt*(a41*k1[i]+a42*k2[i]+a43*k3[i]) - end - f(k4,tmp,p,t+c3*dt) - @tight_loop_macros for i in uidx - @inbounds tmp[i] = uprev[i]+dt*(a51*k1[i]+a52*k2[i]+a53*k3[i]+a54*k4[i]) - end - f(k5,tmp,p,t+c4*dt) - @tight_loop_macros for i in uidx - @inbounds tmp[i] = uprev[i]+dt*(a61*k1[i]+a62*k2[i]+a63*k3[i]+a64*k4[i]+a65*k5[i]) - end - f(k6,tmp,p,t+dt) - @tight_loop_macros for i in uidx - @inbounds tmp[i] = uprev[i]+dt*(a71*k1[i]+a72*k2[i]+a73*k3[i]+a74*k4[i]+a75*k5[i]+a76*k6[i]) - end - f(k7,u,p,t+dt) - copyat_or_push!(k,1,k1) - copyat_or_push!(k,2,k2) - copyat_or_push!(k,3,k3) - copyat_or_push!(k,4,k4) - copyat_or_push!(k,5,k5) - copyat_or_push!(k,6,k6) - copyat_or_push!(k,7,k7) - end - nothing -end -=# - """ An Efficient Runge-Kutta (4,5) Pair by P.Bogacki and L.F.Shampine Computers and Mathematics with Applications, Vol. 32, No. 6, 1996, pages 15 to 28 diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_caches.jl b/lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_caches.jl index c62610cdb3..ac728ae2ae 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_caches.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_caches.jl @@ -426,56 +426,6 @@ function alg_cache(alg::BS5, u, rate_prototype, ::Type{uEltypeNoUnits}, BS5ConstantCache(constvalue(uBottomEltypeNoUnits), constvalue(tTypeNoUnits)) end -@cache struct Tsit5Cache{uType, rateType, uNoUnitsType, StageLimiter, StepLimiter, - Thread} <: OrdinaryDiffEqMutableCache - u::uType - uprev::uType - k1::rateType - k2::rateType - k3::rateType - k4::rateType - k5::rateType - k6::rateType - k7::rateType - utilde::uType - tmp::uType - atmp::uNoUnitsType - stage_limiter!::StageLimiter - step_limiter!::StepLimiter - thread::Thread -end -if isdefined(Base, :Experimental) && isdefined(Base.Experimental, :silence!) - Base.Experimental.silence!(Tsit5Cache) -end - -function alg_cache(alg::Tsit5, u, rate_prototype, ::Type{uEltypeNoUnits}, - ::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t, - dt, reltol, p, calck, - ::Val{true}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits} - k1 = zero(rate_prototype) - k2 = zero(rate_prototype) - k3 = zero(rate_prototype) - k4 = zero(rate_prototype) - k5 = zero(rate_prototype) - k6 = zero(rate_prototype) - k7 = zero(rate_prototype) - utilde = zero(u) - atmp = similar(u, uEltypeNoUnits) - recursivefill!(atmp, false) - tmp = zero(u) - Tsit5Cache(u, uprev, k1, k2, k3, k4, k5, k6, k7, utilde, tmp, atmp, - alg.stage_limiter!, alg.step_limiter!, alg.thread) -end - -TruncatedStacktraces.@truncate_stacktrace Tsit5Cache 1 - -function alg_cache(alg::Tsit5, u, rate_prototype, ::Type{uEltypeNoUnits}, - ::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t, - dt, reltol, p, calck, - ::Val{false}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits} - Tsit5ConstantCache() -end - @cache struct DP5Cache{uType, rateType, uNoUnitsType, StageLimiter, StepLimiter, Thread} <: OrdinaryDiffEqMutableCache u::uType diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_perform_step.jl b/lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_perform_step.jl index 1cd465607d..d9c87c546d 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_perform_step.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_perform_step.jl @@ -727,132 +727,6 @@ end end =# -function initialize!(integrator, cache::Tsit5ConstantCache) - integrator.kshortsize = 7 - integrator.k = typeof(integrator.k)(undef, integrator.kshortsize) - integrator.fsalfirst = integrator.f(integrator.uprev, integrator.p, integrator.t) # Pre-start fsal - integrator.stats.nf += 1 - - # Avoid undefined entries if k is an array of arrays - integrator.fsallast = zero(integrator.fsalfirst) - integrator.k[1] = integrator.fsalfirst - @inbounds for i in 2:(integrator.kshortsize - 1) - integrator.k[i] = zero(integrator.fsalfirst) - end - integrator.k[integrator.kshortsize] = integrator.fsallast -end - -@muladd function perform_step!(integrator, cache::Tsit5ConstantCache, repeat_step = false) - @unpack t, dt, uprev, u, f, p = integrator - T = constvalue(recursive_unitless_bottom_eltype(u)) - T2 = constvalue(typeof(one(t))) - @OnDemandTableauExtract Tsit5ConstantCacheActual T T2 - k1 = integrator.fsalfirst - a = dt * a21 - k2 = f(uprev + a * k1, p, t + c1 * dt) - k3 = f(uprev + dt * (a31 * k1 + a32 * k2), p, t + c2 * dt) - k4 = f(uprev + dt * (a41 * k1 + a42 * k2 + a43 * k3), p, t + c3 * dt) - k5 = f(uprev + dt * (a51 * k1 + a52 * k2 + a53 * k3 + a54 * k4), p, t + c4 * dt) - g6 = uprev + dt * (a61 * k1 + a62 * k2 + a63 * k3 + a64 * k4 + a65 * k5) - k6 = f(g6, p, t + dt) - u = uprev + dt * (a71 * k1 + a72 * k2 + a73 * k3 + a74 * k4 + a75 * k5 + a76 * k6) - integrator.fsallast = f(u, p, t + dt) - k7 = integrator.fsallast - integrator.stats.nf += 6 - if integrator.alg isa CompositeAlgorithm - g7 = u - # Hairer II, page 22 modified to use the Inf norm - integrator.eigen_est = integrator.opts.internalnorm( - maximum(abs.(k7 .- k6) ./ (g7 .- g6)), t) - end - if integrator.opts.adaptive - utilde = dt * - (btilde1 * k1 + btilde2 * k2 + btilde3 * k3 + btilde4 * k4 + btilde5 * k5 + - btilde6 * k6 + btilde7 * k7) - atmp = calculate_residuals(utilde, uprev, u, integrator.opts.abstol, - integrator.opts.reltol, integrator.opts.internalnorm, t) - integrator.EEst = integrator.opts.internalnorm(atmp, t) - end - integrator.k[1] = k1 - integrator.k[2] = k2 - integrator.k[3] = k3 - integrator.k[4] = k4 - integrator.k[5] = k5 - integrator.k[6] = k6 - integrator.k[7] = k7 - integrator.u = u -end - -function initialize!(integrator, cache::Tsit5Cache) - integrator.kshortsize = 7 - integrator.fsalfirst = cache.k1 - integrator.fsallast = cache.k7 # setup pointers - resize!(integrator.k, integrator.kshortsize) - # Setup k pointers - integrator.k[1] = cache.k1 - integrator.k[2] = cache.k2 - integrator.k[3] = cache.k3 - integrator.k[4] = cache.k4 - integrator.k[5] = cache.k5 - integrator.k[6] = cache.k6 - integrator.k[7] = cache.k7 - integrator.f(integrator.fsalfirst, integrator.uprev, integrator.p, integrator.t) # Pre-start fsal - integrator.stats.nf += 1 - return nothing -end - -@muladd function perform_step!(integrator, cache::Tsit5Cache, repeat_step = false) - @unpack t, dt, uprev, u, f, p = integrator - T = constvalue(recursive_unitless_bottom_eltype(u)) - T2 = constvalue(typeof(one(t))) - @OnDemandTableauExtract Tsit5ConstantCacheActual T T2 - @unpack k1, k2, k3, k4, k5, k6, k7, utilde, tmp, atmp, stage_limiter!, step_limiter!, thread = cache - a = dt * a21 - @.. broadcast=false thread=thread tmp=uprev + a * k1 - stage_limiter!(tmp, f, p, t + c1 * dt) - f(k2, tmp, p, t + c1 * dt) - @.. broadcast=false thread=thread tmp=uprev + dt * (a31 * k1 + a32 * k2) - stage_limiter!(tmp, f, p, t + c2 * dt) - f(k3, tmp, p, t + c2 * dt) - @.. broadcast=false thread=thread tmp=uprev + dt * (a41 * k1 + a42 * k2 + a43 * k3) - stage_limiter!(tmp, f, p, t + c3 * dt) - f(k4, tmp, p, t + c3 * dt) - @.. broadcast=false thread=thread tmp=uprev + - dt * (a51 * k1 + a52 * k2 + a53 * k3 + a54 * k4) - stage_limiter!(tmp, f, p, t + c4 * dt) - f(k5, tmp, p, t + c4 * dt) - @.. broadcast=false thread=thread tmp=uprev + - dt * (a61 * k1 + a62 * k2 + a63 * k3 + a64 * k4 + - a65 * k5) - stage_limiter!(tmp, f, p, t + dt) - f(k6, tmp, p, t + dt) - @.. broadcast=false thread=thread u=uprev + - dt * (a71 * k1 + a72 * k2 + a73 * k3 + a74 * k4 + - a75 * k5 + a76 * k6) - stage_limiter!(u, integrator, p, t + dt) - step_limiter!(u, integrator, p, t + dt) - f(k7, u, p, t + dt) - integrator.stats.nf += 6 - if integrator.alg isa CompositeAlgorithm - g7 = u - g6 = tmp - # Hairer II, page 22 modified to use Inf norm - @.. broadcast=false thread=thread utilde=abs((k7 - k6) / (g7 - g6)) - integrator.eigen_est = integrator.opts.internalnorm(norm(utilde, Inf), t) - end - if integrator.opts.adaptive - @.. broadcast=false thread=thread utilde=dt * (btilde1 * k1 + btilde2 * k2 + - btilde3 * k3 + btilde4 * k4 + - btilde5 * k5 + btilde6 * k6 + - btilde7 * k7) - calculate_residuals!(atmp, utilde, uprev, u, integrator.opts.abstol, - integrator.opts.reltol, integrator.opts.internalnorm, t, - thread) - integrator.EEst = integrator.opts.internalnorm(atmp, t) - end - return nothing -end - function initialize!(integrator, cache::DP5ConstantCache) integrator.kshortsize = 4 integrator.k = typeof(integrator.k)(undef, integrator.kshortsize) diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_tableaus.jl b/lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_tableaus.jl index 4e9e0069a0..f5ec9dcb7b 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_tableaus.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_tableaus.jl @@ -498,264 +498,6 @@ function OwrenZen5ConstantCache(T, T2) r62, r75, r74, r73, r72, r85, r84, r83, r82) end -struct Tsit5ConstantCache <: OrdinaryDiffEqConstantCache end -struct Tsit5ConstantCacheActual{T, T2} - c1::T2 - c2::T2 - c3::T2 - c4::T2 - c5::T2 - c6::T2 - a21::T - a31::T - a32::T - a41::T - a42::T - a43::T - a51::T - a52::T - a53::T - a54::T - a61::T - a62::T - a63::T - a64::T - a65::T - a71::T - a72::T - a73::T - a74::T - a75::T - a76::T - btilde1::T - btilde2::T - btilde3::T - btilde4::T - btilde5::T - btilde6::T - btilde7::T -end - -@fold function Tsit5ConstantCacheActual(::Type{T}, - ::Type{T2}) where {T <: CompiledFloats, - T2 <: CompiledFloats} - c1 = convert(T2, 0.161) - c2 = convert(T2, 0.327) - c3 = convert(T2, 0.9) - c4 = convert(T2, 0.9800255409045097) - c5 = convert(T2, 1) - c6 = convert(T2, 1) - a21 = convert(T, 0.161) - a31 = convert(T, -0.008480655492356989) - a32 = convert(T, 0.335480655492357) - a41 = convert(T, 2.8971530571054935) - a42 = convert(T, -6.359448489975075) - a43 = convert(T, 4.3622954328695815) - a51 = convert(T, 5.325864828439257) - a52 = convert(T, -11.748883564062828) - a53 = convert(T, 7.4955393428898365) - a54 = convert(T, -0.09249506636175525) - a61 = convert(T, 5.86145544294642) - a62 = convert(T, -12.92096931784711) - a63 = convert(T, 8.159367898576159) - a64 = convert(T, -0.071584973281401) - a65 = convert(T, -0.028269050394068383) - a71 = convert(T, 0.09646076681806523) - a72 = convert(T, 0.01) - a73 = convert(T, 0.4798896504144996) - a74 = convert(T, 1.379008574103742) - a75 = convert(T, -3.290069515436081) - a76 = convert(T, 2.324710524099774) - # b1 = convert(T,0.09468075576583945) - # b2 = convert(T,0.009183565540343254) - # b3 = convert(T,0.4877705284247616) - # b4 = convert(T,1.234297566930479) - # b5 = convert(T,-2.7077123499835256) - # b6 = convert(T,1.866628418170587) - # b7 = convert(T,0.015151515151515152) - btilde1 = convert(T, -0.00178001105222577714) - btilde2 = convert(T, -0.0008164344596567469) - btilde3 = convert(T, 0.007880878010261995) - btilde4 = convert(T, -0.1447110071732629) - btilde5 = convert(T, 0.5823571654525552) - btilde6 = convert(T, -0.45808210592918697) - btilde7 = convert(T, 0.015151515151515152) - - Tsit5ConstantCacheActual( - c1, c2, c3, c4, c5, c6, a21, a31, a32, a41, a42, a43, a51, a52, - a53, - a54, a61, a62, a63, a64, a65, a71, a72, a73, a74, a75, a76, - btilde1, - btilde2, btilde3, btilde4, btilde5, btilde6, btilde7) -end - -@fold function Tsit5ConstantCacheActual(::Type{T}, ::Type{T2}) where {T, T2} - c1 = convert(T2, 161 // 1000) - c2 = convert(T2, 327 // 1000) - c3 = convert(T2, 9 // 10) - c4 = convert(T2, - big".9800255409045096857298102862870245954942137979563024768854764293221195950761080302604") - c5 = convert(T2, 1) - c6 = convert(T2, 1) - a21 = convert(T, 161 // 1000) - a31 = convert(T, - big"-.8480655492356988544426874250230774675121177393430391537369234245294192976164141156943e-2") - a32 = convert(T, - big".3354806554923569885444268742502307746751211773934303915373692342452941929761641411569") - a41 = convert(T, - big"2.897153057105493432130432594192938764924887287701866490314866693455023795137503079289") - a42 = convert(T, - big"-6.359448489975074843148159912383825625952700647415626703305928850207288721235210244366") - a43 = convert(T, - big"4.362295432869581411017727318190886861027813359713760212991062156752264926097707165077") - a51 = convert(T, - big"5.325864828439256604428877920840511317836476253097040101202360397727981648835607691791") - a52 = convert(T, - big"-11.74888356406282787774717033978577296188744178259862899288666928009020615663593781589") - a53 = convert(T, - big"7.495539342889836208304604784564358155658679161518186721010132816213648793440552049753") - a54 = convert(T, - big"-.9249506636175524925650207933207191611349983406029535244034750452930469056411389539635e-1") - a61 = convert(T, - big"5.861455442946420028659251486982647890394337666164814434818157239052507339770711679748") - a62 = convert(T, - big"-12.92096931784710929170611868178335939541780751955743459166312250439928519268343184452") - a63 = convert(T, - big"8.159367898576158643180400794539253485181918321135053305748355423955009222648673734986") - a64 = convert(T, - big"-.7158497328140099722453054252582973869127213147363544882721139659546372402303777878835e-1") - a65 = convert(T, - big"-.2826905039406838290900305721271224146717633626879770007617876201276764571291579142206e-1") - a71 = convert(T, - big".9646076681806522951816731316512876333711995238157997181903319145764851595234062815396e-1") - a72 = convert(T, 1 // 100) - a73 = convert(T, - big".4798896504144995747752495322905965199130404621990332488332634944254542060153074523509") - a74 = convert(T, - big"1.379008574103741893192274821856872770756462643091360525934940067397245698027561293331") - a75 = convert(T, - big"-3.290069515436080679901047585711363850115683290894936158531296799594813811049925401677") - a76 = convert(T, - big"2.324710524099773982415355918398765796109060233222962411944060046314465391054716027841") - # b1 = convert(T,big".9468075576583945807478876255758922856117527357724631226139574065785592789071067303271e-1") - # b2 = convert(T,big".9183565540343253096776363936645313759813746240984095238905939532922955247253608687270e-2") - # b3 = convert(T,big".4877705284247615707855642599631228241516691959761363774365216240304071651579571959813") - # b4 = convert(T,big"1.234297566930478985655109673884237654035539930748192848315425833500484878378061439761") - # b5 = convert(T,big"-2.707712349983525454881109975059321670689605166938197378763992255714444407154902012702") - # b6 = convert(T,big"1.866628418170587035753719399566211498666255505244122593996591602841258328965767580089") - # b7 = convert(T,1//66) - btilde1 = convert(T, - big"-1.780011052225771443378550607539534775944678804333659557637450799792588061629796e-03") - btilde2 = convert(T, - big"-8.164344596567469032236360633546862401862537590159047610940604670770447527463931e-04") - btilde3 = convert(T, - big"7.880878010261996010314727672526304238628733777103128603258129604952959142646516e-03") - btilde4 = convert(T, - big"-1.44711007173262907537165147972635116720922712343167677619514233896760819649515e-01") - btilde5 = convert(T, - big"5.823571654525552250199376106520421794260781239567387797673045438803694038950012e-01") - btilde6 = convert(T, - big"-4.580821059291869466616365188325542974428047279788398179474684434732070620889539e-01") - btilde7 = convert(T, 1 // 66) - - Tsit5ConstantCacheActual( - c1, c2, c3, c4, c5, c6, a21, a31, a32, a41, a42, a43, a51, a52, - a53, - a54, a61, a62, a63, a64, a65, a71, a72, a73, a74, a75, a76, - btilde1, - btilde2, btilde3, btilde4, btilde5, btilde6, btilde7) -end - -""" -Coefficients for the polynomial -bᵢΘ = ri1*Θ + ri2*Θ^2 + ri3*Θ^3 + ... - -These are the coefficients of the expanded form of the polynomials from - -Runge–Kutta pairs of order 5(4) satisfying only the first column -simplifying assumption - -Ch. Tsitouras -""" -@fold function Tsit5Interp(::Type{T}) where {T <: CompiledFloats} - r11 = convert(T, 1.0) - r12 = convert(T, -2.763706197274826) - r13 = convert(T, 2.9132554618219126) - r14 = convert(T, -1.0530884977290216) - - r22 = convert(T, 0.13169999999999998) - r23 = convert(T, -0.2234) - r24 = convert(T, 0.1017) - - r32 = convert(T, 3.9302962368947516) - r33 = convert(T, -5.941033872131505) - r34 = convert(T, 2.490627285651253) - - r42 = convert(T, -12.411077166933676) - r43 = convert(T, 30.33818863028232) - r44 = convert(T, -16.548102889244902) - - r52 = convert(T, 37.50931341651104) - r53 = convert(T, -88.1789048947664) - r54 = convert(T, 47.37952196281928) - - r62 = convert(T, -27.896526289197286) - r63 = convert(T, 65.09189467479366) - r64 = convert(T, -34.87065786149661) - - r72 = convert(T, 1.5) - r73 = convert(T, -4) - r74 = convert(T, 2.5) - - return r11, r12, r13, r14, r22, r23, r24, r32, r33, r34, r42, r43, r44, r52, r53, r54, - r62, r63, r64, r72, r73, r74 -end - -""" -Coefficients for the polynomial -bᵢΘ = ri1*Θ + ri2*Θ^2 + ri3*Θ^3 + ... - -These are the coefficients of the expanded form of the polynomials from - -Runge–Kutta pairs of order 5(4) satisfying only the first column -simplifying assumption - -Ch. Tsitouras -""" -@fold function Tsit5Interp(::Type{T}) where {T} - r11 = convert(T, big"0.999999999999999974283372471559910888475488471328") - r12 = convert(T, big"-2.763706197274825911336735930481400260916070804192") - r13 = convert(T, big"2.91325546182191274375068099306808") - r14 = convert(T, -1.0530884977290216) - - r22 = convert(T, big"0.13169999999999999727") - r23 = convert(T, big"-0.22339999999999999818") - r24 = convert(T, 0.1017) - - r32 = convert(T, big"3.93029623689475152850687446709813398") - r33 = convert(T, big"-5.94103387213150473470249202589458001") - r34 = convert(T, big"2.490627285651252793") - - r42 = convert(T, big"-12.411077166933676983734381540685453484102414134010752") - r43 = convert(T, big"30.3381886302823215981729903691836576") - r44 = convert(T, big"-16.54810288924490272") - - r52 = convert(T, big"37.50931341651103919496903965334519631242339792120440212") - r53 = convert(T, big"-88.1789048947664011014276693541209817") - r54 = convert(T, big"47.37952196281928122") - - r62 = convert(T, big"-27.896526289197287805948263144598643896") - r63 = convert(T, big"65.09189467479367152629021928716553658") - r64 = convert(T, big"-34.87065786149660974") - - r72 = convert(T, 1.5) - r73 = convert(T, -4) - r74 = convert(T, 2.5) - - return r11, r12, r13, r14, r22, r23, r24, r32, r33, r34, r42, r43, r44, r52, r53, r54, - r62, r63, r64, r72, r73, r74 -end - struct BS5ConstantCache{T, T2} <: OrdinaryDiffEqConstantCache c1::T2 c2::T2 diff --git a/lib/OrdinaryDiffEqTsit5/Project.toml b/lib/OrdinaryDiffEqTsit5/Project.toml new file mode 100644 index 0000000000..921cb4b939 --- /dev/null +++ b/lib/OrdinaryDiffEqTsit5/Project.toml @@ -0,0 +1,23 @@ +name = "OrdinaryDiffEqTsit5" +uuid = "1344f307-1e59-4825-a18e-ace9aa3fa4c6" +authors = ["ParamThakkar123 "] +version = "1.0.0" + +[deps] +OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" +MuladdMacro = "46d2c3a1-f734-5fdb-9937-b9b9aeba4221" +RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd" +FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898" +Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3" + +[compat] +julia = "1.10" + +[extras] +DiffEqDevTools = "f3b72e0c-5b89-59e1-b016-84e28bfd966d" +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" +SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[targets] +test = ["DiffEqDevTools", "Random", "SafeTestsets", "Test"] \ No newline at end of file diff --git a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit.jl b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit.jl new file mode 100644 index 0000000000..dddc703383 --- /dev/null +++ b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit.jl @@ -0,0 +1,19 @@ +module OrdinaryDiffEqTsit + +import OrdinaryDiffEq: alg_order, alg_stability_size, explicit_rk_docstring, trivial_limiter!, + OrdinaryDiffEqAdaptiveAlgorithm, OrdinaryDiffEqMutableCache, alg_cache, + constvalue, uses_uprev, @unpack, perform_step!, calculate_residuals, + calculate_residuals! +import Static: False +import MuladdMacro: @muladd +import FastBroadcast: @.. +import RecursiveArrayTools: recursivefill! + +include("algorithms.jl") +include("alg_utils.jl") +include("tsit_caches.jl") +include("tsit_tableaus.jl") +include("interp_func.jl") +include("tsit_perform_step.jl") + +end \ No newline at end of file diff --git a/lib/OrdinaryDiffEqTsit5/src/alg_utils.jl b/lib/OrdinaryDiffEqTsit5/src/alg_utils.jl new file mode 100644 index 0000000000..f7a6f5e366 --- /dev/null +++ b/lib/OrdinaryDiffEqTsit5/src/alg_utils.jl @@ -0,0 +1,3 @@ +alg_order(alg::Tsit5) = 5 + +alg_stability_size(alg::Tsit5) = 3.5068 \ No newline at end of file diff --git a/lib/OrdinaryDiffEqTsit5/src/algorithms.jl b/lib/OrdinaryDiffEqTsit5/src/algorithms.jl new file mode 100644 index 0000000000..6da2a58444 --- /dev/null +++ b/lib/OrdinaryDiffEqTsit5/src/algorithms.jl @@ -0,0 +1,24 @@ +@doc explicit_rk_docstring( + "A fifth-order explicit Runge-Kutta method with embedded error +estimator of Tsitouras. Free 4th order interpolant.", "Tsit5", + references = "@article{tsitouras2011runge, + title={Runge--Kutta pairs of order 5 (4) satisfying only the first column simplifying assumption}, + author={Tsitouras, Ch}, + journal={Computers \\& Mathematics with Applications}, + volume={62}, + number={2}, + pages={770--775}, + year={2011}, + publisher={Elsevier} + }") +Base.@kwdef struct Tsit5{StageLimiter, StepLimiter, Thread} <: + OrdinaryDiffEqAdaptiveAlgorithm + stage_limiter!::StageLimiter = trivial_limiter! + step_limiter!::StepLimiter = trivial_limiter! + thread::Thread = False() +end +TruncatedStacktraces.@truncate_stacktrace Tsit5 3 +# for backwards compatibility +function Tsit5(stage_limiter!, step_limiter! = trivial_limiter!) + Tsit5(stage_limiter!, step_limiter!, False()) +end \ No newline at end of file diff --git a/lib/OrdinaryDiffEqTsit5/src/interp_func.jl b/lib/OrdinaryDiffEqTsit5/src/interp_func.jl new file mode 100644 index 0000000000..d18ab1ee73 --- /dev/null +++ b/lib/OrdinaryDiffEqTsit5/src/interp_func.jl @@ -0,0 +1,7 @@ +function DiffEqBase.interp_summary(::Type{cacheType}, + dense::Bool) where { + cacheType <: + Union{Tsit5Cache, Tsit5ConstantCache +}} + dense ? "specialized 4th order \"free\" interpolation" : "1st order linear" +end \ No newline at end of file diff --git a/lib/OrdinaryDiffEqTsit5/src/tsit_caches.jl b/lib/OrdinaryDiffEqTsit5/src/tsit_caches.jl new file mode 100644 index 0000000000..eb11c53031 --- /dev/null +++ b/lib/OrdinaryDiffEqTsit5/src/tsit_caches.jl @@ -0,0 +1,49 @@ +@cache struct Tsit5Cache{uType, rateType, uNoUnitsType, StageLimiter, StepLimiter, + Thread} <: OrdinaryDiffEqMutableCache + u::uType + uprev::uType + k1::rateType + k2::rateType + k3::rateType + k4::rateType + k5::rateType + k6::rateType + k7::rateType + utilde::uType + tmp::uType + atmp::uNoUnitsType + stage_limiter!::StageLimiter + step_limiter!::StepLimiter + thread::Thread +end +if isdefined(Base, :Experimental) && isdefined(Base.Experimental, :silence!) + Base.Experimental.silence!(Tsit5Cache) +end + +function alg_cache(alg::Tsit5, u, rate_prototype, ::Type{uEltypeNoUnits}, + ::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t, + dt, reltol, p, calck, + ::Val{true}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits} + k1 = zero(rate_prototype) + k2 = zero(rate_prototype) + k3 = zero(rate_prototype) + k4 = zero(rate_prototype) + k5 = zero(rate_prototype) + k6 = zero(rate_prototype) + k7 = zero(rate_prototype) + utilde = zero(u) + atmp = similar(u, uEltypeNoUnits) + recursivefill!(atmp, false) + tmp = zero(u) + Tsit5Cache(u, uprev, k1, k2, k3, k4, k5, k6, k7, utilde, tmp, atmp, + alg.stage_limiter!, alg.step_limiter!, alg.thread) +end + +TruncatedStacktraces.@truncate_stacktrace Tsit5Cache 1 + +function alg_cache(alg::Tsit5, u, rate_prototype, ::Type{uEltypeNoUnits}, + ::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t, + dt, reltol, p, calck, + ::Val{false}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits} + Tsit5ConstantCache() +end \ No newline at end of file diff --git a/lib/OrdinaryDiffEqTsit5/src/tsit_perform_step.jl b/lib/OrdinaryDiffEqTsit5/src/tsit_perform_step.jl new file mode 100644 index 0000000000..8f05b26869 --- /dev/null +++ b/lib/OrdinaryDiffEqTsit5/src/tsit_perform_step.jl @@ -0,0 +1,232 @@ +@muladd function _ode_addsteps!(k, t, uprev, u, dt, f, p, cache::Tsit5Cache, + always_calc_begin = false, allow_calc_end = true, + force_calc_end = false) + if length(k) < 7 || always_calc_begin + T = constvalue(recursive_unitless_bottom_eltype(u)) + T2 = constvalue(typeof(one(t))) + @OnDemandTableauExtract Tsit5ConstantCacheActual T T2 + @unpack k1, k2, k3, k4, k5, k6, k7, tmp = cache + @.. broadcast=false tmp=uprev + dt * (a21 * k1) + f(k2, tmp, p, t + c1 * dt) + @.. broadcast=false tmp=uprev + dt * (a31 * k1 + a32 * k2) + f(k3, tmp, p, t + c2 * dt) + @.. broadcast=false tmp=uprev + dt * (a41 * k1 + a42 * k2 + a43 * k3) + f(k4, tmp, p, t + c3 * dt) + @.. broadcast=false tmp=uprev + dt * (a51 * k1 + a52 * k2 + a53 * k3 + a54 * k4) + f(k5, tmp, p, t + c4 * dt) + @.. broadcast=false tmp=uprev + + dt * (a61 * k1 + a62 * k2 + a63 * k3 + a64 * k4 + a65 * k5) + f(k6, tmp, p, t + dt) + @.. broadcast=false tmp=uprev + + dt * + (a71 * k1 + a72 * k2 + a73 * k3 + a74 * k4 + a75 * k5 + + a76 * k6) + f(k7, tmp, p, t + dt) + copyat_or_push!(k, 1, k1) + copyat_or_push!(k, 2, k2) + copyat_or_push!(k, 3, k3) + copyat_or_push!(k, 4, k4) + copyat_or_push!(k, 5, k5) + copyat_or_push!(k, 6, k6) + copyat_or_push!(k, 7, k7) + end + nothing +end + +@muladd function _ode_addsteps!(k, t, uprev, u, dt, f, p, cache::Tsit5ConstantCache, + always_calc_begin = false, allow_calc_end = true, + force_calc_end = false) + if length(k) < 7 || always_calc_begin + T = constvalue(recursive_unitless_bottom_eltype(u)) + T2 = constvalue(typeof(one(t))) + @OnDemandTableauExtract Tsit5ConstantCacheActual T T2 + copyat_or_push!(k, 1, f(uprev, p, t)) + copyat_or_push!(k, 2, f(uprev + dt * (a21 * k[1]), p, t + c1 * dt)) + copyat_or_push!(k, 3, f(uprev + dt * (a31 * k[1] + a32 * k[2]), p, t + c2 * dt)) + copyat_or_push!(k, 4, + f(uprev + dt * (a41 * k[1] + a42 * k[2] + a43 * k[3]), p, + t + c3 * dt)) + copyat_or_push!(k, 5, + f(uprev + dt * (a51 * k[1] + a52 * k[2] + a53 * k[3] + a54 * k[4]), + p, t + c4 * dt)) + copyat_or_push!(k, 6, + f( + uprev + + dt * + (a61 * k[1] + a62 * k[2] + a63 * k[3] + a64 * k[4] + a65 * k[5]), + p, t + dt)) + utmp = uprev + + dt * + (a71 * k[1] + a72 * k[2] + a73 * k[3] + a74 * k[4] + a75 * k[5] + a76 * k[6]) + copyat_or_push!(k, 7, f(utmp, p, t + dt)) + end + nothing +end + +#= +@muladd function _ode_addsteps!(k,t,uprev,u,dt,f,p,cache::Tsit5Cache,always_calc_begin = false,allow_calc_end = true,force_calc_end = false) + if length(k)<7 || always_calc_begin + @unpack c1,c2,c3,c4,c5,c6,a21,a31,a32,a41,a42,a43,a51,a52,a53,a54,a61,a62,a63,a64,a65,a71,a72,a73,a74,a75,a76 = cache.tab + @unpack k1,k2,k3,k4,k5,k6,k7,tmp = cache + uidx = eachindex(uprev) + @tight_loop_macros for i in uidx + @inbounds tmp[i] = uprev[i]+dt*(a21*k1[i]) + end + f(k2,tmp,p,t+c1*dt) + @tight_loop_macros for i in uidx + @inbounds tmp[i] = uprev[i]+dt*(a31*k1[i]+a32*k2[i]) + end + f(k3,tmp,p,t+c2*dt) + @tight_loop_macros for i in uidx + @inbounds tmp[i] = uprev[i]+dt*(a41*k1[i]+a42*k2[i]+a43*k3[i]) + end + f(k4,tmp,p,t+c3*dt) + @tight_loop_macros for i in uidx + @inbounds tmp[i] = uprev[i]+dt*(a51*k1[i]+a52*k2[i]+a53*k3[i]+a54*k4[i]) + end + f(k5,tmp,p,t+c4*dt) + @tight_loop_macros for i in uidx + @inbounds tmp[i] = uprev[i]+dt*(a61*k1[i]+a62*k2[i]+a63*k3[i]+a64*k4[i]+a65*k5[i]) + end + f(k6,tmp,p,t+dt) + @tight_loop_macros for i in uidx + @inbounds tmp[i] = uprev[i]+dt*(a71*k1[i]+a72*k2[i]+a73*k3[i]+a74*k4[i]+a75*k5[i]+a76*k6[i]) + end + f(k7,u,p,t+dt) + copyat_or_push!(k,1,k1) + copyat_or_push!(k,2,k2) + copyat_or_push!(k,3,k3) + copyat_or_push!(k,4,k4) + copyat_or_push!(k,5,k5) + copyat_or_push!(k,6,k6) + copyat_or_push!(k,7,k7) + end + nothing +end +=# + +function initialize!(integrator, cache::Tsit5ConstantCache) + integrator.kshortsize = 7 + integrator.k = typeof(integrator.k)(undef, integrator.kshortsize) + integrator.fsalfirst = integrator.f(integrator.uprev, integrator.p, integrator.t) # Pre-start fsal + integrator.stats.nf += 1 + + # Avoid undefined entries if k is an array of arrays + integrator.fsallast = zero(integrator.fsalfirst) + integrator.k[1] = integrator.fsalfirst + @inbounds for i in 2:(integrator.kshortsize - 1) + integrator.k[i] = zero(integrator.fsalfirst) + end + integrator.k[integrator.kshortsize] = integrator.fsallast +end + +@muladd function perform_step!(integrator, cache::Tsit5ConstantCache, repeat_step = false) + @unpack t, dt, uprev, u, f, p = integrator + T = constvalue(recursive_unitless_bottom_eltype(u)) + T2 = constvalue(typeof(one(t))) + @OnDemandTableauExtract Tsit5ConstantCacheActual T T2 + k1 = integrator.fsalfirst + a = dt * a21 + k2 = f(uprev + a * k1, p, t + c1 * dt) + k3 = f(uprev + dt * (a31 * k1 + a32 * k2), p, t + c2 * dt) + k4 = f(uprev + dt * (a41 * k1 + a42 * k2 + a43 * k3), p, t + c3 * dt) + k5 = f(uprev + dt * (a51 * k1 + a52 * k2 + a53 * k3 + a54 * k4), p, t + c4 * dt) + g6 = uprev + dt * (a61 * k1 + a62 * k2 + a63 * k3 + a64 * k4 + a65 * k5) + k6 = f(g6, p, t + dt) + u = uprev + dt * (a71 * k1 + a72 * k2 + a73 * k3 + a74 * k4 + a75 * k5 + a76 * k6) + integrator.fsallast = f(u, p, t + dt) + k7 = integrator.fsallast + integrator.stats.nf += 6 + if integrator.alg isa CompositeAlgorithm + g7 = u + # Hairer II, page 22 modified to use the Inf norm + integrator.eigen_est = integrator.opts.internalnorm( + maximum(abs.(k7 .- k6) ./ (g7 .- g6)), t) + end + if integrator.opts.adaptive + utilde = dt * + (btilde1 * k1 + btilde2 * k2 + btilde3 * k3 + btilde4 * k4 + btilde5 * k5 + + btilde6 * k6 + btilde7 * k7) + atmp = calculate_residuals(utilde, uprev, u, integrator.opts.abstol, + integrator.opts.reltol, integrator.opts.internalnorm, t) + integrator.EEst = integrator.opts.internalnorm(atmp, t) + end + integrator.k[1] = k1 + integrator.k[2] = k2 + integrator.k[3] = k3 + integrator.k[4] = k4 + integrator.k[5] = k5 + integrator.k[6] = k6 + integrator.k[7] = k7 + integrator.u = u +end + +function initialize!(integrator, cache::Tsit5Cache) + integrator.kshortsize = 7 + integrator.fsalfirst = cache.k1 + integrator.fsallast = cache.k7 # setup pointers + resize!(integrator.k, integrator.kshortsize) + # Setup k pointers + integrator.k[1] = cache.k1 + integrator.k[2] = cache.k2 + integrator.k[3] = cache.k3 + integrator.k[4] = cache.k4 + integrator.k[5] = cache.k5 + integrator.k[6] = cache.k6 + integrator.k[7] = cache.k7 + integrator.f(integrator.fsalfirst, integrator.uprev, integrator.p, integrator.t) # Pre-start fsal + integrator.stats.nf += 1 + return nothing +end + +@muladd function perform_step!(integrator, cache::Tsit5Cache, repeat_step = false) + @unpack t, dt, uprev, u, f, p = integrator + T = constvalue(recursive_unitless_bottom_eltype(u)) + T2 = constvalue(typeof(one(t))) + @OnDemandTableauExtract Tsit5ConstantCacheActual T T2 + @unpack k1, k2, k3, k4, k5, k6, k7, utilde, tmp, atmp, stage_limiter!, step_limiter!, thread = cache + a = dt * a21 + @.. broadcast=false thread=thread tmp=uprev + a * k1 + stage_limiter!(tmp, f, p, t + c1 * dt) + f(k2, tmp, p, t + c1 * dt) + @.. broadcast=false thread=thread tmp=uprev + dt * (a31 * k1 + a32 * k2) + stage_limiter!(tmp, f, p, t + c2 * dt) + f(k3, tmp, p, t + c2 * dt) + @.. broadcast=false thread=thread tmp=uprev + dt * (a41 * k1 + a42 * k2 + a43 * k3) + stage_limiter!(tmp, f, p, t + c3 * dt) + f(k4, tmp, p, t + c3 * dt) + @.. broadcast=false thread=thread tmp=uprev + + dt * (a51 * k1 + a52 * k2 + a53 * k3 + a54 * k4) + stage_limiter!(tmp, f, p, t + c4 * dt) + f(k5, tmp, p, t + c4 * dt) + @.. broadcast=false thread=thread tmp=uprev + + dt * (a61 * k1 + a62 * k2 + a63 * k3 + a64 * k4 + + a65 * k5) + stage_limiter!(tmp, f, p, t + dt) + f(k6, tmp, p, t + dt) + @.. broadcast=false thread=thread u=uprev + + dt * (a71 * k1 + a72 * k2 + a73 * k3 + a74 * k4 + + a75 * k5 + a76 * k6) + stage_limiter!(u, integrator, p, t + dt) + step_limiter!(u, integrator, p, t + dt) + f(k7, u, p, t + dt) + integrator.stats.nf += 6 + if integrator.alg isa CompositeAlgorithm + g7 = u + g6 = tmp + # Hairer II, page 22 modified to use Inf norm + @.. broadcast=false thread=thread utilde=abs((k7 - k6) / (g7 - g6)) + integrator.eigen_est = integrator.opts.internalnorm(norm(utilde, Inf), t) + end + if integrator.opts.adaptive + @.. broadcast=false thread=thread utilde=dt * (btilde1 * k1 + btilde2 * k2 + + btilde3 * k3 + btilde4 * k4 + + btilde5 * k5 + btilde6 * k6 + + btilde7 * k7) + calculate_residuals!(atmp, utilde, uprev, u, integrator.opts.abstol, + integrator.opts.reltol, integrator.opts.internalnorm, t, + thread) + integrator.EEst = integrator.opts.internalnorm(atmp, t) + end + return nothing +end \ No newline at end of file diff --git a/lib/OrdinaryDiffEqTsit5/src/tsit_tableaus.jl b/lib/OrdinaryDiffEqTsit5/src/tsit_tableaus.jl new file mode 100644 index 0000000000..dbfdbac5b2 --- /dev/null +++ b/lib/OrdinaryDiffEqTsit5/src/tsit_tableaus.jl @@ -0,0 +1,257 @@ +struct Tsit5ConstantCache <: OrdinaryDiffEqConstantCache end +struct Tsit5ConstantCacheActual{T, T2} + c1::T2 + c2::T2 + c3::T2 + c4::T2 + c5::T2 + c6::T2 + a21::T + a31::T + a32::T + a41::T + a42::T + a43::T + a51::T + a52::T + a53::T + a54::T + a61::T + a62::T + a63::T + a64::T + a65::T + a71::T + a72::T + a73::T + a74::T + a75::T + a76::T + btilde1::T + btilde2::T + btilde3::T + btilde4::T + btilde5::T + btilde6::T + btilde7::T +end + +@fold function Tsit5ConstantCacheActual(::Type{T}, + ::Type{T2}) where {T <: CompiledFloats, + T2 <: CompiledFloats} + c1 = convert(T2, 0.161) + c2 = convert(T2, 0.327) + c3 = convert(T2, 0.9) + c4 = convert(T2, 0.9800255409045097) + c5 = convert(T2, 1) + c6 = convert(T2, 1) + a21 = convert(T, 0.161) + a31 = convert(T, -0.008480655492356989) + a32 = convert(T, 0.335480655492357) + a41 = convert(T, 2.8971530571054935) + a42 = convert(T, -6.359448489975075) + a43 = convert(T, 4.3622954328695815) + a51 = convert(T, 5.325864828439257) + a52 = convert(T, -11.748883564062828) + a53 = convert(T, 7.4955393428898365) + a54 = convert(T, -0.09249506636175525) + a61 = convert(T, 5.86145544294642) + a62 = convert(T, -12.92096931784711) + a63 = convert(T, 8.159367898576159) + a64 = convert(T, -0.071584973281401) + a65 = convert(T, -0.028269050394068383) + a71 = convert(T, 0.09646076681806523) + a72 = convert(T, 0.01) + a73 = convert(T, 0.4798896504144996) + a74 = convert(T, 1.379008574103742) + a75 = convert(T, -3.290069515436081) + a76 = convert(T, 2.324710524099774) + # b1 = convert(T,0.09468075576583945) + # b2 = convert(T,0.009183565540343254) + # b3 = convert(T,0.4877705284247616) + # b4 = convert(T,1.234297566930479) + # b5 = convert(T,-2.7077123499835256) + # b6 = convert(T,1.866628418170587) + # b7 = convert(T,0.015151515151515152) + btilde1 = convert(T, -0.00178001105222577714) + btilde2 = convert(T, -0.0008164344596567469) + btilde3 = convert(T, 0.007880878010261995) + btilde4 = convert(T, -0.1447110071732629) + btilde5 = convert(T, 0.5823571654525552) + btilde6 = convert(T, -0.45808210592918697) + btilde7 = convert(T, 0.015151515151515152) + + Tsit5ConstantCacheActual( + c1, c2, c3, c4, c5, c6, a21, a31, a32, a41, a42, a43, a51, a52, + a53, + a54, a61, a62, a63, a64, a65, a71, a72, a73, a74, a75, a76, + btilde1, + btilde2, btilde3, btilde4, btilde5, btilde6, btilde7) +end + +@fold function Tsit5ConstantCacheActual(::Type{T}, ::Type{T2}) where {T, T2} + c1 = convert(T2, 161 // 1000) + c2 = convert(T2, 327 // 1000) + c3 = convert(T2, 9 // 10) + c4 = convert(T2, + big".9800255409045096857298102862870245954942137979563024768854764293221195950761080302604") + c5 = convert(T2, 1) + c6 = convert(T2, 1) + a21 = convert(T, 161 // 1000) + a31 = convert(T, + big"-.8480655492356988544426874250230774675121177393430391537369234245294192976164141156943e-2") + a32 = convert(T, + big".3354806554923569885444268742502307746751211773934303915373692342452941929761641411569") + a41 = convert(T, + big"2.897153057105493432130432594192938764924887287701866490314866693455023795137503079289") + a42 = convert(T, + big"-6.359448489975074843148159912383825625952700647415626703305928850207288721235210244366") + a43 = convert(T, + big"4.362295432869581411017727318190886861027813359713760212991062156752264926097707165077") + a51 = convert(T, + big"5.325864828439256604428877920840511317836476253097040101202360397727981648835607691791") + a52 = convert(T, + big"-11.74888356406282787774717033978577296188744178259862899288666928009020615663593781589") + a53 = convert(T, + big"7.495539342889836208304604784564358155658679161518186721010132816213648793440552049753") + a54 = convert(T, + big"-.9249506636175524925650207933207191611349983406029535244034750452930469056411389539635e-1") + a61 = convert(T, + big"5.861455442946420028659251486982647890394337666164814434818157239052507339770711679748") + a62 = convert(T, + big"-12.92096931784710929170611868178335939541780751955743459166312250439928519268343184452") + a63 = convert(T, + big"8.159367898576158643180400794539253485181918321135053305748355423955009222648673734986") + a64 = convert(T, + big"-.7158497328140099722453054252582973869127213147363544882721139659546372402303777878835e-1") + a65 = convert(T, + big"-.2826905039406838290900305721271224146717633626879770007617876201276764571291579142206e-1") + a71 = convert(T, + big".9646076681806522951816731316512876333711995238157997181903319145764851595234062815396e-1") + a72 = convert(T, 1 // 100) + a73 = convert(T, + big".4798896504144995747752495322905965199130404621990332488332634944254542060153074523509") + a74 = convert(T, + big"1.379008574103741893192274821856872770756462643091360525934940067397245698027561293331") + a75 = convert(T, + big"-3.290069515436080679901047585711363850115683290894936158531296799594813811049925401677") + a76 = convert(T, + big"2.324710524099773982415355918398765796109060233222962411944060046314465391054716027841") + # b1 = convert(T,big".9468075576583945807478876255758922856117527357724631226139574065785592789071067303271e-1") + # b2 = convert(T,big".9183565540343253096776363936645313759813746240984095238905939532922955247253608687270e-2") + # b3 = convert(T,big".4877705284247615707855642599631228241516691959761363774365216240304071651579571959813") + # b4 = convert(T,big"1.234297566930478985655109673884237654035539930748192848315425833500484878378061439761") + # b5 = convert(T,big"-2.707712349983525454881109975059321670689605166938197378763992255714444407154902012702") + # b6 = convert(T,big"1.866628418170587035753719399566211498666255505244122593996591602841258328965767580089") + # b7 = convert(T,1//66) + btilde1 = convert(T, + big"-1.780011052225771443378550607539534775944678804333659557637450799792588061629796e-03") + btilde2 = convert(T, + big"-8.164344596567469032236360633546862401862537590159047610940604670770447527463931e-04") + btilde3 = convert(T, + big"7.880878010261996010314727672526304238628733777103128603258129604952959142646516e-03") + btilde4 = convert(T, + big"-1.44711007173262907537165147972635116720922712343167677619514233896760819649515e-01") + btilde5 = convert(T, + big"5.823571654525552250199376106520421794260781239567387797673045438803694038950012e-01") + btilde6 = convert(T, + big"-4.580821059291869466616365188325542974428047279788398179474684434732070620889539e-01") + btilde7 = convert(T, 1 // 66) + + Tsit5ConstantCacheActual( + c1, c2, c3, c4, c5, c6, a21, a31, a32, a41, a42, a43, a51, a52, + a53, + a54, a61, a62, a63, a64, a65, a71, a72, a73, a74, a75, a76, + btilde1, + btilde2, btilde3, btilde4, btilde5, btilde6, btilde7) +end + +""" +Coefficients for the polynomial +bᵢΘ = ri1*Θ + ri2*Θ^2 + ri3*Θ^3 + ... + +These are the coefficients of the expanded form of the polynomials from + +Runge–Kutta pairs of order 5(4) satisfying only the first column +simplifying assumption + +Ch. Tsitouras +""" +@fold function Tsit5Interp(::Type{T}) where {T <: CompiledFloats} + r11 = convert(T, 1.0) + r12 = convert(T, -2.763706197274826) + r13 = convert(T, 2.9132554618219126) + r14 = convert(T, -1.0530884977290216) + + r22 = convert(T, 0.13169999999999998) + r23 = convert(T, -0.2234) + r24 = convert(T, 0.1017) + + r32 = convert(T, 3.9302962368947516) + r33 = convert(T, -5.941033872131505) + r34 = convert(T, 2.490627285651253) + + r42 = convert(T, -12.411077166933676) + r43 = convert(T, 30.33818863028232) + r44 = convert(T, -16.548102889244902) + + r52 = convert(T, 37.50931341651104) + r53 = convert(T, -88.1789048947664) + r54 = convert(T, 47.37952196281928) + + r62 = convert(T, -27.896526289197286) + r63 = convert(T, 65.09189467479366) + r64 = convert(T, -34.87065786149661) + + r72 = convert(T, 1.5) + r73 = convert(T, -4) + r74 = convert(T, 2.5) + + return r11, r12, r13, r14, r22, r23, r24, r32, r33, r34, r42, r43, r44, r52, r53, r54, + r62, r63, r64, r72, r73, r74 +end + +""" +Coefficients for the polynomial +bᵢΘ = ri1*Θ + ri2*Θ^2 + ri3*Θ^3 + ... + +These are the coefficients of the expanded form of the polynomials from + +Runge–Kutta pairs of order 5(4) satisfying only the first column +simplifying assumption + +Ch. Tsitouras +""" +@fold function Tsit5Interp(::Type{T}) where {T} + r11 = convert(T, big"0.999999999999999974283372471559910888475488471328") + r12 = convert(T, big"-2.763706197274825911336735930481400260916070804192") + r13 = convert(T, big"2.91325546182191274375068099306808") + r14 = convert(T, -1.0530884977290216) + + r22 = convert(T, big"0.13169999999999999727") + r23 = convert(T, big"-0.22339999999999999818") + r24 = convert(T, 0.1017) + + r32 = convert(T, big"3.93029623689475152850687446709813398") + r33 = convert(T, big"-5.94103387213150473470249202589458001") + r34 = convert(T, big"2.490627285651252793") + + r42 = convert(T, big"-12.411077166933676983734381540685453484102414134010752") + r43 = convert(T, big"30.3381886302823215981729903691836576") + r44 = convert(T, big"-16.54810288924490272") + + r52 = convert(T, big"37.50931341651103919496903965334519631242339792120440212") + r53 = convert(T, big"-88.1789048947664011014276693541209817") + r54 = convert(T, big"47.37952196281928122") + + r62 = convert(T, big"-27.896526289197287805948263144598643896") + r63 = convert(T, big"65.09189467479367152629021928716553658") + r64 = convert(T, big"-34.87065786149660974") + + r72 = convert(T, 1.5) + r73 = convert(T, -4) + r74 = convert(T, 2.5) + + return r11, r12, r13, r14, r22, r23, r24, r32, r33, r34, r42, r43, r44, r52, r53, r54, + r62, r63, r64, r72, r73, r74 +end \ No newline at end of file diff --git a/src/alg_utils.jl b/src/alg_utils.jl index 452dc44794..4bf302afb8 100644 --- a/src/alg_utils.jl +++ b/src/alg_utils.jl @@ -462,11 +462,6 @@ alg_order(alg::CNLF2) = 2 alg_order(alg::AN5) = 5 alg_order(alg::JVODE) = 1 #dummy value - -alg_order(alg::Alshina2) = 2 -alg_order(alg::Alshina3) = 3 -alg_order(alg::Alshina6) = 6 - alg_maximum_order(alg) = alg_order(alg) alg_maximum_order(alg::CompositeAlgorithm) = maximum(alg_order(x) for x in alg.algs) From f21324d29b64fedd183ee23e91b9734a02264c28 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Tue, 30 Jul 2024 22:19:18 +0530 Subject: [PATCH 008/133] added interpolants --- .../src/interp_func.jl | 6 + .../src/interpolants.jl | 1335 +++++++++++++ lib/OrdinaryDiffEqTsit5/src/interpolants.jl | 352 ++++ src/dense/interpolants.jl | 1676 +---------------- src/interp_func.jl | 6 - 5 files changed, 1694 insertions(+), 1681 deletions(-) create mode 100644 lib/OrdinaryDiffEqLowOrderRK/src/interpolants.jl create mode 100644 lib/OrdinaryDiffEqTsit5/src/interpolants.jl diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/interp_func.jl b/lib/OrdinaryDiffEqLowOrderRK/src/interp_func.jl index 8a5c3e26e0..16b40a63aa 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/interp_func.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/interp_func.jl @@ -16,6 +16,12 @@ function DiffEqBase.interp_summary(::Type{cacheType}, OwrenZen5ConstantCache}} dense ? "specialized 5th order \"free\" interpolation" : "1st order linear" end +function DiffEqBase.interp_summary(::Type{cacheType}, + dense::Bool) where { + cacheType <: + Union{DP5ConstantCache, DP5Cache}} + dense ? "specialized 4th order \"free\" interpolation" : "1st order linear" +end function DiffEqBase.interp_summary(::Type{cacheType}, dense::Bool) where { cacheType <: diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/interpolants.jl b/lib/OrdinaryDiffEqLowOrderRK/src/interpolants.jl new file mode 100644 index 0000000000..d6df06413e --- /dev/null +++ b/lib/OrdinaryDiffEqLowOrderRK/src/interpolants.jl @@ -0,0 +1,1335 @@ +RK_WITH_SPECIAL_INTERPOLATIONS = Union{ + DP5ConstantCache, DP5Cache, + OwrenZen3ConstantCache, OwrenZen3Cache, + OwrenZen4ConstantCache, OwrenZen4Cache, + OwrenZen5ConstantCache, OwrenZen5Cache, + BS5ConstantCache, BS5Cache +} + +function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::RK_WITH_SPECIAL_INTERPOLATIONS, + idxs, T::Type{Val{D}}, differential_vars) where {D} + throw(DerivativeOrderNotPossibleError()) +end + +function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::RK_WITH_SPECIAL_INTERPOLATIONS, + idxs, T::Type{Val{D}}, differential_vars) where {D} + throw(DerivativeOrderNotPossibleError()) +end + +""" +Hairer Norsett Wanner Solving Ordinary Differential Euations I - Nonstiff Problems Page 192 +""" + +@def dp5pre0 begin + b10 = Θ + b20 = Θ * (1 - Θ) + b30 = Θ * b20 + b40 = b20^2 +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, cache::DP5ConstantCache, idxs::Nothing, + T::Type{Val{0}}, differential_vars::Nothing) + @dp5pre0 + @inbounds y₀ + dt * (k[1] * b10 + k[2] * b20 + k[3] * b30 + k[4] * b40) +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, cache::DP5Cache, idxs::Nothing, + T::Type{Val{0}}, differential_vars::Nothing) + @dp5pre0 + @inbounds @.. broadcast=false y₀+dt * + (k[1] * b10 + k[2] * b20 + k[3] * b30 + k[4] * b40) +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{DP5ConstantCache, DP5Cache}, idxs, + T::Type{Val{0}}, differential_vars::Nothing) + @dp5pre0 + @views @.. broadcast=false y₀[idxs]+dt * (k[1][idxs] * b10 + k[2][idxs] * b20 + + k[3][idxs] * b30 + k[4][idxs] * b40) +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{DP5ConstantCache, DP5Cache}, idxs::Nothing, + T::Type{Val{0}}, differential_vars::Nothing) + @dp5pre0 + @inbounds @.. broadcast=false out=y₀ + + dt * + (k[1] * b10 + k[2] * b20 + k[3] * b30 + k[4] * b40) + out +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{DP5ConstantCache, DP5Cache}, idxs, + T::Type{Val{0}}, differential_vars::Nothing) + @dp5pre0 + @views @.. broadcast=false out=y₀[idxs] + + dt * + (k[1][idxs] * b10 + k[2][idxs] * b20 + k[3][idxs] * b30 + + k[4][idxs] * b40) + out +end + +@def dp5pre1 begin + b20diff = @evalpoly(Θ, 1, -2) + b30diff = Θ * @evalpoly(Θ, 2, -3) + b40diff = Θ * @evalpoly(Θ, 2, -6, 4) +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{DP5ConstantCache, DP5Cache}, idxs::Nothing, + T::Type{Val{1}}, differential_vars::Nothing) + @dp5pre1 + @inbounds @.. broadcast=false k[1]+k[2]*b20diff+k[3]*b30diff+k[4]*b40diff +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{DP5ConstantCache, DP5Cache}, idxs, + T::Type{Val{1}}, differential_vars::Nothing) + @dp5pre1 + @views @.. broadcast=false k[1][idxs]+k[2][idxs]*b20diff+k[3][idxs]*b30diff+ + k[4][idxs]*b40diff +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{DP5ConstantCache, DP5Cache}, idxs::Nothing, + T::Type{Val{1}}, differential_vars::Nothing) + @dp5pre1 + @inbounds @.. broadcast=false out=k[1] + k[2] * b20diff + k[3] * b30diff + + k[4] * b40diff + out +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{DP5ConstantCache, DP5Cache}, idxs, + T::Type{Val{1}}, differential_vars::Nothing) + @dp5pre1 + @views @.. broadcast=false out=k[1][idxs] + k[2][idxs] * b20diff + + k[3][idxs] * b30diff + k[4][idxs] * b40diff + out +end + +@def dp5pre2 begin + b20diff2 = -2 + b30diff2 = @evalpoly(Θ, 2, -6) + b40diff2 = @evalpoly(Θ, 2, -12, 12) + invdt = inv(dt) +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{DP5ConstantCache, DP5Cache}, idxs::Nothing, + T::Type{Val{2}}, differential_vars::Nothing) + @dp5pre2 + @inbounds @.. broadcast=false (k[2] * b20diff2 + k[3] * b30diff2 + + k[4] * b40diff2)*invdt +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{DP5ConstantCache, DP5Cache}, idxs, + T::Type{Val{2}}, differential_vars::Nothing) + @dp5pre2 + @views @.. broadcast=false (k[2][idxs] * b20diff2 + k[3][idxs] * b30diff2 + + k[4][idxs] * b40diff2)*invdt +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{DP5ConstantCache, DP5Cache}, idxs::Nothing, + T::Type{Val{2}}, differential_vars::Nothing) + @dp5pre2 + @inbounds @.. broadcast=false out=(k[2] * b20diff2 + k[3] * b30diff2 + + k[4] * b40diff2) * + invdt + out +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{DP5ConstantCache, DP5Cache}, idxs, + T::Type{Val{2}}, differential_vars::Nothing) + @dp5pre2 + @views @.. broadcast=false out=(k[2][idxs] * b20diff2 + k[3][idxs] * b30diff2 + + k[4][idxs] * b40diff2) * invdt + out +end + +@def dp5pre3 begin + b30diff3 = -6 + b40diff3 = @evalpoly(Θ, -12, 24) + invdt2 = inv(dt)^2 +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{DP5ConstantCache, DP5Cache}, idxs::Nothing, + T::Type{Val{3}}, differential_vars::Nothing) + @dp5pre3 + @inbounds @.. broadcast=false (k[3] * b30diff3 + k[4] * b40diff3)*invdt2 +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{DP5ConstantCache, DP5Cache}, idxs, + T::Type{Val{3}}, differential_vars::Nothing) + @dp5pre3 + @views @.. broadcast=false (k[3][idxs] * b30diff3 + k[4][idxs] * b40diff3)*invdt2 +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{DP5ConstantCache, DP5Cache}, idxs::Nothing, + T::Type{Val{3}}, differential_vars::Nothing) + @dp5pre3 + @inbounds @.. broadcast=false out=(k[3] * b30diff3 + k[4] * b40diff3) * invdt2 + out +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{DP5ConstantCache, DP5Cache}, idxs, + T::Type{Val{3}}, differential_vars::Nothing) + @dp5pre3 + @views @.. broadcast=false out=(k[3][idxs] * b30diff3 + k[4][idxs] * b40diff3) * invdt2 + out +end + +@def dp5pre4 begin + b40diff4invdt3 = 24 * inv(dt)^3 +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{DP5ConstantCache, DP5Cache}, idxs::Nothing, + T::Type{Val{4}}, differential_vars::Nothing) + @dp5pre4 + @inbounds @.. broadcast=false k[4]*b40diff4invdt3 +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{DP5ConstantCache, DP5Cache}, idxs, + T::Type{Val{4}}, differential_vars::Nothing) + @dp5pre4 + @views @.. broadcast=false k[4][idxs]*b40diff4invdt3 +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{DP5ConstantCache, DP5Cache}, idxs::Nothing, + T::Type{Val{4}}, differential_vars::Nothing) + @dp5pre4 + @inbounds @.. broadcast=false out=k[4] * b40diff4invdt3 + out +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{DP5ConstantCache, DP5Cache}, idxs, + T::Type{Val{4}}, differential_vars::Nothing) + @dp5pre4 + @views @.. broadcast=false out=k[4][idxs] * b40diff4invdt3 + out +end + +""" +""" +@def owrenzen3unpack begin + if cache isa OrdinaryDiffEqMutableCache + @unpack r13, r12, r23, r22, r33, r32 = cache.tab + else + @unpack r13, r12, r23, r22, r33, r32 = cache + end +end + +@def owrenzen3pre0 begin + @owrenzen3unpack + Θ² = Θ * Θ + b1Θ = Θ * @evalpoly(Θ, 1, r12, r13) + b2Θ = Θ² * @evalpoly(Θ, r22, r23) + b3Θ = Θ² * @evalpoly(Θ, r32, r33) + b4Θ = Θ² * @evalpoly(Θ, -1, 1) +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen3ConstantCache, OwrenZen3Cache}, + idxs::Nothing, T::Type{Val{0}}, differential_vars::Nothing) + @owrenzen3pre0 + @inbounds @.. broadcast=false y₀+dt * + (k[1] * b1Θ + k[2] * b2Θ + k[3] * b3Θ + k[4] * b4Θ) +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen3ConstantCache, OwrenZen3Cache}, + idxs, T::Type{Val{0}}, differential_vars::Nothing) + @owrenzen3pre0 + @views @.. broadcast=false y₀[idxs]+dt * (k[1][idxs] * b1Θ + k[2][idxs] * b2Θ + + k[3][idxs] * b3Θ + + k[4][idxs] * b4Θ) +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen3ConstantCache, OwrenZen3Cache}, + idxs::Nothing, T::Type{Val{0}}, differential_vars::Nothing) + @owrenzen3pre0 + @inbounds @.. broadcast=false out=y₀ + + dt * + (k[1] * b1Θ + k[2] * b2Θ + k[3] * b3Θ + k[4] * b4Θ) + out +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen3ConstantCache, OwrenZen3Cache}, + idxs, T::Type{Val{0}}, differential_vars::Nothing) + @owrenzen3pre0 + @views @.. broadcast=false out=y₀[idxs] + + dt * + (k[1][idxs] * b1Θ + k[2][idxs] * b2Θ + k[3][idxs] * b3Θ + + k[4][idxs] * b4Θ) + out +end + +@def owrenzen3pre1 begin + @owrenzen3unpack + b1Θdiff = @evalpoly(Θ, 1, 2*r12, 3*r13) + b2Θdiff = Θ * @evalpoly(Θ, 2*r22, 3*r23) + b3Θdiff = Θ * @evalpoly(Θ, 2*r32, 3*r33) + b4Θdiff = Θ * @evalpoly(Θ, -2, 3) +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen3ConstantCache, OwrenZen3Cache}, + idxs::Nothing, T::Type{Val{1}}, differential_vars::Nothing) + @owrenzen3pre1 + @inbounds @.. broadcast=false k[1]*b1Θdiff+k[2]*b2Θdiff+k[3]*b3Θdiff+k[4]*b4Θdiff +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen3ConstantCache, OwrenZen3Cache}, + idxs, T::Type{Val{1}}, differential_vars::Nothing) + @owrenzen3pre1 + @views @.. broadcast=false k[1][idxs]*b1Θdiff+k[2][idxs]*b2Θdiff+k[3][idxs]*b3Θdiff+ + k[4][idxs]*b4Θdiff +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen3ConstantCache, OwrenZen3Cache}, + idxs::Nothing, T::Type{Val{1}}, differential_vars::Nothing) + @owrenzen3pre1 + @inbounds @.. broadcast=false out=k[1] * b1Θdiff + k[2] * b2Θdiff + k[3] * b3Θdiff + + k[4] * b4Θdiff + out +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen3ConstantCache, OwrenZen3Cache}, + idxs, T::Type{Val{1}}, differential_vars::Nothing) + @owrenzen3pre1 + @views @.. broadcast=false out=k[1][idxs] * b1Θdiff + k[2][idxs] * b2Θdiff + + k[3][idxs] * b3Θdiff + k[4][idxs] * b4Θdiff + out +end + +@def owrenzen3pre2 begin + @owrenzen3unpack + b1Θdiff2 = @evalpoly(Θ, 2*r12, 6*r13) + b2Θdiff2 = @evalpoly(Θ, 2*r22, 6*r23) + b3Θdiff2 = @evalpoly(Θ, 2*r32, 6*r33) + b4Θdiff2 = @evalpoly(Θ, -2, 6) + invdt = inv(dt) +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen3ConstantCache, OwrenZen3Cache}, + idxs::Nothing, T::Type{Val{2}}, differential_vars::Nothing) + @owrenzen3pre2 + @inbounds @.. broadcast=false (k[1] * b1Θdiff2 + k[2] * b2Θdiff2 + k[3] * b3Θdiff2 + + k[4] * b4Θdiff2)*invdt +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen3ConstantCache, OwrenZen3Cache}, + idxs, T::Type{Val{2}}, differential_vars::Nothing) + @owrenzen3pre2 + @views @.. broadcast=false (k[1][idxs] * b1Θdiff2 + k[2][idxs] * b2Θdiff2 + + k[3][idxs] * b3Θdiff2 + k[4][idxs] * b4Θdiff2)*invdt +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen3ConstantCache, OwrenZen3Cache}, + idxs::Nothing, T::Type{Val{2}}, differential_vars::Nothing) + @owrenzen3pre2 + @inbounds @.. broadcast=false out=(k[1] * b1Θdiff2 + k[2] * b2Θdiff2 + k[3] * b3Θdiff2 + + k[4] * b4Θdiff2) * invdt + out +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen3ConstantCache, OwrenZen3Cache}, + idxs, T::Type{Val{2}}, differential_vars::Nothing) + @owrenzen3pre2 + @views @.. broadcast=false out=(k[1][idxs] * b1Θdiff2 + k[2][idxs] * b2Θdiff2 + + k[3][idxs] * b3Θdiff2 + k[4][idxs] * b4Θdiff2) * invdt + out +end + +@def owrenzen3pre3 begin + @owrenzen3unpack + b1Θdiff3 = 6 * r13 + b2Θdiff3 = 6 * r23 + b3Θdiff3 = 6 * r33 + b4Θdiff3 = 6 + invdt2 = inv(dt)^2 +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen3ConstantCache, OwrenZen3Cache}, + idxs::Nothing, T::Type{Val{3}}, differential_vars::Nothing) + @owrenzen3pre3 + @inbounds @.. broadcast=false (k[1] * b1Θdiff3 + k[2] * b2Θdiff3 + k[3] * b3Θdiff3 + + k[4] * b4Θdiff3)*invdt2 +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen3ConstantCache, OwrenZen3Cache}, + idxs, T::Type{Val{3}}, differential_vars::Nothing) + @owrenzen3pre3 + @views @.. broadcast=false (k[1][idxs] * b1Θdiff3 + k[2][idxs] * b2Θdiff3 + + k[3][idxs] * b3Θdiff3 + k[4][idxs] * b4Θdiff3)*invdt2 +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen3ConstantCache, OwrenZen3Cache}, + idxs::Nothing, T::Type{Val{3}}, differential_vars::Nothing) + @owrenzen3pre3 + @inbounds @.. broadcast=false out=(k[1] * b1Θdiff3 + k[2] * b2Θdiff3 + k[3] * b3Θdiff3 + + k[4] * b4Θdiff3) * invdt2 + out +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen3ConstantCache, OwrenZen3Cache}, + idxs, T::Type{Val{3}}, differential_vars::Nothing) + @owrenzen3pre3 + @views @.. broadcast=false out=(k[1][idxs] * b1Θdiff3 + k[2][idxs] * b2Θdiff3 + + k[3][idxs] * b3Θdiff3 + k[4][idxs] * b4Θdiff3) * invdt2 + out +end + +""" +""" +@def owrenzen4unpack begin + if cache isa OrdinaryDiffEqMutableCache + @unpack r14, r13, r12, r34, r33, r32, r44, r43, r42, r54, r53, r52, r64, r63, r62 = cache.tab + else + @unpack r14, r13, r12, r34, r33, r32, r44, r43, r42, r54, r53, r52, r64, r63, r62 = cache + end +end + +@def owrenzen4pre0 begin + @owrenzen4unpack + Θ² = Θ * Θ + b1Θ = Θ * @evalpoly(Θ, 1, r12, r13, r14) + b3Θ = Θ² * @evalpoly(Θ, r32, r33, r34) + b4Θ = Θ² * @evalpoly(Θ, r42, r43, r44) + b5Θ = Θ² * @evalpoly(Θ, r52, r53, r54) + b6Θ = Θ² * @evalpoly(Θ, r62, r63, r64) +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, + idxs::Nothing, T::Type{Val{0}}, differential_vars::Nothing) + @owrenzen4pre0 + # return @.. broadcast=false y₀ + dt*(k[1]*b1Θ + k[3]*b3Θ + k[4]*b4Θ + k[5]*b5Θ + k[6]*b6Θ) + return @inbounds y₀ + + dt * (k[1] * b1Θ + k[3] * b3Θ + k[4] * b4Θ + k[5] * b5Θ + k[6] * b6Θ) +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, + idxs, T::Type{Val{0}}, differential_vars::Nothing) + @owrenzen4pre0 + # return @.. broadcast=false y₀[idxs] + dt*(k[1][idxs]*b1Θ + k[3][idxs]*b3Θ + + # k[4][idxs]*b4Θ + k[5][idxs]*b5Θ + k[6][idxs]*b6Θ) + return y₀[idxs] + + dt * (k[1][idxs] * b1Θ + k[3][idxs] * b3Θ + + k[4][idxs] * b4Θ + k[5][idxs] * b5Θ + k[6][idxs] * b6Θ) +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, + idxs::Nothing, T::Type{Val{0}}, differential_vars::Nothing) + @owrenzen4pre0 + @inbounds @.. broadcast=false out=y₀ + + dt * + (k[1] * b1Θ + k[3] * b3Θ + k[4] * b4Θ + k[5] * b5Θ + + k[6] * b6Θ) + #@inbounds for i in eachindex(out) + # out[i] = y₀[i] + dt*(k[1][i]*b1Θ + k[3][i]*b3Θ + k[4][i]*b4Θ + + # k[5][i]*b5Θ + k[6][i]*b6Θ) + #end + out +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, + idxs, T::Type{Val{0}}, differential_vars::Nothing) + @owrenzen4pre0 + @inbounds @.. broadcast=false out=y₀[idxs] + + dt * (k[1][idxs] * b1Θ + k[3][idxs] * b3Θ + + k[4][idxs] * b4Θ + k[5][idxs] * b5Θ + + k[6][idxs] * b6Θ) + #@inbounds for (j,i) in enumerate(idxs) + # out[j] = y₀[i] + dt*(k[1][i]*b1Θ + k[3][i]*b3Θ + k[4][i]*b4Θ + + # k[5][i]*b5Θ + k[6][i]*b6Θ) + #end + out +end + +@def owrenzen4pre1 begin + @owrenzen4unpack + b1Θdiff = @evalpoly(Θ, 1, 2*r12, 3*r13, 4*r14) + b3Θdiff = Θ * @evalpoly(Θ, 2*r32, 3*r33, 4*r34) + b4Θdiff = Θ * @evalpoly(Θ, 2*r42, 3*r43, 4*r44) + b5Θdiff = Θ * @evalpoly(Θ, 2*r52, 3*r53, 4*r54) + b6Θdiff = Θ * @evalpoly(Θ, 2*r62, 3*r63, 4*r64) +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, + idxs::Nothing, T::Type{Val{1}}, differential_vars::Nothing) + @owrenzen4pre1 + @inbounds @.. broadcast=false k[1]*b1Θdiff+k[3]*b3Θdiff+k[4]*b4Θdiff+k[5]*b5Θdiff+ + k[6]*b6Θdiff +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, + idxs, T::Type{Val{1}}, differential_vars::Nothing) + @owrenzen4pre1 + @views @.. broadcast=false k[1][idxs]*b1Θdiff+k[3][idxs]*b3Θdiff+k[4][idxs]*b4Θdiff+ + k[5][idxs]*b5Θdiff+k[6][idxs]*b6Θdiff +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, + idxs::Nothing, T::Type{Val{1}}, differential_vars::Nothing) + @owrenzen4pre1 + @inbounds @.. broadcast=false out=k[1] * b1Θdiff + k[3] * b3Θdiff + k[4] * b4Θdiff + + k[5] * b5Θdiff + k[6] * b6Θdiff + out +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, + idxs, T::Type{Val{1}}, differential_vars::Nothing) + @owrenzen4pre1 + @views @.. broadcast=false out=k[1][idxs] * b1Θdiff + k[3][idxs] * b3Θdiff + + k[4][idxs] * b4Θdiff + + k[5][idxs] * b5Θdiff + k[6][idxs] * b6Θdiff + out +end + +@def owrenzen4pre2 begin + @owrenzen4unpack + b1Θdiff2 = @evalpoly(Θ, 2*r12, 6*r13, 12*r14) + b3Θdiff2 = @evalpoly(Θ, 2*r32, 6*r33, 12*r34) + b4Θdiff2 = @evalpoly(Θ, 2*r42, 6*r43, 12*r44) + b5Θdiff2 = @evalpoly(Θ, 2*r52, 6*r53, 12*r54) + b6Θdiff2 = @evalpoly(Θ, 2*r62, 6*r63, 12*r64) + invdt = inv(dt) +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, + idxs::Nothing, T::Type{Val{2}}, differential_vars::Nothing) + @owrenzen4pre2 + @.. broadcast=false (k[1] * b1Θdiff2 + k[3] * b3Θdiff2 + k[4] * b4Θdiff2 + + k[5] * b5Θdiff2 + k[6] * b6Θdiff2)*invdt +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, + idxs, T::Type{Val{2}}, differential_vars::Nothing) + @owrenzen4pre2 + @views @.. broadcast=false (k[1][idxs] * b1Θdiff2 + k[3][idxs] * b3Θdiff2 + + k[4][idxs] * b4Θdiff2 + + k[5][idxs] * b5Θdiff2 + k[6][idxs] * b6Θdiff2)*invdt +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, + idxs::Nothing, T::Type{Val{2}}, differential_vars::Nothing) + @owrenzen4pre2 + @inbounds @.. broadcast=false out=(k[1] * b1Θdiff2 + k[3] * b3Θdiff2 + k[4] * b4Θdiff2 + + k[5] * b5Θdiff2 + k[6] * b6Θdiff2) * invdt + out +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, + idxs, T::Type{Val{2}}, differential_vars::Nothing) + @owrenzen4pre2 + @views @.. broadcast=false out=(k[1][idxs] * b1Θdiff2 + k[3][idxs] * b3Θdiff2 + + k[4][idxs] * b4Θdiff2 + + k[5][idxs] * b5Θdiff2 + k[6][idxs] * b6Θdiff2) * invdt + out +end + +@def owrenzen4pre3 begin + @owrenzen4unpack + b1Θdiff3 = @evalpoly(Θ, 6*r13, 24*r14) + b3Θdiff3 = @evalpoly(Θ, 6*r33, 24*r34) + b4Θdiff3 = @evalpoly(Θ, 6*r43, 24*r44) + b5Θdiff3 = @evalpoly(Θ, 6*r53, 24*r54) + b6Θdiff3 = @evalpoly(Θ, 6*r63, 24*r64) + invdt2 = inv(dt)^2 +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, + idxs::Nothing, T::Type{Val{3}}, differential_vars::Nothing) + @owrenzen4pre3 + @inbounds @.. broadcast=false (k[1] * b1Θdiff3 + k[3] * b3Θdiff3 + k[4] * b4Θdiff3 + + k[5] * b5Θdiff3 + k[6] * b6Θdiff3)*invdt2 +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, + idxs, T::Type{Val{3}}, differential_vars::Nothing) + @owrenzen4pre3 + @views @.. broadcast=false (k[1][idxs] * b1Θdiff3 + k[3][idxs] * b3Θdiff3 + + k[4][idxs] * b4Θdiff3 + + k[5][idxs] * b5Θdiff3 + k[6][idxs] * b6Θdiff3)*invdt2 +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, + idxs::Nothing, T::Type{Val{3}}, differential_vars::Nothing) + @owrenzen4pre3 + @inbounds @.. broadcast=false out=(k[1] * b1Θdiff3 + k[3] * b3Θdiff3 + k[4] * b4Θdiff3 + + k[5] * b5Θdiff3 + k[6] * b6Θdiff3) * invdt2 + out +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, + idxs, T::Type{Val{3}}, differential_vars::Nothing) + @owrenzen4pre3 + @views @.. broadcast=false out=(k[1][idxs] * b1Θdiff3 + k[3][idxs] * b3Θdiff3 + + k[4][idxs] * b4Θdiff3 + + k[5][idxs] * b5Θdiff3 + k[6][idxs] * b6Θdiff3) * invdt2 + out +end + +@def owrenzen4pre4 begin + @owrenzen4unpack + b1Θdiff4 = 24 * r14 + b3Θdiff4 = 24 * r34 + b4Θdiff4 = 24 * r44 + b5Θdiff4 = 24 * r54 + b6Θdiff4 = 24 * r64 + invdt3 = inv(dt)^3 +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, + idxs::Nothing, T::Type{Val{4}}, differential_vars::Nothing) + @owrenzen4pre4 + @.. broadcast=false (k[1] * b1Θdiff4 + k[3] * b3Θdiff4 + k[4] * b4Θdiff4 + + k[5] * b5Θdiff4 + k[6] * b6Θdiff4)*invdt3 +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, + idxs, T::Type{Val{4}}, differential_vars::Nothing) + @owrenzen4pre4 + @views @.. broadcast=false (k[1][idxs] * b1Θdiff4 + k[3][idxs] * b3Θdiff4 + + k[4][idxs] * b4Θdiff4 + + k[5][idxs] * b5Θdiff4 + k[6][idxs] * b6Θdiff4)*invdt3 +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, + idxs::Nothing, T::Type{Val{4}}, differential_vars::Nothing) + @owrenzen4pre4 + @inbounds @.. broadcast=false out=(k[1] * b1Θdiff4 + k[3] * b3Θdiff4 + k[4] * b4Θdiff4 + + k[5] * b5Θdiff4 + k[6] * b6Θdiff4) * invdt3 + out +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, + idxs, T::Type{Val{4}}, differential_vars::Nothing) + @owrenzen4pre4 + @views @.. broadcast=false out=(k[1][idxs] * b1Θdiff4 + k[3][idxs] * b3Θdiff4 + + k[4][idxs] * b4Θdiff4 + + k[5][idxs] * b5Θdiff4 + k[6][idxs] * b6Θdiff4) * invdt3 + out +end + +""" +""" +@def owrenzen5unpack begin + if cache isa OrdinaryDiffEqMutableCache + @unpack r15, r14, r13, r12, r35, r34, r33, r32, r45, r44, r43, r42, r55, r54, r53, r52, r65, r64, r63, r62, r75, r74, r73, r72, r85, r84, r83, r82 = cache.tab + else + @unpack r15, r14, r13, r12, r35, r34, r33, r32, r45, r44, r43, r42, r55, r54, r53, r52, r65, r64, r63, r62, r75, r74, r73, r72, r85, r84, r83, r82 = cache + end +end + +@def owrenzen5pre0 begin + @owrenzen5unpack + Θ² = Θ * Θ + b1Θ = Θ * @evalpoly(Θ, 1, r12, r13, r14, r15) + b3Θ = Θ² * @evalpoly(Θ, r32, r33, r34, r35) + b4Θ = Θ² * @evalpoly(Θ, r42, r43, r44, r45) + b5Θ = Θ² * @evalpoly(Θ, r52, r53, r54, r55) + b6Θ = Θ² * @evalpoly(Θ, r62, r63, r64, r65) + b7Θ = Θ² * @evalpoly(Θ, r72, r73, r74, r75) + b8Θ = Θ² * @evalpoly(Θ, r82, r83, r84, r85) +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, + idxs::Nothing, T::Type{Val{0}}, differential_vars::Nothing) + @owrenzen5pre0 + # return @.. broadcast=false y₀ + dt*(k[1]*b1Θ + k[3]*b3Θ + k[4]*b4Θ + k[5]*b5Θ + k[6]*b6Θ + + # k[7]*b7Θ + k[8]*b8Θ) + return @inbounds y₀ + + dt * (k[1] * b1Θ + k[3] * b3Θ + k[4] * b4Θ + k[5] * b5Θ + k[6] * b6Θ + + k[7] * b7Θ + k[8] * b8Θ) +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, + idxs, T::Type{Val{0}}, differential_vars::Nothing) + @owrenzen5pre0 + # return @.. broadcast=false y₀[idxs] + dt*(k[1][idxs]*b1Θ + k[3][idxs]*b3Θ + + # k[4][idxs]*b4Θ + k[5][idxs]*b5Θ + k[6][idxs]*b6Θ + + # k[7][idxs]*b7Θ + k[8][idxs]*b8Θ) + return y₀[idxs] + + dt * (k[1][idxs] * b1Θ + k[3][idxs] * b3Θ + + k[4][idxs] * b4Θ + k[5][idxs] * b5Θ + k[6][idxs] * b6Θ + + k[7][idxs] * b7Θ + k[8][idxs] * b8Θ) +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, + idxs::Nothing, T::Type{Val{0}}, differential_vars::Nothing) + @owrenzen5pre0 + @inbounds @.. broadcast=false out=y₀ + + dt * + (k[1] * b1Θ + k[3] * b3Θ + k[4] * b4Θ + k[5] * b5Θ + + k[6] * b6Θ + + k[7] * b7Θ + k[8] * b8Θ) + #@inbounds for i in eachindex(out) + # out[i] = y₀[i] + dt*(k[1][i]*b1Θ + k[3][i]*b3Θ + k[4][i]*b4Θ + + # k[5][i]*b5Θ + k[6][i]*b6Θ + k[7][i]*b7Θ + k[8][i]*b8Θ) + #end + out +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, + idxs, T::Type{Val{0}}, differential_vars::Nothing) + @owrenzen5pre0 + @views @.. broadcast=false out=y₀[idxs] + + dt * (k[1][idxs] * b1Θ + k[3][idxs] * b3Θ + + k[4][idxs] * b4Θ + k[5][idxs] * b5Θ + k[6][idxs] * b6Θ + + k[7][idxs] * b7Θ + k[8][idxs] * b8Θ) + #@inbounds for (j,i) in enumerate(idxs) + # out[j] = y₀[i] + dt*(k[1][i]*b1Θ + k[3][i]*b3Θ + k[4][i]*b4Θ + + # k[5][i]*b5Θ + k[6][i]*b6Θ + k[7][i]*b7Θ + k[8][i]*b8Θ) + #end + out +end + +@def owrenzen5pre1 begin + @owrenzen5unpack + b1Θdiff = @evalpoly(Θ, 1, 2*r12, 3*r13, 4*r14, 5*r15) + b3Θdiff = Θ * @evalpoly(Θ, 2*r32, 3*r33, 4*r34, 5*r35) + b4Θdiff = Θ * @evalpoly(Θ, 2*r42, 3*r43, 4*r44, 5*r45) + b5Θdiff = Θ * @evalpoly(Θ, 2*r52, 3*r53, 4*r54, 5*r55) + b6Θdiff = Θ * @evalpoly(Θ, 2*r62, 3*r63, 4*r64, 5*r65) + b7Θdiff = Θ * @evalpoly(Θ, 2*r72, 3*r73, 4*r74, 5*r75) + b8Θdiff = Θ * @evalpoly(Θ, 2*r82, 3*r83, 4*r84, 5*r85) +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, + idxs::Nothing, T::Type{Val{1}}, differential_vars::Nothing) + @owrenzen5pre1 + return @inbounds k[1] * b1Θdiff + k[3] * b3Θdiff + k[4] * b4Θdiff + k[5] * b5Θdiff + + k[6] * b6Θdiff + k[7] * b7Θdiff + k[8] * b8Θdiff +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, + idxs, T::Type{Val{1}}, differential_vars::Nothing) + @owrenzen5pre1 + k[1][idxs] * b1Θdiff + k[3][idxs] * b3Θdiff + k[4][idxs] * b4Θdiff + + k[5][idxs] * b5Θdiff + + k[6][idxs] * b6Θdiff + k[7][idxs] * b7Θdiff + k[8][idxs] * b8Θdiff +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, + idxs::Nothing, T::Type{Val{1}}, differential_vars::Nothing) + @owrenzen5pre1 + @inbounds @.. broadcast=false out=k[1] * b1Θdiff + k[3] * b3Θdiff + k[4] * b4Θdiff + + k[5] * b5Θdiff + k[6] * b6Θdiff + k[7] * b7Θdiff + + k[8] * b8Θdiff + #@inbounds for i in eachindex(out) + # out[i] = k[1][i]*b1Θdiff + k[3][i]*b3Θdiff + k[4][i]*b4Θdiff + + # k[5][i]*b5Θdiff + k[6][i]*b6Θdiff + k[7][i]*b7Θdiff + k[8][i]*b8Θdiff + #end + out +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, + idxs, T::Type{Val{1}}, differential_vars::Nothing) + @owrenzen5pre1 + @views @.. broadcast=false out=k[1][idxs] * b1Θdiff + k[3][idxs] * b3Θdiff + + k[4][idxs] * b4Θdiff + + k[5][idxs] * b5Θdiff + k[6][idxs] * b6Θdiff + + k[7][idxs] * b7Θdiff + k[8][idxs] * b8Θdiff + #@inbounds for (j,i) in enumerate(idxs) + # out[j] = k[1][i]*b1Θdiff + k[3][i]*b3Θdiff + k[4][i]*b4Θdiff + + # k[5][i]*b5Θdiff + k[6][i]*b6Θdiff + k[7][i]*b7Θdiff + k[8][i]*b8Θdiff + #end + out +end + +@def owrenzen5pre2 begin + @owrenzen5unpack + b1Θdiff2 = @evalpoly(Θ, 2*r12, 6*r13, 12*r14, 20*r15) + b3Θdiff2 = @evalpoly(Θ, 2*r32, 6*r33, 12*r34, 20*r35) + b4Θdiff2 = @evalpoly(Θ, 2*r42, 6*r43, 12*r44, 20*r45) + b5Θdiff2 = @evalpoly(Θ, 2*r52, 6*r53, 12*r54, 20*r55) + b6Θdiff2 = @evalpoly(Θ, 2*r62, 6*r63, 12*r64, 20*r65) + b7Θdiff2 = @evalpoly(Θ, 2*r72, 6*r73, 12*r74, 20*r75) + b8Θdiff2 = @evalpoly(Θ, 2*r82, 6*r83, 12*r84, 20*r85) + invdt = inv(dt) +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, + idxs::Nothing, T::Type{Val{2}}, differential_vars::Nothing) + @owrenzen5pre2 + return @inbounds (k[1] * b1Θdiff2 + k[3] * b3Θdiff2 + k[4] * b4Θdiff2 + + k[5] * b5Θdiff2 + + k[6] * b6Θdiff2 + k[7] * b7Θdiff2 + k[8] * b8Θdiff2) * invdt +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, + idxs, T::Type{Val{2}}, differential_vars::Nothing) + @owrenzen5pre2 + (k[1][idxs] * b1Θdiff2 + k[3][idxs] * b3Θdiff2 + k[4][idxs] * b4Θdiff2 + + k[5][idxs] * b5Θdiff2 + + k[6][idxs] * b6Θdiff2 + k[7][idxs] * b7Θdiff2 + k[8][idxs] * b8Θdiff2) * invdt +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, + idxs::Nothing, T::Type{Val{2}}, differential_vars::Nothing) + @owrenzen5pre2 + @inbounds @.. broadcast=false out=(k[1] * b1Θdiff2 + k[3] * b3Θdiff2 + k[4] * b4Θdiff2 + + k[5] * b5Θdiff2 + k[6] * b6Θdiff2 + k[7] * b7Θdiff2 + + k[8] * b8Θdiff2) * invdt + #@inbounds for i in eachindex(out) + # out[i] = (k[1][i]*b1Θdiff2 + k[3][i]*b3Θdiff2 + k[4][i]*b4Θdiff2 + + # k[5][i]*b5Θdiff2 + k[6][i]*b6Θdiff2 + k[7][i]*b7Θdiff2 + k[8][i]*b8Θdiff2)*invdt + #end + out +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, + idxs, T::Type{Val{2}}, differential_vars::Nothing) + @owrenzen5pre2 + @views @.. broadcast=false out=(k[1][idxs] * b1Θdiff2 + k[3][idxs] * b3Θdiff2 + + k[4][idxs] * b4Θdiff2 + + k[5][idxs] * b5Θdiff2 + k[6][idxs] * b6Θdiff2 + + k[7][idxs] * b7Θdiff2 + k[8][idxs] * b8Θdiff2) * invdt + #@inbounds for (j,i) in enumerate(idxs) + # out[j] = (k[1][i]*b1Θdiff2 + k[3][i]*b3Θdiff2 + k[4][i]*b4Θdiff2 + + # k[5][i]*b5Θdiff2 + k[6][i]*b6Θdiff2 + k[7][i]*b7Θdiff2 + k[8][i]*b8Θdiff2)*invdt + #end + out +end + +@def owrenzen5pre3 begin + @owrenzen5unpack + b1Θdiff3 = @evalpoly(Θ, 6*r13, 24*r14, 60*r15) + b3Θdiff3 = @evalpoly(Θ, 6*r33, 24*r34, 60*r35) + b4Θdiff3 = @evalpoly(Θ, 6*r43, 24*r44, 60*r45) + b5Θdiff3 = @evalpoly(Θ, 6*r53, 24*r54, 60*r55) + b6Θdiff3 = @evalpoly(Θ, 6*r63, 24*r64, 60*r65) + b7Θdiff3 = @evalpoly(Θ, 6*r73, 24*r74, 60*r75) + b8Θdiff3 = @evalpoly(Θ, 6*r83, 24*r84, 60*r85) + invdt2 = inv(dt)^2 +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, + idxs::Nothing, T::Type{Val{3}}, differential_vars::Nothing) + @owrenzen5pre3 + return @inbounds (k[1] * b1Θdiff3 + k[3] * b3Θdiff3 + k[4] * b4Θdiff3 + + k[5] * b5Θdiff3 + + k[6] * b6Θdiff3 + k[7] * b7Θdiff3 + k[8] * b8Θdiff3) * invdt2 +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, + idxs, T::Type{Val{3}}, differential_vars::Nothing) + @owrenzen5pre3 + (k[1][idxs] * b1Θdiff3 + k[3][idxs] * b3Θdiff3 + k[4][idxs] * b4Θdiff3 + + k[5][idxs] * b5Θdiff3 + + k[6][idxs] * b6Θdiff3 + k[7][idxs] * b7Θdiff3 + k[8][idxs] * b8Θdiff3) * invdt2 +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, + idxs::Nothing, T::Type{Val{3}}, differential_vars::Nothing) + @owrenzen5pre3 + @inbounds @.. broadcast=false out=(k[1] * b1Θdiff3 + k[3] * b3Θdiff3 + k[4] * b4Θdiff3 + + k[5] * b5Θdiff3 + k[6] * b6Θdiff3 + k[7] * b7Θdiff3 + + k[8] * b8Θdiff3) * invdt2 + #@inbounds for i in eachindex(out) + # out[i] = (k[1][i]*b1Θdiff3 + k[3][i]*b3Θdiff3 + k[4][i]*b4Θdiff3 + + # k[5][i]*b5Θdiff3 + k[6][i]*b6Θdiff3 + k[7][i]*b7Θdiff3 + k[8][i]*b8Θdiff3)*invdt2 + #end + out +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, + idxs, T::Type{Val{3}}, differential_vars::Nothing) + @owrenzen5pre3 + @views @.. broadcast=false out=(k[1][idxs] * b1Θdiff3 + k[3][idxs] * b3Θdiff3 + + k[4][idxs] * b4Θdiff3 + + k[5][idxs] * b5Θdiff3 + k[6][idxs] * b6Θdiff3 + + k[7][idxs] * b7Θdiff3 + k[8][idxs] * b8Θdiff3) * invdt2 + #@inbounds for (j,i) in enumerate(idxs) + # out[j] = (k[1][i]*b1Θdiff3 + k[3][i]*b3Θdiff3 + k[4][i]*b4Θdiff3 + + # k[5][i]*b5Θdiff3 + k[6][i]*b6Θdiff3 + k[7][i]*b7Θdiff3 + k[8][i]*b8Θdiff3)*invdt2 + #end + out +end + +@def owrenzen5pre4 begin + @owrenzen5unpack + b1Θdiff4 = @evalpoly(Θ, 24*r14, 120*r15) + b3Θdiff4 = @evalpoly(Θ, 24*r34, 120*r35) + b4Θdiff4 = @evalpoly(Θ, 24*r44, 120*r45) + b5Θdiff4 = @evalpoly(Θ, 24*r54, 120*r55) + b6Θdiff4 = @evalpoly(Θ, 24*r64, 120*r65) + b7Θdiff4 = @evalpoly(Θ, 24*r74, 120*r75) + b8Θdiff4 = @evalpoly(Θ, 24*r84, 120*r85) + invdt3 = inv(dt)^3 +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, + idxs::Nothing, T::Type{Val{4}}, differential_vars::Nothing) + @owrenzen5pre4 + return @inbounds (k[1] * b1Θdiff4 + k[3] * b3Θdiff4 + k[4] * b4Θdiff4 + + k[5] * b5Θdiff4 + + k[6] * b6Θdiff4 + k[7] * b7Θdiff4 + k[8] * b8Θdiff4) * invdt3 +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, + idxs, T::Type{Val{4}}, differential_vars::Nothing) + @owrenzen5pre4 + (k[1][idxs] * b1Θdiff4 + k[3][idxs] * b3Θdiff4 + k[4][idxs] * b4Θdiff4 + + k[5][idxs] * b5Θdiff4 + + k[6][idxs] * b6Θdiff4 + k[7][idxs] * b7Θdiff4 + k[8][idxs] * b8Θdiff4) * invdt3 +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, + idxs::Nothing, T::Type{Val{4}}, differential_vars::Nothing) + @owrenzen5pre4 + @inbounds @.. broadcast=false out=(k[1] * b1Θdiff4 + k[3] * b3Θdiff4 + k[4] * b4Θdiff4 + + k[5] * b5Θdiff4 + k[6] * b6Θdiff4 + k[7] * b7Θdiff4 + + k[8] * b8Θdiff4) * invdt3 + #@inbounds for i in eachindex(out) + # out[i] = (k[1][i]*b1Θdiff4 + k[3][i]*b3Θdiff4 + k[4][i]*b4Θdiff4 + + # k[5][i]*b5Θdiff4 + k[6][i]*b6Θdiff4 + k[7][i]*b7Θdiff4 + k[8][i]*b8Θdiff4)*invdt3 + #end + out +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, + idxs, T::Type{Val{4}}, differential_vars::Nothing) + @owrenzen5pre4 + @views @.. broadcast=false out=(k[1][idxs] * b1Θdiff4 + k[3][idxs] * b3Θdiff4 + + k[4][idxs] * b4Θdiff4 + + k[5][idxs] * b5Θdiff4 + k[6][idxs] * b6Θdiff4 + + k[7][idxs] * b7Θdiff4 + k[8][idxs] * b8Θdiff4) * invdt3 + #@inbounds for (j,i) in enumerate(idxs) + # out[j] = (k[1][i]*b1Θdiff4 + k[3][i]*b3Θdiff4 + k[4][i]*b4Θdiff4 + + # k[5][i]*b5Θdiff4 + k[6][i]*b6Θdiff4 + k[7][i]*b7Θdiff4 + k[8][i]*b8Θdiff4)*invdt3 + #end + out +end + +@def owrenzen5pre5 begin + @owrenzen5unpack + b1Θdiff5 = 120 * r15 + b3Θdiff5 = 120 * r35 + b4Θdiff5 = 120 * r45 + b5Θdiff5 = 120 * r55 + b6Θdiff5 = 120 * r65 + b7Θdiff5 = 120 * r75 + b8Θdiff5 = 120 * r85 + invdt4 = inv(dt)^4 +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, + idxs::Nothing, T::Type{Val{5}}, differential_vars::Nothing) + @owrenzen5pre5 + return @inbounds (k[1] * b1Θdiff5 + k[3] * b3Θdiff5 + k[4] * b4Θdiff5 + + k[5] * b5Θdiff5 + + k[6] * b6Θdiff5 + k[7] * b7Θdiff5 + k[8] * b8Θdiff5) * invdt4 +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, + idxs, T::Type{Val{5}}, differential_vars::Nothing) + @owrenzen5pre5 + (k[1][idxs] * b1Θdiff5 + k[3][idxs] * b3Θdiff5 + k[4][idxs] * b4Θdiff5 + + k[5][idxs] * b5Θdiff5 + + k[6][idxs] * b6Θdiff5 + k[7][idxs] * b7Θdiff5 + k[8][idxs] * b8Θdiff5) * invdt4 +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, + idxs::Nothing, T::Type{Val{5}}, differential_vars::Nothing) + @owrenzen5pre5 + @inbounds @.. broadcast=false out=(k[1] * b1Θdiff5 + k[3] * b3Θdiff5 + k[4] * b4Θdiff5 + + k[5] * b5Θdiff5 + k[6] * b6Θdiff5 + k[7] * b7Θdiff5 + + k[8] * b8Θdiff5) * invdt4 + #@inbounds for i in eachindex(out) + # out[i] = (k[1][i]*b1Θdiff5 + k[3][i]*b3Θdiff5 + k[4][i]*b4Θdiff5 + + # k[5][i]*b5Θdiff5 + k[6][i]*b6Θdiff5 + k[7][i]*b7Θdiff5 + k[8][i]*b8Θdiff5)*invdt4 + #end + out +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, + idxs, T::Type{Val{5}}, differential_vars::Nothing) + @owrenzen5pre5 + @views @.. broadcast=false out=(k[1][idxs] * b1Θdiff5 + k[3][idxs] * b3Θdiff5 + + k[4][idxs] * b4Θdiff5 + + k[5][idxs] * b5Θdiff5 + k[6][idxs] * b6Θdiff5 + + k[7][idxs] * b7Θdiff5 + k[8][idxs] * b8Θdiff5) * invdt4 + #@inbounds for (j,i) in enumerate(idxs) + # out[j] = (k[1][i]*b1Θdiff5 + k[3][i]*b3Θdiff5 + k[4][i]*b4Θdiff5 + + # k[5][i]*b5Θdiff5 + k[6][i]*b6Θdiff5 + k[7][i]*b7Θdiff5 + k[8][i]*b8Θdiff5)*invdt4 + #end + out +end + +""" +Coefficients taken from RKSuite +""" +@def bs5unpack begin + if cache isa OrdinaryDiffEqMutableCache + @unpack r016, r015, r014, r013, r012, r036, r035, r034, r033, r032, r046, r045, r044, r043, r042, r056, r055, r054, r053, r052, r066, r065, r064, r063, r062, r076, r075, r074, r073, r072, r086, r085, r084, r083, r082, r096, r095, r094, r093, r106, r105, r104, r103, r102, r116, r115, r114, r113, r112 = cache.tab + else + @unpack r016, r015, r014, r013, r012, r036, r035, r034, r033, r032, r046, r045, r044, r043, r042, r056, r055, r054, r053, r052, r066, r065, r064, r063, r062, r076, r075, r074, r073, r072, r086, r085, r084, r083, r082, r096, r095, r094, r093, r106, r105, r104, r103, r102, r116, r115, r114, r113, r112 = cache + end +end + +@def bs5pre0 begin + @bs5unpack + Θ² = Θ * Θ + b1Θ = Θ² * @evalpoly(Θ, r012, r013, r014, r015, r016) + b3Θ = Θ² * @evalpoly(Θ, r032, r033, r034, r035, r036) + b4Θ = Θ² * @evalpoly(Θ, r042, r043, r044, r045, r046) + b5Θ = Θ² * @evalpoly(Θ, r052, r053, r054, r055, r056) + b6Θ = Θ² * @evalpoly(Θ, r062, r063, r064, r065, r066) + b7Θ = Θ² * @evalpoly(Θ, r072, r073, r074, r075, r076) + b8Θ = Θ² * @evalpoly(Θ, r082, r083, r084, r085, r086) + b9Θ = (Θ² * Θ) * @evalpoly(Θ, r093, r094, r095, + r096) + b10Θ = Θ² * @evalpoly(Θ, r102, r103, r104, r105, r106) + b11Θ = Θ² * @evalpoly(Θ, r112, r113, r114, r115, r116) +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, cache::BS5ConstantCache, idxs::Nothing, + T::Type{Val{0}}, differential_vars::Nothing) + @bs5pre0 + # return @.. broadcast=false y₀ + dt*Θ*k[1] + dt*(k[1]*b1Θ + k[3]*b3Θ + k[4]*b4Θ + k[5]*b5Θ + k[6]*b6Θ + k[7]*b7Θ + k[8]*b8Θ + k[9]*b9Θ + k[10]*b10Θ + k[11]*b11Θ) + return @inbounds y₀ + dt * Θ * k[1] + + dt * (k[1] * b1Θ + k[3] * b3Θ + k[4] * b4Θ + k[5] * b5Θ + + k[6] * b6Θ + k[7] * b7Θ + k[8] * b8Θ + k[9] * b9Θ + k[10] * b10Θ + + k[11] * b11Θ) +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, cache::BS5Cache, idxs::Nothing, + T::Type{Val{0}}, differential_vars::Nothing) + @bs5pre0 + # return @.. broadcast=false y₀ + dt*Θ*k[1] + dt*(k[1]*b1Θ + k[3]*b3Θ + k[4]*b4Θ + k[5]*b5Θ + k[6]*b6Θ + k[7]*b7Θ + k[8]*b8Θ + k[9]*b9Θ + k[10]*b10Θ + k[11]*b11Θ) + return @inbounds @.. broadcast=false y₀+dt*Θ*k[1]+ + dt*(k[1] * b1Θ + k[3] * b3Θ + k[4] * b4Θ + + k[5] * b5Θ + + k[6] * b6Θ + k[7] * b7Θ + k[8] * b8Θ + + k[9] * b9Θ + k[10] * b10Θ + k[11] * b11Θ) +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{BS5ConstantCache, BS5Cache}, idxs, + T::Type{Val{0}}, differential_vars::Nothing) + @bs5pre0 + # return @.. broadcast=false y₀[idxs] + dt*Θ*k[1][idxs] + dt*(k[1][idxs]*b1Θ + k[3][idxs]*b3Θ + + # k[4][idxs]*b4Θ + k[5][idxs]*b5Θ + k[6][idxs]*b6Θ + k[7][idxs]*b7Θ + + # k[8][idxs]*b8Θ + k[9][idxs]*b9Θ + k[10][idxs]*b10Θ + k[11][idxs]*b11Θ) + return y₀[idxs] + dt * Θ * k[1][idxs] + + dt * (k[1][idxs] * b1Θ + k[3][idxs] * b3Θ + + k[4][idxs] * b4Θ + k[5][idxs] * b5Θ + k[6][idxs] * b6Θ + k[7][idxs] * b7Θ + + k[8][idxs] * b8Θ + k[9][idxs] * b9Θ + k[10][idxs] * b10Θ + k[11][idxs] * b11Θ) +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{BS5ConstantCache, BS5Cache}, idxs::Nothing, + T::Type{Val{0}}, differential_vars::Nothing) + @bs5pre0 + @inbounds @.. broadcast=false out=y₀ + dt * Θ * k[1] + + dt * + (k[1] * b1Θ + k[3] * b3Θ + k[4] * b4Θ + k[5] * b5Θ + + k[6] * b6Θ + k[7] * b7Θ + k[8] * b8Θ + k[9] * b9Θ + + k[10] * b10Θ + k[11] * b11Θ) + #@inbounds for i in eachindex(out) + # out[i] = y₀[i] + dt*Θ*k[1][i] + dt*(k[1][i]*b1Θ + k[3][i]*b3Θ + k[4][i]*b4Θ + k[5][i]*b5Θ + k[6][i]*b6Θ + k[7][i]*b7Θ + k[8][i]*b8Θ + k[9][i]*b9Θ + k[10][i]*b10Θ + k[11][i]*b11Θ) + #end + out +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{BS5ConstantCache, BS5Cache}, idxs, + T::Type{Val{0}}, differential_vars::Nothing) + @bs5pre0 + @views @.. broadcast=false out=y₀[idxs] + dt * Θ * k[1][idxs] + + dt * + (k[1][idxs] * b1Θ + k[3][idxs] * b3Θ + k[4][idxs] * b4Θ + + k[5][idxs] * b5Θ + k[6][idxs] * b6Θ + k[7][idxs] * b7Θ + + k[8][idxs] * b8Θ + k[9][idxs] * b9Θ + + k[10][idxs] * b10Θ + k[11][idxs] * b11Θ) + #@inbounds for (j,i) in enumerate(idxs) + # out[j] = y₀[i] + dt*Θ*k[1][i] + dt*(k[1][i]*b1Θ + k[3][i]*b3Θ + k[4][i]*b4Θ + k[5][i]*b5Θ + k[6][i]*b6Θ + k[7][i]*b7Θ + k[8][i]*b8Θ + k[9][i]*b9Θ + k[10][i]*b10Θ + k[11][i]*b11Θ) + #end + out +end + +@def bs5pre1 begin + @bs5unpack + Θ² = Θ * Θ + b1Θdiff = Θ * @evalpoly(Θ, 2*r012, 3*r013, 4*r014, 5*r015, 6*r016) + b3Θdiff = Θ * @evalpoly(Θ, 2*r032, 3*r033, 4*r034, 5*r035, 6*r036) + b4Θdiff = Θ * @evalpoly(Θ, 2*r042, 3*r043, 4*r044, 5*r045, 6*r046) + b5Θdiff = Θ * @evalpoly(Θ, 2*r052, 3*r053, 4*r054, 5*r055, 6*r056) + b6Θdiff = Θ * @evalpoly(Θ, 2*r062, 3*r063, 4*r064, 5*r065, 6*r066) + b7Θdiff = Θ * @evalpoly(Θ, 2*r072, 3*r073, 4*r074, 5*r075, 6*r076) + b8Θdiff = Θ * @evalpoly(Θ, 2*r082, 3*r083, 4*r084, 5*r085, 6*r086) + b9Θdiff = Θ² * @evalpoly(Θ, 3*r093, 4*r094, 5*r095, 6*r096) + b10Θdiff = Θ * @evalpoly(Θ, 2*r102, 3*r103, 4*r104, 5*r105, 6*r106) + b11Θdiff = Θ * @evalpoly(Θ, 2*r112, 3*r113, 4*r114, 5*r115, 6*r116) +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{BS5ConstantCache, BS5Cache}, idxs::Nothing, + T::Type{Val{1}}, differential_vars::Nothing) + @bs5pre1 + # return @.. broadcast=false k[1] + k[1]*b1Θdiff + k[3]*b3Θdiff + k[4]*b4Θdiff + k[5]*b5Θdiff + k[6]*b6Θdiff + k[7]*b7Θdiff + k[8]*b8Θdiff + k[9]*b9Θdiff + k[10]*b10Θdiff + k[11]*b11Θdiff + return @inbounds k[1] + k[1] * b1Θdiff + k[3] * b3Θdiff + k[4] * b4Θdiff + + k[5] * b5Θdiff + + k[6] * b6Θdiff + k[7] * b7Θdiff + k[8] * b8Θdiff + k[9] * b9Θdiff + + k[10] * b10Θdiff + k[11] * b11Θdiff +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{BS5ConstantCache, BS5Cache}, idxs, + T::Type{Val{1}}, differential_vars::Nothing) + @bs5pre1 + # return @.. broadcast=false k[1][idxs] + k[1][idxs]*b1Θdiff + k[3][idxs]*b3Θdiff + + # k[4][idxs]*b4Θdiff + k[5][idxs]*b5Θdiff + k[6][idxs]*b6Θdiff + + # k[7][idxs]*b7Θdiff + k[8][idxs]*b8Θdiff + k[9][idxs]*b9Θdiff + + # k[10][idxs]*b10Θdiff + k[11][idxs]*b11Θdiff + return @inbounds k[1][idxs] + k[1][idxs] * b1Θdiff + k[3][idxs] * b3Θdiff + + k[4][idxs] * b4Θdiff + k[5][idxs] * b5Θdiff + k[6][idxs] * b6Θdiff + + k[7][idxs] * b7Θdiff + k[8][idxs] * b8Θdiff + k[9][idxs] * b9Θdiff + + k[10][idxs] * b10Θdiff + k[11][idxs] * b11Θdiff +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{BS5ConstantCache, BS5Cache}, idxs::Nothing, + T::Type{Val{1}}, differential_vars::Nothing) + @bs5pre1 + @inbounds @.. broadcast=false out=k[1] + k[1] * b1Θdiff + k[3] * b3Θdiff + + k[4] * b4Θdiff + k[5] * b5Θdiff + k[6] * b6Θdiff + + k[7] * b7Θdiff + k[8] * b8Θdiff + k[9] * b9Θdiff + + k[10] * b10Θdiff + k[11] * b11Θdiff + #@inbounds for i in eachindex(out) + # out[i] = k[1][i] + k[1][i]*b1Θdiff + k[3][i]*b3Θdiff + k[4][i]*b4Θdiff + k[5][i]*b5Θdiff + k[6][i]*b6Θdiff + k[7][i]*b7Θdiff + k[8][i]*b8Θdiff + k[9][i]*b9Θdiff + k[10][i]*b10Θdiff + k[11][i]*b11Θdiff + #end + out +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{BS5ConstantCache, BS5Cache}, idxs, + T::Type{Val{1}}, differential_vars::Nothing) + @bs5pre1 + @views @.. broadcast=false out=k[1][idxs] + k[1][idxs] * b1Θdiff + + k[3][idxs] * b3Θdiff + k[4][idxs] * b4Θdiff + + k[5][idxs] * b5Θdiff + k[6][idxs] * b6Θdiff + + k[7][idxs] * b7Θdiff + k[8][idxs] * b8Θdiff + + k[9][idxs] * b9Θdiff + k[10][idxs] * b10Θdiff + + k[11][idxs] * b11Θdiff + #@inbounds for (j,i) in enumerate(idxs) + # out[j] = k[1][i] + k[1][i]*b1Θdiff + k[3][i]*b3Θdiff + k[4][i]*b4Θdiff + k[5][i]*b5Θdiff + k[6][i]*b6Θdiff + k[7][i]*b7Θdiff + k[8][i]*b8Θdiff + k[9][i]*b9Θdiff + k[10][i]*b10Θdiff + k[11][i]*b11Θdiff + #end + out +end + +""" +""" +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{DP8ConstantCache, DP8Cache}, idxs::Nothing, + T::Type{Val{0}}, differential_vars::Nothing) + Θ1 = 1 - Θ + # return @.. broadcast=false y₀ + dt*Θ*(k[1] + Θ1*(k[2] + Θ*(k[3]+Θ1*(k[4] + Θ*(k[5] + Θ1*(k[6]+Θ*k[7])))))) + return @inbounds y₀ + + dt * Θ * + (k[1] + + Θ1 * (k[2] + + Θ * (k[3] + Θ1 * (k[4] + Θ * (k[5] + Θ1 * (k[6] + Θ * k[7])))))) +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{DP8ConstantCache, DP8Cache}, idxs, + T::Type{Val{0}}, differential_vars::Nothing) + Θ1 = 1 - Θ + # return @.. broadcast=false y₀[idxs] + dt*Θ*(k[1][idxs] + Θ1*(k[2][idxs] + Θ*(k[3][idxs]+Θ1*(k[4][idxs] + Θ*(k[5][idxs] + Θ1*(k[6][idxs]+Θ*k[7][idxs])))))) + return y₀[idxs] + + dt * Θ * + (k[1][idxs] + + Θ1 * (k[2][idxs] + + Θ * (k[3][idxs] + + Θ1 * (k[4][idxs] + Θ * (k[5][idxs] + Θ1 * (k[6][idxs] + Θ * k[7][idxs])))))) +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{DP8ConstantCache, DP8Cache}, idxs::Nothing, + T::Type{Val{0}}, differential_vars::Nothing) + Θ1 = 1 - Θ + @inbounds @.. broadcast=false out=y₀ + + dt * Θ * + (k[1] + + Θ1 * (k[2] + + Θ * (k[3] + + Θ1 * + (k[4] + Θ * (k[5] + Θ1 * (k[6] + Θ * k[7])))))) + #@inbounds for i in eachindex(out) + # out[i] = y₀[i] + dt*Θ*(k[1][i] + Θ1*(k[2][i] + Θ*(k[3][i]+Θ1*(k[4][i] + Θ*(k[5][i] + Θ1*(k[6][i]+Θ*k[7][i])))))) + #end + out +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{DP8ConstantCache, DP8Cache}, idxs, + T::Type{Val{0}}, differential_vars::Nothing) + Θ1 = 1 - Θ + @views @.. broadcast=false out=y₀[idxs] + + dt * Θ * + (k[1][idxs] + + Θ1 * (k[2][idxs] + + Θ * (k[3][idxs] + + Θ1 * (k[4][idxs] + + Θ * + (k[5][idxs] + Θ1 * (k[6][idxs] + Θ * k[7][idxs])))))) + #@inbounds for (j,i) in enumerate(idxs) + # out[j] = y₀[i] + dt*Θ*(k[1][i] + Θ1*(k[2][i] + Θ*(k[3][i]+Θ1*(k[4][i] + Θ*(k[5][i] + Θ1*(k[6][i]+Θ*k[7][i])))))) + #end + out +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{DP8ConstantCache, DP8Cache}, idxs::Nothing, + T::Type{Val{1}}, differential_vars::Nothing) + @inbounds b1diff = @.. broadcast=false k[1]+k[2] + @inbounds b2diff = @.. broadcast=false -2*k[2]+2*k[3]+2*k[4] + @inbounds b3diff = @.. broadcast=false -3 * k[3]-6 * k[4]+3*k[5]+3*k[6] + @inbounds b4diff = @.. broadcast=false 4 * k[4] - 8 * k[5] - 12 * k[6]+4 * k[7] + @inbounds b5diff = @.. broadcast=false 5 * k[5] + 15 * k[6]-15 * k[7] + @inbounds b6diff = @.. broadcast=false -6 * k[6]+18 * k[7] + @inbounds b7diff = @.. broadcast=false -7*k[7] + # return @.. broadcast=false b1diff + Θ*(b2diff + Θ*(b3diff + Θ*(b4diff + Θ*(b5diff + Θ*(b6diff + Θ*b7diff))))) + return b1diff + + Θ * + (b2diff + Θ * (b3diff + Θ * (b4diff + Θ * (b5diff + Θ * (b6diff + Θ * b7diff))))) +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{DP8ConstantCache, DP8Cache}, idxs, + T::Type{Val{1}}, differential_vars::Nothing) + b1diff = @.. broadcast=false k[1][idxs]+k[2][idxs] + b2diff = @.. broadcast=false -2*k[2][idxs]+2*k[3][idxs]+2*k[4][idxs] + b3diff = @.. broadcast=false -3 * k[3][idxs]-6 * k[4][idxs]+3*k[5][idxs]+3*k[6][idxs] + b4diff = @.. broadcast=false 4 * k[4][idxs] - 8 * k[5][idxs] - + 12 * k[6][idxs]+4 * k[7][idxs] + b5diff = @.. broadcast=false 5 * k[5][idxs] + 15 * k[6][idxs]-15 * k[7][idxs] + b6diff = @.. broadcast=false -6 * k[6][idxs]+18 * k[7][idxs] + b7diff = @.. broadcast=false -7*k[7][idxs] + # return @.. broadcast=false b1diff + Θ*(b2diff + Θ*(b3diff + Θ*(b4diff + Θ*(b5diff + Θ*(b6diff + Θ*b7diff))))) + return b1diff + + Θ * + (b2diff + Θ * (b3diff + Θ * (b4diff + Θ * (b5diff + Θ * (b6diff + Θ * b7diff))))) +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{DP8ConstantCache, DP8Cache}, idxs::Nothing, + T::Type{Val{1}}, differential_vars::Nothing) + # b1diff = k[1] + k[2] + # b2diff = -2*k[2] + 2*k[3] + 2*k[4] + # b3diff = -3*k[3] - 6*k[4] + 3*k[5] + 3*k[6] + # b4diff = 4*k[4] - 8*k[5] - 12*k[6] + 4*k[7] + # b5diff = 5*k[5] + 15*k[6] - 15*k[7] + # b6diff = -6*k[6] + 18*k[7] + # @.. broadcast=false out = b1diff + Θ*(b2diff + Θ*(b3diff + Θ*(b4diff + + # Θ*(b5diff + Θ*(b6diff - 7*k[7]*Θ))))) + @views @.. broadcast=false out=k[1] + k[2] + + Θ * (-2 * k[2] + 2 * k[3] + 2 * k[4] + + Θ * (-3 * k[3] - 6 * k[4] + 3 * k[5] + 3 * k[6] + + Θ * (4 * k[4] - 8 * k[5] - 12 * k[6] + 4 * k[7] + + Θ * (5 * k[5] + 15 * k[6] - 15 * k[7] + + Θ * (-6 * k[6] + 18 * k[7] - 7 * k[7] * Θ))))) + out +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{DP8ConstantCache, DP8Cache}, idxs, + T::Type{Val{1}}, differential_vars::Nothing) + # b1diff = k[1][idxs] + k[2][idxs] + # b2diff = -2*k[2][idxs] + 2*k[3][idxs] + 2*k[4][idxs] + # b3diff = -3*k[3][idxs] - 6*k[4][idxs] + 3*k[5][idxs] + 3*k[6][idxs] + # b4diff = 4*k[4][idxs] - 8*k[5][idxs] - 12*k[6][idxs] + 4*k[7][idxs] + # b5diff = 5*k[5][idxs] + 15*k[6][idxs] - 15*k[7][idxs] + # b6diff = -6*k[6][idxs] + 18*k[7][idxs] + #@views @.. broadcast=false out = b1diff + Θ*(b2diff + Θ*(b3diff + Θ*(b4diff + + # Θ*(b5diff + Θ*(b6diff - 7*k[7][idxs]*Θ))))) + @views @.. broadcast=false out=k[1][idxs] + k[2][idxs] + + Θ * (-2 * k[2][idxs] + 2 * k[3][idxs] + 2 * k[4][idxs] + + Θ * + (-3 * k[3][idxs] - 6 * k[4][idxs] + 3 * k[5][idxs] + + 3 * k[6][idxs] + + Θ * + (4 * k[4][idxs] - 8 * k[5][idxs] - 12 * k[6][idxs] + + 4 * k[7][idxs] + + Θ * + (5 * k[5][idxs] + 15 * k[6][idxs] - 15 * k[7][idxs] + + Θ * (-6 * k[6][idxs] + 18 * k[7][idxs] - + 7 * k[7][idxs] * Θ))))) + out +end + +""" +""" \ No newline at end of file diff --git a/lib/OrdinaryDiffEqTsit5/src/interpolants.jl b/lib/OrdinaryDiffEqTsit5/src/interpolants.jl new file mode 100644 index 0000000000..8d02bac703 --- /dev/null +++ b/lib/OrdinaryDiffEqTsit5/src/interpolants.jl @@ -0,0 +1,352 @@ +RK_WITH_SPECIAL_INTERPOLATIONS = Union{Tsit5ConstantCache, Tsit5Cache} + +function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::RK_WITH_SPECIAL_INTERPOLATIONS, + idxs, T::Type{Val{D}}, differential_vars) where {D} + throw(DerivativeOrderNotPossibleError()) +end + +function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::RK_WITH_SPECIAL_INTERPOLATIONS, + idxs, T::Type{Val{D}}, differential_vars) where {D} + throw(DerivativeOrderNotPossibleError()) +end + +""" +Runge–Kutta pairs of order 5(4) satisfying only the first column +simplifying assumption + +Ch. Tsitouras +""" +@def tsit5unpack begin + var"#T#" = constvalue(recursive_unitless_bottom_eltype(y₁)) + r11, r12, r13, r14, r22, r23, r24, r32, r33, r34, r42, r43, r44, r52, r53, r54, r62, r63, r64, r72, r73, r74 = Tsit5Interp(var"#T#") +end + +@def tsit5pre0 begin + @tsit5unpack + Θ² = Θ * Θ + b1Θ = Θ * @evalpoly(Θ, r11, r12, r13, r14) + b2Θ = Θ² * @evalpoly(Θ, r22, r23, r24) + b3Θ = Θ² * @evalpoly(Θ, r32, r33, r34) + b4Θ = Θ² * @evalpoly(Θ, r42, r43, r44) + b5Θ = Θ² * @evalpoly(Θ, r52, r53, r54) + b6Θ = Θ² * @evalpoly(Θ, r62, r63, r64) + b7Θ = Θ² * @evalpoly(Θ, r72, r73, r74) +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, cache::Tsit5ConstantCache, + idxs::Nothing, T::Type{Val{0}}, differential_vars::Nothing) + @tsit5pre0 + #@.. broadcast=false y₀ + dt*(k[1]*b1Θ + k[2]*b2Θ + k[3]*b3Θ + k[4]*b4Θ + k[5]*b5Θ + k[6]*b6Θ + k[7]*b7Θ) + return @inbounds y₀ + + dt * (k[1] * b1Θ + k[2] * b2Θ + k[3] * b3Θ + k[4] * b4Θ + + k[5] * b5Θ + k[6] * b6Θ + k[7] * b7Θ) +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, cache::Tsit5Cache, idxs::Nothing, + T::Type{Val{0}}, differential_vars::Nothing) + @tsit5pre0 + return @inbounds @.. broadcast=false y₀+dt * (k[1] * b1Θ + k[2] * b2Θ + k[3] * b3Θ + + k[4] * b4Θ + + k[5] * b5Θ + k[6] * b6Θ + k[7] * b7Θ) +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{Tsit5ConstantCache, Tsit5Cache}, idxs, + T::Type{Val{0}}, differential_vars::Nothing) + @tsit5pre0 + return y₀[idxs] + + dt * (k[1][idxs] * b1Θ + k[2][idxs] * b2Θ + k[3][idxs] * b3Θ + + k[4][idxs] * b4Θ + k[5][idxs] * b5Θ + k[6][idxs] * b6Θ + k[7][idxs] * b7Θ) +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{Tsit5ConstantCache, Tsit5Cache}, + idxs::Nothing, T::Type{Val{0}}, differential_vars::Nothing) + @tsit5pre0 + @inbounds @.. broadcast=false out=y₀ + + dt * + (k[1] * b1Θ + k[2] * b2Θ + k[3] * b3Θ + k[4] * b4Θ + + k[5] * b5Θ + k[6] * b6Θ + k[7] * b7Θ) + out +end + +@muladd function _ode_interpolant!(out::Array, Θ, dt, y₀, y₁, k, + cache::Union{Tsit5ConstantCache, Tsit5Cache}, + idxs::Nothing, T::Type{Val{0}}, differential_vars::Nothing) + @tsit5pre0 + @inbounds @simd ivdep for i in eachindex(out) + out[i] = y₀[i] + + dt * (k[1][i] * b1Θ + k[2][i] * b2Θ + k[3][i] * b3Θ + k[4][i] * b4Θ + + k[5][i] * b5Θ + k[6][i] * b6Θ + k[7][i] * b7Θ) + end + out +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{Tsit5ConstantCache, Tsit5Cache}, idxs, + T::Type{Val{0}}, differential_vars::Nothing) + @tsit5pre0 + @views @.. broadcast=false out=y₀[idxs] + + dt * + (k[1][idxs] * b1Θ + k[2][idxs] * b2Θ + k[3][idxs] * b3Θ + + k[4][idxs] * b4Θ + k[5][idxs] * b5Θ + k[6][idxs] * b6Θ + + k[7][idxs] * b7Θ) + #@inbounds for (j,i) in enumerate(idxs) + # out[j] = y₀[i] + dt*(k[1][i]*b1Θ + k[2][i]*b2Θ + k[3][i]*b3Θ + k[4][i]*b4Θ + k[5][i]*b5Θ + k[6][i]*b6Θ + k[7][i]*b7Θ) + #end + out +end + +@muladd function _ode_interpolant!(out::Array, Θ, dt, y₀, y₁, k, + cache::Union{Tsit5ConstantCache, Tsit5Cache}, idxs, + T::Type{Val{0}}, differential_vars::Nothing) + @tsit5pre0 + @inbounds for (j, i) in enumerate(idxs) + out[j] = y₀[i] + + dt * (k[1][i] * b1Θ + k[2][i] * b2Θ + k[3][i] * b3Θ + k[4][i] * b4Θ + + k[5][i] * b5Θ + k[6][i] * b6Θ + k[7][i] * b7Θ) + end + out +end + +@def tsit5pre1 begin + @tsit5unpack + b1Θdiff = @evalpoly(Θ, r11, 2*r12, 3*r13, 4*r14) + b2Θdiff = Θ * @evalpoly(Θ, 2*r22, 3*r23, 4*r24) + b3Θdiff = Θ * @evalpoly(Θ, 2*r32, 3*r33, 4*r34) + b4Θdiff = Θ * @evalpoly(Θ, 2*r42, 3*r43, 4*r44) + b5Θdiff = Θ * @evalpoly(Θ, 2*r52, 3*r53, 4*r54) + b6Θdiff = Θ * @evalpoly(Θ, 2*r62, 3*r63, 4*r64) + b7Θdiff = Θ * @evalpoly(Θ, 2*r72, 3*r73, 4*r74) +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, cache::Tsit5ConstantCache, + idxs::Nothing, T::Type{Val{1}}, differential_vars::Nothing) + @tsit5pre1 + # return @.. broadcast=false k[1]*b1Θdiff + k[2]*b2Θdiff + k[3]*b3Θdiff + k[4]*b4Θdiff + k[5]*b5Θdiff + k[6]*b6Θdiff + k[7]*b7Θdiff + return @inbounds k[1] * b1Θdiff + k[2] * b2Θdiff + k[3] * b3Θdiff + k[4] * b4Θdiff + + k[5] * b5Θdiff + k[6] * b6Θdiff + k[7] * b7Θdiff +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, cache::Tsit5Cache, idxs::Nothing, + T::Type{Val{1}}, differential_vars::Nothing) + @tsit5pre1 + return @inbounds @.. broadcast=false k[1]*b1Θdiff+k[2]*b2Θdiff+k[3]*b3Θdiff+ + k[4]*b4Θdiff+k[5]*b5Θdiff+k[6]*b6Θdiff+k[7]*b7Θdiff +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{Tsit5ConstantCache, Tsit5Cache}, idxs, + T::Type{Val{1}}, differential_vars::Nothing) + @tsit5pre1 + # return @.. broadcast=false k[1][idxs]*b1Θdiff + k[2][idxs]*b2Θdiff + k[3][idxs]*b3Θdiff + k[4][idxs]*b4Θdiff + k[5][idxs]*b5Θdiff + k[6][idxs]*b6Θdiff + k[7][idxs]*b7Θdiff + return k[1][idxs] * b1Θdiff + k[2][idxs] * b2Θdiff + k[3][idxs] * b3Θdiff + + k[4][idxs] * b4Θdiff + k[5][idxs] * b5Θdiff + k[6][idxs] * b6Θdiff + + k[7][idxs] * b7Θdiff +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{Tsit5ConstantCache, Tsit5Cache}, + idxs::Nothing, T::Type{Val{1}}, differential_vars::Nothing) + @tsit5pre1 + @inbounds @.. broadcast=false out=k[1] * b1Θdiff + k[2] * b2Θdiff + k[3] * b3Θdiff + + k[4] * b4Θdiff + k[5] * b5Θdiff + k[6] * b6Θdiff + + k[7] * b7Θdiff + #@inbounds for i in eachindex(out) + # out[i] = k[1][i]*b1Θdiff + k[2][i]*b2Θdiff + k[3][i]*b3Θdiff + k[4][i]*b4Θdiff + k[5][i]*b5Θdiff + k[6][i]*b6Θdiff + k[7][i]*b7Θdiff + #end + out +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{Tsit5ConstantCache, Tsit5Cache}, idxs, + T::Type{Val{1}}, differential_vars::Nothing) + @tsit5pre1 + @views @.. broadcast=false out=k[1][idxs] * b1Θdiff + k[2][idxs] * b2Θdiff + + k[3][idxs] * b3Θdiff + k[4][idxs] * b4Θdiff + + k[5][idxs] * b5Θdiff + k[6][idxs] * b6Θdiff + + k[7][idxs] * b7Θdiff + #@inbounds for (j,i) in enumerate(idxs) + # out[j] = k[1][i]*b1Θdiff + k[2][i]*b2Θdiff + k[3][i]*b3Θdiff + k[4][i]*b4Θdiff + k[5][i]*b5Θdiff + k[6][i]*b6Θdiff + k[7][i]*b7Θdiff + #end + out +end + +@def tsit5pre2 begin + @tsit5unpack + b1Θdiff2 = @evalpoly(Θ, 2*r12, 6*r13, 12*r14) + b2Θdiff2 = @evalpoly(Θ, 2*r22, 6*r23, 12*r24) + b3Θdiff2 = @evalpoly(Θ, 2*r32, 6*r33, 12*r34) + b4Θdiff2 = @evalpoly(Θ, 2*r42, 6*r43, 12*r44) + b5Θdiff2 = @evalpoly(Θ, 2*r52, 6*r53, 12*r54) + b6Θdiff2 = @evalpoly(Θ, 2*r62, 6*r63, 12*r64) + b7Θdiff2 = @evalpoly(Θ, 2*r72, 6*r73, 12*r74) + invdt = inv(dt) +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{Tsit5ConstantCache, Tsit5Cache}, + idxs::Nothing, T::Type{Val{2}}, differential_vars::Nothing) + @tsit5pre2 + # return @.. broadcast=false k[1]*b1Θdiff2 + k[2]*b2Θdiff2 + k[3]*b3Θdiff2 + k[4]*b4Θdiff2 + k[5]*b5Θdiff2 + k[6]*b6Θdiff2 + k[7]*b7Θdiff2 + return @inbounds (k[1] * b1Θdiff2 + k[2] * b2Θdiff2 + k[3] * b3Θdiff2 + + k[4] * b4Θdiff2 + + k[5] * b5Θdiff2 + k[6] * b6Θdiff2 + k[7] * b7Θdiff2) * invdt +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{Tsit5ConstantCache, Tsit5Cache}, idxs, + T::Type{Val{2}}, differential_vars::Nothing) + @tsit5pre2 + # return @.. broadcast=false k[1][idxs]*b1Θdiff2 + k[2][idxs]*b2Θdiff2 + k[3][idxs]*b3Θdiff2 + k[4][idxs]*b4Θdiff2 + k[5][idxs]*b5Θdiff2 + k[6][idxs]*b6Θdiff2 + k[7][idxs]*b7Θdiff2 + return (k[1][idxs] * b1Θdiff2 + k[2][idxs] * b2Θdiff2 + k[3][idxs] * b3Θdiff2 + + k[4][idxs] * b4Θdiff2 + k[5][idxs] * b5Θdiff2 + k[6][idxs] * b6Θdiff2 + + k[7][idxs] * b7Θdiff2) * invdt +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{Tsit5ConstantCache, Tsit5Cache}, + idxs::Nothing, T::Type{Val{2}}, differential_vars::Nothing) + @tsit5pre2 + @inbounds @.. broadcast=false out=(k[1] * b1Θdiff2 + k[2] * b2Θdiff2 + k[3] * b3Θdiff2 + + k[4] * b4Θdiff2 + k[5] * b5Θdiff2 + k[6] * b6Θdiff2 + + k[7] * b7Θdiff2) * invdt + #@inbounds for i in eachindex(out) + # out[i] = (k[1][i]*b1Θdiff2 + k[2][i]*b2Θdiff2 + k[3][i]*b3Θdiff2 + k[4][i]*b4Θdiff2 + k[5][i]*b5Θdiff2 + k[6][i]*b6Θdiff2 + k[7][i]*b7Θdiff2)*invdt + #end + out +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{Tsit5ConstantCache, Tsit5Cache}, idxs, + T::Type{Val{2}}, differential_vars::Nothing) + @tsit5pre2 + @views @.. broadcast=false out=(k[1][idxs] * b1Θdiff2 + k[2][idxs] * b2Θdiff2 + + k[3][idxs] * b3Θdiff2 + k[4][idxs] * b4Θdiff2 + + k[5][idxs] * b5Θdiff2 + k[6][idxs] * b6Θdiff2 + + k[7][idxs] * b7Θdiff2) * invdt + #@inbounds for (j,i) in enumerate(idxs) + # out[j] = (k[1][i]*b1Θdiff2 + k[2][i]*b2Θdiff2 + k[3][i]*b3Θdiff2 + k[4][i]*b4Θdiff2 + k[5][i]*b5Θdiff2 + k[6][i]*b6Θdiff2 + k[7][i]*b7Θdiff2)*invdt + #end + out +end + +@def tsit5pre3 begin + @tsit5unpack + b1Θdiff3 = @evalpoly(Θ, 6*r13, 24*r14) + b2Θdiff3 = @evalpoly(Θ, 6*r23, 24*r24) + b3Θdiff3 = @evalpoly(Θ, 6*r33, 24*r34) + b4Θdiff3 = @evalpoly(Θ, 6*r43, 24*r44) + b5Θdiff3 = @evalpoly(Θ, 6*r53, 24*r54) + b6Θdiff3 = @evalpoly(Θ, 6*r63, 24*r64) + b7Θdiff3 = @evalpoly(Θ, 6*r73, 24*r74) + invdt2 = inv(dt)^2 +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{Tsit5ConstantCache, Tsit5Cache}, + idxs::Nothing, T::Type{Val{3}}, differential_vars::Nothing) + @tsit5pre3 + # return @.. broadcast=false k[1]*b1Θdiff3 + k[2]*b2Θdiff3 + k[3]*b3Θdiff3 + k[4]*b4Θdiff3 + k[5]*b5Θdiff3 + k[6]*b6Θdiff3 + k[7]*b7Θdiff3 + return @inbounds (k[1] * b1Θdiff3 + k[2] * b2Θdiff3 + k[3] * b3Θdiff3 + + k[4] * b4Θdiff3 + + k[5] * b5Θdiff3 + k[6] * b6Θdiff3 + k[7] * b7Θdiff3) * invdt2 +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{Tsit5ConstantCache, Tsit5Cache}, idxs, + T::Type{Val{3}}, differential_vars::Nothing) + @tsit5pre3 + # return @.. broadcast=false k[1][idxs]*b1Θdiff3 + k[2][idxs]*b2Θdiff3 + k[3][idxs]*b3Θdiff3 + k[4][idxs]*b4Θdiff3 + k[5][idxs]*b5Θdiff3 + k[6][idxs]*b6Θdiff3 + k[7][idxs]*b7Θdiff3 + return (k[1][idxs] * b1Θdiff3 + k[2][idxs] * b2Θdiff3 + k[3][idxs] * b3Θdiff3 + + k[4][idxs] * b4Θdiff3 + k[5][idxs] * b5Θdiff3 + k[6][idxs] * b6Θdiff3 + + k[7][idxs] * b7Θdiff3) * invdt2 +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{Tsit5ConstantCache, Tsit5Cache}, + idxs::Nothing, T::Type{Val{3}}, differential_vars::Nothing) + @tsit5pre3 + @inbounds @.. broadcast=false out=(k[1] * b1Θdiff3 + k[2] * b2Θdiff3 + k[3] * b3Θdiff3 + + k[4] * b4Θdiff3 + k[5] * b5Θdiff3 + k[6] * b6Θdiff3 + + k[7] * b7Θdiff3) * invdt2 + #@inbounds for i in eachindex(out) + # out[i] = (k[1][i]*b1Θdiff3 + k[2][i]*b2Θdiff3 + k[3][i]*b3Θdiff3 + k[4][i]*b4Θdiff3 + k[5][i]*b5Θdiff3 + k[6][i]*b6Θdiff3 + k[7][i]*b7Θdiff3)*invdt2 + #end + out +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{Tsit5ConstantCache, Tsit5Cache}, idxs, + T::Type{Val{3}}, differential_vars::Nothing) + @tsit5pre3 + @views @.. broadcast=false out=(k[1][idxs] * b1Θdiff3 + k[2][idxs] * b2Θdiff3 + + k[3][idxs] * b3Θdiff3 + k[4][idxs] * b4Θdiff3 + + k[5][idxs] * b5Θdiff3 + k[6][idxs] * b6Θdiff3 + + k[7][idxs] * b7Θdiff3) * invdt2 + #@inbounds for (j,i) in enumerate(idxs) + # out[j] = (k[1][i]*b1Θdiff3 + k[2][i]*b2Θdiff3 + k[3][i]*b3Θdiff3 + k[4][i]*b4Θdiff3 + k[5][i]*b5Θdiff3 + k[6][i]*b6Θdiff3 + k[7][i]*b7Θdiff3)*invdt2 + #end + out +end + +@def tsit5pre4 begin + @tsit5unpack + b1Θdiff4 = 24 * r14 + b2Θdiff4 = 24 * r24 + b3Θdiff4 = 24 * r34 + b4Θdiff4 = 24 * r44 + b5Θdiff4 = 24 * r54 + b6Θdiff4 = 24 * r64 + b7Θdiff4 = 24 * r74 + invdt3 = inv(dt)^3 +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{Tsit5ConstantCache, Tsit5Cache}, + idxs::Nothing, T::Type{Val{4}}, differential_vars::Nothing) + @tsit5pre4 + # return @.. broadcast=false k[1]*b1Θdiff4 + k[2]*b2Θdiff4 + k[3]*b3Θdiff4 + k[4]*b4Θdiff4 + k[5]*b5Θdiff4 + k[6]*b6Θdiff4 + k[7]*b7Θdiff4 + return @inbounds (k[1] * b1Θdiff4 + k[2] * b2Θdiff4 + k[3] * b3Θdiff4 + + k[4] * b4Θdiff4 + + k[5] * b5Θdiff4 + k[6] * b6Θdiff4 + k[7] * b7Θdiff4) * invdt3 +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{Tsit5ConstantCache, Tsit5Cache}, idxs, + T::Type{Val{4}}, differential_vars::Nothing) + @tsit5pre4 + # return @.. broadcast=false k[1][idxs]*b1Θdiff4 + k[2][idxs]*b2Θdiff4 + k[3][idxs]*b3Θdiff4 + k[4][idxs]*b4Θdiff4 + k[5][idxs]*b5Θdiff4 + k[6][idxs]*b6Θdiff4 + k[7][idxs]*b7Θdiff4 + return (k[1][idxs] * b1Θdiff4 + k[2][idxs] * b2Θdiff4 + k[3][idxs] * b3Θdiff4 + + k[4][idxs] * b4Θdiff4 + k[5][idxs] * b5Θdiff4 + k[6][idxs] * b6Θdiff4 + + k[7][idxs] * b7Θdiff4) * invdt3 +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{Tsit5ConstantCache, Tsit5Cache}, + idxs::Nothing, T::Type{Val{4}}, differential_vars::Nothing) + @tsit5pre4 + @inbounds @.. broadcast=false out=(k[1] * b1Θdiff4 + k[2] * b2Θdiff4 + k[3] * b3Θdiff4 + + k[4] * b4Θdiff4 + k[5] * b5Θdiff4 + k[6] * b6Θdiff4 + + k[7] * b7Θdiff4) * invdt3 + #@inbounds for i in eachindex(out) + # out[i] = (k[1][i]*b1Θdiff4 + k[2][i]*b2Θdiff4 + k[3][i]*b3Θdiff4 + k[4][i]*b4Θdiff4 + k[5][i]*b5Θdiff4 + k[6][i]*b6Θdiff4 + k[7][i]*b7Θdiff4)*invdt3 + #end + out +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{Tsit5ConstantCache, Tsit5Cache}, idxs, + T::Type{Val{4}}, differential_vars::Nothing) + @tsit5pre4 + @views @.. broadcast=false out=(k[1][idxs] * b1Θdiff4 + k[2][idxs] * b2Θdiff4 + + k[3][idxs] * b3Θdiff4 + k[4][idxs] * b4Θdiff4 + + k[5][idxs] * b5Θdiff4 + k[6][idxs] * b6Θdiff4 + + k[7][idxs] * b7Θdiff4) * invdt3 + #@inbounds for (j,i) in enumerate(idxs) + # out[j] = (k[1][i]*b1Θdiff4 + k[2][i]*b2Θdiff4 + k[3][i]*b3Θdiff4 + k[4][i]*b4Θdiff4 + k[5][i]*b5Θdiff4 + k[6][i]*b6Θdiff4 + k[7][i]*b7Θdiff4)*invdt3 + #end + out +end \ No newline at end of file diff --git a/src/dense/interpolants.jl b/src/dense/interpolants.jl index ebf6d226bc..560686250f 100644 --- a/src/dense/interpolants.jl +++ b/src/dense/interpolants.jl @@ -1,23 +1,3 @@ -RK_WITH_SPECIAL_INTERPOLATIONS = Union{FunctionMapConstantCache, FunctionMapCache, - DP5ConstantCache, DP5Cache, - Tsit5ConstantCache, Tsit5Cache, - OwrenZen3ConstantCache, OwrenZen3Cache, - OwrenZen4ConstantCache, OwrenZen4Cache, - OwrenZen5ConstantCache, OwrenZen5Cache, - BS5ConstantCache, BS5Cache -} -function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::RK_WITH_SPECIAL_INTERPOLATIONS, - idxs, T::Type{Val{D}}, differential_vars) where {D} - throw(DerivativeOrderNotPossibleError()) -end - -function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::RK_WITH_SPECIAL_INTERPOLATIONS, - idxs, T::Type{Val{D}}, differential_vars) where {D} - throw(DerivativeOrderNotPossibleError()) -end - #### @muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, @@ -42,1658 +22,4 @@ end cache::Union{FunctionMapConstantCache, FunctionMapCache}, idxs, T::Type{Val{0}}, differential_vars::Nothing) @views out[idxs] .= y₀[idxs] -end - -""" -Hairer Norsett Wanner Solving Ordinary Differential Euations I - Nonstiff Problems Page 192 -""" -@def dp5pre0 begin - b10 = Θ - b20 = Θ * (1 - Θ) - b30 = Θ * b20 - b40 = b20^2 -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, cache::DP5ConstantCache, idxs::Nothing, - T::Type{Val{0}}, differential_vars::Nothing) - @dp5pre0 - @inbounds y₀ + dt * (k[1] * b10 + k[2] * b20 + k[3] * b30 + k[4] * b40) -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, cache::DP5Cache, idxs::Nothing, - T::Type{Val{0}}, differential_vars::Nothing) - @dp5pre0 - @inbounds @.. broadcast=false y₀+dt * - (k[1] * b10 + k[2] * b20 + k[3] * b30 + k[4] * b40) -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{DP5ConstantCache, DP5Cache}, idxs, - T::Type{Val{0}}, differential_vars::Nothing) - @dp5pre0 - @views @.. broadcast=false y₀[idxs]+dt * (k[1][idxs] * b10 + k[2][idxs] * b20 + - k[3][idxs] * b30 + k[4][idxs] * b40) -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{DP5ConstantCache, DP5Cache}, idxs::Nothing, - T::Type{Val{0}}, differential_vars::Nothing) - @dp5pre0 - @inbounds @.. broadcast=false out=y₀ + - dt * - (k[1] * b10 + k[2] * b20 + k[3] * b30 + k[4] * b40) - out -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{DP5ConstantCache, DP5Cache}, idxs, - T::Type{Val{0}}, differential_vars::Nothing) - @dp5pre0 - @views @.. broadcast=false out=y₀[idxs] + - dt * - (k[1][idxs] * b10 + k[2][idxs] * b20 + k[3][idxs] * b30 + - k[4][idxs] * b40) - out -end - -@def dp5pre1 begin - b20diff = @evalpoly(Θ, 1, -2) - b30diff = Θ * @evalpoly(Θ, 2, -3) - b40diff = Θ * @evalpoly(Θ, 2, -6, 4) -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{DP5ConstantCache, DP5Cache}, idxs::Nothing, - T::Type{Val{1}}, differential_vars::Nothing) - @dp5pre1 - @inbounds @.. broadcast=false k[1]+k[2]*b20diff+k[3]*b30diff+k[4]*b40diff -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{DP5ConstantCache, DP5Cache}, idxs, - T::Type{Val{1}}, differential_vars::Nothing) - @dp5pre1 - @views @.. broadcast=false k[1][idxs]+k[2][idxs]*b20diff+k[3][idxs]*b30diff+ - k[4][idxs]*b40diff -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{DP5ConstantCache, DP5Cache}, idxs::Nothing, - T::Type{Val{1}}, differential_vars::Nothing) - @dp5pre1 - @inbounds @.. broadcast=false out=k[1] + k[2] * b20diff + k[3] * b30diff + - k[4] * b40diff - out -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{DP5ConstantCache, DP5Cache}, idxs, - T::Type{Val{1}}, differential_vars::Nothing) - @dp5pre1 - @views @.. broadcast=false out=k[1][idxs] + k[2][idxs] * b20diff + - k[3][idxs] * b30diff + k[4][idxs] * b40diff - out -end - -@def dp5pre2 begin - b20diff2 = -2 - b30diff2 = @evalpoly(Θ, 2, -6) - b40diff2 = @evalpoly(Θ, 2, -12, 12) - invdt = inv(dt) -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{DP5ConstantCache, DP5Cache}, idxs::Nothing, - T::Type{Val{2}}, differential_vars::Nothing) - @dp5pre2 - @inbounds @.. broadcast=false (k[2] * b20diff2 + k[3] * b30diff2 + - k[4] * b40diff2)*invdt -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{DP5ConstantCache, DP5Cache}, idxs, - T::Type{Val{2}}, differential_vars::Nothing) - @dp5pre2 - @views @.. broadcast=false (k[2][idxs] * b20diff2 + k[3][idxs] * b30diff2 + - k[4][idxs] * b40diff2)*invdt -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{DP5ConstantCache, DP5Cache}, idxs::Nothing, - T::Type{Val{2}}, differential_vars::Nothing) - @dp5pre2 - @inbounds @.. broadcast=false out=(k[2] * b20diff2 + k[3] * b30diff2 + - k[4] * b40diff2) * - invdt - out -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{DP5ConstantCache, DP5Cache}, idxs, - T::Type{Val{2}}, differential_vars::Nothing) - @dp5pre2 - @views @.. broadcast=false out=(k[2][idxs] * b20diff2 + k[3][idxs] * b30diff2 + - k[4][idxs] * b40diff2) * invdt - out -end - -@def dp5pre3 begin - b30diff3 = -6 - b40diff3 = @evalpoly(Θ, -12, 24) - invdt2 = inv(dt)^2 -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{DP5ConstantCache, DP5Cache}, idxs::Nothing, - T::Type{Val{3}}, differential_vars::Nothing) - @dp5pre3 - @inbounds @.. broadcast=false (k[3] * b30diff3 + k[4] * b40diff3)*invdt2 -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{DP5ConstantCache, DP5Cache}, idxs, - T::Type{Val{3}}, differential_vars::Nothing) - @dp5pre3 - @views @.. broadcast=false (k[3][idxs] * b30diff3 + k[4][idxs] * b40diff3)*invdt2 -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{DP5ConstantCache, DP5Cache}, idxs::Nothing, - T::Type{Val{3}}, differential_vars::Nothing) - @dp5pre3 - @inbounds @.. broadcast=false out=(k[3] * b30diff3 + k[4] * b40diff3) * invdt2 - out -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{DP5ConstantCache, DP5Cache}, idxs, - T::Type{Val{3}}, differential_vars::Nothing) - @dp5pre3 - @views @.. broadcast=false out=(k[3][idxs] * b30diff3 + k[4][idxs] * b40diff3) * invdt2 - out -end - -@def dp5pre4 begin - b40diff4invdt3 = 24 * inv(dt)^3 -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{DP5ConstantCache, DP5Cache}, idxs::Nothing, - T::Type{Val{4}}, differential_vars::Nothing) - @dp5pre4 - @inbounds @.. broadcast=false k[4]*b40diff4invdt3 -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{DP5ConstantCache, DP5Cache}, idxs, - T::Type{Val{4}}, differential_vars::Nothing) - @dp5pre4 - @views @.. broadcast=false k[4][idxs]*b40diff4invdt3 -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{DP5ConstantCache, DP5Cache}, idxs::Nothing, - T::Type{Val{4}}, differential_vars::Nothing) - @dp5pre4 - @inbounds @.. broadcast=false out=k[4] * b40diff4invdt3 - out -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{DP5ConstantCache, DP5Cache}, idxs, - T::Type{Val{4}}, differential_vars::Nothing) - @dp5pre4 - @views @.. broadcast=false out=k[4][idxs] * b40diff4invdt3 - out -end - -""" -Runge–Kutta pairs of order 5(4) satisfying only the first column -simplifying assumption - -Ch. Tsitouras -""" -@def tsit5unpack begin - var"#T#" = constvalue(recursive_unitless_bottom_eltype(y₁)) - r11, r12, r13, r14, r22, r23, r24, r32, r33, r34, r42, r43, r44, r52, r53, r54, r62, r63, r64, r72, r73, r74 = Tsit5Interp(var"#T#") -end - -@def tsit5pre0 begin - @tsit5unpack - Θ² = Θ * Θ - b1Θ = Θ * @evalpoly(Θ, r11, r12, r13, r14) - b2Θ = Θ² * @evalpoly(Θ, r22, r23, r24) - b3Θ = Θ² * @evalpoly(Θ, r32, r33, r34) - b4Θ = Θ² * @evalpoly(Θ, r42, r43, r44) - b5Θ = Θ² * @evalpoly(Θ, r52, r53, r54) - b6Θ = Θ² * @evalpoly(Θ, r62, r63, r64) - b7Θ = Θ² * @evalpoly(Θ, r72, r73, r74) -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, cache::Tsit5ConstantCache, - idxs::Nothing, T::Type{Val{0}}, differential_vars::Nothing) - @tsit5pre0 - #@.. broadcast=false y₀ + dt*(k[1]*b1Θ + k[2]*b2Θ + k[3]*b3Θ + k[4]*b4Θ + k[5]*b5Θ + k[6]*b6Θ + k[7]*b7Θ) - return @inbounds y₀ + - dt * (k[1] * b1Θ + k[2] * b2Θ + k[3] * b3Θ + k[4] * b4Θ + - k[5] * b5Θ + k[6] * b6Θ + k[7] * b7Θ) -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, cache::Tsit5Cache, idxs::Nothing, - T::Type{Val{0}}, differential_vars::Nothing) - @tsit5pre0 - return @inbounds @.. broadcast=false y₀+dt * (k[1] * b1Θ + k[2] * b2Θ + k[3] * b3Θ + - k[4] * b4Θ + - k[5] * b5Θ + k[6] * b6Θ + k[7] * b7Θ) -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{Tsit5ConstantCache, Tsit5Cache}, idxs, - T::Type{Val{0}}, differential_vars::Nothing) - @tsit5pre0 - return y₀[idxs] + - dt * (k[1][idxs] * b1Θ + k[2][idxs] * b2Θ + k[3][idxs] * b3Θ + - k[4][idxs] * b4Θ + k[5][idxs] * b5Θ + k[6][idxs] * b6Θ + k[7][idxs] * b7Θ) -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{Tsit5ConstantCache, Tsit5Cache}, - idxs::Nothing, T::Type{Val{0}}, differential_vars::Nothing) - @tsit5pre0 - @inbounds @.. broadcast=false out=y₀ + - dt * - (k[1] * b1Θ + k[2] * b2Θ + k[3] * b3Θ + k[4] * b4Θ + - k[5] * b5Θ + k[6] * b6Θ + k[7] * b7Θ) - out -end - -@muladd function _ode_interpolant!(out::Array, Θ, dt, y₀, y₁, k, - cache::Union{Tsit5ConstantCache, Tsit5Cache}, - idxs::Nothing, T::Type{Val{0}}, differential_vars::Nothing) - @tsit5pre0 - @inbounds @simd ivdep for i in eachindex(out) - out[i] = y₀[i] + - dt * (k[1][i] * b1Θ + k[2][i] * b2Θ + k[3][i] * b3Θ + k[4][i] * b4Θ + - k[5][i] * b5Θ + k[6][i] * b6Θ + k[7][i] * b7Θ) - end - out -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{Tsit5ConstantCache, Tsit5Cache}, idxs, - T::Type{Val{0}}, differential_vars::Nothing) - @tsit5pre0 - @views @.. broadcast=false out=y₀[idxs] + - dt * - (k[1][idxs] * b1Θ + k[2][idxs] * b2Θ + k[3][idxs] * b3Θ + - k[4][idxs] * b4Θ + k[5][idxs] * b5Θ + k[6][idxs] * b6Θ + - k[7][idxs] * b7Θ) - #@inbounds for (j,i) in enumerate(idxs) - # out[j] = y₀[i] + dt*(k[1][i]*b1Θ + k[2][i]*b2Θ + k[3][i]*b3Θ + k[4][i]*b4Θ + k[5][i]*b5Θ + k[6][i]*b6Θ + k[7][i]*b7Θ) - #end - out -end - -@muladd function _ode_interpolant!(out::Array, Θ, dt, y₀, y₁, k, - cache::Union{Tsit5ConstantCache, Tsit5Cache}, idxs, - T::Type{Val{0}}, differential_vars::Nothing) - @tsit5pre0 - @inbounds for (j, i) in enumerate(idxs) - out[j] = y₀[i] + - dt * (k[1][i] * b1Θ + k[2][i] * b2Θ + k[3][i] * b3Θ + k[4][i] * b4Θ + - k[5][i] * b5Θ + k[6][i] * b6Θ + k[7][i] * b7Θ) - end - out -end - -@def tsit5pre1 begin - @tsit5unpack - b1Θdiff = @evalpoly(Θ, r11, 2*r12, 3*r13, 4*r14) - b2Θdiff = Θ * @evalpoly(Θ, 2*r22, 3*r23, 4*r24) - b3Θdiff = Θ * @evalpoly(Θ, 2*r32, 3*r33, 4*r34) - b4Θdiff = Θ * @evalpoly(Θ, 2*r42, 3*r43, 4*r44) - b5Θdiff = Θ * @evalpoly(Θ, 2*r52, 3*r53, 4*r54) - b6Θdiff = Θ * @evalpoly(Θ, 2*r62, 3*r63, 4*r64) - b7Θdiff = Θ * @evalpoly(Θ, 2*r72, 3*r73, 4*r74) -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, cache::Tsit5ConstantCache, - idxs::Nothing, T::Type{Val{1}}, differential_vars::Nothing) - @tsit5pre1 - # return @.. broadcast=false k[1]*b1Θdiff + k[2]*b2Θdiff + k[3]*b3Θdiff + k[4]*b4Θdiff + k[5]*b5Θdiff + k[6]*b6Θdiff + k[7]*b7Θdiff - return @inbounds k[1] * b1Θdiff + k[2] * b2Θdiff + k[3] * b3Θdiff + k[4] * b4Θdiff + - k[5] * b5Θdiff + k[6] * b6Θdiff + k[7] * b7Θdiff -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, cache::Tsit5Cache, idxs::Nothing, - T::Type{Val{1}}, differential_vars::Nothing) - @tsit5pre1 - return @inbounds @.. broadcast=false k[1]*b1Θdiff+k[2]*b2Θdiff+k[3]*b3Θdiff+ - k[4]*b4Θdiff+k[5]*b5Θdiff+k[6]*b6Θdiff+k[7]*b7Θdiff -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{Tsit5ConstantCache, Tsit5Cache}, idxs, - T::Type{Val{1}}, differential_vars::Nothing) - @tsit5pre1 - # return @.. broadcast=false k[1][idxs]*b1Θdiff + k[2][idxs]*b2Θdiff + k[3][idxs]*b3Θdiff + k[4][idxs]*b4Θdiff + k[5][idxs]*b5Θdiff + k[6][idxs]*b6Θdiff + k[7][idxs]*b7Θdiff - return k[1][idxs] * b1Θdiff + k[2][idxs] * b2Θdiff + k[3][idxs] * b3Θdiff + - k[4][idxs] * b4Θdiff + k[5][idxs] * b5Θdiff + k[6][idxs] * b6Θdiff + - k[7][idxs] * b7Θdiff -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{Tsit5ConstantCache, Tsit5Cache}, - idxs::Nothing, T::Type{Val{1}}, differential_vars::Nothing) - @tsit5pre1 - @inbounds @.. broadcast=false out=k[1] * b1Θdiff + k[2] * b2Θdiff + k[3] * b3Θdiff + - k[4] * b4Θdiff + k[5] * b5Θdiff + k[6] * b6Θdiff + - k[7] * b7Θdiff - #@inbounds for i in eachindex(out) - # out[i] = k[1][i]*b1Θdiff + k[2][i]*b2Θdiff + k[3][i]*b3Θdiff + k[4][i]*b4Θdiff + k[5][i]*b5Θdiff + k[6][i]*b6Θdiff + k[7][i]*b7Θdiff - #end - out -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{Tsit5ConstantCache, Tsit5Cache}, idxs, - T::Type{Val{1}}, differential_vars::Nothing) - @tsit5pre1 - @views @.. broadcast=false out=k[1][idxs] * b1Θdiff + k[2][idxs] * b2Θdiff + - k[3][idxs] * b3Θdiff + k[4][idxs] * b4Θdiff + - k[5][idxs] * b5Θdiff + k[6][idxs] * b6Θdiff + - k[7][idxs] * b7Θdiff - #@inbounds for (j,i) in enumerate(idxs) - # out[j] = k[1][i]*b1Θdiff + k[2][i]*b2Θdiff + k[3][i]*b3Θdiff + k[4][i]*b4Θdiff + k[5][i]*b5Θdiff + k[6][i]*b6Θdiff + k[7][i]*b7Θdiff - #end - out -end - -@def tsit5pre2 begin - @tsit5unpack - b1Θdiff2 = @evalpoly(Θ, 2*r12, 6*r13, 12*r14) - b2Θdiff2 = @evalpoly(Θ, 2*r22, 6*r23, 12*r24) - b3Θdiff2 = @evalpoly(Θ, 2*r32, 6*r33, 12*r34) - b4Θdiff2 = @evalpoly(Θ, 2*r42, 6*r43, 12*r44) - b5Θdiff2 = @evalpoly(Θ, 2*r52, 6*r53, 12*r54) - b6Θdiff2 = @evalpoly(Θ, 2*r62, 6*r63, 12*r64) - b7Θdiff2 = @evalpoly(Θ, 2*r72, 6*r73, 12*r74) - invdt = inv(dt) -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{Tsit5ConstantCache, Tsit5Cache}, - idxs::Nothing, T::Type{Val{2}}, differential_vars::Nothing) - @tsit5pre2 - # return @.. broadcast=false k[1]*b1Θdiff2 + k[2]*b2Θdiff2 + k[3]*b3Θdiff2 + k[4]*b4Θdiff2 + k[5]*b5Θdiff2 + k[6]*b6Θdiff2 + k[7]*b7Θdiff2 - return @inbounds (k[1] * b1Θdiff2 + k[2] * b2Θdiff2 + k[3] * b3Θdiff2 + - k[4] * b4Θdiff2 + - k[5] * b5Θdiff2 + k[6] * b6Θdiff2 + k[7] * b7Θdiff2) * invdt -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{Tsit5ConstantCache, Tsit5Cache}, idxs, - T::Type{Val{2}}, differential_vars::Nothing) - @tsit5pre2 - # return @.. broadcast=false k[1][idxs]*b1Θdiff2 + k[2][idxs]*b2Θdiff2 + k[3][idxs]*b3Θdiff2 + k[4][idxs]*b4Θdiff2 + k[5][idxs]*b5Θdiff2 + k[6][idxs]*b6Θdiff2 + k[7][idxs]*b7Θdiff2 - return (k[1][idxs] * b1Θdiff2 + k[2][idxs] * b2Θdiff2 + k[3][idxs] * b3Θdiff2 + - k[4][idxs] * b4Θdiff2 + k[5][idxs] * b5Θdiff2 + k[6][idxs] * b6Θdiff2 + - k[7][idxs] * b7Θdiff2) * invdt -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{Tsit5ConstantCache, Tsit5Cache}, - idxs::Nothing, T::Type{Val{2}}, differential_vars::Nothing) - @tsit5pre2 - @inbounds @.. broadcast=false out=(k[1] * b1Θdiff2 + k[2] * b2Θdiff2 + k[3] * b3Θdiff2 + - k[4] * b4Θdiff2 + k[5] * b5Θdiff2 + k[6] * b6Θdiff2 + - k[7] * b7Θdiff2) * invdt - #@inbounds for i in eachindex(out) - # out[i] = (k[1][i]*b1Θdiff2 + k[2][i]*b2Θdiff2 + k[3][i]*b3Θdiff2 + k[4][i]*b4Θdiff2 + k[5][i]*b5Θdiff2 + k[6][i]*b6Θdiff2 + k[7][i]*b7Θdiff2)*invdt - #end - out -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{Tsit5ConstantCache, Tsit5Cache}, idxs, - T::Type{Val{2}}, differential_vars::Nothing) - @tsit5pre2 - @views @.. broadcast=false out=(k[1][idxs] * b1Θdiff2 + k[2][idxs] * b2Θdiff2 + - k[3][idxs] * b3Θdiff2 + k[4][idxs] * b4Θdiff2 + - k[5][idxs] * b5Θdiff2 + k[6][idxs] * b6Θdiff2 + - k[7][idxs] * b7Θdiff2) * invdt - #@inbounds for (j,i) in enumerate(idxs) - # out[j] = (k[1][i]*b1Θdiff2 + k[2][i]*b2Θdiff2 + k[3][i]*b3Θdiff2 + k[4][i]*b4Θdiff2 + k[5][i]*b5Θdiff2 + k[6][i]*b6Θdiff2 + k[7][i]*b7Θdiff2)*invdt - #end - out -end - -@def tsit5pre3 begin - @tsit5unpack - b1Θdiff3 = @evalpoly(Θ, 6*r13, 24*r14) - b2Θdiff3 = @evalpoly(Θ, 6*r23, 24*r24) - b3Θdiff3 = @evalpoly(Θ, 6*r33, 24*r34) - b4Θdiff3 = @evalpoly(Θ, 6*r43, 24*r44) - b5Θdiff3 = @evalpoly(Θ, 6*r53, 24*r54) - b6Θdiff3 = @evalpoly(Θ, 6*r63, 24*r64) - b7Θdiff3 = @evalpoly(Θ, 6*r73, 24*r74) - invdt2 = inv(dt)^2 -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{Tsit5ConstantCache, Tsit5Cache}, - idxs::Nothing, T::Type{Val{3}}, differential_vars::Nothing) - @tsit5pre3 - # return @.. broadcast=false k[1]*b1Θdiff3 + k[2]*b2Θdiff3 + k[3]*b3Θdiff3 + k[4]*b4Θdiff3 + k[5]*b5Θdiff3 + k[6]*b6Θdiff3 + k[7]*b7Θdiff3 - return @inbounds (k[1] * b1Θdiff3 + k[2] * b2Θdiff3 + k[3] * b3Θdiff3 + - k[4] * b4Θdiff3 + - k[5] * b5Θdiff3 + k[6] * b6Θdiff3 + k[7] * b7Θdiff3) * invdt2 -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{Tsit5ConstantCache, Tsit5Cache}, idxs, - T::Type{Val{3}}, differential_vars::Nothing) - @tsit5pre3 - # return @.. broadcast=false k[1][idxs]*b1Θdiff3 + k[2][idxs]*b2Θdiff3 + k[3][idxs]*b3Θdiff3 + k[4][idxs]*b4Θdiff3 + k[5][idxs]*b5Θdiff3 + k[6][idxs]*b6Θdiff3 + k[7][idxs]*b7Θdiff3 - return (k[1][idxs] * b1Θdiff3 + k[2][idxs] * b2Θdiff3 + k[3][idxs] * b3Θdiff3 + - k[4][idxs] * b4Θdiff3 + k[5][idxs] * b5Θdiff3 + k[6][idxs] * b6Θdiff3 + - k[7][idxs] * b7Θdiff3) * invdt2 -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{Tsit5ConstantCache, Tsit5Cache}, - idxs::Nothing, T::Type{Val{3}}, differential_vars::Nothing) - @tsit5pre3 - @inbounds @.. broadcast=false out=(k[1] * b1Θdiff3 + k[2] * b2Θdiff3 + k[3] * b3Θdiff3 + - k[4] * b4Θdiff3 + k[5] * b5Θdiff3 + k[6] * b6Θdiff3 + - k[7] * b7Θdiff3) * invdt2 - #@inbounds for i in eachindex(out) - # out[i] = (k[1][i]*b1Θdiff3 + k[2][i]*b2Θdiff3 + k[3][i]*b3Θdiff3 + k[4][i]*b4Θdiff3 + k[5][i]*b5Θdiff3 + k[6][i]*b6Θdiff3 + k[7][i]*b7Θdiff3)*invdt2 - #end - out -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{Tsit5ConstantCache, Tsit5Cache}, idxs, - T::Type{Val{3}}, differential_vars::Nothing) - @tsit5pre3 - @views @.. broadcast=false out=(k[1][idxs] * b1Θdiff3 + k[2][idxs] * b2Θdiff3 + - k[3][idxs] * b3Θdiff3 + k[4][idxs] * b4Θdiff3 + - k[5][idxs] * b5Θdiff3 + k[6][idxs] * b6Θdiff3 + - k[7][idxs] * b7Θdiff3) * invdt2 - #@inbounds for (j,i) in enumerate(idxs) - # out[j] = (k[1][i]*b1Θdiff3 + k[2][i]*b2Θdiff3 + k[3][i]*b3Θdiff3 + k[4][i]*b4Θdiff3 + k[5][i]*b5Θdiff3 + k[6][i]*b6Θdiff3 + k[7][i]*b7Θdiff3)*invdt2 - #end - out -end - -@def tsit5pre4 begin - @tsit5unpack - b1Θdiff4 = 24 * r14 - b2Θdiff4 = 24 * r24 - b3Θdiff4 = 24 * r34 - b4Θdiff4 = 24 * r44 - b5Θdiff4 = 24 * r54 - b6Θdiff4 = 24 * r64 - b7Θdiff4 = 24 * r74 - invdt3 = inv(dt)^3 -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{Tsit5ConstantCache, Tsit5Cache}, - idxs::Nothing, T::Type{Val{4}}, differential_vars::Nothing) - @tsit5pre4 - # return @.. broadcast=false k[1]*b1Θdiff4 + k[2]*b2Θdiff4 + k[3]*b3Θdiff4 + k[4]*b4Θdiff4 + k[5]*b5Θdiff4 + k[6]*b6Θdiff4 + k[7]*b7Θdiff4 - return @inbounds (k[1] * b1Θdiff4 + k[2] * b2Θdiff4 + k[3] * b3Θdiff4 + - k[4] * b4Θdiff4 + - k[5] * b5Θdiff4 + k[6] * b6Θdiff4 + k[7] * b7Θdiff4) * invdt3 -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{Tsit5ConstantCache, Tsit5Cache}, idxs, - T::Type{Val{4}}, differential_vars::Nothing) - @tsit5pre4 - # return @.. broadcast=false k[1][idxs]*b1Θdiff4 + k[2][idxs]*b2Θdiff4 + k[3][idxs]*b3Θdiff4 + k[4][idxs]*b4Θdiff4 + k[5][idxs]*b5Θdiff4 + k[6][idxs]*b6Θdiff4 + k[7][idxs]*b7Θdiff4 - return (k[1][idxs] * b1Θdiff4 + k[2][idxs] * b2Θdiff4 + k[3][idxs] * b3Θdiff4 + - k[4][idxs] * b4Θdiff4 + k[5][idxs] * b5Θdiff4 + k[6][idxs] * b6Θdiff4 + - k[7][idxs] * b7Θdiff4) * invdt3 -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{Tsit5ConstantCache, Tsit5Cache}, - idxs::Nothing, T::Type{Val{4}}, differential_vars::Nothing) - @tsit5pre4 - @inbounds @.. broadcast=false out=(k[1] * b1Θdiff4 + k[2] * b2Θdiff4 + k[3] * b3Θdiff4 + - k[4] * b4Θdiff4 + k[5] * b5Θdiff4 + k[6] * b6Θdiff4 + - k[7] * b7Θdiff4) * invdt3 - #@inbounds for i in eachindex(out) - # out[i] = (k[1][i]*b1Θdiff4 + k[2][i]*b2Θdiff4 + k[3][i]*b3Θdiff4 + k[4][i]*b4Θdiff4 + k[5][i]*b5Θdiff4 + k[6][i]*b6Θdiff4 + k[7][i]*b7Θdiff4)*invdt3 - #end - out -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{Tsit5ConstantCache, Tsit5Cache}, idxs, - T::Type{Val{4}}, differential_vars::Nothing) - @tsit5pre4 - @views @.. broadcast=false out=(k[1][idxs] * b1Θdiff4 + k[2][idxs] * b2Θdiff4 + - k[3][idxs] * b3Θdiff4 + k[4][idxs] * b4Θdiff4 + - k[5][idxs] * b5Θdiff4 + k[6][idxs] * b6Θdiff4 + - k[7][idxs] * b7Θdiff4) * invdt3 - #@inbounds for (j,i) in enumerate(idxs) - # out[j] = (k[1][i]*b1Θdiff4 + k[2][i]*b2Θdiff4 + k[3][i]*b3Θdiff4 + k[4][i]*b4Θdiff4 + k[5][i]*b5Θdiff4 + k[6][i]*b6Θdiff4 + k[7][i]*b7Θdiff4)*invdt3 - #end - out -end - -""" -""" -@def owrenzen3unpack begin - if cache isa OrdinaryDiffEqMutableCache - @unpack r13, r12, r23, r22, r33, r32 = cache.tab - else - @unpack r13, r12, r23, r22, r33, r32 = cache - end -end - -@def owrenzen3pre0 begin - @owrenzen3unpack - Θ² = Θ * Θ - b1Θ = Θ * @evalpoly(Θ, 1, r12, r13) - b2Θ = Θ² * @evalpoly(Θ, r22, r23) - b3Θ = Θ² * @evalpoly(Θ, r32, r33) - b4Θ = Θ² * @evalpoly(Θ, -1, 1) -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen3ConstantCache, OwrenZen3Cache}, - idxs::Nothing, T::Type{Val{0}}, differential_vars::Nothing) - @owrenzen3pre0 - @inbounds @.. broadcast=false y₀+dt * - (k[1] * b1Θ + k[2] * b2Θ + k[3] * b3Θ + k[4] * b4Θ) -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen3ConstantCache, OwrenZen3Cache}, - idxs, T::Type{Val{0}}, differential_vars::Nothing) - @owrenzen3pre0 - @views @.. broadcast=false y₀[idxs]+dt * (k[1][idxs] * b1Θ + k[2][idxs] * b2Θ + - k[3][idxs] * b3Θ + - k[4][idxs] * b4Θ) -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen3ConstantCache, OwrenZen3Cache}, - idxs::Nothing, T::Type{Val{0}}, differential_vars::Nothing) - @owrenzen3pre0 - @inbounds @.. broadcast=false out=y₀ + - dt * - (k[1] * b1Θ + k[2] * b2Θ + k[3] * b3Θ + k[4] * b4Θ) - out -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen3ConstantCache, OwrenZen3Cache}, - idxs, T::Type{Val{0}}, differential_vars::Nothing) - @owrenzen3pre0 - @views @.. broadcast=false out=y₀[idxs] + - dt * - (k[1][idxs] * b1Θ + k[2][idxs] * b2Θ + k[3][idxs] * b3Θ + - k[4][idxs] * b4Θ) - out -end - -@def owrenzen3pre1 begin - @owrenzen3unpack - b1Θdiff = @evalpoly(Θ, 1, 2*r12, 3*r13) - b2Θdiff = Θ * @evalpoly(Θ, 2*r22, 3*r23) - b3Θdiff = Θ * @evalpoly(Θ, 2*r32, 3*r33) - b4Θdiff = Θ * @evalpoly(Θ, -2, 3) -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen3ConstantCache, OwrenZen3Cache}, - idxs::Nothing, T::Type{Val{1}}, differential_vars::Nothing) - @owrenzen3pre1 - @inbounds @.. broadcast=false k[1]*b1Θdiff+k[2]*b2Θdiff+k[3]*b3Θdiff+k[4]*b4Θdiff -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen3ConstantCache, OwrenZen3Cache}, - idxs, T::Type{Val{1}}, differential_vars::Nothing) - @owrenzen3pre1 - @views @.. broadcast=false k[1][idxs]*b1Θdiff+k[2][idxs]*b2Θdiff+k[3][idxs]*b3Θdiff+ - k[4][idxs]*b4Θdiff -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen3ConstantCache, OwrenZen3Cache}, - idxs::Nothing, T::Type{Val{1}}, differential_vars::Nothing) - @owrenzen3pre1 - @inbounds @.. broadcast=false out=k[1] * b1Θdiff + k[2] * b2Θdiff + k[3] * b3Θdiff + - k[4] * b4Θdiff - out -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen3ConstantCache, OwrenZen3Cache}, - idxs, T::Type{Val{1}}, differential_vars::Nothing) - @owrenzen3pre1 - @views @.. broadcast=false out=k[1][idxs] * b1Θdiff + k[2][idxs] * b2Θdiff + - k[3][idxs] * b3Θdiff + k[4][idxs] * b4Θdiff - out -end - -@def owrenzen3pre2 begin - @owrenzen3unpack - b1Θdiff2 = @evalpoly(Θ, 2*r12, 6*r13) - b2Θdiff2 = @evalpoly(Θ, 2*r22, 6*r23) - b3Θdiff2 = @evalpoly(Θ, 2*r32, 6*r33) - b4Θdiff2 = @evalpoly(Θ, -2, 6) - invdt = inv(dt) -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen3ConstantCache, OwrenZen3Cache}, - idxs::Nothing, T::Type{Val{2}}, differential_vars::Nothing) - @owrenzen3pre2 - @inbounds @.. broadcast=false (k[1] * b1Θdiff2 + k[2] * b2Θdiff2 + k[3] * b3Θdiff2 + - k[4] * b4Θdiff2)*invdt -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen3ConstantCache, OwrenZen3Cache}, - idxs, T::Type{Val{2}}, differential_vars::Nothing) - @owrenzen3pre2 - @views @.. broadcast=false (k[1][idxs] * b1Θdiff2 + k[2][idxs] * b2Θdiff2 + - k[3][idxs] * b3Θdiff2 + k[4][idxs] * b4Θdiff2)*invdt -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen3ConstantCache, OwrenZen3Cache}, - idxs::Nothing, T::Type{Val{2}}, differential_vars::Nothing) - @owrenzen3pre2 - @inbounds @.. broadcast=false out=(k[1] * b1Θdiff2 + k[2] * b2Θdiff2 + k[3] * b3Θdiff2 + - k[4] * b4Θdiff2) * invdt - out -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen3ConstantCache, OwrenZen3Cache}, - idxs, T::Type{Val{2}}, differential_vars::Nothing) - @owrenzen3pre2 - @views @.. broadcast=false out=(k[1][idxs] * b1Θdiff2 + k[2][idxs] * b2Θdiff2 + - k[3][idxs] * b3Θdiff2 + k[4][idxs] * b4Θdiff2) * invdt - out -end - -@def owrenzen3pre3 begin - @owrenzen3unpack - b1Θdiff3 = 6 * r13 - b2Θdiff3 = 6 * r23 - b3Θdiff3 = 6 * r33 - b4Θdiff3 = 6 - invdt2 = inv(dt)^2 -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen3ConstantCache, OwrenZen3Cache}, - idxs::Nothing, T::Type{Val{3}}, differential_vars::Nothing) - @owrenzen3pre3 - @inbounds @.. broadcast=false (k[1] * b1Θdiff3 + k[2] * b2Θdiff3 + k[3] * b3Θdiff3 + - k[4] * b4Θdiff3)*invdt2 -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen3ConstantCache, OwrenZen3Cache}, - idxs, T::Type{Val{3}}, differential_vars::Nothing) - @owrenzen3pre3 - @views @.. broadcast=false (k[1][idxs] * b1Θdiff3 + k[2][idxs] * b2Θdiff3 + - k[3][idxs] * b3Θdiff3 + k[4][idxs] * b4Θdiff3)*invdt2 -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen3ConstantCache, OwrenZen3Cache}, - idxs::Nothing, T::Type{Val{3}}, differential_vars::Nothing) - @owrenzen3pre3 - @inbounds @.. broadcast=false out=(k[1] * b1Θdiff3 + k[2] * b2Θdiff3 + k[3] * b3Θdiff3 + - k[4] * b4Θdiff3) * invdt2 - out -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen3ConstantCache, OwrenZen3Cache}, - idxs, T::Type{Val{3}}, differential_vars::Nothing) - @owrenzen3pre3 - @views @.. broadcast=false out=(k[1][idxs] * b1Θdiff3 + k[2][idxs] * b2Θdiff3 + - k[3][idxs] * b3Θdiff3 + k[4][idxs] * b4Θdiff3) * invdt2 - out -end - -""" -""" -@def owrenzen4unpack begin - if cache isa OrdinaryDiffEqMutableCache - @unpack r14, r13, r12, r34, r33, r32, r44, r43, r42, r54, r53, r52, r64, r63, r62 = cache.tab - else - @unpack r14, r13, r12, r34, r33, r32, r44, r43, r42, r54, r53, r52, r64, r63, r62 = cache - end -end - -@def owrenzen4pre0 begin - @owrenzen4unpack - Θ² = Θ * Θ - b1Θ = Θ * @evalpoly(Θ, 1, r12, r13, r14) - b3Θ = Θ² * @evalpoly(Θ, r32, r33, r34) - b4Θ = Θ² * @evalpoly(Θ, r42, r43, r44) - b5Θ = Θ² * @evalpoly(Θ, r52, r53, r54) - b6Θ = Θ² * @evalpoly(Θ, r62, r63, r64) -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, - idxs::Nothing, T::Type{Val{0}}, differential_vars::Nothing) - @owrenzen4pre0 - # return @.. broadcast=false y₀ + dt*(k[1]*b1Θ + k[3]*b3Θ + k[4]*b4Θ + k[5]*b5Θ + k[6]*b6Θ) - return @inbounds y₀ + - dt * (k[1] * b1Θ + k[3] * b3Θ + k[4] * b4Θ + k[5] * b5Θ + k[6] * b6Θ) -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, - idxs, T::Type{Val{0}}, differential_vars::Nothing) - @owrenzen4pre0 - # return @.. broadcast=false y₀[idxs] + dt*(k[1][idxs]*b1Θ + k[3][idxs]*b3Θ + - # k[4][idxs]*b4Θ + k[5][idxs]*b5Θ + k[6][idxs]*b6Θ) - return y₀[idxs] + - dt * (k[1][idxs] * b1Θ + k[3][idxs] * b3Θ + - k[4][idxs] * b4Θ + k[5][idxs] * b5Θ + k[6][idxs] * b6Θ) -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, - idxs::Nothing, T::Type{Val{0}}, differential_vars::Nothing) - @owrenzen4pre0 - @inbounds @.. broadcast=false out=y₀ + - dt * - (k[1] * b1Θ + k[3] * b3Θ + k[4] * b4Θ + k[5] * b5Θ + - k[6] * b6Θ) - #@inbounds for i in eachindex(out) - # out[i] = y₀[i] + dt*(k[1][i]*b1Θ + k[3][i]*b3Θ + k[4][i]*b4Θ + - # k[5][i]*b5Θ + k[6][i]*b6Θ) - #end - out -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, - idxs, T::Type{Val{0}}, differential_vars::Nothing) - @owrenzen4pre0 - @inbounds @.. broadcast=false out=y₀[idxs] + - dt * (k[1][idxs] * b1Θ + k[3][idxs] * b3Θ + - k[4][idxs] * b4Θ + k[5][idxs] * b5Θ + - k[6][idxs] * b6Θ) - #@inbounds for (j,i) in enumerate(idxs) - # out[j] = y₀[i] + dt*(k[1][i]*b1Θ + k[3][i]*b3Θ + k[4][i]*b4Θ + - # k[5][i]*b5Θ + k[6][i]*b6Θ) - #end - out -end - -@def owrenzen4pre1 begin - @owrenzen4unpack - b1Θdiff = @evalpoly(Θ, 1, 2*r12, 3*r13, 4*r14) - b3Θdiff = Θ * @evalpoly(Θ, 2*r32, 3*r33, 4*r34) - b4Θdiff = Θ * @evalpoly(Θ, 2*r42, 3*r43, 4*r44) - b5Θdiff = Θ * @evalpoly(Θ, 2*r52, 3*r53, 4*r54) - b6Θdiff = Θ * @evalpoly(Θ, 2*r62, 3*r63, 4*r64) -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, - idxs::Nothing, T::Type{Val{1}}, differential_vars::Nothing) - @owrenzen4pre1 - @inbounds @.. broadcast=false k[1]*b1Θdiff+k[3]*b3Θdiff+k[4]*b4Θdiff+k[5]*b5Θdiff+ - k[6]*b6Θdiff -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, - idxs, T::Type{Val{1}}, differential_vars::Nothing) - @owrenzen4pre1 - @views @.. broadcast=false k[1][idxs]*b1Θdiff+k[3][idxs]*b3Θdiff+k[4][idxs]*b4Θdiff+ - k[5][idxs]*b5Θdiff+k[6][idxs]*b6Θdiff -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, - idxs::Nothing, T::Type{Val{1}}, differential_vars::Nothing) - @owrenzen4pre1 - @inbounds @.. broadcast=false out=k[1] * b1Θdiff + k[3] * b3Θdiff + k[4] * b4Θdiff + - k[5] * b5Θdiff + k[6] * b6Θdiff - out -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, - idxs, T::Type{Val{1}}, differential_vars::Nothing) - @owrenzen4pre1 - @views @.. broadcast=false out=k[1][idxs] * b1Θdiff + k[3][idxs] * b3Θdiff + - k[4][idxs] * b4Θdiff + - k[5][idxs] * b5Θdiff + k[6][idxs] * b6Θdiff - out -end - -@def owrenzen4pre2 begin - @owrenzen4unpack - b1Θdiff2 = @evalpoly(Θ, 2*r12, 6*r13, 12*r14) - b3Θdiff2 = @evalpoly(Θ, 2*r32, 6*r33, 12*r34) - b4Θdiff2 = @evalpoly(Θ, 2*r42, 6*r43, 12*r44) - b5Θdiff2 = @evalpoly(Θ, 2*r52, 6*r53, 12*r54) - b6Θdiff2 = @evalpoly(Θ, 2*r62, 6*r63, 12*r64) - invdt = inv(dt) -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, - idxs::Nothing, T::Type{Val{2}}, differential_vars::Nothing) - @owrenzen4pre2 - @.. broadcast=false (k[1] * b1Θdiff2 + k[3] * b3Θdiff2 + k[4] * b4Θdiff2 + - k[5] * b5Θdiff2 + k[6] * b6Θdiff2)*invdt -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, - idxs, T::Type{Val{2}}, differential_vars::Nothing) - @owrenzen4pre2 - @views @.. broadcast=false (k[1][idxs] * b1Θdiff2 + k[3][idxs] * b3Θdiff2 + - k[4][idxs] * b4Θdiff2 + - k[5][idxs] * b5Θdiff2 + k[6][idxs] * b6Θdiff2)*invdt -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, - idxs::Nothing, T::Type{Val{2}}, differential_vars::Nothing) - @owrenzen4pre2 - @inbounds @.. broadcast=false out=(k[1] * b1Θdiff2 + k[3] * b3Θdiff2 + k[4] * b4Θdiff2 + - k[5] * b5Θdiff2 + k[6] * b6Θdiff2) * invdt - out -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, - idxs, T::Type{Val{2}}, differential_vars::Nothing) - @owrenzen4pre2 - @views @.. broadcast=false out=(k[1][idxs] * b1Θdiff2 + k[3][idxs] * b3Θdiff2 + - k[4][idxs] * b4Θdiff2 + - k[5][idxs] * b5Θdiff2 + k[6][idxs] * b6Θdiff2) * invdt - out -end - -@def owrenzen4pre3 begin - @owrenzen4unpack - b1Θdiff3 = @evalpoly(Θ, 6*r13, 24*r14) - b3Θdiff3 = @evalpoly(Θ, 6*r33, 24*r34) - b4Θdiff3 = @evalpoly(Θ, 6*r43, 24*r44) - b5Θdiff3 = @evalpoly(Θ, 6*r53, 24*r54) - b6Θdiff3 = @evalpoly(Θ, 6*r63, 24*r64) - invdt2 = inv(dt)^2 -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, - idxs::Nothing, T::Type{Val{3}}, differential_vars::Nothing) - @owrenzen4pre3 - @inbounds @.. broadcast=false (k[1] * b1Θdiff3 + k[3] * b3Θdiff3 + k[4] * b4Θdiff3 + - k[5] * b5Θdiff3 + k[6] * b6Θdiff3)*invdt2 -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, - idxs, T::Type{Val{3}}, differential_vars::Nothing) - @owrenzen4pre3 - @views @.. broadcast=false (k[1][idxs] * b1Θdiff3 + k[3][idxs] * b3Θdiff3 + - k[4][idxs] * b4Θdiff3 + - k[5][idxs] * b5Θdiff3 + k[6][idxs] * b6Θdiff3)*invdt2 -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, - idxs::Nothing, T::Type{Val{3}}, differential_vars::Nothing) - @owrenzen4pre3 - @inbounds @.. broadcast=false out=(k[1] * b1Θdiff3 + k[3] * b3Θdiff3 + k[4] * b4Θdiff3 + - k[5] * b5Θdiff3 + k[6] * b6Θdiff3) * invdt2 - out -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, - idxs, T::Type{Val{3}}, differential_vars::Nothing) - @owrenzen4pre3 - @views @.. broadcast=false out=(k[1][idxs] * b1Θdiff3 + k[3][idxs] * b3Θdiff3 + - k[4][idxs] * b4Θdiff3 + - k[5][idxs] * b5Θdiff3 + k[6][idxs] * b6Θdiff3) * invdt2 - out -end - -@def owrenzen4pre4 begin - @owrenzen4unpack - b1Θdiff4 = 24 * r14 - b3Θdiff4 = 24 * r34 - b4Θdiff4 = 24 * r44 - b5Θdiff4 = 24 * r54 - b6Θdiff4 = 24 * r64 - invdt3 = inv(dt)^3 -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, - idxs::Nothing, T::Type{Val{4}}, differential_vars::Nothing) - @owrenzen4pre4 - @.. broadcast=false (k[1] * b1Θdiff4 + k[3] * b3Θdiff4 + k[4] * b4Θdiff4 + - k[5] * b5Θdiff4 + k[6] * b6Θdiff4)*invdt3 -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, - idxs, T::Type{Val{4}}, differential_vars::Nothing) - @owrenzen4pre4 - @views @.. broadcast=false (k[1][idxs] * b1Θdiff4 + k[3][idxs] * b3Θdiff4 + - k[4][idxs] * b4Θdiff4 + - k[5][idxs] * b5Θdiff4 + k[6][idxs] * b6Θdiff4)*invdt3 -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, - idxs::Nothing, T::Type{Val{4}}, differential_vars::Nothing) - @owrenzen4pre4 - @inbounds @.. broadcast=false out=(k[1] * b1Θdiff4 + k[3] * b3Θdiff4 + k[4] * b4Θdiff4 + - k[5] * b5Θdiff4 + k[6] * b6Θdiff4) * invdt3 - out -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen4ConstantCache, OwrenZen4Cache}, - idxs, T::Type{Val{4}}, differential_vars::Nothing) - @owrenzen4pre4 - @views @.. broadcast=false out=(k[1][idxs] * b1Θdiff4 + k[3][idxs] * b3Θdiff4 + - k[4][idxs] * b4Θdiff4 + - k[5][idxs] * b5Θdiff4 + k[6][idxs] * b6Θdiff4) * invdt3 - out -end - -""" -""" -@def owrenzen5unpack begin - if cache isa OrdinaryDiffEqMutableCache - @unpack r15, r14, r13, r12, r35, r34, r33, r32, r45, r44, r43, r42, r55, r54, r53, r52, r65, r64, r63, r62, r75, r74, r73, r72, r85, r84, r83, r82 = cache.tab - else - @unpack r15, r14, r13, r12, r35, r34, r33, r32, r45, r44, r43, r42, r55, r54, r53, r52, r65, r64, r63, r62, r75, r74, r73, r72, r85, r84, r83, r82 = cache - end -end - -@def owrenzen5pre0 begin - @owrenzen5unpack - Θ² = Θ * Θ - b1Θ = Θ * @evalpoly(Θ, 1, r12, r13, r14, r15) - b3Θ = Θ² * @evalpoly(Θ, r32, r33, r34, r35) - b4Θ = Θ² * @evalpoly(Θ, r42, r43, r44, r45) - b5Θ = Θ² * @evalpoly(Θ, r52, r53, r54, r55) - b6Θ = Θ² * @evalpoly(Θ, r62, r63, r64, r65) - b7Θ = Θ² * @evalpoly(Θ, r72, r73, r74, r75) - b8Θ = Θ² * @evalpoly(Θ, r82, r83, r84, r85) -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, - idxs::Nothing, T::Type{Val{0}}, differential_vars::Nothing) - @owrenzen5pre0 - # return @.. broadcast=false y₀ + dt*(k[1]*b1Θ + k[3]*b3Θ + k[4]*b4Θ + k[5]*b5Θ + k[6]*b6Θ + - # k[7]*b7Θ + k[8]*b8Θ) - return @inbounds y₀ + - dt * (k[1] * b1Θ + k[3] * b3Θ + k[4] * b4Θ + k[5] * b5Θ + k[6] * b6Θ + - k[7] * b7Θ + k[8] * b8Θ) -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, - idxs, T::Type{Val{0}}, differential_vars::Nothing) - @owrenzen5pre0 - # return @.. broadcast=false y₀[idxs] + dt*(k[1][idxs]*b1Θ + k[3][idxs]*b3Θ + - # k[4][idxs]*b4Θ + k[5][idxs]*b5Θ + k[6][idxs]*b6Θ + - # k[7][idxs]*b7Θ + k[8][idxs]*b8Θ) - return y₀[idxs] + - dt * (k[1][idxs] * b1Θ + k[3][idxs] * b3Θ + - k[4][idxs] * b4Θ + k[5][idxs] * b5Θ + k[6][idxs] * b6Θ + - k[7][idxs] * b7Θ + k[8][idxs] * b8Θ) -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, - idxs::Nothing, T::Type{Val{0}}, differential_vars::Nothing) - @owrenzen5pre0 - @inbounds @.. broadcast=false out=y₀ + - dt * - (k[1] * b1Θ + k[3] * b3Θ + k[4] * b4Θ + k[5] * b5Θ + - k[6] * b6Θ + - k[7] * b7Θ + k[8] * b8Θ) - #@inbounds for i in eachindex(out) - # out[i] = y₀[i] + dt*(k[1][i]*b1Θ + k[3][i]*b3Θ + k[4][i]*b4Θ + - # k[5][i]*b5Θ + k[6][i]*b6Θ + k[7][i]*b7Θ + k[8][i]*b8Θ) - #end - out -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, - idxs, T::Type{Val{0}}, differential_vars::Nothing) - @owrenzen5pre0 - @views @.. broadcast=false out=y₀[idxs] + - dt * (k[1][idxs] * b1Θ + k[3][idxs] * b3Θ + - k[4][idxs] * b4Θ + k[5][idxs] * b5Θ + k[6][idxs] * b6Θ + - k[7][idxs] * b7Θ + k[8][idxs] * b8Θ) - #@inbounds for (j,i) in enumerate(idxs) - # out[j] = y₀[i] + dt*(k[1][i]*b1Θ + k[3][i]*b3Θ + k[4][i]*b4Θ + - # k[5][i]*b5Θ + k[6][i]*b6Θ + k[7][i]*b7Θ + k[8][i]*b8Θ) - #end - out -end - -@def owrenzen5pre1 begin - @owrenzen5unpack - b1Θdiff = @evalpoly(Θ, 1, 2*r12, 3*r13, 4*r14, 5*r15) - b3Θdiff = Θ * @evalpoly(Θ, 2*r32, 3*r33, 4*r34, 5*r35) - b4Θdiff = Θ * @evalpoly(Θ, 2*r42, 3*r43, 4*r44, 5*r45) - b5Θdiff = Θ * @evalpoly(Θ, 2*r52, 3*r53, 4*r54, 5*r55) - b6Θdiff = Θ * @evalpoly(Θ, 2*r62, 3*r63, 4*r64, 5*r65) - b7Θdiff = Θ * @evalpoly(Θ, 2*r72, 3*r73, 4*r74, 5*r75) - b8Θdiff = Θ * @evalpoly(Θ, 2*r82, 3*r83, 4*r84, 5*r85) -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, - idxs::Nothing, T::Type{Val{1}}, differential_vars::Nothing) - @owrenzen5pre1 - return @inbounds k[1] * b1Θdiff + k[3] * b3Θdiff + k[4] * b4Θdiff + k[5] * b5Θdiff + - k[6] * b6Θdiff + k[7] * b7Θdiff + k[8] * b8Θdiff -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, - idxs, T::Type{Val{1}}, differential_vars::Nothing) - @owrenzen5pre1 - k[1][idxs] * b1Θdiff + k[3][idxs] * b3Θdiff + k[4][idxs] * b4Θdiff + - k[5][idxs] * b5Θdiff + - k[6][idxs] * b6Θdiff + k[7][idxs] * b7Θdiff + k[8][idxs] * b8Θdiff -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, - idxs::Nothing, T::Type{Val{1}}, differential_vars::Nothing) - @owrenzen5pre1 - @inbounds @.. broadcast=false out=k[1] * b1Θdiff + k[3] * b3Θdiff + k[4] * b4Θdiff + - k[5] * b5Θdiff + k[6] * b6Θdiff + k[7] * b7Θdiff + - k[8] * b8Θdiff - #@inbounds for i in eachindex(out) - # out[i] = k[1][i]*b1Θdiff + k[3][i]*b3Θdiff + k[4][i]*b4Θdiff + - # k[5][i]*b5Θdiff + k[6][i]*b6Θdiff + k[7][i]*b7Θdiff + k[8][i]*b8Θdiff - #end - out -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, - idxs, T::Type{Val{1}}, differential_vars::Nothing) - @owrenzen5pre1 - @views @.. broadcast=false out=k[1][idxs] * b1Θdiff + k[3][idxs] * b3Θdiff + - k[4][idxs] * b4Θdiff + - k[5][idxs] * b5Θdiff + k[6][idxs] * b6Θdiff + - k[7][idxs] * b7Θdiff + k[8][idxs] * b8Θdiff - #@inbounds for (j,i) in enumerate(idxs) - # out[j] = k[1][i]*b1Θdiff + k[3][i]*b3Θdiff + k[4][i]*b4Θdiff + - # k[5][i]*b5Θdiff + k[6][i]*b6Θdiff + k[7][i]*b7Θdiff + k[8][i]*b8Θdiff - #end - out -end - -@def owrenzen5pre2 begin - @owrenzen5unpack - b1Θdiff2 = @evalpoly(Θ, 2*r12, 6*r13, 12*r14, 20*r15) - b3Θdiff2 = @evalpoly(Θ, 2*r32, 6*r33, 12*r34, 20*r35) - b4Θdiff2 = @evalpoly(Θ, 2*r42, 6*r43, 12*r44, 20*r45) - b5Θdiff2 = @evalpoly(Θ, 2*r52, 6*r53, 12*r54, 20*r55) - b6Θdiff2 = @evalpoly(Θ, 2*r62, 6*r63, 12*r64, 20*r65) - b7Θdiff2 = @evalpoly(Θ, 2*r72, 6*r73, 12*r74, 20*r75) - b8Θdiff2 = @evalpoly(Θ, 2*r82, 6*r83, 12*r84, 20*r85) - invdt = inv(dt) -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, - idxs::Nothing, T::Type{Val{2}}, differential_vars::Nothing) - @owrenzen5pre2 - return @inbounds (k[1] * b1Θdiff2 + k[3] * b3Θdiff2 + k[4] * b4Θdiff2 + - k[5] * b5Θdiff2 + - k[6] * b6Θdiff2 + k[7] * b7Θdiff2 + k[8] * b8Θdiff2) * invdt -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, - idxs, T::Type{Val{2}}, differential_vars::Nothing) - @owrenzen5pre2 - (k[1][idxs] * b1Θdiff2 + k[3][idxs] * b3Θdiff2 + k[4][idxs] * b4Θdiff2 + - k[5][idxs] * b5Θdiff2 + - k[6][idxs] * b6Θdiff2 + k[7][idxs] * b7Θdiff2 + k[8][idxs] * b8Θdiff2) * invdt -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, - idxs::Nothing, T::Type{Val{2}}, differential_vars::Nothing) - @owrenzen5pre2 - @inbounds @.. broadcast=false out=(k[1] * b1Θdiff2 + k[3] * b3Θdiff2 + k[4] * b4Θdiff2 + - k[5] * b5Θdiff2 + k[6] * b6Θdiff2 + k[7] * b7Θdiff2 + - k[8] * b8Θdiff2) * invdt - #@inbounds for i in eachindex(out) - # out[i] = (k[1][i]*b1Θdiff2 + k[3][i]*b3Θdiff2 + k[4][i]*b4Θdiff2 + - # k[5][i]*b5Θdiff2 + k[6][i]*b6Θdiff2 + k[7][i]*b7Θdiff2 + k[8][i]*b8Θdiff2)*invdt - #end - out -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, - idxs, T::Type{Val{2}}, differential_vars::Nothing) - @owrenzen5pre2 - @views @.. broadcast=false out=(k[1][idxs] * b1Θdiff2 + k[3][idxs] * b3Θdiff2 + - k[4][idxs] * b4Θdiff2 + - k[5][idxs] * b5Θdiff2 + k[6][idxs] * b6Θdiff2 + - k[7][idxs] * b7Θdiff2 + k[8][idxs] * b8Θdiff2) * invdt - #@inbounds for (j,i) in enumerate(idxs) - # out[j] = (k[1][i]*b1Θdiff2 + k[3][i]*b3Θdiff2 + k[4][i]*b4Θdiff2 + - # k[5][i]*b5Θdiff2 + k[6][i]*b6Θdiff2 + k[7][i]*b7Θdiff2 + k[8][i]*b8Θdiff2)*invdt - #end - out -end - -@def owrenzen5pre3 begin - @owrenzen5unpack - b1Θdiff3 = @evalpoly(Θ, 6*r13, 24*r14, 60*r15) - b3Θdiff3 = @evalpoly(Θ, 6*r33, 24*r34, 60*r35) - b4Θdiff3 = @evalpoly(Θ, 6*r43, 24*r44, 60*r45) - b5Θdiff3 = @evalpoly(Θ, 6*r53, 24*r54, 60*r55) - b6Θdiff3 = @evalpoly(Θ, 6*r63, 24*r64, 60*r65) - b7Θdiff3 = @evalpoly(Θ, 6*r73, 24*r74, 60*r75) - b8Θdiff3 = @evalpoly(Θ, 6*r83, 24*r84, 60*r85) - invdt2 = inv(dt)^2 -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, - idxs::Nothing, T::Type{Val{3}}, differential_vars::Nothing) - @owrenzen5pre3 - return @inbounds (k[1] * b1Θdiff3 + k[3] * b3Θdiff3 + k[4] * b4Θdiff3 + - k[5] * b5Θdiff3 + - k[6] * b6Θdiff3 + k[7] * b7Θdiff3 + k[8] * b8Θdiff3) * invdt2 -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, - idxs, T::Type{Val{3}}, differential_vars::Nothing) - @owrenzen5pre3 - (k[1][idxs] * b1Θdiff3 + k[3][idxs] * b3Θdiff3 + k[4][idxs] * b4Θdiff3 + - k[5][idxs] * b5Θdiff3 + - k[6][idxs] * b6Θdiff3 + k[7][idxs] * b7Θdiff3 + k[8][idxs] * b8Θdiff3) * invdt2 -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, - idxs::Nothing, T::Type{Val{3}}, differential_vars::Nothing) - @owrenzen5pre3 - @inbounds @.. broadcast=false out=(k[1] * b1Θdiff3 + k[3] * b3Θdiff3 + k[4] * b4Θdiff3 + - k[5] * b5Θdiff3 + k[6] * b6Θdiff3 + k[7] * b7Θdiff3 + - k[8] * b8Θdiff3) * invdt2 - #@inbounds for i in eachindex(out) - # out[i] = (k[1][i]*b1Θdiff3 + k[3][i]*b3Θdiff3 + k[4][i]*b4Θdiff3 + - # k[5][i]*b5Θdiff3 + k[6][i]*b6Θdiff3 + k[7][i]*b7Θdiff3 + k[8][i]*b8Θdiff3)*invdt2 - #end - out -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, - idxs, T::Type{Val{3}}, differential_vars::Nothing) - @owrenzen5pre3 - @views @.. broadcast=false out=(k[1][idxs] * b1Θdiff3 + k[3][idxs] * b3Θdiff3 + - k[4][idxs] * b4Θdiff3 + - k[5][idxs] * b5Θdiff3 + k[6][idxs] * b6Θdiff3 + - k[7][idxs] * b7Θdiff3 + k[8][idxs] * b8Θdiff3) * invdt2 - #@inbounds for (j,i) in enumerate(idxs) - # out[j] = (k[1][i]*b1Θdiff3 + k[3][i]*b3Θdiff3 + k[4][i]*b4Θdiff3 + - # k[5][i]*b5Θdiff3 + k[6][i]*b6Θdiff3 + k[7][i]*b7Θdiff3 + k[8][i]*b8Θdiff3)*invdt2 - #end - out -end - -@def owrenzen5pre4 begin - @owrenzen5unpack - b1Θdiff4 = @evalpoly(Θ, 24*r14, 120*r15) - b3Θdiff4 = @evalpoly(Θ, 24*r34, 120*r35) - b4Θdiff4 = @evalpoly(Θ, 24*r44, 120*r45) - b5Θdiff4 = @evalpoly(Θ, 24*r54, 120*r55) - b6Θdiff4 = @evalpoly(Θ, 24*r64, 120*r65) - b7Θdiff4 = @evalpoly(Θ, 24*r74, 120*r75) - b8Θdiff4 = @evalpoly(Θ, 24*r84, 120*r85) - invdt3 = inv(dt)^3 -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, - idxs::Nothing, T::Type{Val{4}}, differential_vars::Nothing) - @owrenzen5pre4 - return @inbounds (k[1] * b1Θdiff4 + k[3] * b3Θdiff4 + k[4] * b4Θdiff4 + - k[5] * b5Θdiff4 + - k[6] * b6Θdiff4 + k[7] * b7Θdiff4 + k[8] * b8Θdiff4) * invdt3 -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, - idxs, T::Type{Val{4}}, differential_vars::Nothing) - @owrenzen5pre4 - (k[1][idxs] * b1Θdiff4 + k[3][idxs] * b3Θdiff4 + k[4][idxs] * b4Θdiff4 + - k[5][idxs] * b5Θdiff4 + - k[6][idxs] * b6Θdiff4 + k[7][idxs] * b7Θdiff4 + k[8][idxs] * b8Θdiff4) * invdt3 -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, - idxs::Nothing, T::Type{Val{4}}, differential_vars::Nothing) - @owrenzen5pre4 - @inbounds @.. broadcast=false out=(k[1] * b1Θdiff4 + k[3] * b3Θdiff4 + k[4] * b4Θdiff4 + - k[5] * b5Θdiff4 + k[6] * b6Θdiff4 + k[7] * b7Θdiff4 + - k[8] * b8Θdiff4) * invdt3 - #@inbounds for i in eachindex(out) - # out[i] = (k[1][i]*b1Θdiff4 + k[3][i]*b3Θdiff4 + k[4][i]*b4Θdiff4 + - # k[5][i]*b5Θdiff4 + k[6][i]*b6Θdiff4 + k[7][i]*b7Θdiff4 + k[8][i]*b8Θdiff4)*invdt3 - #end - out -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, - idxs, T::Type{Val{4}}, differential_vars::Nothing) - @owrenzen5pre4 - @views @.. broadcast=false out=(k[1][idxs] * b1Θdiff4 + k[3][idxs] * b3Θdiff4 + - k[4][idxs] * b4Θdiff4 + - k[5][idxs] * b5Θdiff4 + k[6][idxs] * b6Θdiff4 + - k[7][idxs] * b7Θdiff4 + k[8][idxs] * b8Θdiff4) * invdt3 - #@inbounds for (j,i) in enumerate(idxs) - # out[j] = (k[1][i]*b1Θdiff4 + k[3][i]*b3Θdiff4 + k[4][i]*b4Θdiff4 + - # k[5][i]*b5Θdiff4 + k[6][i]*b6Θdiff4 + k[7][i]*b7Θdiff4 + k[8][i]*b8Θdiff4)*invdt3 - #end - out -end - -@def owrenzen5pre5 begin - @owrenzen5unpack - b1Θdiff5 = 120 * r15 - b3Θdiff5 = 120 * r35 - b4Θdiff5 = 120 * r45 - b5Θdiff5 = 120 * r55 - b6Θdiff5 = 120 * r65 - b7Θdiff5 = 120 * r75 - b8Θdiff5 = 120 * r85 - invdt4 = inv(dt)^4 -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, - idxs::Nothing, T::Type{Val{5}}, differential_vars::Nothing) - @owrenzen5pre5 - return @inbounds (k[1] * b1Θdiff5 + k[3] * b3Θdiff5 + k[4] * b4Θdiff5 + - k[5] * b5Θdiff5 + - k[6] * b6Θdiff5 + k[7] * b7Θdiff5 + k[8] * b8Θdiff5) * invdt4 -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, - idxs, T::Type{Val{5}}, differential_vars::Nothing) - @owrenzen5pre5 - (k[1][idxs] * b1Θdiff5 + k[3][idxs] * b3Θdiff5 + k[4][idxs] * b4Θdiff5 + - k[5][idxs] * b5Θdiff5 + - k[6][idxs] * b6Θdiff5 + k[7][idxs] * b7Θdiff5 + k[8][idxs] * b8Θdiff5) * invdt4 -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, - idxs::Nothing, T::Type{Val{5}}, differential_vars::Nothing) - @owrenzen5pre5 - @inbounds @.. broadcast=false out=(k[1] * b1Θdiff5 + k[3] * b3Θdiff5 + k[4] * b4Θdiff5 + - k[5] * b5Θdiff5 + k[6] * b6Θdiff5 + k[7] * b7Θdiff5 + - k[8] * b8Θdiff5) * invdt4 - #@inbounds for i in eachindex(out) - # out[i] = (k[1][i]*b1Θdiff5 + k[3][i]*b3Θdiff5 + k[4][i]*b4Θdiff5 + - # k[5][i]*b5Θdiff5 + k[6][i]*b6Θdiff5 + k[7][i]*b7Θdiff5 + k[8][i]*b8Θdiff5)*invdt4 - #end - out -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{OwrenZen5ConstantCache, OwrenZen5Cache}, - idxs, T::Type{Val{5}}, differential_vars::Nothing) - @owrenzen5pre5 - @views @.. broadcast=false out=(k[1][idxs] * b1Θdiff5 + k[3][idxs] * b3Θdiff5 + - k[4][idxs] * b4Θdiff5 + - k[5][idxs] * b5Θdiff5 + k[6][idxs] * b6Θdiff5 + - k[7][idxs] * b7Θdiff5 + k[8][idxs] * b8Θdiff5) * invdt4 - #@inbounds for (j,i) in enumerate(idxs) - # out[j] = (k[1][i]*b1Θdiff5 + k[3][i]*b3Θdiff5 + k[4][i]*b4Θdiff5 + - # k[5][i]*b5Θdiff5 + k[6][i]*b6Θdiff5 + k[7][i]*b7Θdiff5 + k[8][i]*b8Θdiff5)*invdt4 - #end - out -end - -""" -Coefficients taken from RKSuite -""" -@def bs5unpack begin - if cache isa OrdinaryDiffEqMutableCache - @unpack r016, r015, r014, r013, r012, r036, r035, r034, r033, r032, r046, r045, r044, r043, r042, r056, r055, r054, r053, r052, r066, r065, r064, r063, r062, r076, r075, r074, r073, r072, r086, r085, r084, r083, r082, r096, r095, r094, r093, r106, r105, r104, r103, r102, r116, r115, r114, r113, r112 = cache.tab - else - @unpack r016, r015, r014, r013, r012, r036, r035, r034, r033, r032, r046, r045, r044, r043, r042, r056, r055, r054, r053, r052, r066, r065, r064, r063, r062, r076, r075, r074, r073, r072, r086, r085, r084, r083, r082, r096, r095, r094, r093, r106, r105, r104, r103, r102, r116, r115, r114, r113, r112 = cache - end -end - -@def bs5pre0 begin - @bs5unpack - Θ² = Θ * Θ - b1Θ = Θ² * @evalpoly(Θ, r012, r013, r014, r015, r016) - b3Θ = Θ² * @evalpoly(Θ, r032, r033, r034, r035, r036) - b4Θ = Θ² * @evalpoly(Θ, r042, r043, r044, r045, r046) - b5Θ = Θ² * @evalpoly(Θ, r052, r053, r054, r055, r056) - b6Θ = Θ² * @evalpoly(Θ, r062, r063, r064, r065, r066) - b7Θ = Θ² * @evalpoly(Θ, r072, r073, r074, r075, r076) - b8Θ = Θ² * @evalpoly(Θ, r082, r083, r084, r085, r086) - b9Θ = (Θ² * Θ) * @evalpoly(Θ, r093, r094, r095, - r096) - b10Θ = Θ² * @evalpoly(Θ, r102, r103, r104, r105, r106) - b11Θ = Θ² * @evalpoly(Θ, r112, r113, r114, r115, r116) -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, cache::BS5ConstantCache, idxs::Nothing, - T::Type{Val{0}}, differential_vars::Nothing) - @bs5pre0 - # return @.. broadcast=false y₀ + dt*Θ*k[1] + dt*(k[1]*b1Θ + k[3]*b3Θ + k[4]*b4Θ + k[5]*b5Θ + k[6]*b6Θ + k[7]*b7Θ + k[8]*b8Θ + k[9]*b9Θ + k[10]*b10Θ + k[11]*b11Θ) - return @inbounds y₀ + dt * Θ * k[1] + - dt * (k[1] * b1Θ + k[3] * b3Θ + k[4] * b4Θ + k[5] * b5Θ + - k[6] * b6Θ + k[7] * b7Θ + k[8] * b8Θ + k[9] * b9Θ + k[10] * b10Θ + - k[11] * b11Θ) -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, cache::BS5Cache, idxs::Nothing, - T::Type{Val{0}}, differential_vars::Nothing) - @bs5pre0 - # return @.. broadcast=false y₀ + dt*Θ*k[1] + dt*(k[1]*b1Θ + k[3]*b3Θ + k[4]*b4Θ + k[5]*b5Θ + k[6]*b6Θ + k[7]*b7Θ + k[8]*b8Θ + k[9]*b9Θ + k[10]*b10Θ + k[11]*b11Θ) - return @inbounds @.. broadcast=false y₀+dt*Θ*k[1]+ - dt*(k[1] * b1Θ + k[3] * b3Θ + k[4] * b4Θ + - k[5] * b5Θ + - k[6] * b6Θ + k[7] * b7Θ + k[8] * b8Θ + - k[9] * b9Θ + k[10] * b10Θ + k[11] * b11Θ) -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{BS5ConstantCache, BS5Cache}, idxs, - T::Type{Val{0}}, differential_vars::Nothing) - @bs5pre0 - # return @.. broadcast=false y₀[idxs] + dt*Θ*k[1][idxs] + dt*(k[1][idxs]*b1Θ + k[3][idxs]*b3Θ + - # k[4][idxs]*b4Θ + k[5][idxs]*b5Θ + k[6][idxs]*b6Θ + k[7][idxs]*b7Θ + - # k[8][idxs]*b8Θ + k[9][idxs]*b9Θ + k[10][idxs]*b10Θ + k[11][idxs]*b11Θ) - return y₀[idxs] + dt * Θ * k[1][idxs] + - dt * (k[1][idxs] * b1Θ + k[3][idxs] * b3Θ + - k[4][idxs] * b4Θ + k[5][idxs] * b5Θ + k[6][idxs] * b6Θ + k[7][idxs] * b7Θ + - k[8][idxs] * b8Θ + k[9][idxs] * b9Θ + k[10][idxs] * b10Θ + k[11][idxs] * b11Θ) -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{BS5ConstantCache, BS5Cache}, idxs::Nothing, - T::Type{Val{0}}, differential_vars::Nothing) - @bs5pre0 - @inbounds @.. broadcast=false out=y₀ + dt * Θ * k[1] + - dt * - (k[1] * b1Θ + k[3] * b3Θ + k[4] * b4Θ + k[5] * b5Θ + - k[6] * b6Θ + k[7] * b7Θ + k[8] * b8Θ + k[9] * b9Θ + - k[10] * b10Θ + k[11] * b11Θ) - #@inbounds for i in eachindex(out) - # out[i] = y₀[i] + dt*Θ*k[1][i] + dt*(k[1][i]*b1Θ + k[3][i]*b3Θ + k[4][i]*b4Θ + k[5][i]*b5Θ + k[6][i]*b6Θ + k[7][i]*b7Θ + k[8][i]*b8Θ + k[9][i]*b9Θ + k[10][i]*b10Θ + k[11][i]*b11Θ) - #end - out -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{BS5ConstantCache, BS5Cache}, idxs, - T::Type{Val{0}}, differential_vars::Nothing) - @bs5pre0 - @views @.. broadcast=false out=y₀[idxs] + dt * Θ * k[1][idxs] + - dt * - (k[1][idxs] * b1Θ + k[3][idxs] * b3Θ + k[4][idxs] * b4Θ + - k[5][idxs] * b5Θ + k[6][idxs] * b6Θ + k[7][idxs] * b7Θ + - k[8][idxs] * b8Θ + k[9][idxs] * b9Θ + - k[10][idxs] * b10Θ + k[11][idxs] * b11Θ) - #@inbounds for (j,i) in enumerate(idxs) - # out[j] = y₀[i] + dt*Θ*k[1][i] + dt*(k[1][i]*b1Θ + k[3][i]*b3Θ + k[4][i]*b4Θ + k[5][i]*b5Θ + k[6][i]*b6Θ + k[7][i]*b7Θ + k[8][i]*b8Θ + k[9][i]*b9Θ + k[10][i]*b10Θ + k[11][i]*b11Θ) - #end - out -end - -@def bs5pre1 begin - @bs5unpack - Θ² = Θ * Θ - b1Θdiff = Θ * @evalpoly(Θ, 2*r012, 3*r013, 4*r014, 5*r015, 6*r016) - b3Θdiff = Θ * @evalpoly(Θ, 2*r032, 3*r033, 4*r034, 5*r035, 6*r036) - b4Θdiff = Θ * @evalpoly(Θ, 2*r042, 3*r043, 4*r044, 5*r045, 6*r046) - b5Θdiff = Θ * @evalpoly(Θ, 2*r052, 3*r053, 4*r054, 5*r055, 6*r056) - b6Θdiff = Θ * @evalpoly(Θ, 2*r062, 3*r063, 4*r064, 5*r065, 6*r066) - b7Θdiff = Θ * @evalpoly(Θ, 2*r072, 3*r073, 4*r074, 5*r075, 6*r076) - b8Θdiff = Θ * @evalpoly(Θ, 2*r082, 3*r083, 4*r084, 5*r085, 6*r086) - b9Θdiff = Θ² * @evalpoly(Θ, 3*r093, 4*r094, 5*r095, 6*r096) - b10Θdiff = Θ * @evalpoly(Θ, 2*r102, 3*r103, 4*r104, 5*r105, 6*r106) - b11Θdiff = Θ * @evalpoly(Θ, 2*r112, 3*r113, 4*r114, 5*r115, 6*r116) -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{BS5ConstantCache, BS5Cache}, idxs::Nothing, - T::Type{Val{1}}, differential_vars::Nothing) - @bs5pre1 - # return @.. broadcast=false k[1] + k[1]*b1Θdiff + k[3]*b3Θdiff + k[4]*b4Θdiff + k[5]*b5Θdiff + k[6]*b6Θdiff + k[7]*b7Θdiff + k[8]*b8Θdiff + k[9]*b9Θdiff + k[10]*b10Θdiff + k[11]*b11Θdiff - return @inbounds k[1] + k[1] * b1Θdiff + k[3] * b3Θdiff + k[4] * b4Θdiff + - k[5] * b5Θdiff + - k[6] * b6Θdiff + k[7] * b7Θdiff + k[8] * b8Θdiff + k[9] * b9Θdiff + - k[10] * b10Θdiff + k[11] * b11Θdiff -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{BS5ConstantCache, BS5Cache}, idxs, - T::Type{Val{1}}, differential_vars::Nothing) - @bs5pre1 - # return @.. broadcast=false k[1][idxs] + k[1][idxs]*b1Θdiff + k[3][idxs]*b3Θdiff + - # k[4][idxs]*b4Θdiff + k[5][idxs]*b5Θdiff + k[6][idxs]*b6Θdiff + - # k[7][idxs]*b7Θdiff + k[8][idxs]*b8Θdiff + k[9][idxs]*b9Θdiff + - # k[10][idxs]*b10Θdiff + k[11][idxs]*b11Θdiff - return @inbounds k[1][idxs] + k[1][idxs] * b1Θdiff + k[3][idxs] * b3Θdiff + - k[4][idxs] * b4Θdiff + k[5][idxs] * b5Θdiff + k[6][idxs] * b6Θdiff + - k[7][idxs] * b7Θdiff + k[8][idxs] * b8Θdiff + k[9][idxs] * b9Θdiff + - k[10][idxs] * b10Θdiff + k[11][idxs] * b11Θdiff -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{BS5ConstantCache, BS5Cache}, idxs::Nothing, - T::Type{Val{1}}, differential_vars::Nothing) - @bs5pre1 - @inbounds @.. broadcast=false out=k[1] + k[1] * b1Θdiff + k[3] * b3Θdiff + - k[4] * b4Θdiff + k[5] * b5Θdiff + k[6] * b6Θdiff + - k[7] * b7Θdiff + k[8] * b8Θdiff + k[9] * b9Θdiff + - k[10] * b10Θdiff + k[11] * b11Θdiff - #@inbounds for i in eachindex(out) - # out[i] = k[1][i] + k[1][i]*b1Θdiff + k[3][i]*b3Θdiff + k[4][i]*b4Θdiff + k[5][i]*b5Θdiff + k[6][i]*b6Θdiff + k[7][i]*b7Θdiff + k[8][i]*b8Θdiff + k[9][i]*b9Θdiff + k[10][i]*b10Θdiff + k[11][i]*b11Θdiff - #end - out -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{BS5ConstantCache, BS5Cache}, idxs, - T::Type{Val{1}}, differential_vars::Nothing) - @bs5pre1 - @views @.. broadcast=false out=k[1][idxs] + k[1][idxs] * b1Θdiff + - k[3][idxs] * b3Θdiff + k[4][idxs] * b4Θdiff + - k[5][idxs] * b5Θdiff + k[6][idxs] * b6Θdiff + - k[7][idxs] * b7Θdiff + k[8][idxs] * b8Θdiff + - k[9][idxs] * b9Θdiff + k[10][idxs] * b10Θdiff + - k[11][idxs] * b11Θdiff - #@inbounds for (j,i) in enumerate(idxs) - # out[j] = k[1][i] + k[1][i]*b1Θdiff + k[3][i]*b3Θdiff + k[4][i]*b4Θdiff + k[5][i]*b5Θdiff + k[6][i]*b6Θdiff + k[7][i]*b7Θdiff + k[8][i]*b8Θdiff + k[9][i]*b9Θdiff + k[10][i]*b10Θdiff + k[11][i]*b11Θdiff - #end - out -end - -""" -""" -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{DP8ConstantCache, DP8Cache}, idxs::Nothing, - T::Type{Val{0}}, differential_vars::Nothing) - Θ1 = 1 - Θ - # return @.. broadcast=false y₀ + dt*Θ*(k[1] + Θ1*(k[2] + Θ*(k[3]+Θ1*(k[4] + Θ*(k[5] + Θ1*(k[6]+Θ*k[7])))))) - return @inbounds y₀ + - dt * Θ * - (k[1] + - Θ1 * (k[2] + - Θ * (k[3] + Θ1 * (k[4] + Θ * (k[5] + Θ1 * (k[6] + Θ * k[7])))))) -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{DP8ConstantCache, DP8Cache}, idxs, - T::Type{Val{0}}, differential_vars::Nothing) - Θ1 = 1 - Θ - # return @.. broadcast=false y₀[idxs] + dt*Θ*(k[1][idxs] + Θ1*(k[2][idxs] + Θ*(k[3][idxs]+Θ1*(k[4][idxs] + Θ*(k[5][idxs] + Θ1*(k[6][idxs]+Θ*k[7][idxs])))))) - return y₀[idxs] + - dt * Θ * - (k[1][idxs] + - Θ1 * (k[2][idxs] + - Θ * (k[3][idxs] + - Θ1 * (k[4][idxs] + Θ * (k[5][idxs] + Θ1 * (k[6][idxs] + Θ * k[7][idxs])))))) -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{DP8ConstantCache, DP8Cache}, idxs::Nothing, - T::Type{Val{0}}, differential_vars::Nothing) - Θ1 = 1 - Θ - @inbounds @.. broadcast=false out=y₀ + - dt * Θ * - (k[1] + - Θ1 * (k[2] + - Θ * (k[3] + - Θ1 * - (k[4] + Θ * (k[5] + Θ1 * (k[6] + Θ * k[7])))))) - #@inbounds for i in eachindex(out) - # out[i] = y₀[i] + dt*Θ*(k[1][i] + Θ1*(k[2][i] + Θ*(k[3][i]+Θ1*(k[4][i] + Θ*(k[5][i] + Θ1*(k[6][i]+Θ*k[7][i])))))) - #end - out -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{DP8ConstantCache, DP8Cache}, idxs, - T::Type{Val{0}}, differential_vars::Nothing) - Θ1 = 1 - Θ - @views @.. broadcast=false out=y₀[idxs] + - dt * Θ * - (k[1][idxs] + - Θ1 * (k[2][idxs] + - Θ * (k[3][idxs] + - Θ1 * (k[4][idxs] + - Θ * - (k[5][idxs] + Θ1 * (k[6][idxs] + Θ * k[7][idxs])))))) - #@inbounds for (j,i) in enumerate(idxs) - # out[j] = y₀[i] + dt*Θ*(k[1][i] + Θ1*(k[2][i] + Θ*(k[3][i]+Θ1*(k[4][i] + Θ*(k[5][i] + Θ1*(k[6][i]+Θ*k[7][i])))))) - #end - out -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{DP8ConstantCache, DP8Cache}, idxs::Nothing, - T::Type{Val{1}}, differential_vars::Nothing) - @inbounds b1diff = @.. broadcast=false k[1]+k[2] - @inbounds b2diff = @.. broadcast=false -2*k[2]+2*k[3]+2*k[4] - @inbounds b3diff = @.. broadcast=false -3 * k[3]-6 * k[4]+3*k[5]+3*k[6] - @inbounds b4diff = @.. broadcast=false 4 * k[4] - 8 * k[5] - 12 * k[6]+4 * k[7] - @inbounds b5diff = @.. broadcast=false 5 * k[5] + 15 * k[6]-15 * k[7] - @inbounds b6diff = @.. broadcast=false -6 * k[6]+18 * k[7] - @inbounds b7diff = @.. broadcast=false -7*k[7] - # return @.. broadcast=false b1diff + Θ*(b2diff + Θ*(b3diff + Θ*(b4diff + Θ*(b5diff + Θ*(b6diff + Θ*b7diff))))) - return b1diff + - Θ * - (b2diff + Θ * (b3diff + Θ * (b4diff + Θ * (b5diff + Θ * (b6diff + Θ * b7diff))))) -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{DP8ConstantCache, DP8Cache}, idxs, - T::Type{Val{1}}, differential_vars::Nothing) - b1diff = @.. broadcast=false k[1][idxs]+k[2][idxs] - b2diff = @.. broadcast=false -2*k[2][idxs]+2*k[3][idxs]+2*k[4][idxs] - b3diff = @.. broadcast=false -3 * k[3][idxs]-6 * k[4][idxs]+3*k[5][idxs]+3*k[6][idxs] - b4diff = @.. broadcast=false 4 * k[4][idxs] - 8 * k[5][idxs] - - 12 * k[6][idxs]+4 * k[7][idxs] - b5diff = @.. broadcast=false 5 * k[5][idxs] + 15 * k[6][idxs]-15 * k[7][idxs] - b6diff = @.. broadcast=false -6 * k[6][idxs]+18 * k[7][idxs] - b7diff = @.. broadcast=false -7*k[7][idxs] - # return @.. broadcast=false b1diff + Θ*(b2diff + Θ*(b3diff + Θ*(b4diff + Θ*(b5diff + Θ*(b6diff + Θ*b7diff))))) - return b1diff + - Θ * - (b2diff + Θ * (b3diff + Θ * (b4diff + Θ * (b5diff + Θ * (b6diff + Θ * b7diff))))) -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{DP8ConstantCache, DP8Cache}, idxs::Nothing, - T::Type{Val{1}}, differential_vars::Nothing) - # b1diff = k[1] + k[2] - # b2diff = -2*k[2] + 2*k[3] + 2*k[4] - # b3diff = -3*k[3] - 6*k[4] + 3*k[5] + 3*k[6] - # b4diff = 4*k[4] - 8*k[5] - 12*k[6] + 4*k[7] - # b5diff = 5*k[5] + 15*k[6] - 15*k[7] - # b6diff = -6*k[6] + 18*k[7] - # @.. broadcast=false out = b1diff + Θ*(b2diff + Θ*(b3diff + Θ*(b4diff + - # Θ*(b5diff + Θ*(b6diff - 7*k[7]*Θ))))) - @views @.. broadcast=false out=k[1] + k[2] + - Θ * (-2 * k[2] + 2 * k[3] + 2 * k[4] + - Θ * (-3 * k[3] - 6 * k[4] + 3 * k[5] + 3 * k[6] + - Θ * (4 * k[4] - 8 * k[5] - 12 * k[6] + 4 * k[7] + - Θ * (5 * k[5] + 15 * k[6] - 15 * k[7] + - Θ * (-6 * k[6] + 18 * k[7] - 7 * k[7] * Θ))))) - out -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{DP8ConstantCache, DP8Cache}, idxs, - T::Type{Val{1}}, differential_vars::Nothing) - # b1diff = k[1][idxs] + k[2][idxs] - # b2diff = -2*k[2][idxs] + 2*k[3][idxs] + 2*k[4][idxs] - # b3diff = -3*k[3][idxs] - 6*k[4][idxs] + 3*k[5][idxs] + 3*k[6][idxs] - # b4diff = 4*k[4][idxs] - 8*k[5][idxs] - 12*k[6][idxs] + 4*k[7][idxs] - # b5diff = 5*k[5][idxs] + 15*k[6][idxs] - 15*k[7][idxs] - # b6diff = -6*k[6][idxs] + 18*k[7][idxs] - #@views @.. broadcast=false out = b1diff + Θ*(b2diff + Θ*(b3diff + Θ*(b4diff + - # Θ*(b5diff + Θ*(b6diff - 7*k[7][idxs]*Θ))))) - @views @.. broadcast=false out=k[1][idxs] + k[2][idxs] + - Θ * (-2 * k[2][idxs] + 2 * k[3][idxs] + 2 * k[4][idxs] + - Θ * - (-3 * k[3][idxs] - 6 * k[4][idxs] + 3 * k[5][idxs] + - 3 * k[6][idxs] + - Θ * - (4 * k[4][idxs] - 8 * k[5][idxs] - 12 * k[6][idxs] + - 4 * k[7][idxs] + - Θ * - (5 * k[5][idxs] + 15 * k[6][idxs] - 15 * k[7][idxs] + - Θ * (-6 * k[6][idxs] + 18 * k[7][idxs] - - 7 * k[7][idxs] * Θ))))) - out -end - -""" -""" +end \ No newline at end of file diff --git a/src/interp_func.jl b/src/interp_func.jl index a3a916de18..782aec1b3b 100644 --- a/src/interp_func.jl +++ b/src/interp_func.jl @@ -39,12 +39,6 @@ function DiffEqBase.interp_summary(::Type{cacheType}, dense::Bool) where {cacheType <: FunctionMapCache} "left-endpoint piecewise constant" end -function DiffEqBase.interp_summary(::Type{cacheType}, - dense::Bool) where { - cacheType <: - Union{DP5ConstantCache, DP5Cache}} - dense ? "specialized 4th order \"free\" interpolation" : "1st order linear" -end function DiffEqBase.interp_summary(::Type{cacheType}, dense::Bool) where { cacheType <: From aa889f2b36499510277ea73d9d200b927f7179be Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Tue, 30 Jul 2024 22:21:51 +0530 Subject: [PATCH 009/133] trivial_limiter! --- .../src/OrdinaryDiffEqLowStorageRK.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqLowStorageRK/src/OrdinaryDiffEqLowStorageRK.jl b/lib/OrdinaryDiffEqLowStorageRK/src/OrdinaryDiffEqLowStorageRK.jl index 81c1801ae0..dc47a17215 100644 --- a/lib/OrdinaryDiffEqLowStorageRK/src/OrdinaryDiffEqLowStorageRK.jl +++ b/lib/OrdinaryDiffEqLowStorageRK/src/OrdinaryDiffEqLowStorageRK.jl @@ -9,7 +9,8 @@ import OrdinaryDiffEq: alg_order, alg_adaptive_order, calculate_residuals!, OrdinaryDiffEqAdaptiveAlgorithm, uses_uprev, default_controller, PIDController, alg_cache, _vec, _reshape, @cache, isfsal, full_cache, - constvalue, _unwrap_val, du_alias_or_new, ArrayFuse + constvalue, _unwrap_val, du_alias_or_new, ArrayFuse, + trivial_limiter! using DiffEqBase, FastBroadcast, Polyester, MuladdMacro, RecursiveArrayTools import StaticArrays: SArray, MVector, SVector, @SVector, StaticArray, MMatrix, SA From fa5c07a80ff50cb6c696231f4edf7742e05b6b92 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Tue, 30 Jul 2024 22:28:57 +0530 Subject: [PATCH 010/133] trivial_limiter! --- .../src/OrdinaryDiffEqLowStorageRK.jl | 2 +- lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit.jl | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/OrdinaryDiffEqLowStorageRK/src/OrdinaryDiffEqLowStorageRK.jl b/lib/OrdinaryDiffEqLowStorageRK/src/OrdinaryDiffEqLowStorageRK.jl index dc47a17215..4ecc2a7e9d 100644 --- a/lib/OrdinaryDiffEqLowStorageRK/src/OrdinaryDiffEqLowStorageRK.jl +++ b/lib/OrdinaryDiffEqLowStorageRK/src/OrdinaryDiffEqLowStorageRK.jl @@ -10,7 +10,7 @@ import OrdinaryDiffEq: alg_order, alg_adaptive_order, calculate_residuals!, default_controller, PIDController, alg_cache, _vec, _reshape, @cache, isfsal, full_cache, constvalue, _unwrap_val, du_alias_or_new, ArrayFuse, - trivial_limiter! + trivial_limiter!, perform_step!, initialize! using DiffEqBase, FastBroadcast, Polyester, MuladdMacro, RecursiveArrayTools import StaticArrays: SArray, MVector, SVector, @SVector, StaticArray, MMatrix, SA diff --git a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit.jl b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit.jl index dddc703383..93df489aa2 100644 --- a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit.jl +++ b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit.jl @@ -3,11 +3,12 @@ module OrdinaryDiffEqTsit import OrdinaryDiffEq: alg_order, alg_stability_size, explicit_rk_docstring, trivial_limiter!, OrdinaryDiffEqAdaptiveAlgorithm, OrdinaryDiffEqMutableCache, alg_cache, constvalue, uses_uprev, @unpack, perform_step!, calculate_residuals, - calculate_residuals! + calculate_residuals!, _ode_interpolant, _ode_interpolant! import Static: False import MuladdMacro: @muladd import FastBroadcast: @.. import RecursiveArrayTools: recursivefill! +import DiffEqBase: @def include("algorithms.jl") include("alg_utils.jl") From 54be9238816de3b4d1c4d90b7c2eb6514aa64cee Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Tue, 30 Jul 2024 22:32:43 +0530 Subject: [PATCH 011/133] trivial_limiter! --- .../src/OrdinaryDiffEqLowStorageRK.jl | 1 + lib/OrdinaryDiffEqLowStorageRK/src/algorithms.jl | 3 --- lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit.jl | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/OrdinaryDiffEqLowStorageRK/src/OrdinaryDiffEqLowStorageRK.jl b/lib/OrdinaryDiffEqLowStorageRK/src/OrdinaryDiffEqLowStorageRK.jl index 4ecc2a7e9d..9b089f35c6 100644 --- a/lib/OrdinaryDiffEqLowStorageRK/src/OrdinaryDiffEqLowStorageRK.jl +++ b/lib/OrdinaryDiffEqLowStorageRK/src/OrdinaryDiffEqLowStorageRK.jl @@ -13,6 +13,7 @@ import OrdinaryDiffEq: alg_order, alg_adaptive_order, calculate_residuals!, trivial_limiter!, perform_step!, initialize! using DiffEqBase, FastBroadcast, Polyester, MuladdMacro, RecursiveArrayTools import StaticArrays: SArray, MVector, SVector, @SVector, StaticArray, MMatrix, SA +import Static: False include("algorithms.jl") include("alg_utils.jl") diff --git a/lib/OrdinaryDiffEqLowStorageRK/src/algorithms.jl b/lib/OrdinaryDiffEqLowStorageRK/src/algorithms.jl index 47184a341a..58b3b3808f 100644 --- a/lib/OrdinaryDiffEqLowStorageRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqLowStorageRK/src/algorithms.jl @@ -1,6 +1,3 @@ -using OrdinaryDiffEq: explicit_rk_docstring, trivial_limiter! -using Static: False - @doc explicit_rk_docstring( "A second-order, five-stage explicit Runge-Kutta method for wave propagation equations. Fixed timestep only.", "ORK256", diff --git a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit.jl b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit.jl index 93df489aa2..c0eac1b9c6 100644 --- a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit.jl +++ b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit.jl @@ -2,7 +2,7 @@ module OrdinaryDiffEqTsit import OrdinaryDiffEq: alg_order, alg_stability_size, explicit_rk_docstring, trivial_limiter!, OrdinaryDiffEqAdaptiveAlgorithm, OrdinaryDiffEqMutableCache, alg_cache, - constvalue, uses_uprev, @unpack, perform_step!, calculate_residuals, + constvalue, @unpack, perform_step!, calculate_residuals, calculate_residuals!, _ode_interpolant, _ode_interpolant! import Static: False import MuladdMacro: @muladd From 05a8df511c547290a8a3992df9e5695462b29c4b Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Tue, 30 Jul 2024 22:36:27 +0530 Subject: [PATCH 012/133] explicit_rk_docstring --- .../src/OrdinaryDiffEqLowStorageRK.jl | 2 +- lib/OrdinaryDiffEqLowStorageRK/src/low_storage_rk_caches.jl | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/OrdinaryDiffEqLowStorageRK/src/OrdinaryDiffEqLowStorageRK.jl b/lib/OrdinaryDiffEqLowStorageRK/src/OrdinaryDiffEqLowStorageRK.jl index 9b089f35c6..21b2b09ab5 100644 --- a/lib/OrdinaryDiffEqLowStorageRK/src/OrdinaryDiffEqLowStorageRK.jl +++ b/lib/OrdinaryDiffEqLowStorageRK/src/OrdinaryDiffEqLowStorageRK.jl @@ -10,7 +10,7 @@ import OrdinaryDiffEq: alg_order, alg_adaptive_order, calculate_residuals!, default_controller, PIDController, alg_cache, _vec, _reshape, @cache, isfsal, full_cache, constvalue, _unwrap_val, du_alias_or_new, ArrayFuse, - trivial_limiter!, perform_step!, initialize! + trivial_limiter!, perform_step!, initialize!, explicit_rk_docstring using DiffEqBase, FastBroadcast, Polyester, MuladdMacro, RecursiveArrayTools import StaticArrays: SArray, MVector, SVector, @SVector, StaticArray, MMatrix, SA import Static: False diff --git a/lib/OrdinaryDiffEqLowStorageRK/src/low_storage_rk_caches.jl b/lib/OrdinaryDiffEqLowStorageRK/src/low_storage_rk_caches.jl index 0c24c6702e..4e5712e005 100644 --- a/lib/OrdinaryDiffEqLowStorageRK/src/low_storage_rk_caches.jl +++ b/lib/OrdinaryDiffEqLowStorageRK/src/low_storage_rk_caches.jl @@ -1,4 +1,3 @@ - # 2N low storage methods introduced by Williamson @cache struct LowStorageRK2NCache{uType, rateType, TabType, StageLimiter, StepLimiter, Thread} <: OrdinaryDiffEqMutableCache From 92095666917017fd43c9910e875367af33345eb5 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Tue, 30 Jul 2024 22:41:15 +0530 Subject: [PATCH 013/133] changes --- src/OrdinaryDiffEq.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/OrdinaryDiffEq.jl b/src/OrdinaryDiffEq.jl index a0a9572676..a8ed8fe871 100644 --- a/src/OrdinaryDiffEq.jl +++ b/src/OrdinaryDiffEq.jl @@ -295,6 +295,10 @@ export Euler, SplitEuler, Heun, Ralston, Midpoint, RK4, PSRK4p7q6, PSRK3p5q4, PSRK3p6q5, Stepanov5, SIR54, Alshina2, Alshina3, Alshina6 +include("../lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit.jl") +using ..OrdinaryDiffEqTsit5 +export Tsit5 + PrecompileTools.@compile_workload begin function lorenz(du, u, p, t) du[1] = 10.0(u[2] - u[1]) From 1756924b192ba5c17673069fd7d97262924b7076 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Tue, 30 Jul 2024 22:47:27 +0530 Subject: [PATCH 014/133] changes --- lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit.jl b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit.jl index c0eac1b9c6..7bcccf7e58 100644 --- a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit.jl +++ b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit.jl @@ -17,4 +17,6 @@ include("tsit_tableaus.jl") include("interp_func.jl") include("tsit_perform_step.jl") +export Tsit5 + end \ No newline at end of file From 4dd381482547cc3019cf2af32857f480f0b5f252 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Tue, 30 Jul 2024 22:50:27 +0530 Subject: [PATCH 015/133] changes --- .../src/{OrdinaryDiffEqTsit.jl => OrdinaryDiffEqTsit5.jl} | 0 src/OrdinaryDiffEq.jl | 8 ++++---- 2 files changed, 4 insertions(+), 4 deletions(-) rename lib/OrdinaryDiffEqTsit5/src/{OrdinaryDiffEqTsit.jl => OrdinaryDiffEqTsit5.jl} (100%) diff --git a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit.jl b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl similarity index 100% rename from lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit.jl rename to lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl diff --git a/src/OrdinaryDiffEq.jl b/src/OrdinaryDiffEq.jl index a8ed8fe871..dce07c0c22 100644 --- a/src/OrdinaryDiffEq.jl +++ b/src/OrdinaryDiffEq.jl @@ -263,6 +263,10 @@ export ABDF2, QNDF1, QBDF1, QNDF2, QBDF2, QNDF, QBDF, FBDF, SBDF2, SBDF3, SBDF4, MEBDF2, IMEXEuler, IMEXEulerARK, DImplicitEuler, DABDF2, DFBDF +include("../lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl") +using ..OrdinaryDiffEqTsit5 +export Tsit5 + include("../lib/OrdinaryDiffEqDefault/src/OrdinaryDiffEqDefault.jl") using ..OrdinaryDiffEqDefault export DefaultODEAlgorithm @@ -295,10 +299,6 @@ export Euler, SplitEuler, Heun, Ralston, Midpoint, RK4, PSRK4p7q6, PSRK3p5q4, PSRK3p6q5, Stepanov5, SIR54, Alshina2, Alshina3, Alshina6 -include("../lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit.jl") -using ..OrdinaryDiffEqTsit5 -export Tsit5 - PrecompileTools.@compile_workload begin function lorenz(du, u, p, t) du[1] = 10.0(u[2] - u[1]) From 135b5afdf2f3fe9d39864271078a6f1f9056641f Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Tue, 30 Jul 2024 22:58:58 +0530 Subject: [PATCH 016/133] Fixes --- lib/OrdinaryDiffEqTsit5/Project.toml | 2 +- lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/OrdinaryDiffEqTsit5/Project.toml b/lib/OrdinaryDiffEqTsit5/Project.toml index 921cb4b939..acb022d54a 100644 --- a/lib/OrdinaryDiffEqTsit5/Project.toml +++ b/lib/OrdinaryDiffEqTsit5/Project.toml @@ -1,5 +1,5 @@ name = "OrdinaryDiffEqTsit5" -uuid = "1344f307-1e59-4825-a18e-ace9aa3fa4c6" +uuid = "b1df2697-797e-41e3-8120-5422d3b24e4a" authors = ["ParamThakkar123 "] version = "1.0.0" diff --git a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl index 7bcccf7e58..1335f560ba 100644 --- a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl +++ b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl @@ -1,4 +1,4 @@ -module OrdinaryDiffEqTsit +module OrdinaryDiffEqTsit5 import OrdinaryDiffEq: alg_order, alg_stability_size, explicit_rk_docstring, trivial_limiter!, OrdinaryDiffEqAdaptiveAlgorithm, OrdinaryDiffEqMutableCache, alg_cache, From b71cb79c7fc4d0c75d43e8345155931c8e81eb55 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Tue, 30 Jul 2024 23:05:22 +0530 Subject: [PATCH 017/133] TruncatedStacktraces --- lib/OrdinaryDiffEqTsit5/Project.toml | 1 + lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/OrdinaryDiffEqTsit5/Project.toml b/lib/OrdinaryDiffEqTsit5/Project.toml index acb022d54a..9fc00a8796 100644 --- a/lib/OrdinaryDiffEqTsit5/Project.toml +++ b/lib/OrdinaryDiffEqTsit5/Project.toml @@ -9,6 +9,7 @@ MuladdMacro = "46d2c3a1-f734-5fdb-9937-b9b9aeba4221" RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd" FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898" Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3" +TruncatedStacktraces = "781d530d-4396-4725-bb49-402e4bee1e77" [compat] julia = "1.10" diff --git a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl index 1335f560ba..262a1aa88f 100644 --- a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl +++ b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl @@ -9,6 +9,7 @@ import MuladdMacro: @muladd import FastBroadcast: @.. import RecursiveArrayTools: recursivefill! import DiffEqBase: @def +using TruncatedStacktraces include("algorithms.jl") include("alg_utils.jl") From 56e59f98911323ece8177d596710ae6f11d3e8fc Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Tue, 30 Jul 2024 23:07:58 +0530 Subject: [PATCH 018/133] @cache --- lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl index 262a1aa88f..7d1a5ad4d5 100644 --- a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl +++ b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl @@ -2,7 +2,7 @@ module OrdinaryDiffEqTsit5 import OrdinaryDiffEq: alg_order, alg_stability_size, explicit_rk_docstring, trivial_limiter!, OrdinaryDiffEqAdaptiveAlgorithm, OrdinaryDiffEqMutableCache, alg_cache, - constvalue, @unpack, perform_step!, calculate_residuals, + constvalue, @unpack, perform_step!, calculate_residuals, @cache, calculate_residuals!, _ode_interpolant, _ode_interpolant! import Static: False import MuladdMacro: @muladd From e86154ef37e00aa07670c3b33bf1f81de26091f9 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Tue, 30 Jul 2024 23:44:10 +0530 Subject: [PATCH 019/133] trivial_limiter! --- lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl index 7d1a5ad4d5..f21d07b8cd 100644 --- a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl +++ b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl @@ -1,7 +1,8 @@ module OrdinaryDiffEqTsit5 -import OrdinaryDiffEq: alg_order, alg_stability_size, explicit_rk_docstring, trivial_limiter!, +import OrdinaryDiffEq: alg_order, alg_stability_size, explicit_rk_docstring, OrdinaryDiffEqAdaptiveAlgorithm, OrdinaryDiffEqMutableCache, alg_cache, + OrdinaryDiffEqConstantCache, constvalue, @unpack, perform_step!, calculate_residuals, @cache, calculate_residuals!, _ode_interpolant, _ode_interpolant! import Static: False From 475e4eca08a79e3c3c3b9e41a50dbcd07461fc42 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Tue, 30 Jul 2024 18:16:00 -0400 Subject: [PATCH 020/133] Update algorithms.jl --- src/algorithms.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/algorithms.jl b/src/algorithms.jl index 6cf380a214..45dcab90df 100644 --- a/src/algorithms.jl +++ b/src/algorithms.jl @@ -82,6 +82,8 @@ TruncatedStacktraces.@truncate_stacktrace ExplicitRK ################################################################################ +@inline trivial_limiter!(u, integrator, p, t) = nothing + # Adams Bashforth and Adams moulton methods """ From 3432c119ec739460aa9a2b49a5cd3f06ff2aceaf Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Wed, 31 Jul 2024 09:10:14 +0530 Subject: [PATCH 021/133] @fold --- lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl | 2 +- lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl index f0a5522f0c..baea5e922f 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl @@ -5,7 +5,7 @@ import OrdinaryDiffEq: alg_order, isfsal, beta2_default, beta1_default, alg_stab explicit_rk_docstring, trivial_limiter!, OrdinaryDiffEqAdaptiveAlgorithm, unwrap_alg, @unpack, initialize!, perform_step!, calculate_residuals, calculate_residuals!, _ode_addsteps!, @OnDemandTableauExtract, constvalue, - OrdinaryDiffEqMutableCache, uses_uprev, OrdinaryDiffEqConstantCache + OrdinaryDiffEqMutableCache, uses_uprev, OrdinaryDiffEqConstantCache, @fold import DiffEqBase: @tight_loop_macros import MuladdMacro: @muladd import FastBroadcast: @.. diff --git a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl index f21d07b8cd..1db2dcc0ef 100644 --- a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl +++ b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl @@ -2,7 +2,7 @@ module OrdinaryDiffEqTsit5 import OrdinaryDiffEq: alg_order, alg_stability_size, explicit_rk_docstring, OrdinaryDiffEqAdaptiveAlgorithm, OrdinaryDiffEqMutableCache, alg_cache, - OrdinaryDiffEqConstantCache, + OrdinaryDiffEqConstantCache, @fold, constvalue, @unpack, perform_step!, calculate_residuals, @cache, calculate_residuals!, _ode_interpolant, _ode_interpolant! import Static: False From 8f70743c35671d7b9e07c964b9c35b707cc8dca1 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Wed, 31 Jul 2024 05:05:01 -0400 Subject: [PATCH 022/133] Update lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl --- lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl index 1db2dcc0ef..d50f8730bb 100644 --- a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl +++ b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl @@ -4,7 +4,8 @@ import OrdinaryDiffEq: alg_order, alg_stability_size, explicit_rk_docstring, OrdinaryDiffEqAdaptiveAlgorithm, OrdinaryDiffEqMutableCache, alg_cache, OrdinaryDiffEqConstantCache, @fold, constvalue, @unpack, perform_step!, calculate_residuals, @cache, - calculate_residuals!, _ode_interpolant, _ode_interpolant! + calculate_residuals!, _ode_interpolant, _ode_interpolant!, + CompiledFloats import Static: False import MuladdMacro: @muladd import FastBroadcast: @.. From e9dda029c05f5d37b5c272e47ea1b61fd2a81755 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Wed, 31 Jul 2024 15:04:31 +0530 Subject: [PATCH 023/133] DiffEqBase --- lib/OrdinaryDiffEqTsit5/Project.toml | 1 + lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqTsit5/Project.toml b/lib/OrdinaryDiffEqTsit5/Project.toml index 9fc00a8796..3d197ae0c8 100644 --- a/lib/OrdinaryDiffEqTsit5/Project.toml +++ b/lib/OrdinaryDiffEqTsit5/Project.toml @@ -10,6 +10,7 @@ RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd" FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898" Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3" TruncatedStacktraces = "781d530d-4396-4725-bb49-402e4bee1e77" +DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" [compat] julia = "1.10" diff --git a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl index d50f8730bb..5d562b73b6 100644 --- a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl +++ b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl @@ -10,7 +10,7 @@ import Static: False import MuladdMacro: @muladd import FastBroadcast: @.. import RecursiveArrayTools: recursivefill! -import DiffEqBase: @def +using DiffEqBase using TruncatedStacktraces include("algorithms.jl") From 00e95a9e4cb81e179dce7f5f522cd197dca43d14 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Wed, 31 Jul 2024 15:09:43 +0530 Subject: [PATCH 024/133] @OnDemandTableauExtract --- lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl index 5d562b73b6..8c67fd2f44 100644 --- a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl +++ b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl @@ -5,7 +5,7 @@ import OrdinaryDiffEq: alg_order, alg_stability_size, explicit_rk_docstring, OrdinaryDiffEqConstantCache, @fold, constvalue, @unpack, perform_step!, calculate_residuals, @cache, calculate_residuals!, _ode_interpolant, _ode_interpolant!, - CompiledFloats + CompiledFloats, @OnDemandTableauExtract import Static: False import MuladdMacro: @muladd import FastBroadcast: @.. From cd7dc0ee178d3688dc1fcdbf038dac89b9f21151 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Wed, 31 Jul 2024 15:22:12 +0530 Subject: [PATCH 025/133] trivial_limiter! --- lib/OrdinaryDiffEqDefault/src/OrdinaryDiffEqDefault.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqDefault/src/OrdinaryDiffEqDefault.jl b/lib/OrdinaryDiffEqDefault/src/OrdinaryDiffEqDefault.jl index 0c09b330b0..0a4f80b53a 100644 --- a/lib/OrdinaryDiffEqDefault/src/OrdinaryDiffEqDefault.jl +++ b/lib/OrdinaryDiffEqDefault/src/OrdinaryDiffEqDefault.jl @@ -2,7 +2,7 @@ module OrdinaryDiffEqDefault using OrdinaryDiffEq: Vern7, Vern8, Vern9, Vern6, Tsit5, Rosenbrock23, Rodas5P, FBDF, alg_stability_size, beta2_default, beta1_default, AutoSwitchCache, - ODEIntegrator, + ODEIntegrator, trivial_limiter!, CompositeAlgorithm, OrdinaryDiffEqAlgorithm, OrdinaryDiffEqMutableCache, AutoAlgSwitch import OrdinaryDiffEq: is_mass_matrix_alg, default_autoswitch From 30756094be66de18d73b7ed639ee12f3b2910d3f Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Wed, 31 Jul 2024 15:25:04 +0530 Subject: [PATCH 026/133] trivial_limiter! --- lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl index 8c67fd2f44..d2272764bb 100644 --- a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl +++ b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl @@ -2,7 +2,7 @@ module OrdinaryDiffEqTsit5 import OrdinaryDiffEq: alg_order, alg_stability_size, explicit_rk_docstring, OrdinaryDiffEqAdaptiveAlgorithm, OrdinaryDiffEqMutableCache, alg_cache, - OrdinaryDiffEqConstantCache, @fold, + OrdinaryDiffEqConstantCache, @fold, trivial_limiter!, constvalue, @unpack, perform_step!, calculate_residuals, @cache, calculate_residuals!, _ode_interpolant, _ode_interpolant!, CompiledFloats, @OnDemandTableauExtract From c8cc3cc1ea008dc2c91513761bb54de1d515e182 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Wed, 31 Jul 2024 15:27:22 +0530 Subject: [PATCH 027/133] CompiledFloats --- lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl b/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl index 0639bcd45b..7b2164b6e9 100644 --- a/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl +++ b/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl @@ -4,7 +4,7 @@ import OrdinaryDiffEq: alg_order, qmax_default, qmin_default, beta2_default, bet explicit_rk_docstring, OrdinaryDiffEqAdaptiveAlgorithm, trivial_limiter!, _ode_addsteps!, @unpack, @cache, OrdinaryDiffEqMutableCache, constvalue, alg_cache, uses_uprev, initialize!, perform_step!, OrdinaryDiffEqConstantCache, - calculate_residuals!, calculate_residuals + calculate_residuals!, calculate_residuals, CompiledFloats import Static: False import MuladdMacro: @muladd import FastBroadcast: @.. From 85d27e3058d6ae999037eb47b8323ba824b6ef22 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Wed, 31 Jul 2024 15:39:30 +0530 Subject: [PATCH 028/133] DiffEqBase --- lib/OrdinaryDiffEqHighOrderRK/Project.toml | 1 + lib/OrdinaryDiffEqLowOrderRK/Project.toml | 1 + lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqHighOrderRK/Project.toml b/lib/OrdinaryDiffEqHighOrderRK/Project.toml index 2a3cee12e9..6399ba3488 100644 --- a/lib/OrdinaryDiffEqHighOrderRK/Project.toml +++ b/lib/OrdinaryDiffEqHighOrderRK/Project.toml @@ -9,6 +9,7 @@ MuladdMacro = "46d2c3a1-f734-5fdb-9937-b9b9aeba4221" RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd" FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898" Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3" +DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" [compat] julia = "1.10" diff --git a/lib/OrdinaryDiffEqLowOrderRK/Project.toml b/lib/OrdinaryDiffEqLowOrderRK/Project.toml index b95f383c78..41a4698bcf 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/Project.toml +++ b/lib/OrdinaryDiffEqLowOrderRK/Project.toml @@ -9,6 +9,7 @@ MuladdMacro = "46d2c3a1-f734-5fdb-9937-b9b9aeba4221" RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd" FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898" Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3" +DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" [compat] julia = "1.10" diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl index baea5e922f..8d5cb52f57 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl @@ -6,7 +6,7 @@ import OrdinaryDiffEq: alg_order, isfsal, beta2_default, beta1_default, alg_stab unwrap_alg, @unpack, initialize!, perform_step!, calculate_residuals, calculate_residuals!, _ode_addsteps!, @OnDemandTableauExtract, constvalue, OrdinaryDiffEqMutableCache, uses_uprev, OrdinaryDiffEqConstantCache, @fold -import DiffEqBase: @tight_loop_macros +using DiffEqBase import MuladdMacro: @muladd import FastBroadcast: @.. import RecursiveArrayTools: recursivefill! From 4b0f31be6bdaf6d5b96f79ca01fc9b4ee497ec95 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Wed, 31 Jul 2024 15:42:10 +0530 Subject: [PATCH 029/133] @cache --- lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl index 8d5cb52f57..3960280440 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl @@ -5,7 +5,8 @@ import OrdinaryDiffEq: alg_order, isfsal, beta2_default, beta1_default, alg_stab explicit_rk_docstring, trivial_limiter!, OrdinaryDiffEqAdaptiveAlgorithm, unwrap_alg, @unpack, initialize!, perform_step!, calculate_residuals, calculate_residuals!, _ode_addsteps!, @OnDemandTableauExtract, constvalue, - OrdinaryDiffEqMutableCache, uses_uprev, OrdinaryDiffEqConstantCache, @fold + OrdinaryDiffEqMutableCache, uses_uprev, OrdinaryDiffEqConstantCache, @fold, + @cache using DiffEqBase import MuladdMacro: @muladd import FastBroadcast: @.. From b898c57539d8739b9ff025f057dc55f4e07c3544 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Wed, 31 Jul 2024 15:54:18 +0530 Subject: [PATCH 030/133] CompiledFloats --- lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl index 3960280440..1198ef36b1 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl @@ -6,7 +6,7 @@ import OrdinaryDiffEq: alg_order, isfsal, beta2_default, beta1_default, alg_stab unwrap_alg, @unpack, initialize!, perform_step!, calculate_residuals, calculate_residuals!, _ode_addsteps!, @OnDemandTableauExtract, constvalue, OrdinaryDiffEqMutableCache, uses_uprev, OrdinaryDiffEqConstantCache, @fold, - @cache + @cache, CompiledFloats using DiffEqBase import MuladdMacro: @muladd import FastBroadcast: @.. From cbf64633a5a4e8c5cebfbd725836cd5392744470 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Wed, 31 Jul 2024 15:59:53 +0530 Subject: [PATCH 031/133] DP8ConstantCache --- .../src/OrdinaryDiffEqHighOrderRK.jl | 1 + lib/OrdinaryDiffEqHighOrderRK/src/interp_func.jl | 6 ++++++ lib/OrdinaryDiffEqLowOrderRK/src/interp_func.jl | 6 ------ 3 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 lib/OrdinaryDiffEqHighOrderRK/src/interp_func.jl diff --git a/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl b/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl index 7b2164b6e9..ca87eec983 100644 --- a/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl +++ b/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl @@ -14,6 +14,7 @@ include("algorithms.jl") include("alg_utils.jl") include("high_order_rk_caches.jl") include("high_order_rk_tableaus.jl") +include("interp_func.jl") include("high_order_rk_addsteps.jl") include("high_order_rk_perform_step.jl") diff --git a/lib/OrdinaryDiffEqHighOrderRK/src/interp_func.jl b/lib/OrdinaryDiffEqHighOrderRK/src/interp_func.jl new file mode 100644 index 0000000000..6be33c0ada --- /dev/null +++ b/lib/OrdinaryDiffEqHighOrderRK/src/interp_func.jl @@ -0,0 +1,6 @@ +function DiffEqBase.interp_summary(::Type{cacheType}, + dense::Bool) where { + cacheType <: + Union{DP8ConstantCache, DP8Cache}} + dense ? "specialized 7th order interpolation" : "1st order linear" +end \ No newline at end of file diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/interp_func.jl b/lib/OrdinaryDiffEqLowOrderRK/src/interp_func.jl index 16b40a63aa..2886094976 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/interp_func.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/interp_func.jl @@ -27,10 +27,4 @@ function DiffEqBase.interp_summary(::Type{cacheType}, cacheType <: Union{BS5ConstantCache, BS5Cache}} dense ? "specialized 5th order lazy interpolation" : "1st order linear" -end -function DiffEqBase.interp_summary(::Type{cacheType}, - dense::Bool) where { - cacheType <: - Union{DP8ConstantCache, DP8Cache}} - dense ? "specialized 7th order interpolation" : "1st order linear" end \ No newline at end of file From b5854c640cb6e418ed0550b4883379e850fdb510 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Wed, 31 Jul 2024 16:03:08 +0530 Subject: [PATCH 032/133] DiffEqBase --- lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl b/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl index ca87eec983..97acfcc34c 100644 --- a/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl +++ b/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl @@ -7,6 +7,7 @@ import OrdinaryDiffEq: alg_order, qmax_default, qmin_default, beta2_default, bet calculate_residuals!, calculate_residuals, CompiledFloats import Static: False import MuladdMacro: @muladd +using DiffEqBase import FastBroadcast: @.. import RecursiveArrayTools: recursivefill! From 20c62f442e12d0b68fe84c6b7cb3bb72b066ee5d Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Wed, 31 Jul 2024 16:16:42 +0530 Subject: [PATCH 033/133] FunctionMap --- lib/OrdinaryDiffEqLowOrderRK/src/alg_utils.jl | 8 +++++++ .../src/algorithms.jl | 5 +++- .../src/interp_func.jl | 9 +++++++ .../src/low_order_rk_caches.jl | 24 +++++++++++++++++++ src/OrdinaryDiffEq.jl | 4 ++-- src/alg_utils.jl | 8 ------- src/algorithms.jl | 3 --- src/caches/basic_caches.jl | 24 ------------------- src/interp_func.jl | 9 ------- 9 files changed, 47 insertions(+), 47 deletions(-) diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/alg_utils.jl b/lib/OrdinaryDiffEqLowOrderRK/src/alg_utils.jl index f9c206588e..2f8a88f6d9 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/alg_utils.jl @@ -24,16 +24,20 @@ alg_order(alg::SIR54) = 5 alg_order(alg::Alshina2) = 2 alg_order(alg::Alshina3) = 3 alg_order(alg::Alshina6) = 6 +alg_order(alg::FunctionMap) = 0 isfsal(alg::FRK65) = true isfsal(alg::RKO65) = false isfsal(alg::PSRK3p5q4) = false isfsal(alg::PSRK3p6q5) = false isfsal(alg::PSRK4p7q6) = false +isfsal(alg::FunctionMap) = false beta2_default(alg::DP5) = 4 // 100 +beta2_default(alg::FunctionMap) = 0 beta1_default(alg::DP5, beta2) = typeof(beta2)(1 // alg_order(alg)) - 3beta2 / 4 +beta1_default(alg::FunctionMap, beta2) = 0 alg_stability_size(alg::DP5) = 3.3066 @@ -44,4 +48,8 @@ function DiffEqBase.prepare_alg( u0::AbstractArray, p, prob) alg +end + +function FunctionMap_scale_by_time(alg::FunctionMap{scale_by_time}) where {scale_by_time} + scale_by_time end \ No newline at end of file diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/algorithms.jl b/lib/OrdinaryDiffEqLowOrderRK/src/algorithms.jl index 8eaeed7d66..2503de20e1 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/algorithms.jl @@ -612,4 +612,7 @@ function Base.show(io::IO, alg::Alshina6) print(io, "Alshina6(stage_limiter! = ", alg.stage_limiter!, ", step_limiter! = ", alg.step_limiter!, ", thread = ", alg.thread, ")") -end \ No newline at end of file +end + +struct FunctionMap{scale_by_time} <: OrdinaryDiffEqAlgorithm end +FunctionMap(; scale_by_time = false) = FunctionMap{scale_by_time}() \ No newline at end of file diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/interp_func.jl b/lib/OrdinaryDiffEqLowOrderRK/src/interp_func.jl index 2886094976..c039dfe666 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/interp_func.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/interp_func.jl @@ -27,4 +27,13 @@ function DiffEqBase.interp_summary(::Type{cacheType}, cacheType <: Union{BS5ConstantCache, BS5Cache}} dense ? "specialized 5th order lazy interpolation" : "1st order linear" +end +function DiffEqBase.interp_summary(::Type{cacheType}, + dense::Bool) where {cacheType <: + FunctionMapConstantCache} + "left-endpoint piecewise constant" +end +function DiffEqBase.interp_summary(::Type{cacheType}, + dense::Bool) where {cacheType <: FunctionMapCache} + "left-endpoint piecewise constant" end \ No newline at end of file diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_caches.jl b/lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_caches.jl index ac728ae2ae..c7f12271c4 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_caches.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_caches.jl @@ -1484,4 +1484,28 @@ function alg_cache(alg::Alshina6, u, rate_prototype, ::Type{uEltypeNoUnits}, tab = Alshina6ConstantCache(constvalue(uBottomEltypeNoUnits), constvalue(tTypeNoUnits)) Alshina6Cache(u, uprev, k1, k2, k3, k4, k5, k6, k7, tmp, tab, alg.stage_limiter!, alg.step_limiter!, alg.thread) +end + +@cache struct FunctionMapCache{uType, rateType} <: OrdinaryDiffEqMutableCache + u::uType + uprev::uType + tmp::rateType +end + +function alg_cache(alg::FunctionMap, u, rate_prototype, ::Type{uEltypeNoUnits}, + ::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t, + dt, reltol, p, calck, + ::Val{true}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits} + FunctionMapCache(u, uprev, + FunctionMap_scale_by_time(alg) ? rate_prototype : + (eltype(u) <: Enum ? copy(u) : zero(u))) +end + +struct FunctionMapConstantCache <: OrdinaryDiffEqConstantCache end + +function alg_cache(alg::FunctionMap, u, rate_prototype, ::Type{uEltypeNoUnits}, + ::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t, + dt, reltol, p, calck, + ::Val{false}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits} + FunctionMapConstantCache() end \ No newline at end of file diff --git a/src/OrdinaryDiffEq.jl b/src/OrdinaryDiffEq.jl index dce07c0c22..c0fcce8b9b 100644 --- a/src/OrdinaryDiffEq.jl +++ b/src/OrdinaryDiffEq.jl @@ -297,7 +297,7 @@ export Euler, SplitEuler, Heun, Ralston, Midpoint, RK4, BS3, OwrenZen3, OwrenZen4, OwrenZen5, BS5, Tsit5, DP5, Anas5, RKO65, FRK65, RKM, MSRK5, MSRK6, PSRK4p7q6, PSRK3p5q4, PSRK3p6q5, Stepanov5, SIR54, - Alshina2, Alshina3, Alshina6 + Alshina2, Alshina3, Alshina6, FunctionMap PrecompileTools.@compile_workload begin function lorenz(du, u, p, t) @@ -427,7 +427,7 @@ export constructDormandPrince # Reexport the Alg Types -export FunctionMap, ExplicitRK, CompositeAlgorithm +export ExplicitRK, CompositeAlgorithm export MagnusMidpoint, LinearExponential, MagnusLeapfrog, LieEuler, CayleyEuler, MagnusGauss4, MagnusNC6, MagnusGL6, MagnusGL8, MagnusNC8, MagnusGL4, diff --git a/src/alg_utils.jl b/src/alg_utils.jl index 4bf302afb8..fb6203dab3 100644 --- a/src/alg_utils.jl +++ b/src/alg_utils.jl @@ -28,7 +28,6 @@ isfsal(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm}) = true isfsal(tab::DiffEqBase.ExplicitRKTableau) = tab.fsal # isfsal(alg::CompositeAlgorithm) = isfsal(alg.algs[alg.current]) -isfsal(alg::FunctionMap) = false isfsal(alg::Rodas3P) = false isfsal(alg::Rodas23W) = false isfsal(alg::Rodas5) = false @@ -365,7 +364,6 @@ function get_current_adaptive_order(alg::CompositeAlgorithm, cache) _eval_index(alg_adaptive_order, alg.algs, cache.current)::Int end -alg_order(alg::FunctionMap) = 0 alg_order(alg::LawsonEuler) = 1 alg_order(alg::NorsettEuler) = 1 alg_order(alg::LieEuler) = 1 @@ -513,12 +511,10 @@ end function beta2_default(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm}) isadaptive(alg) ? 2 // (5alg_order(alg)) : 0 end -beta2_default(alg::FunctionMap) = 0 function beta1_default(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm}, beta2) isadaptive(alg) ? 7 // (10alg_order(alg)) : 0 end -beta1_default(alg::FunctionMap, beta2) = 0 function gamma_default(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm}) isadaptive(alg) ? 9 // 10 : 0 @@ -538,10 +534,6 @@ qsteady_max_default(alg::JVODE) = 3 // 2 #TODO #DiffEqBase.nlsolve_default(::QNDF, ::Val{κ}) = 1//2 -function FunctionMap_scale_by_time(alg::FunctionMap{scale_by_time}) where {scale_by_time} - scale_by_time -end - # SSP coefficients ssp_coefficient(alg) = error("$alg is not a strong stability preserving method.") diff --git a/src/algorithms.jl b/src/algorithms.jl index 45dcab90df..0b708d24a9 100644 --- a/src/algorithms.jl +++ b/src/algorithms.jl @@ -46,9 +46,6 @@ abstract type OrdinaryDiffEqAdaptivePartitionedAlgorithm <: OrdinaryDiffEqAdapti const PartitionedAlgorithm = Union{OrdinaryDiffEqPartitionedAlgorithm, OrdinaryDiffEqAdaptivePartitionedAlgorithm} -struct FunctionMap{scale_by_time} <: OrdinaryDiffEqAlgorithm end -FunctionMap(; scale_by_time = false) = FunctionMap{scale_by_time}() - function DiffEqBase.remake(thing::OrdinaryDiffEqAlgorithm; kwargs...) T = SciMLBase.remaker_of(thing) T(; SciMLBase.struct_as_namedtuple(thing)..., kwargs...) diff --git a/src/caches/basic_caches.jl b/src/caches/basic_caches.jl index b5dd5edb7a..c6e4757ba5 100644 --- a/src/caches/basic_caches.jl +++ b/src/caches/basic_caches.jl @@ -100,30 +100,6 @@ end alg_cache(alg::OrdinaryDiffEqAlgorithm, prob, callback::F) where {F} = ODEEmptyCache() -@cache struct FunctionMapCache{uType, rateType} <: OrdinaryDiffEqMutableCache - u::uType - uprev::uType - tmp::rateType -end - -function alg_cache(alg::FunctionMap, u, rate_prototype, ::Type{uEltypeNoUnits}, - ::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t, - dt, reltol, p, calck, - ::Val{true}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits} - FunctionMapCache(u, uprev, - FunctionMap_scale_by_time(alg) ? rate_prototype : - (eltype(u) <: Enum ? copy(u) : zero(u))) -end - -struct FunctionMapConstantCache <: OrdinaryDiffEqConstantCache end - -function alg_cache(alg::FunctionMap, u, rate_prototype, ::Type{uEltypeNoUnits}, - ::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t, - dt, reltol, p, calck, - ::Val{false}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits} - FunctionMapConstantCache() -end - @cache struct ExplicitRKCache{uType, rateType, uNoUnitsType, TabType} <: OrdinaryDiffEqMutableCache u::uType diff --git a/src/interp_func.jl b/src/interp_func.jl index 782aec1b3b..8ed016333a 100644 --- a/src/interp_func.jl +++ b/src/interp_func.jl @@ -30,15 +30,6 @@ function DiffEqBase.interp_summary(interp::OrdinaryDiffEqInterpolation{ } DiffEqBase.interp_summary(cacheType, interp.dense) end -function DiffEqBase.interp_summary(::Type{cacheType}, - dense::Bool) where {cacheType <: - FunctionMapConstantCache} - "left-endpoint piecewise constant" -end -function DiffEqBase.interp_summary(::Type{cacheType}, - dense::Bool) where {cacheType <: FunctionMapCache} - "left-endpoint piecewise constant" -end function DiffEqBase.interp_summary(::Type{cacheType}, dense::Bool) where { cacheType <: From cd9d69cd5874d6025e153df60a57ad26bb194821 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Wed, 31 Jul 2024 16:24:19 +0530 Subject: [PATCH 034/133] FunctionMap --- lib/OrdinaryDiffEqLowOrderRK/Project.toml | 1 + .../src/OrdinaryDiffEqLowOrderRK.jl | 2 +- lib/OrdinaryDiffEqLowOrderRK/src/alg_utils.jl | 12 ++++++++++++ src/alg_utils.jl | 10 +++------- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/OrdinaryDiffEqLowOrderRK/Project.toml b/lib/OrdinaryDiffEqLowOrderRK/Project.toml index 41a4698bcf..2934309198 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/Project.toml +++ b/lib/OrdinaryDiffEqLowOrderRK/Project.toml @@ -10,6 +10,7 @@ RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd" FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898" Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3" DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" +SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462" [compat] julia = "1.10" diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl index 1198ef36b1..0be574b061 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl @@ -7,7 +7,7 @@ import OrdinaryDiffEq: alg_order, isfsal, beta2_default, beta1_default, alg_stab calculate_residuals!, _ode_addsteps!, @OnDemandTableauExtract, constvalue, OrdinaryDiffEqMutableCache, uses_uprev, OrdinaryDiffEqConstantCache, @fold, @cache, CompiledFloats -using DiffEqBase +using DiffEqBase, SciMLBase import MuladdMacro: @muladd import FastBroadcast: @.. import RecursiveArrayTools: recursivefill! diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/alg_utils.jl b/lib/OrdinaryDiffEqLowOrderRK/src/alg_utils.jl index 2f8a88f6d9..246359beb4 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/alg_utils.jl @@ -1,3 +1,15 @@ +function SciMLBase.isautodifferentiable(alg::FunctionMap) + true +end +function SciMLBase.allows_arbitrary_number_types(alg::FunctionMap) + true +end +function SciMLBase.allowscomplex(alg::FunctionMap) + true +end + +SciMLBase.isdiscrete(alg::FunctionMap) = true + alg_order(alg::Euler) = 1 alg_order(alg::SplitEuler) = 1 alg_order(alg::Heun) = 2 diff --git a/src/alg_utils.jl b/src/alg_utils.jl index fb6203dab3..832336c461 100644 --- a/src/alg_utils.jl +++ b/src/alg_utils.jl @@ -1,17 +1,13 @@ ## SciMLBase Trait Definitions -function SciMLBase.isautodifferentiable(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm, - FunctionMap}) +function SciMLBase.isautodifferentiable(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm}) true end -function SciMLBase.allows_arbitrary_number_types(alg::Union{OrdinaryDiffEqAlgorithm, - DAEAlgorithm, FunctionMap}) +function SciMLBase.allows_arbitrary_number_types(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm}) true end -function SciMLBase.allowscomplex(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm, - FunctionMap}) +function SciMLBase.allowscomplex(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm}) true end -SciMLBase.isdiscrete(alg::FunctionMap) = true function SciMLBase.forwarddiffs_model(alg::Union{OrdinaryDiffEqAdaptiveImplicitAlgorithm, DAEAlgorithm, OrdinaryDiffEqImplicitAlgorithm, From 04b47eac26a50256189e1ac927e9c0e984cb180f Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Wed, 31 Jul 2024 16:27:42 +0530 Subject: [PATCH 035/133] FunctionMapConstantCache --- .../src/fixed_timestep_perform_step.jl | 44 +++++++++++++++++++ .../fixed_timestep_perform_step.jl | 43 ------------------ 2 files changed, 44 insertions(+), 43 deletions(-) delete mode 100644 src/perform_step/fixed_timestep_perform_step.jl diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/fixed_timestep_perform_step.jl b/lib/OrdinaryDiffEqLowOrderRK/src/fixed_timestep_perform_step.jl index c46a3f1992..217f815f6d 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/fixed_timestep_perform_step.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/fixed_timestep_perform_step.jl @@ -484,4 +484,48 @@ end step_limiter!(u, integrator, p, t + dt) f(k7, u, p, t + dt) integrator.stats.nf += 6 +end + +function initialize!(integrator, cache::FunctionMapConstantCache) + integrator.kshortsize = 0 + integrator.k = typeof(integrator.k)(undef, integrator.kshortsize) +end + +function perform_step!(integrator, cache::FunctionMapConstantCache, repeat_step = false) + @unpack uprev, dt, t, f, p = integrator + alg = unwrap_alg(integrator, nothing) + if integrator.f != DiffEqBase.DISCRETE_OUTOFPLACE_DEFAULT && + !(integrator.f isa DiffEqBase.EvalFunc && + integrator.f.f === DiffEqBase.DISCRETE_OUTOFPLACE_DEFAULT) + if FunctionMap_scale_by_time(alg) + tmp = f(uprev, p, t + dt) + integrator.stats.nf += 1 + @muladd integrator.u = @.. broadcast=false uprev+dt * tmp + else + integrator.u = f(uprev, p, t + dt) + integrator.stats.nf += 1 + end + end +end + +function initialize!(integrator, cache::FunctionMapCache) + integrator.kshortsize = 0 + resize!(integrator.k, integrator.kshortsize) +end + +function perform_step!(integrator, cache::FunctionMapCache, repeat_step = false) + @unpack u, uprev, dt, t, f, p = integrator + alg = unwrap_alg(integrator, nothing) + @unpack tmp = cache + if integrator.f != DiffEqBase.DISCRETE_INPLACE_DEFAULT && + !(integrator.f isa DiffEqBase.EvalFunc && + integrator.f.f === DiffEqBase.DISCRETE_INPLACE_DEFAULT) + if FunctionMap_scale_by_time(alg) + f(tmp, uprev, p, t + dt) + @muladd @.. broadcast=false u=uprev + dt * tmp + else + f(u, uprev, p, t + dt) + end + integrator.stats.nf += 1 + end end \ No newline at end of file diff --git a/src/perform_step/fixed_timestep_perform_step.jl b/src/perform_step/fixed_timestep_perform_step.jl deleted file mode 100644 index 2923459c72..0000000000 --- a/src/perform_step/fixed_timestep_perform_step.jl +++ /dev/null @@ -1,43 +0,0 @@ -function initialize!(integrator, cache::FunctionMapConstantCache) - integrator.kshortsize = 0 - integrator.k = typeof(integrator.k)(undef, integrator.kshortsize) -end - -function perform_step!(integrator, cache::FunctionMapConstantCache, repeat_step = false) - @unpack uprev, dt, t, f, p = integrator - alg = unwrap_alg(integrator, nothing) - if integrator.f != DiffEqBase.DISCRETE_OUTOFPLACE_DEFAULT && - !(integrator.f isa DiffEqBase.EvalFunc && - integrator.f.f === DiffEqBase.DISCRETE_OUTOFPLACE_DEFAULT) - if FunctionMap_scale_by_time(alg) - tmp = f(uprev, p, t + dt) - integrator.stats.nf += 1 - @muladd integrator.u = @.. broadcast=false uprev+dt * tmp - else - integrator.u = f(uprev, p, t + dt) - integrator.stats.nf += 1 - end - end -end - -function initialize!(integrator, cache::FunctionMapCache) - integrator.kshortsize = 0 - resize!(integrator.k, integrator.kshortsize) -end - -function perform_step!(integrator, cache::FunctionMapCache, repeat_step = false) - @unpack u, uprev, dt, t, f, p = integrator - alg = unwrap_alg(integrator, nothing) - @unpack tmp = cache - if integrator.f != DiffEqBase.DISCRETE_INPLACE_DEFAULT && - !(integrator.f isa DiffEqBase.EvalFunc && - integrator.f.f === DiffEqBase.DISCRETE_INPLACE_DEFAULT) - if FunctionMap_scale_by_time(alg) - f(tmp, uprev, p, t + dt) - @muladd @.. broadcast=false u=uprev + dt * tmp - else - f(u, uprev, p, t + dt) - end - integrator.stats.nf += 1 - end -end \ No newline at end of file From d5cd505a0dc806a2e102b5c84adb2e9f484e3f44 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Wed, 31 Jul 2024 16:29:41 +0530 Subject: [PATCH 036/133] Fixes --- src/OrdinaryDiffEq.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/OrdinaryDiffEq.jl b/src/OrdinaryDiffEq.jl index c0fcce8b9b..2498a7fbd3 100644 --- a/src/OrdinaryDiffEq.jl +++ b/src/OrdinaryDiffEq.jl @@ -165,7 +165,6 @@ include("cache_utils.jl") include("initialize_dae.jl") include("wrappers.jl") -include("perform_step/fixed_timestep_perform_step.jl") include("perform_step/linear_perform_step.jl") include("perform_step/exponential_rk_perform_step.jl") include("perform_step/explicit_rk_perform_step.jl") From 64c71000cac984542e458d4cf56e122bb3813955 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Wed, 31 Jul 2024 16:32:10 +0530 Subject: [PATCH 037/133] Interpolants --- .../src/interpolants.jl | 28 ++++++++++++++++++- src/OrdinaryDiffEq.jl | 1 - src/dense/interpolants.jl | 25 ----------------- 3 files changed, 27 insertions(+), 27 deletions(-) delete mode 100644 src/dense/interpolants.jl diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/interpolants.jl b/lib/OrdinaryDiffEqLowOrderRK/src/interpolants.jl index d6df06413e..6b4a1578b3 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/interpolants.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/interpolants.jl @@ -1332,4 +1332,30 @@ end end """ -""" \ No newline at end of file +""" + +#### + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{FunctionMapConstantCache, FunctionMapCache}, + idxs::Nothing, T::Type{Val{0}}, differential_vars::Nothing) + y₀ +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{FunctionMapConstantCache, FunctionMapCache}, + idxs, T::Type{Val{0}}, differential_vars::Nothing) + y₀[idxs] +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{FunctionMapConstantCache, FunctionMapCache}, + idxs::Nothing, T::Type{Val{0}}, differential_vars::Nothing) + recursivecopy!(out, y₀) +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{FunctionMapConstantCache, FunctionMapCache}, + idxs, T::Type{Val{0}}, differential_vars::Nothing) + @views out[idxs] .= y₀[idxs] +end \ No newline at end of file diff --git a/src/OrdinaryDiffEq.jl b/src/OrdinaryDiffEq.jl index 2498a7fbd3..1449629f4e 100644 --- a/src/OrdinaryDiffEq.jl +++ b/src/OrdinaryDiffEq.jl @@ -174,7 +174,6 @@ include("perform_step/adams_bashforth_moulton_perform_step.jl") include("perform_step/nordsieck_perform_step.jl") include("dense/generic_dense.jl") -include("dense/interpolants.jl") include("dense/rosenbrock_interpolants.jl") include("dense/stiff_addsteps.jl") diff --git a/src/dense/interpolants.jl b/src/dense/interpolants.jl deleted file mode 100644 index 560686250f..0000000000 --- a/src/dense/interpolants.jl +++ /dev/null @@ -1,25 +0,0 @@ -#### - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{FunctionMapConstantCache, FunctionMapCache}, - idxs::Nothing, T::Type{Val{0}}, differential_vars::Nothing) - y₀ -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{FunctionMapConstantCache, FunctionMapCache}, - idxs, T::Type{Val{0}}, differential_vars::Nothing) - y₀[idxs] -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{FunctionMapConstantCache, FunctionMapCache}, - idxs::Nothing, T::Type{Val{0}}, differential_vars::Nothing) - recursivecopy!(out, y₀) -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{FunctionMapConstantCache, FunctionMapCache}, - idxs, T::Type{Val{0}}, differential_vars::Nothing) - @views out[idxs] .= y₀[idxs] -end \ No newline at end of file From c5eccec7f9c1d2d8e65f31e193d7e62e2dfe7d29 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Wed, 31 Jul 2024 16:35:44 +0530 Subject: [PATCH 038/133] @tight_loop_macros --- lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl | 1 + lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl b/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl index 97acfcc34c..2d54a3e8cb 100644 --- a/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl +++ b/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl @@ -10,6 +10,7 @@ import MuladdMacro: @muladd using DiffEqBase import FastBroadcast: @.. import RecursiveArrayTools: recursivefill! +using DiffEqBase: @def, @tight_loop_macros include("algorithms.jl") include("alg_utils.jl") diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl index 0be574b061..1703aa9c64 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl @@ -12,6 +12,7 @@ import MuladdMacro: @muladd import FastBroadcast: @.. import RecursiveArrayTools: recursivefill! import Static: False +using DiffEqBase: @def, @tight_loop_macros include("algorithms.jl") include("alg_utils.jl") From 7908b40b7392dc554d22e9573fd18fb1904d518c Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Wed, 31 Jul 2024 19:52:24 +0530 Subject: [PATCH 039/133] OrdinaryDiffEqFunctionMap --- lib/OrdinaryDiffEqFunctionMap/Project.toml | 25 +++++++++++ .../src/OrdinaryDiffEqFunctionMap.jl | 22 ++++++++++ .../src/alg_utils.jl | 21 +++++++++ .../src/algorithms.jl | 2 + .../src/fixed_timestep_perform_step.jl | 43 ++++++++++++++++++ .../src/functionmap_caches.jl | 23 ++++++++++ .../src/functionmap_perform_step.jl | 11 +++++ .../src/interp_func.jl | 9 ++++ .../src/interpolants.jl | 23 ++++++++++ lib/OrdinaryDiffEqLowOrderRK/src/alg_utils.jl | 19 -------- .../src/algorithms.jl | 5 +-- .../src/fixed_timestep_perform_step.jl | 44 ------------------- .../src/interp_func.jl | 9 ---- .../src/interpolants.jl | 28 +----------- .../src/low_order_rk_addsteps.jl | 12 ----- .../src/low_order_rk_caches.jl | 24 ---------- 16 files changed, 181 insertions(+), 139 deletions(-) create mode 100644 lib/OrdinaryDiffEqFunctionMap/Project.toml create mode 100644 lib/OrdinaryDiffEqFunctionMap/src/OrdinaryDiffEqFunctionMap.jl create mode 100644 lib/OrdinaryDiffEqFunctionMap/src/alg_utils.jl create mode 100644 lib/OrdinaryDiffEqFunctionMap/src/algorithms.jl create mode 100644 lib/OrdinaryDiffEqFunctionMap/src/fixed_timestep_perform_step.jl create mode 100644 lib/OrdinaryDiffEqFunctionMap/src/functionmap_caches.jl create mode 100644 lib/OrdinaryDiffEqFunctionMap/src/functionmap_perform_step.jl create mode 100644 lib/OrdinaryDiffEqFunctionMap/src/interp_func.jl create mode 100644 lib/OrdinaryDiffEqFunctionMap/src/interpolants.jl diff --git a/lib/OrdinaryDiffEqFunctionMap/Project.toml b/lib/OrdinaryDiffEqFunctionMap/Project.toml new file mode 100644 index 0000000000..b1bbc16fcb --- /dev/null +++ b/lib/OrdinaryDiffEqFunctionMap/Project.toml @@ -0,0 +1,25 @@ +name = "OrdinaryDiffEqFunctionMap" +uuid = "d3585ca7-f5d3-4ba6-8057-292ed1abd90f" +authors = ["ParamThakkar123 "] +version = "1.0.0" + +[deps] +OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" +MuladdMacro = "46d2c3a1-f734-5fdb-9937-b9b9aeba4221" +RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd" +FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898" +Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3" +DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" +SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462" + +[compat] +julia = "1.10" + +[extras] +DiffEqDevTools = "f3b72e0c-5b89-59e1-b016-84e28bfd966d" +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" +SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[targets] +test = ["DiffEqDevTools", "Random", "SafeTestsets", "Test"] \ No newline at end of file diff --git a/lib/OrdinaryDiffEqFunctionMap/src/OrdinaryDiffEqFunctionMap.jl b/lib/OrdinaryDiffEqFunctionMap/src/OrdinaryDiffEqFunctionMap.jl new file mode 100644 index 0000000000..828c15e6a4 --- /dev/null +++ b/lib/OrdinaryDiffEqFunctionMap/src/OrdinaryDiffEqFunctionMap.jl @@ -0,0 +1,22 @@ +module OrdinaryDiffEqFunctionMap + +import OrdinaryDiffEq: isfsal, beta2_default, beta1_default, OrdinaryDiffEqAlgorithm, + initialize!, perform_step!, @unpack, unwrap_alg, OrdinaryDiffEqMutableCache, + alg_cache, @cache, _ode_addsteps!, _ode_interpolant!, _ode_interpolant, +using DiffEqBase +import RecursiveArrayTools: recursivecopy! +import FastBroadcast: @.. +import MuladdMacro: @muladd +import Static: False + +include("algorithms.jl") +include("alg_utils.jl") +include("functionmap_caches.jl") +include("interp_func.jl") +include("interpolants.jl") +include("functionmap_perform_step.jl") +include("fixed_timestep_perform_step.jl") + +export FunctionMap + +end \ No newline at end of file diff --git a/lib/OrdinaryDiffEqFunctionMap/src/alg_utils.jl b/lib/OrdinaryDiffEqFunctionMap/src/alg_utils.jl new file mode 100644 index 0000000000..6712b49d36 --- /dev/null +++ b/lib/OrdinaryDiffEqFunctionMap/src/alg_utils.jl @@ -0,0 +1,21 @@ +function SciMLBase.isautodifferentiable(alg::FunctionMap) + true +end +function SciMLBase.allows_arbitrary_number_types(alg::FunctionMap) + true +end +function SciMLBase.allowscomplex(alg::FunctionMap) + true +end + +SciMLBase.isdiscrete(alg::FunctionMap) = true + +isfsal(alg::FunctionMap) = false + +beta2_default(alg::FunctionMap) = 0 + +beta1_default(alg::FunctionMap, beta2) = 0 + +function FunctionMap_scale_by_time(alg::FunctionMap{scale_by_time}) where {scale_by_time} + scale_by_time +end \ No newline at end of file diff --git a/lib/OrdinaryDiffEqFunctionMap/src/algorithms.jl b/lib/OrdinaryDiffEqFunctionMap/src/algorithms.jl new file mode 100644 index 0000000000..c0123f8a07 --- /dev/null +++ b/lib/OrdinaryDiffEqFunctionMap/src/algorithms.jl @@ -0,0 +1,2 @@ +struct FunctionMap{scale_by_time} <: OrdinaryDiffEqAlgorithm end +FunctionMap(; scale_by_time = false) = FunctionMap{scale_by_time}() \ No newline at end of file diff --git a/lib/OrdinaryDiffEqFunctionMap/src/fixed_timestep_perform_step.jl b/lib/OrdinaryDiffEqFunctionMap/src/fixed_timestep_perform_step.jl new file mode 100644 index 0000000000..c8bc2548f9 --- /dev/null +++ b/lib/OrdinaryDiffEqFunctionMap/src/fixed_timestep_perform_step.jl @@ -0,0 +1,43 @@ +function initialize!(integrator, cache::FunctionMapCache) + integrator.kshortsize = 0 + resize!(integrator.k, integrator.kshortsize) +end + +function perform_step!(integrator, cache::FunctionMapCache, repeat_step = false) + @unpack u, uprev, dt, t, f, p = integrator + alg = unwrap_alg(integrator, nothing) + @unpack tmp = cache + if integrator.f != DiffEqBase.DISCRETE_INPLACE_DEFAULT && + !(integrator.f isa DiffEqBase.EvalFunc && + integrator.f.f === DiffEqBase.DISCRETE_INPLACE_DEFAULT) + if FunctionMap_scale_by_time(alg) + f(tmp, uprev, p, t + dt) + @muladd @.. broadcast=false u=uprev + dt * tmp + else + f(u, uprev, p, t + dt) + end + integrator.stats.nf += 1 + end +end + +function perform_step!(integrator, cache::FunctionMapConstantCache, repeat_step = false) + @unpack uprev, dt, t, f, p = integrator + alg = unwrap_alg(integrator, nothing) + if integrator.f != DiffEqBase.DISCRETE_OUTOFPLACE_DEFAULT && + !(integrator.f isa DiffEqBase.EvalFunc && + integrator.f.f === DiffEqBase.DISCRETE_OUTOFPLACE_DEFAULT) + if FunctionMap_scale_by_time(alg) + tmp = f(uprev, p, t + dt) + integrator.stats.nf += 1 + @muladd integrator.u = @.. broadcast=false uprev+dt * tmp + else + integrator.u = f(uprev, p, t + dt) + integrator.stats.nf += 1 + end + end +end + +function initialize!(integrator, cache::FunctionMapConstantCache) + integrator.kshortsize = 0 + integrator.k = typeof(integrator.k)(undef, integrator.kshortsize) +end \ No newline at end of file diff --git a/lib/OrdinaryDiffEqFunctionMap/src/functionmap_caches.jl b/lib/OrdinaryDiffEqFunctionMap/src/functionmap_caches.jl new file mode 100644 index 0000000000..cac0e0cab4 --- /dev/null +++ b/lib/OrdinaryDiffEqFunctionMap/src/functionmap_caches.jl @@ -0,0 +1,23 @@ +@cache struct FunctionMapCache{uType, rateType} <: OrdinaryDiffEqMutableCache + u::uType + uprev::uType + tmp::rateType +end + +function alg_cache(alg::FunctionMap, u, rate_prototype, ::Type{uEltypeNoUnits}, + ::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t, + dt, reltol, p, calck, + ::Val{true}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits} + FunctionMapCache(u, uprev, + FunctionMap_scale_by_time(alg) ? rate_prototype : + (eltype(u) <: Enum ? copy(u) : zero(u))) +end + +struct FunctionMapConstantCache <: OrdinaryDiffEqConstantCache end + +function alg_cache(alg::FunctionMap, u, rate_prototype, ::Type{uEltypeNoUnits}, + ::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t, + dt, reltol, p, calck, + ::Val{false}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits} + FunctionMapConstantCache() +end \ No newline at end of file diff --git a/lib/OrdinaryDiffEqFunctionMap/src/functionmap_perform_step.jl b/lib/OrdinaryDiffEqFunctionMap/src/functionmap_perform_step.jl new file mode 100644 index 0000000000..66115aca4b --- /dev/null +++ b/lib/OrdinaryDiffEqFunctionMap/src/functionmap_perform_step.jl @@ -0,0 +1,11 @@ +function _ode_addsteps!(k, t, uprev, u, dt, f, p, cache::FunctionMapCache, + always_calc_begin = false, allow_calc_end = true, + force_calc_end = false) + nothing +end + +function _ode_addsteps!(k, t, uprev, u, dt, f, p, cache::FunctionMapConstantCache, + always_calc_begin = false, allow_calc_end = true, + force_calc_end = false) + nothing +end \ No newline at end of file diff --git a/lib/OrdinaryDiffEqFunctionMap/src/interp_func.jl b/lib/OrdinaryDiffEqFunctionMap/src/interp_func.jl new file mode 100644 index 0000000000..3f78c44044 --- /dev/null +++ b/lib/OrdinaryDiffEqFunctionMap/src/interp_func.jl @@ -0,0 +1,9 @@ +function DiffEqBase.interp_summary(::Type{cacheType}, + dense::Bool) where {cacheType <: + FunctionMapConstantCache} + "left-endpoint piecewise constant" +end +function DiffEqBase.interp_summary(::Type{cacheType}, + dense::Bool) where {cacheType <: FunctionMapCache} + "left-endpoint piecewise constant" +end \ No newline at end of file diff --git a/lib/OrdinaryDiffEqFunctionMap/src/interpolants.jl b/lib/OrdinaryDiffEqFunctionMap/src/interpolants.jl new file mode 100644 index 0000000000..4f537264bb --- /dev/null +++ b/lib/OrdinaryDiffEqFunctionMap/src/interpolants.jl @@ -0,0 +1,23 @@ +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{FunctionMapConstantCache, FunctionMapCache}, + idxs::Nothing, T::Type{Val{0}}, differential_vars::Nothing) + y₀ +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{FunctionMapConstantCache, FunctionMapCache}, + idxs, T::Type{Val{0}}, differential_vars::Nothing) + y₀[idxs] +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{FunctionMapConstantCache, FunctionMapCache}, + idxs::Nothing, T::Type{Val{0}}, differential_vars::Nothing) + recursivecopy!(out, y₀) +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{FunctionMapConstantCache, FunctionMapCache}, + idxs, T::Type{Val{0}}, differential_vars::Nothing) + @views out[idxs] .= y₀[idxs] +end \ No newline at end of file diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/alg_utils.jl b/lib/OrdinaryDiffEqLowOrderRK/src/alg_utils.jl index 246359beb4..fd6d6b6c43 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/alg_utils.jl @@ -1,15 +1,3 @@ -function SciMLBase.isautodifferentiable(alg::FunctionMap) - true -end -function SciMLBase.allows_arbitrary_number_types(alg::FunctionMap) - true -end -function SciMLBase.allowscomplex(alg::FunctionMap) - true -end - -SciMLBase.isdiscrete(alg::FunctionMap) = true - alg_order(alg::Euler) = 1 alg_order(alg::SplitEuler) = 1 alg_order(alg::Heun) = 2 @@ -43,13 +31,10 @@ isfsal(alg::RKO65) = false isfsal(alg::PSRK3p5q4) = false isfsal(alg::PSRK3p6q5) = false isfsal(alg::PSRK4p7q6) = false -isfsal(alg::FunctionMap) = false beta2_default(alg::DP5) = 4 // 100 -beta2_default(alg::FunctionMap) = 0 beta1_default(alg::DP5, beta2) = typeof(beta2)(1 // alg_order(alg)) - 3beta2 / 4 -beta1_default(alg::FunctionMap, beta2) = 0 alg_stability_size(alg::DP5) = 3.3066 @@ -60,8 +45,4 @@ function DiffEqBase.prepare_alg( u0::AbstractArray, p, prob) alg -end - -function FunctionMap_scale_by_time(alg::FunctionMap{scale_by_time}) where {scale_by_time} - scale_by_time end \ No newline at end of file diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/algorithms.jl b/lib/OrdinaryDiffEqLowOrderRK/src/algorithms.jl index 2503de20e1..8eaeed7d66 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/algorithms.jl @@ -612,7 +612,4 @@ function Base.show(io::IO, alg::Alshina6) print(io, "Alshina6(stage_limiter! = ", alg.stage_limiter!, ", step_limiter! = ", alg.step_limiter!, ", thread = ", alg.thread, ")") -end - -struct FunctionMap{scale_by_time} <: OrdinaryDiffEqAlgorithm end -FunctionMap(; scale_by_time = false) = FunctionMap{scale_by_time}() \ No newline at end of file +end \ No newline at end of file diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/fixed_timestep_perform_step.jl b/lib/OrdinaryDiffEqLowOrderRK/src/fixed_timestep_perform_step.jl index 217f815f6d..c46a3f1992 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/fixed_timestep_perform_step.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/fixed_timestep_perform_step.jl @@ -484,48 +484,4 @@ end step_limiter!(u, integrator, p, t + dt) f(k7, u, p, t + dt) integrator.stats.nf += 6 -end - -function initialize!(integrator, cache::FunctionMapConstantCache) - integrator.kshortsize = 0 - integrator.k = typeof(integrator.k)(undef, integrator.kshortsize) -end - -function perform_step!(integrator, cache::FunctionMapConstantCache, repeat_step = false) - @unpack uprev, dt, t, f, p = integrator - alg = unwrap_alg(integrator, nothing) - if integrator.f != DiffEqBase.DISCRETE_OUTOFPLACE_DEFAULT && - !(integrator.f isa DiffEqBase.EvalFunc && - integrator.f.f === DiffEqBase.DISCRETE_OUTOFPLACE_DEFAULT) - if FunctionMap_scale_by_time(alg) - tmp = f(uprev, p, t + dt) - integrator.stats.nf += 1 - @muladd integrator.u = @.. broadcast=false uprev+dt * tmp - else - integrator.u = f(uprev, p, t + dt) - integrator.stats.nf += 1 - end - end -end - -function initialize!(integrator, cache::FunctionMapCache) - integrator.kshortsize = 0 - resize!(integrator.k, integrator.kshortsize) -end - -function perform_step!(integrator, cache::FunctionMapCache, repeat_step = false) - @unpack u, uprev, dt, t, f, p = integrator - alg = unwrap_alg(integrator, nothing) - @unpack tmp = cache - if integrator.f != DiffEqBase.DISCRETE_INPLACE_DEFAULT && - !(integrator.f isa DiffEqBase.EvalFunc && - integrator.f.f === DiffEqBase.DISCRETE_INPLACE_DEFAULT) - if FunctionMap_scale_by_time(alg) - f(tmp, uprev, p, t + dt) - @muladd @.. broadcast=false u=uprev + dt * tmp - else - f(u, uprev, p, t + dt) - end - integrator.stats.nf += 1 - end end \ No newline at end of file diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/interp_func.jl b/lib/OrdinaryDiffEqLowOrderRK/src/interp_func.jl index c039dfe666..2886094976 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/interp_func.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/interp_func.jl @@ -27,13 +27,4 @@ function DiffEqBase.interp_summary(::Type{cacheType}, cacheType <: Union{BS5ConstantCache, BS5Cache}} dense ? "specialized 5th order lazy interpolation" : "1st order linear" -end -function DiffEqBase.interp_summary(::Type{cacheType}, - dense::Bool) where {cacheType <: - FunctionMapConstantCache} - "left-endpoint piecewise constant" -end -function DiffEqBase.interp_summary(::Type{cacheType}, - dense::Bool) where {cacheType <: FunctionMapCache} - "left-endpoint piecewise constant" end \ No newline at end of file diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/interpolants.jl b/lib/OrdinaryDiffEqLowOrderRK/src/interpolants.jl index 6b4a1578b3..d6df06413e 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/interpolants.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/interpolants.jl @@ -1332,30 +1332,4 @@ end end """ -""" - -#### - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{FunctionMapConstantCache, FunctionMapCache}, - idxs::Nothing, T::Type{Val{0}}, differential_vars::Nothing) - y₀ -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{FunctionMapConstantCache, FunctionMapCache}, - idxs, T::Type{Val{0}}, differential_vars::Nothing) - y₀[idxs] -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{FunctionMapConstantCache, FunctionMapCache}, - idxs::Nothing, T::Type{Val{0}}, differential_vars::Nothing) - recursivecopy!(out, y₀) -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{FunctionMapConstantCache, FunctionMapCache}, - idxs, T::Type{Val{0}}, differential_vars::Nothing) - @views out[idxs] .= y₀[idxs] -end \ No newline at end of file +""" \ No newline at end of file diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_addsteps.jl b/lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_addsteps.jl index 95a7c53ae2..9ddb007ecb 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_addsteps.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_addsteps.jl @@ -1,15 +1,3 @@ -function _ode_addsteps!(k, t, uprev, u, dt, f, p, cache::FunctionMapCache, - always_calc_begin = false, allow_calc_end = true, - force_calc_end = false) - nothing -end - -function _ode_addsteps!(k, t, uprev, u, dt, f, p, cache::FunctionMapConstantCache, - always_calc_begin = false, allow_calc_end = true, - force_calc_end = false) - nothing -end - @muladd function _ode_addsteps!(k, t, uprev, u, dt, f, p, cache::OwrenZen4Cache, always_calc_begin = false, allow_calc_end = true, force_calc_end = false) diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_caches.jl b/lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_caches.jl index c7f12271c4..ac728ae2ae 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_caches.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/low_order_rk_caches.jl @@ -1484,28 +1484,4 @@ function alg_cache(alg::Alshina6, u, rate_prototype, ::Type{uEltypeNoUnits}, tab = Alshina6ConstantCache(constvalue(uBottomEltypeNoUnits), constvalue(tTypeNoUnits)) Alshina6Cache(u, uprev, k1, k2, k3, k4, k5, k6, k7, tmp, tab, alg.stage_limiter!, alg.step_limiter!, alg.thread) -end - -@cache struct FunctionMapCache{uType, rateType} <: OrdinaryDiffEqMutableCache - u::uType - uprev::uType - tmp::rateType -end - -function alg_cache(alg::FunctionMap, u, rate_prototype, ::Type{uEltypeNoUnits}, - ::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t, - dt, reltol, p, calck, - ::Val{true}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits} - FunctionMapCache(u, uprev, - FunctionMap_scale_by_time(alg) ? rate_prototype : - (eltype(u) <: Enum ? copy(u) : zero(u))) -end - -struct FunctionMapConstantCache <: OrdinaryDiffEqConstantCache end - -function alg_cache(alg::FunctionMap, u, rate_prototype, ::Type{uEltypeNoUnits}, - ::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t, - dt, reltol, p, calck, - ::Val{false}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits} - FunctionMapConstantCache() end \ No newline at end of file From 642810eaaa08ea3b70f59fe7a2bc84957ede7344 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Wed, 31 Jul 2024 20:32:17 +0530 Subject: [PATCH 040/133] FunctionMap --- lib/OrdinaryDiffEqFunctionMap/src/OrdinaryDiffEqFunctionMap.jl | 1 + lib/OrdinaryDiffEqFunctionMap/src/alg_utils.jl | 2 ++ lib/OrdinaryDiffEqLowOrderRK/src/alg_utils.jl | 1 - 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqFunctionMap/src/OrdinaryDiffEqFunctionMap.jl b/lib/OrdinaryDiffEqFunctionMap/src/OrdinaryDiffEqFunctionMap.jl index 828c15e6a4..6ebfff0b2c 100644 --- a/lib/OrdinaryDiffEqFunctionMap/src/OrdinaryDiffEqFunctionMap.jl +++ b/lib/OrdinaryDiffEqFunctionMap/src/OrdinaryDiffEqFunctionMap.jl @@ -3,6 +3,7 @@ module OrdinaryDiffEqFunctionMap import OrdinaryDiffEq: isfsal, beta2_default, beta1_default, OrdinaryDiffEqAlgorithm, initialize!, perform_step!, @unpack, unwrap_alg, OrdinaryDiffEqMutableCache, alg_cache, @cache, _ode_addsteps!, _ode_interpolant!, _ode_interpolant, + alg_order using DiffEqBase import RecursiveArrayTools: recursivecopy! import FastBroadcast: @.. diff --git a/lib/OrdinaryDiffEqFunctionMap/src/alg_utils.jl b/lib/OrdinaryDiffEqFunctionMap/src/alg_utils.jl index 6712b49d36..caf8d67292 100644 --- a/lib/OrdinaryDiffEqFunctionMap/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqFunctionMap/src/alg_utils.jl @@ -12,6 +12,8 @@ SciMLBase.isdiscrete(alg::FunctionMap) = true isfsal(alg::FunctionMap) = false +alg_order(alg::FunctionMap) = 0 + beta2_default(alg::FunctionMap) = 0 beta1_default(alg::FunctionMap, beta2) = 0 diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/alg_utils.jl b/lib/OrdinaryDiffEqLowOrderRK/src/alg_utils.jl index fd6d6b6c43..f9c206588e 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/alg_utils.jl @@ -24,7 +24,6 @@ alg_order(alg::SIR54) = 5 alg_order(alg::Alshina2) = 2 alg_order(alg::Alshina3) = 3 alg_order(alg::Alshina6) = 6 -alg_order(alg::FunctionMap) = 0 isfsal(alg::FRK65) = true isfsal(alg::RKO65) = false From 0de6d31a4610d0101a443ebf097b7f862e594b7b Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Wed, 31 Jul 2024 20:38:56 +0530 Subject: [PATCH 041/133] fixes --- src/OrdinaryDiffEq.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/OrdinaryDiffEq.jl b/src/OrdinaryDiffEq.jl index 1449629f4e..4ca6156a35 100644 --- a/src/OrdinaryDiffEq.jl +++ b/src/OrdinaryDiffEq.jl @@ -295,7 +295,11 @@ export Euler, SplitEuler, Heun, Ralston, Midpoint, RK4, BS3, OwrenZen3, OwrenZen4, OwrenZen5, BS5, Tsit5, DP5, Anas5, RKO65, FRK65, RKM, MSRK5, MSRK6, PSRK4p7q6, PSRK3p5q4, PSRK3p6q5, Stepanov5, SIR54, - Alshina2, Alshina3, Alshina6, FunctionMap + Alshina2, Alshina3, Alshina6 + +include("../lib/OrdinaryDiffEqFunctionMap/src/OrdinaryDiffEqFunctionMap.jl") +using ..OrdinaryDiffEqFunctionMap +export FunctionMap PrecompileTools.@compile_workload begin function lorenz(du, u, p, t) From 39c81df10f9c9ebc1e1dcd87e8321265ff6e65dc Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Wed, 31 Jul 2024 22:00:07 +0530 Subject: [PATCH 042/133] OrdinaryDiffEqConstantCache --- lib/OrdinaryDiffEqFunctionMap/src/OrdinaryDiffEqFunctionMap.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqFunctionMap/src/OrdinaryDiffEqFunctionMap.jl b/lib/OrdinaryDiffEqFunctionMap/src/OrdinaryDiffEqFunctionMap.jl index 6ebfff0b2c..5396c1f389 100644 --- a/lib/OrdinaryDiffEqFunctionMap/src/OrdinaryDiffEqFunctionMap.jl +++ b/lib/OrdinaryDiffEqFunctionMap/src/OrdinaryDiffEqFunctionMap.jl @@ -3,7 +3,7 @@ module OrdinaryDiffEqFunctionMap import OrdinaryDiffEq: isfsal, beta2_default, beta1_default, OrdinaryDiffEqAlgorithm, initialize!, perform_step!, @unpack, unwrap_alg, OrdinaryDiffEqMutableCache, alg_cache, @cache, _ode_addsteps!, _ode_interpolant!, _ode_interpolant, - alg_order + alg_order, OrdinaryDiffEqConstantCache using DiffEqBase import RecursiveArrayTools: recursivecopy! import FastBroadcast: @.. From f50c16bbbe40b6aa590e14ddbc2b479456a9fe09 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Wed, 31 Jul 2024 23:12:29 +0530 Subject: [PATCH 043/133] OrdinaryDiffEqConstantCache --- .../src/integrator_interface.jl | 30 ++++++++++++++++++ src/OrdinaryDiffEq.jl | 3 +- src/integrators/integrator_interface.jl | 31 ------------------- 3 files changed, 32 insertions(+), 32 deletions(-) create mode 100644 lib/OrdinaryDiffEqFunctionMap/src/integrator_interface.jl diff --git a/lib/OrdinaryDiffEqFunctionMap/src/integrator_interface.jl b/lib/OrdinaryDiffEqFunctionMap/src/integrator_interface.jl new file mode 100644 index 0000000000..092ac3c2e4 --- /dev/null +++ b/lib/OrdinaryDiffEqFunctionMap/src/integrator_interface.jl @@ -0,0 +1,30 @@ +@inline function DiffEqBase.get_du(integrator::ODEIntegrator) + integrator.cache isa FunctionMapCache || + integrator.cache isa FunctionMapConstantCache && + error("Derivatives are not defined for this stepper.") + return if isdefined(integrator, :fsallast) + integrator.fsallast + else + integrator(integrator.t, Val{1}) + end +end + +@inline function DiffEqBase.get_du!(out, integrator::ODEIntegrator) + integrator.cache isa FunctionMapCache || + integrator.cache isa FunctionMapConstantCache && + error("Derivatives are not defined for this stepper.") + if integrator.cache isa FunctionMapCache + out .= integrator.cache.tmp + else + return if isdefined(integrator, :fsallast) && + !(integrator.alg isa + Union{Rosenbrock23, Rosenbrock32, Rodas23W, + Rodas3P, Rodas4, Rodas4P, Rodas4P2, Rodas5, + Rodas5P, Rodas5Pe, Rodas5Pr}) + # Special stiff interpolations do not store the right value in fsallast + out .= integrator.fsallast + else + integrator(out, integrator.t, Val{1}) + end + end +end \ No newline at end of file diff --git a/src/OrdinaryDiffEq.jl b/src/OrdinaryDiffEq.jl index 4ca6156a35..1396dcb387 100644 --- a/src/OrdinaryDiffEq.jl +++ b/src/OrdinaryDiffEq.jl @@ -173,7 +173,6 @@ include("perform_step/composite_perform_step.jl") include("perform_step/adams_bashforth_moulton_perform_step.jl") include("perform_step/nordsieck_perform_step.jl") -include("dense/generic_dense.jl") include("dense/rosenbrock_interpolants.jl") include("dense/stiff_addsteps.jl") @@ -301,6 +300,8 @@ include("../lib/OrdinaryDiffEqFunctionMap/src/OrdinaryDiffEqFunctionMap.jl") using ..OrdinaryDiffEqFunctionMap export FunctionMap +include("dense/generic_dense.jl") + PrecompileTools.@compile_workload begin function lorenz(du, u, p, t) du[1] = 10.0(u[2] - u[1]) diff --git a/src/integrators/integrator_interface.jl b/src/integrators/integrator_interface.jl index 571841f981..b2223d419e 100644 --- a/src/integrators/integrator_interface.jl +++ b/src/integrators/integrator_interface.jl @@ -76,37 +76,6 @@ function set_proposed_dt!(integrator::ODEIntegrator, integrator2::ODEIntegrator) integrator.dtacc = integrator2.dtacc end -@inline function DiffEqBase.get_du(integrator::ODEIntegrator) - integrator.cache isa FunctionMapCache || - integrator.cache isa FunctionMapConstantCache && - error("Derivatives are not defined for this stepper.") - return if isdefined(integrator, :fsallast) - integrator.fsallast - else - integrator(integrator.t, Val{1}) - end -end - -@inline function DiffEqBase.get_du!(out, integrator::ODEIntegrator) - integrator.cache isa FunctionMapCache || - integrator.cache isa FunctionMapConstantCache && - error("Derivatives are not defined for this stepper.") - if integrator.cache isa FunctionMapCache - out .= integrator.cache.tmp - else - return if isdefined(integrator, :fsallast) && - !(integrator.alg isa - Union{Rosenbrock23, Rosenbrock32, Rodas23W, - Rodas3P, Rodas4, Rodas4P, Rodas4P2, Rodas5, - Rodas5P, Rodas5Pe, Rodas5Pr}) - # Special stiff interpolations do not store the right value in fsallast - out .= integrator.fsallast - else - integrator(out, integrator.t, Val{1}) - end - end -end - #TODO: Bigger caches for most algorithms @inline function DiffEqBase.get_tmp_cache(integrator::ODEIntegrator) get_tmp_cache(integrator::ODEIntegrator, integrator.alg, integrator.cache) From 561bc9e1c6a1ed9a59aaa95633aef4f9b34ab297 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Thu, 1 Aug 2024 22:30:12 +0530 Subject: [PATCH 044/133] solve.jl --- src/OrdinaryDiffEq.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OrdinaryDiffEq.jl b/src/OrdinaryDiffEq.jl index 1396dcb387..9089e08975 100644 --- a/src/OrdinaryDiffEq.jl +++ b/src/OrdinaryDiffEq.jl @@ -182,7 +182,6 @@ include("adams_utils.jl") include("derivative_wrappers.jl") include("iterator_interface.jl") include("constants.jl") -include("solve.jl") include("initdt.jl") include("interp_func.jl") @@ -301,6 +300,7 @@ using ..OrdinaryDiffEqFunctionMap export FunctionMap include("dense/generic_dense.jl") +include("solve.jl") PrecompileTools.@compile_workload begin function lorenz(du, u, p, t) From ec2ed26aa29df7f249ce7489e95d3d445e16a4ca Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Fri, 2 Aug 2024 17:06:21 +0530 Subject: [PATCH 045/133] Added Adams-Bashforth-Moulton methods --- .../Project.toml | 4 + .../OrdinaryDiffEqAdamsBashforthMoulton.jl | 5 + .../src}/adams_bashforth_moulton_caches.jl | 2 +- .../adams_bashforth_moulton_perform_step.jl | 2 +- .../src}/adams_utils.jl | 2 +- .../src/alg_utils.jl | 15 ++ .../src/algorithms.jl | 142 +++++++++++++++++ .../test}/adams_tests.jl | 2 +- .../test/runtests.jl | 3 + src/OrdinaryDiffEq.jl | 14 +- src/alg_utils.jl | 17 -- src/algorithms.jl | 148 +----------------- test/runtests.jl | 2 +- 13 files changed, 180 insertions(+), 178 deletions(-) create mode 100644 lib/OrdinaryDiffEqAdamsBashforthMoulton/Project.toml create mode 100644 lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl rename {src/caches => lib/OrdinaryDiffEqAdamsBashforthMoulton/src}/adams_bashforth_moulton_caches.jl (99%) rename {src/perform_step => lib/OrdinaryDiffEqAdamsBashforthMoulton/src}/adams_bashforth_moulton_perform_step.jl (99%) rename {src => lib/OrdinaryDiffEqAdamsBashforthMoulton/src}/adams_utils.jl (99%) create mode 100644 lib/OrdinaryDiffEqAdamsBashforthMoulton/src/alg_utils.jl create mode 100644 lib/OrdinaryDiffEqAdamsBashforthMoulton/src/algorithms.jl rename {test/algconvergence => lib/OrdinaryDiffEqAdamsBashforthMoulton/test}/adams_tests.jl (99%) create mode 100644 lib/OrdinaryDiffEqAdamsBashforthMoulton/test/runtests.jl diff --git a/lib/OrdinaryDiffEqAdamsBashforthMoulton/Project.toml b/lib/OrdinaryDiffEqAdamsBashforthMoulton/Project.toml new file mode 100644 index 0000000000..1f0cda1aaf --- /dev/null +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/Project.toml @@ -0,0 +1,4 @@ +name = "OrdinaryDiffEqAdamsBashforthMoulton" +uuid = "89bda076-bce5-4f1c-845f-551c83cdda9a" +authors = ["ParamThakkar123 "] +version = "0.1.0" diff --git a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl new file mode 100644 index 0000000000..2040f55ff5 --- /dev/null +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl @@ -0,0 +1,5 @@ +module OrdinaryDiffEqAdamsBashforthMoulton + +greet() = print("Hello World!") + +end # module OrdinaryDiffEqAdamsBashforthMoulton diff --git a/src/caches/adams_bashforth_moulton_caches.jl b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_bashforth_moulton_caches.jl similarity index 99% rename from src/caches/adams_bashforth_moulton_caches.jl rename to lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_bashforth_moulton_caches.jl index 3f8a84278c..78799efb27 100644 --- a/src/caches/adams_bashforth_moulton_caches.jl +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_bashforth_moulton_caches.jl @@ -1135,4 +1135,4 @@ function alg_cache(alg::CNLF2, u, rate_prototype, ::Type{uEltypeNoUnits}, tprev2 = t CNLF2Cache(u, uprev, uprev2, fsalfirst, k1, k2, du₁, nlsolver, uprev3, tprev2) -end +end \ No newline at end of file diff --git a/src/perform_step/adams_bashforth_moulton_perform_step.jl b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_bashforth_moulton_perform_step.jl similarity index 99% rename from src/perform_step/adams_bashforth_moulton_perform_step.jl rename to lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_bashforth_moulton_perform_step.jl index e9e9c1d9aa..65ba186b25 100644 --- a/src/perform_step/adams_bashforth_moulton_perform_step.jl +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_bashforth_moulton_perform_step.jl @@ -1745,4 +1745,4 @@ function perform_step!(integrator, cache::CNLF2Cache, repeat_step = false) cache.k2 .= du₁ f(integrator.fsallast, u, p, t + dt) integrator.stats.nf += 1 -end +end \ No newline at end of file diff --git a/src/adams_utils.jl b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_utils.jl similarity index 99% rename from src/adams_utils.jl rename to lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_utils.jl index 274a7b3b5b..ab206ddc0f 100644 --- a/src/adams_utils.jl +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_utils.jl @@ -138,4 +138,4 @@ const global γstar = [ -0.0046775, -0.00421495, -0.0038269 -] +] \ No newline at end of file diff --git a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/alg_utils.jl b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/alg_utils.jl new file mode 100644 index 0000000000..e578c5cf98 --- /dev/null +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/alg_utils.jl @@ -0,0 +1,15 @@ +alg_order(alg::AB3) = 3 +alg_order(alg::ABM32) = 3 +alg_order(alg::AB4) = 4 +alg_order(alg::ABM43) = 4 +alg_order(alg::AB5) = 5 +alg_order(alg::ABM54) = 5 +alg_order(alg::VCAB3) = 3 +alg_order(alg::VCAB4) = 4 +alg_order(alg::VCAB5) = 5 +alg_order(alg::VCABM3) = 3 +alg_order(alg::VCABM4) = 4 +alg_order(alg::VCABM5) = 5 +alg_order(alg::VCABM) = 1 #dummy value + +isstandard(alg::VCABM) = true \ No newline at end of file diff --git a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/algorithms.jl b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/algorithms.jl new file mode 100644 index 0000000000..2fd47adaa5 --- /dev/null +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/algorithms.jl @@ -0,0 +1,142 @@ +# Adams Bashforth and Adams moulton methods + +""" +E. Hairer, S. P. Norsett, G. Wanner, Solving Ordinary Differential Equations I, Nonstiff +Problems. Computational Mathematics (2nd revised ed.), Springer (1996) doi: +https://doi.org/10.1007/978-3-540-78862-1 + +AB3: Adams-Bashforth Explicit Method +The 3-step third order multistep method. Ralston's Second Order Method is used to calculate starting values. +""" +struct AB3 <: OrdinaryDiffEqAlgorithm end + +""" +E. Hairer, S. P. Norsett, G. Wanner, Solving Ordinary Differential Equations I, Nonstiff +Problems. Computational Mathematics (2nd revised ed.), Springer (1996) doi: +https://doi.org/10.1007/978-3-540-78862-1 + +AB4: Adams-Bashforth Explicit Method +The 4-step fourth order multistep method. Runge-Kutta method of order 4 is used to calculate starting values. +""" +struct AB4 <: OrdinaryDiffEqAlgorithm end + +""" +E. Hairer, S. P. Norsett, G. Wanner, Solving Ordinary Differential Equations I, Nonstiff +Problems. Computational Mathematics (2nd revised ed.), Springer (1996) doi: +https://doi.org/10.1007/978-3-540-78862-1 + +AB5: Adams-Bashforth Explicit Method +The 3-step third order multistep method. Ralston's Second Order Method is used to calculate starting values. +""" +struct AB5 <: OrdinaryDiffEqAlgorithm end + +""" +E. Hairer, S. P. Norsett, G. Wanner, Solving Ordinary Differential Equations I, Nonstiff +Problems. Computational Mathematics (2nd revised ed.), Springer (1996) doi: +https://doi.org/10.1007/978-3-540-78862-1 + +ABM32: Adams-Bashforth Explicit Method +It is third order method. In ABM32, AB3 works as predictor and Adams Moulton 2-steps method works as Corrector. +Ralston's Second Order Method is used to calculate starting values. +""" +struct ABM32 <: OrdinaryDiffEqAlgorithm end + +""" +E. Hairer, S. P. Norsett, G. Wanner, Solving Ordinary Differential Equations I, Nonstiff +Problems. Computational Mathematics (2nd revised ed.), Springer (1996) doi: +https://doi.org/10.1007/978-3-540-78862-1 + +ABM43: Adams-Bashforth Explicit Method +It is fourth order method. In ABM43, AB4 works as predictor and Adams Moulton 3-steps method works as Corrector. +Runge-Kutta method of order 4 is used to calculate starting values. +""" +struct ABM43 <: OrdinaryDiffEqAlgorithm end + +""" +E. Hairer, S. P. Norsett, G. Wanner, Solving Ordinary Differential Equations I, Nonstiff +Problems. Computational Mathematics (2nd revised ed.), Springer (1996) doi: +https://doi.org/10.1007/978-3-540-78862-1 + +ABM54: Adams-Bashforth Explicit Method +It is fifth order method. In ABM54, AB5 works as predictor and Adams Moulton 4-steps method works as Corrector. +Runge-Kutta method of order 4 is used to calculate starting values. +""" +struct ABM54 <: OrdinaryDiffEqAlgorithm end + +# Variable Step Size Adams methods + +""" +E. Hairer, S. P. Norsett, G. Wanner, Solving Ordinary Differential Equations I, Nonstiff +Problems. Computational Mathematics (2nd revised ed.), Springer (1996) doi: +https://doi.org/10.1007/978-3-540-78862-1 + +VCAB3: Adaptive step size Adams explicit Method +The 3rd order Adams method. Bogacki-Shampine 3/2 method is used to calculate starting values. +""" +struct VCAB3 <: OrdinaryDiffEqAdaptiveAlgorithm end + +""" +E. Hairer, S. P. Norsett, G. Wanner, Solving Ordinary Differential Equations I, Nonstiff +Problems. Computational Mathematics (2nd revised ed.), Springer (1996) doi: +https://doi.org/10.1007/978-3-540-78862-1 + +VCAB4: Adaptive step size Adams explicit Method +The 4th order Adams method. Runge-Kutta 4 is used to calculate starting values. +""" +struct VCAB4 <: OrdinaryDiffEqAdaptiveAlgorithm end + +""" +E. Hairer, S. P. Norsett, G. Wanner, Solving Ordinary Differential Equations I, Nonstiff +Problems. Computational Mathematics (2nd revised ed.), Springer (1996) doi: +https://doi.org/10.1007/978-3-540-78862-1 + +VCAB5: Adaptive step size Adams explicit Method +The 5th order Adams method. Runge-Kutta 4 is used to calculate starting values. +""" +struct VCAB5 <: OrdinaryDiffEqAdaptiveAlgorithm end + +""" +E. Hairer, S. P. Norsett, G. Wanner, Solving Ordinary Differential Equations I, Nonstiff +Problems. Computational Mathematics (2nd revised ed.), Springer (1996) doi: +https://doi.org/10.1007/978-3-540-78862-1 + +VCABM3: Adaptive step size Adams explicit Method +The 3rd order Adams-Moulton method. Bogacki-Shampine 3/2 method is used to calculate starting values. +""" +struct VCABM3 <: OrdinaryDiffEqAdaptiveAlgorithm end + +""" +E. Hairer, S. P. Norsett, G. Wanner, Solving Ordinary Differential Equations I, Nonstiff +Problems. Computational Mathematics (2nd revised ed.), Springer (1996) doi: +https://doi.org/10.1007/978-3-540-78862-1 + +VCABM4: Adaptive step size Adams explicit Method +The 4th order Adams-Moulton method. Runge-Kutta 4 is used to calculate starting values. +""" +struct VCABM4 <: OrdinaryDiffEqAdaptiveAlgorithm end + +""" +E. Hairer, S. P. Norsett, G. Wanner, Solving Ordinary Differential Equations I, Nonstiff +Problems. Computational Mathematics (2nd revised ed.), Springer (1996) doi: +https://doi.org/10.1007/978-3-540-78862-1 + +VCABM5: Adaptive step size Adams explicit Method +The 5th order Adams-Moulton method. Runge-Kutta 4 is used to calculate starting values. +""" +struct VCABM5 <: OrdinaryDiffEqAdaptiveAlgorithm end + +# Variable Order and Variable Step Size Adams methods + +""" +E. Hairer, S. P. Norsett, G. Wanner, Solving Ordinary Differential Equations I, Nonstiff +Problems. Computational Mathematics (2nd revised ed.), Springer (1996) doi: +https://doi.org/10.1007/978-3-540-78862-1 + +VCABM: Adaptive step size Adams explicit Method +An adaptive order adaptive time Adams Moulton method. +It uses an order adaptivity algorithm is derived from Shampine's DDEABM. +""" +struct VCABM <: OrdinaryDiffEqAdamsVarOrderVarStepAlgorithm end + +const MultistepAlgorithms = Union{ + AB3, AB4, AB5, ABM32, ABM43, ABM54} \ No newline at end of file diff --git a/test/algconvergence/adams_tests.jl b/lib/OrdinaryDiffEqAdamsBashforthMoulton/test/adams_tests.jl similarity index 99% rename from test/algconvergence/adams_tests.jl rename to lib/OrdinaryDiffEqAdamsBashforthMoulton/test/adams_tests.jl index 4ab409511f..6ac2846509 100644 --- a/test/algconvergence/adams_tests.jl +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/test/adams_tests.jl @@ -51,4 +51,4 @@ for i in 1:2 sol1 = solve(prob, VCAB5(), dt = 1 // 256, adaptive = false) sol2 = solve(prob, AB5(), dt = 1 // 256) @test sol1.u ≈ sol2.u -end +end \ No newline at end of file diff --git a/lib/OrdinaryDiffEqAdamsBashforthMoulton/test/runtests.jl b/lib/OrdinaryDiffEqAdamsBashforthMoulton/test/runtests.jl new file mode 100644 index 0000000000..48449d5351 --- /dev/null +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/test/runtests.jl @@ -0,0 +1,3 @@ +using SafeTestsets + +@time @safetestset "Adams Variable Coefficients Tests" include("adams_tests.jl") \ No newline at end of file diff --git a/src/OrdinaryDiffEq.jl b/src/OrdinaryDiffEq.jl index 9089e08975..2d8e4245b8 100644 --- a/src/OrdinaryDiffEq.jl +++ b/src/OrdinaryDiffEq.jl @@ -152,7 +152,6 @@ include("caches/basic_caches.jl") include("caches/linear_caches.jl") include("caches/linear_nonlinear_caches.jl") include("caches/rosenbrock_caches.jl") -include("caches/adams_bashforth_moulton_caches.jl") include("caches/nordsieck_caches.jl") include("tableaus/rosenbrock_tableaus.jl") @@ -170,7 +169,6 @@ include("perform_step/exponential_rk_perform_step.jl") include("perform_step/explicit_rk_perform_step.jl") include("perform_step/rosenbrock_perform_step.jl") include("perform_step/composite_perform_step.jl") -include("perform_step/adams_bashforth_moulton_perform_step.jl") include("perform_step/nordsieck_perform_step.jl") include("dense/rosenbrock_interpolants.jl") @@ -178,7 +176,6 @@ include("dense/stiff_addsteps.jl") include("derivative_utils.jl") include("nordsieck_utils.jl") -include("adams_utils.jl") include("derivative_wrappers.jl") include("iterator_interface.jl") include("constants.jl") @@ -299,6 +296,11 @@ include("../lib/OrdinaryDiffEqFunctionMap/src/OrdinaryDiffEqFunctionMap.jl") using ..OrdinaryDiffEqFunctionMap export FunctionMap +include("../lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl") +using ..OrdinaryDiffEqAdamsBashforthMoulton +export AB3, AB4, AB5, ABM32, ABM43, ABM54, VCAB3, + VCAB4, VCAB5, VCABM3, VCABM4, VCABM5, VCABM + include("dense/generic_dense.jl") include("solve.jl") @@ -449,12 +451,6 @@ export LawsonEuler, NorsettEuler, ETD1, ETDRK2, ETDRK3, ETDRK4, HochOst4, Exp4, export SHLDDRK52, SHLDDRK_2N -export AB3, AB4, AB5, ABM32, ABM43, ABM54 - -export VCAB3, VCAB4, VCAB5, VCABM3, VCABM4, VCABM5 - -export VCABM - export CNAB2, CNLF2 export AN5, JVODE, JVODE_Adams, JVODE_BDF diff --git a/src/alg_utils.jl b/src/alg_utils.jl index 832336c461..12e2284dfc 100644 --- a/src/alg_utils.jl +++ b/src/alg_utils.jl @@ -434,22 +434,6 @@ alg_order(alg::Rodas5P) = 5 alg_order(alg::Rodas5Pr) = 5 alg_order(alg::Rodas5Pe) = 5 -alg_order(alg::AB3) = 3 -alg_order(alg::AB4) = 4 -alg_order(alg::AB5) = 5 -alg_order(alg::ABM32) = 3 -alg_order(alg::ABM43) = 4 -alg_order(alg::ABM54) = 5 - -alg_order(alg::VCAB3) = 3 -alg_order(alg::VCAB4) = 4 -alg_order(alg::VCAB5) = 5 -alg_order(alg::VCABM3) = 3 -alg_order(alg::VCABM4) = 4 -alg_order(alg::VCABM5) = 5 - -alg_order(alg::VCABM) = 1 #dummy value - alg_order(alg::CNAB2) = 2 alg_order(alg::CNLF2) = 2 @@ -598,7 +582,6 @@ ispredictive(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm}) = false ispredictive(alg::OrdinaryDiffEqNewtonAdaptiveAlgorithm) = alg.controller === :Predictive isstandard(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm}) = false isstandard(alg::OrdinaryDiffEqNewtonAdaptiveAlgorithm) = alg.controller === :Standard -isstandard(alg::VCABM) = true isWmethod(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm}) = false isWmethod(alg::Rosenbrock23) = true diff --git a/src/algorithms.jl b/src/algorithms.jl index 0b708d24a9..2e17664ee9 100644 --- a/src/algorithms.jl +++ b/src/algorithms.jl @@ -81,146 +81,6 @@ TruncatedStacktraces.@truncate_stacktrace ExplicitRK @inline trivial_limiter!(u, integrator, p, t) = nothing -# Adams Bashforth and Adams moulton methods - -""" -E. Hairer, S. P. Norsett, G. Wanner, Solving Ordinary Differential Equations I, Nonstiff -Problems. Computational Mathematics (2nd revised ed.), Springer (1996) doi: -https://doi.org/10.1007/978-3-540-78862-1 - -AB3: Adams-Bashforth Explicit Method -The 3-step third order multistep method. Ralston's Second Order Method is used to calculate starting values. -""" -struct AB3 <: OrdinaryDiffEqAlgorithm end - -""" -E. Hairer, S. P. Norsett, G. Wanner, Solving Ordinary Differential Equations I, Nonstiff -Problems. Computational Mathematics (2nd revised ed.), Springer (1996) doi: -https://doi.org/10.1007/978-3-540-78862-1 - -AB4: Adams-Bashforth Explicit Method -The 4-step fourth order multistep method. Runge-Kutta method of order 4 is used to calculate starting values. -""" -struct AB4 <: OrdinaryDiffEqAlgorithm end - -""" -E. Hairer, S. P. Norsett, G. Wanner, Solving Ordinary Differential Equations I, Nonstiff -Problems. Computational Mathematics (2nd revised ed.), Springer (1996) doi: -https://doi.org/10.1007/978-3-540-78862-1 - -AB5: Adams-Bashforth Explicit Method -The 3-step third order multistep method. Ralston's Second Order Method is used to calculate starting values. -""" -struct AB5 <: OrdinaryDiffEqAlgorithm end - -""" -E. Hairer, S. P. Norsett, G. Wanner, Solving Ordinary Differential Equations I, Nonstiff -Problems. Computational Mathematics (2nd revised ed.), Springer (1996) doi: -https://doi.org/10.1007/978-3-540-78862-1 - -ABM32: Adams-Bashforth Explicit Method -It is third order method. In ABM32, AB3 works as predictor and Adams Moulton 2-steps method works as Corrector. -Ralston's Second Order Method is used to calculate starting values. -""" -struct ABM32 <: OrdinaryDiffEqAlgorithm end - -""" -E. Hairer, S. P. Norsett, G. Wanner, Solving Ordinary Differential Equations I, Nonstiff -Problems. Computational Mathematics (2nd revised ed.), Springer (1996) doi: -https://doi.org/10.1007/978-3-540-78862-1 - -ABM43: Adams-Bashforth Explicit Method -It is fourth order method. In ABM43, AB4 works as predictor and Adams Moulton 3-steps method works as Corrector. -Runge-Kutta method of order 4 is used to calculate starting values. -""" -struct ABM43 <: OrdinaryDiffEqAlgorithm end - -""" -E. Hairer, S. P. Norsett, G. Wanner, Solving Ordinary Differential Equations I, Nonstiff -Problems. Computational Mathematics (2nd revised ed.), Springer (1996) doi: -https://doi.org/10.1007/978-3-540-78862-1 - -ABM54: Adams-Bashforth Explicit Method -It is fifth order method. In ABM54, AB5 works as predictor and Adams Moulton 4-steps method works as Corrector. -Runge-Kutta method of order 4 is used to calculate starting values. -""" -struct ABM54 <: OrdinaryDiffEqAlgorithm end - -# Variable Step Size Adams methods - -""" -E. Hairer, S. P. Norsett, G. Wanner, Solving Ordinary Differential Equations I, Nonstiff -Problems. Computational Mathematics (2nd revised ed.), Springer (1996) doi: -https://doi.org/10.1007/978-3-540-78862-1 - -VCAB3: Adaptive step size Adams explicit Method -The 3rd order Adams method. Bogacki-Shampine 3/2 method is used to calculate starting values. -""" -struct VCAB3 <: OrdinaryDiffEqAdaptiveAlgorithm end - -""" -E. Hairer, S. P. Norsett, G. Wanner, Solving Ordinary Differential Equations I, Nonstiff -Problems. Computational Mathematics (2nd revised ed.), Springer (1996) doi: -https://doi.org/10.1007/978-3-540-78862-1 - -VCAB4: Adaptive step size Adams explicit Method -The 4th order Adams method. Runge-Kutta 4 is used to calculate starting values. -""" -struct VCAB4 <: OrdinaryDiffEqAdaptiveAlgorithm end - -""" -E. Hairer, S. P. Norsett, G. Wanner, Solving Ordinary Differential Equations I, Nonstiff -Problems. Computational Mathematics (2nd revised ed.), Springer (1996) doi: -https://doi.org/10.1007/978-3-540-78862-1 - -VCAB5: Adaptive step size Adams explicit Method -The 5th order Adams method. Runge-Kutta 4 is used to calculate starting values. -""" -struct VCAB5 <: OrdinaryDiffEqAdaptiveAlgorithm end - -""" -E. Hairer, S. P. Norsett, G. Wanner, Solving Ordinary Differential Equations I, Nonstiff -Problems. Computational Mathematics (2nd revised ed.), Springer (1996) doi: -https://doi.org/10.1007/978-3-540-78862-1 - -VCABM3: Adaptive step size Adams explicit Method -The 3rd order Adams-Moulton method. Bogacki-Shampine 3/2 method is used to calculate starting values. -""" -struct VCABM3 <: OrdinaryDiffEqAdaptiveAlgorithm end - -""" -E. Hairer, S. P. Norsett, G. Wanner, Solving Ordinary Differential Equations I, Nonstiff -Problems. Computational Mathematics (2nd revised ed.), Springer (1996) doi: -https://doi.org/10.1007/978-3-540-78862-1 - -VCABM4: Adaptive step size Adams explicit Method -The 4th order Adams-Moulton method. Runge-Kutta 4 is used to calculate starting values. -""" -struct VCABM4 <: OrdinaryDiffEqAdaptiveAlgorithm end - -""" -E. Hairer, S. P. Norsett, G. Wanner, Solving Ordinary Differential Equations I, Nonstiff -Problems. Computational Mathematics (2nd revised ed.), Springer (1996) doi: -https://doi.org/10.1007/978-3-540-78862-1 - -VCABM5: Adaptive step size Adams explicit Method -The 5th order Adams-Moulton method. Runge-Kutta 4 is used to calculate starting values. -""" -struct VCABM5 <: OrdinaryDiffEqAdaptiveAlgorithm end - -# Variable Order and Variable Step Size Adams methods - -""" -E. Hairer, S. P. Norsett, G. Wanner, Solving Ordinary Differential Equations I, Nonstiff -Problems. Computational Mathematics (2nd revised ed.), Springer (1996) doi: -https://doi.org/10.1007/978-3-540-78862-1 - -VCABM: Adaptive step size Adams explicit Method -An adaptive order adaptive time Adams Moulton method. -It uses an order adaptivity algorithm is derived from Shampine's DDEABM. -""" -struct VCABM <: OrdinaryDiffEqAdamsVarOrderVarStepAlgorithm end - # IMEX Multistep methods struct CNAB2{CS, AD, F, F2, P, FDT, ST, CJ} <: @@ -672,10 +532,4 @@ struct AutoSwitch{nAlg, sAlg, tolType, T} dtfac::T stiffalgfirst::Bool switch_max::Int -end - -### Algorithm Groups - -# ABDF2 -const MultistepAlgorithms = Union{ - AB3, AB4, AB5, ABM32, ABM43, ABM54} +end \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index 0c7baef7e6..4a8d65cd80 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -207,7 +207,7 @@ end @time @safetestset "Convergence Tests" include("algconvergence/ode_convergence_tests.jl") @time @safetestset "DAE Convergence Tests" include("../lib/OrdinaryDiffEqBDF/test/dae_convergence_tests.jl") @time @safetestset "Non-autonomous Convergence Tests" include("algconvergence/non-autonomous_convergence_tests.jl") - @time @safetestset "Adams Variable Coefficients Tests" include("algconvergence/adams_tests.jl") + @time @safetestset "Adams Variable Coefficients Tests" include("../lib/OrdinaryDiffEqAdamsBashforthMoulton/test/adams_tests.jl") @time @safetestset "Nordsieck Tests" include("algconvergence/nordsieck_tests.jl") end From 822fd9ea78e3e0017237de7f26772c2271e07a26 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Fri, 2 Aug 2024 17:16:09 +0530 Subject: [PATCH 046/133] imports --- .../src/OrdinaryDiffEqAdamsBashforthMoulton.jl | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl index 2040f55ff5..de613bb5d7 100644 --- a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl @@ -1,5 +1,14 @@ module OrdinaryDiffEqAdamsBashforthMoulton -greet() = print("Hello World!") +import OrdinaryDiffEq: OrdinaryDiffEqMutableCache, OrdinaryDiffEqConstantCache, @cache, alg_cache, + initialize!, @unpack, perform_step!, alg_order, isstandard, OrdinaryDiffEqAlgorithm, + OrdinaryDiffEqAdaptiveAlgorithm, OrdinaryDiffEqAdamsVarOrderVarStepAlgorithm +using MuladdMacro, FastBroadcast -end # module OrdinaryDiffEqAdamsBashforthMoulton +include("algorithms.jl") +include("alg_utils.jl") +include("adams_bashforth_moulton_caches.jl") +include("adams_utils.jl") +include("adams_bashforth_moulton_perform_step.jl") + +end From 19a48d9d07279d3b0a214ccf6dd63c4998710628 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Fri, 2 Aug 2024 17:19:47 +0530 Subject: [PATCH 047/133] Fixes --- .../src/adams_bashforth_moulton_caches.jl | 117 ------------------ src/caches/imex_multistep_caches.jl | 116 +++++++++++++++++ 2 files changed, 116 insertions(+), 117 deletions(-) create mode 100644 src/caches/imex_multistep_caches.jl diff --git a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_bashforth_moulton_caches.jl b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_bashforth_moulton_caches.jl index 78799efb27..e842455393 100644 --- a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_bashforth_moulton_caches.jl +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_bashforth_moulton_caches.jl @@ -1018,121 +1018,4 @@ function alg_cache(alg::VCABM, u, rate_prototype, ::Type{uEltypeNoUnits}, u, uprev, fsalfirst, k4, ϕstar_nm1, dts, c, g, ϕ_n, ϕ_np1, ϕstar_n, β, order, max_order, atmp, tmp, ξ, ξ0, utilde, utildem1, utildem2, utildep1, atmpm1, atmpm2, atmpp1, 1) -end - -# IMEX Multistep methods - -# CNAB2 - -@cache mutable struct CNAB2ConstantCache{rateType, N, uType, tType} <: - OrdinaryDiffEqConstantCache - k2::rateType - nlsolver::N - uprev3::uType - tprev2::tType -end - -@cache mutable struct CNAB2Cache{uType, rateType, N, tType} <: OrdinaryDiffEqMutableCache - u::uType - uprev::uType - uprev2::uType - fsalfirst::rateType - k1::rateType - k2::rateType - du₁::rateType - nlsolver::N - uprev3::uType - tprev2::tType -end - -function alg_cache(alg::CNAB2, u, rate_prototype, ::Type{uEltypeNoUnits}, - ::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t, - dt, reltol, p, calck, - ::Val{false}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits} - γ, c = 1 // 2, 1 - nlsolver = build_nlsolver(alg, u, uprev, p, t, dt, f, rate_prototype, uEltypeNoUnits, - uBottomEltypeNoUnits, tTypeNoUnits, γ, c, Val(false)) - - k2 = rate_prototype - uprev3 = u - tprev2 = t - - CNAB2ConstantCache(k2, nlsolver, uprev3, tprev2) -end - -function alg_cache(alg::CNAB2, u, rate_prototype, ::Type{uEltypeNoUnits}, - ::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t, - dt, reltol, p, calck, - ::Val{true}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits} - γ, c = 1 // 2, 1 - nlsolver = build_nlsolver(alg, u, uprev, p, t, dt, f, rate_prototype, uEltypeNoUnits, - uBottomEltypeNoUnits, tTypeNoUnits, γ, c, Val(true)) - fsalfirst = zero(rate_prototype) - - k1 = zero(rate_prototype) - k2 = zero(rate_prototype) - du₁ = zero(rate_prototype) - uprev3 = zero(u) - tprev2 = t - - CNAB2Cache(u, uprev, uprev2, fsalfirst, k1, k2, du₁, nlsolver, uprev3, tprev2) -end - -# CNLF2 - -@cache mutable struct CNLF2ConstantCache{rateType, N, uType, tType} <: - OrdinaryDiffEqConstantCache - k2::rateType - nlsolver::N - uprev2::uType - uprev3::uType - tprev2::tType -end - -@cache mutable struct CNLF2Cache{uType, rateType, N, tType} <: OrdinaryDiffEqMutableCache - u::uType - uprev::uType - uprev2::uType - fsalfirst::rateType - k1::rateType - k2::rateType - du₁::rateType - nlsolver::N - uprev3::uType - tprev2::tType -end - -function alg_cache(alg::CNLF2, u, rate_prototype, ::Type{uEltypeNoUnits}, - ::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t, - dt, reltol, p, calck, - ::Val{false}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits} - γ, c = 1 // 1, 1 - nlsolver = build_nlsolver(alg, u, uprev, p, t, dt, f, rate_prototype, uEltypeNoUnits, - uBottomEltypeNoUnits, tTypeNoUnits, γ, c, Val(false)) - - k2 = rate_prototype - uprev2 = u - uprev3 = u - tprev2 = t - - CNLF2ConstantCache(k2, nlsolver, uprev2, uprev3, tprev2) -end - -function alg_cache(alg::CNLF2, u, rate_prototype, ::Type{uEltypeNoUnits}, - ::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t, - dt, reltol, p, calck, - ::Val{true}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits} - γ, c = 1 // 1, 1 - nlsolver = build_nlsolver(alg, u, uprev, p, t, dt, f, rate_prototype, uEltypeNoUnits, - uBottomEltypeNoUnits, tTypeNoUnits, γ, c, Val(true)) - fsalfirst = zero(rate_prototype) - - k1 = zero(rate_prototype) - k2 = zero(rate_prototype) - du₁ = zero(rate_prototype) - uprev2 = zero(u) - uprev3 = zero(u) - tprev2 = t - - CNLF2Cache(u, uprev, uprev2, fsalfirst, k1, k2, du₁, nlsolver, uprev3, tprev2) end \ No newline at end of file diff --git a/src/caches/imex_multistep_caches.jl b/src/caches/imex_multistep_caches.jl new file mode 100644 index 0000000000..a147c20bc5 --- /dev/null +++ b/src/caches/imex_multistep_caches.jl @@ -0,0 +1,116 @@ +# IMEX Multistep methods + +# CNAB2 + +@cache mutable struct CNAB2ConstantCache{rateType, N, uType, tType} <: + OrdinaryDiffEqConstantCache + k2::rateType + nlsolver::N + uprev3::uType + tprev2::tType +end + +@cache mutable struct CNAB2Cache{uType, rateType, N, tType} <: OrdinaryDiffEqMutableCache + u::uType + uprev::uType + uprev2::uType + fsalfirst::rateType + k1::rateType + k2::rateType + du₁::rateType + nlsolver::N + uprev3::uType + tprev2::tType +end + +function alg_cache(alg::CNAB2, u, rate_prototype, ::Type{uEltypeNoUnits}, + ::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t, + dt, reltol, p, calck, + ::Val{false}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits} + γ, c = 1 // 2, 1 + nlsolver = build_nlsolver(alg, u, uprev, p, t, dt, f, rate_prototype, uEltypeNoUnits, + uBottomEltypeNoUnits, tTypeNoUnits, γ, c, Val(false)) + + k2 = rate_prototype + uprev3 = u + tprev2 = t + + CNAB2ConstantCache(k2, nlsolver, uprev3, tprev2) +end + +function alg_cache(alg::CNAB2, u, rate_prototype, ::Type{uEltypeNoUnits}, + ::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t, + dt, reltol, p, calck, + ::Val{true}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits} + γ, c = 1 // 2, 1 + nlsolver = build_nlsolver(alg, u, uprev, p, t, dt, f, rate_prototype, uEltypeNoUnits, + uBottomEltypeNoUnits, tTypeNoUnits, γ, c, Val(true)) + fsalfirst = zero(rate_prototype) + + k1 = zero(rate_prototype) + k2 = zero(rate_prototype) + du₁ = zero(rate_prototype) + uprev3 = zero(u) + tprev2 = t + + CNAB2Cache(u, uprev, uprev2, fsalfirst, k1, k2, du₁, nlsolver, uprev3, tprev2) +end + +# CNLF2 + +@cache mutable struct CNLF2ConstantCache{rateType, N, uType, tType} <: + OrdinaryDiffEqConstantCache + k2::rateType + nlsolver::N + uprev2::uType + uprev3::uType + tprev2::tType +end + +@cache mutable struct CNLF2Cache{uType, rateType, N, tType} <: OrdinaryDiffEqMutableCache + u::uType + uprev::uType + uprev2::uType + fsalfirst::rateType + k1::rateType + k2::rateType + du₁::rateType + nlsolver::N + uprev3::uType + tprev2::tType +end + +function alg_cache(alg::CNLF2, u, rate_prototype, ::Type{uEltypeNoUnits}, + ::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t, + dt, reltol, p, calck, + ::Val{false}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits} + γ, c = 1 // 1, 1 + nlsolver = build_nlsolver(alg, u, uprev, p, t, dt, f, rate_prototype, uEltypeNoUnits, + uBottomEltypeNoUnits, tTypeNoUnits, γ, c, Val(false)) + + k2 = rate_prototype + uprev2 = u + uprev3 = u + tprev2 = t + + CNLF2ConstantCache(k2, nlsolver, uprev2, uprev3, tprev2) +end + +function alg_cache(alg::CNLF2, u, rate_prototype, ::Type{uEltypeNoUnits}, + ::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t, + dt, reltol, p, calck, + ::Val{true}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits} + γ, c = 1 // 1, 1 + nlsolver = build_nlsolver(alg, u, uprev, p, t, dt, f, rate_prototype, uEltypeNoUnits, + uBottomEltypeNoUnits, tTypeNoUnits, γ, c, Val(true)) + fsalfirst = zero(rate_prototype) + + k1 = zero(rate_prototype) + k2 = zero(rate_prototype) + du₁ = zero(rate_prototype) + uprev2 = zero(u) + uprev3 = zero(u) + tprev2 = t + + CNLF2Cache(u, uprev, uprev2, fsalfirst, k1, k2, du₁, nlsolver, uprev3, tprev2) +end \ No newline at end of file From a6c9c28f697f097496b33f4f16fb3eb7b36864b9 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Fri, 2 Aug 2024 17:23:21 +0530 Subject: [PATCH 048/133] Fixes --- src/OrdinaryDiffEq.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OrdinaryDiffEq.jl b/src/OrdinaryDiffEq.jl index 2d8e4245b8..ee10215dde 100644 --- a/src/OrdinaryDiffEq.jl +++ b/src/OrdinaryDiffEq.jl @@ -151,6 +151,7 @@ include("generic_rosenbrock.jl") include("caches/basic_caches.jl") include("caches/linear_caches.jl") include("caches/linear_nonlinear_caches.jl") +include("caches/imex_multistep_caches.jl") include("caches/rosenbrock_caches.jl") include("caches/nordsieck_caches.jl") From fd3f786cf126619db5935e63d747625ba1fb03f4 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Fri, 2 Aug 2024 17:29:57 +0530 Subject: [PATCH 049/133] Fixes --- .../adams_bashforth_moulton_perform_step.jl | 206 ------------------ src/OrdinaryDiffEq.jl | 1 + .../imex_multistep_perform_step.jl | 205 +++++++++++++++++ 3 files changed, 206 insertions(+), 206 deletions(-) create mode 100644 src/perform_step/imex_multistep_perform_step.jl diff --git a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_bashforth_moulton_perform_step.jl b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_bashforth_moulton_perform_step.jl index 65ba186b25..eaba2d6193 100644 --- a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_bashforth_moulton_perform_step.jl +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_bashforth_moulton_perform_step.jl @@ -1539,210 +1539,4 @@ end cache.ϕstar_nm1, cache.ϕstar_n = ϕstar_n, ϕstar_nm1 return nothing end # inbounds -end - -# CNAB2 - -function initialize!(integrator, cache::CNAB2ConstantCache) - integrator.kshortsize = 2 - integrator.k = typeof(integrator.k)(undef, integrator.kshortsize) - integrator.fsalfirst = integrator.f.f1(integrator.uprev, integrator.p, integrator.t) + - integrator.f.f2(integrator.uprev, integrator.p, integrator.t) # Pre-start fsal - integrator.stats.nf += 1 - integrator.stats.nf2 += 1 - - # Avoid undefined entries if k is an array of arrays - integrator.fsallast = zero(integrator.fsalfirst) - integrator.k[1] = integrator.fsalfirst - integrator.k[2] = integrator.fsallast -end - -function perform_step!(integrator, cache::CNAB2ConstantCache, repeat_step = false) - @unpack t, dt, uprev, u, f, p = integrator - @unpack k2, nlsolver = cache - cnt = integrator.iter - f1 = integrator.f.f1 - f2 = integrator.f.f2 - du₁ = f1(uprev, p, t) - integrator.stats.nf += 1 - k1 = integrator.fsalfirst - du₁ - # Explicit part - if cnt == 1 - tmp = uprev + dt * k1 - else - tmp = uprev + dt * (3 // 2 * k1 - 1 // 2 * k2) - end - nlsolver.tmp = tmp - # Implicit part - # precalculations - γ = 1 // 2 - γdt = γ * dt - - # initial guess - zprev = dt * du₁ - nlsolver.z = z = zprev # Constant extrapolation - - nlsolver.tmp += γ * zprev - markfirststage!(nlsolver) - z = nlsolve!(nlsolver, integrator, cache, repeat_step) - nlsolvefail(nlsolver) && return - u = nlsolver.tmp + 1 // 2 * z - - cache.k2 = k1 - integrator.fsallast = f1(u, p, t + dt) + f2(u, p, t + dt) - integrator.stats.nf += 1 - integrator.stats.nf2 += 1 - integrator.k[1] = integrator.fsalfirst - integrator.k[2] = integrator.fsallast - integrator.u = u -end - -function initialize!(integrator, cache::CNAB2Cache) - integrator.kshortsize = 2 - integrator.fsalfirst = cache.fsalfirst - integrator.fsallast = du_alias_or_new(cache.nlsolver, integrator.fsalfirst) - resize!(integrator.k, integrator.kshortsize) - integrator.k[1] = integrator.fsalfirst - integrator.k[2] = integrator.fsallast - integrator.f(integrator.fsalfirst, integrator.uprev, integrator.p, integrator.t) - integrator.stats.nf += 1 -end - -function perform_step!(integrator, cache::CNAB2Cache, repeat_step = false) - @unpack t, dt, uprev, u, f, p = integrator - @unpack k1, k2, du₁, nlsolver = cache - @unpack z, tmp = nlsolver - @unpack f1 = f - cnt = integrator.iter - - f1(du₁, uprev, p, t) - integrator.stats.nf += 1 - @.. broadcast=false k1=integrator.fsalfirst - du₁ - # Explicit part - if cnt == 1 - @.. broadcast=false tmp=uprev + dt * k1 - else - @.. broadcast=false tmp=uprev + dt * (3 // 2 * k1 - 1 // 2 * k2) - end - # Implicit part - # precalculations - γ = 1 // 2 - γdt = γ * dt - - # initial guess - @.. broadcast=false z=dt * du₁ - @.. broadcast=false tmp+=γ * z - markfirststage!(nlsolver) - z = nlsolve!(nlsolver, integrator, cache, repeat_step) - nlsolvefail(nlsolver) && return - @.. broadcast=false u=tmp + 1 // 2 * z - - cache.k2 .= k1 - f(integrator.fsallast, u, p, t + dt) - integrator.stats.nf += 1 -end - -# CNLF2 - -function initialize!(integrator, cache::CNLF2ConstantCache) - integrator.kshortsize = 2 - integrator.k = typeof(integrator.k)(undef, integrator.kshortsize) - integrator.fsalfirst = integrator.f.f1(integrator.uprev, integrator.p, integrator.t) + - integrator.f.f2(integrator.uprev, integrator.p, integrator.t) # Pre-start fsal - integrator.stats.nf += 1 - integrator.stats.nf2 += 1 - - # Avoid undefined entries if k is an array of arrays - integrator.fsallast = zero(integrator.fsalfirst) - integrator.k[1] = integrator.fsalfirst - integrator.k[2] = integrator.fsallast -end - -function perform_step!(integrator, cache::CNLF2ConstantCache, repeat_step = false) - @unpack t, dt, uprev, u, f, p = integrator - @unpack k2, uprev2, nlsolver = cache - cnt = integrator.iter - f1 = integrator.f.f1 - f2 = integrator.f.f2 - du₁ = f1(uprev, p, t) - integrator.stats.nf += 1 - # Explicit part - if cnt == 1 - tmp = uprev + dt * (integrator.fsalfirst - du₁) - else - tmp = uprev2 + 2 // 1 * dt * (integrator.fsalfirst - du₁) - end - # Implicit part - # precalculations - γ = 1 // 1 - if cnt != 1 - tmp += γ * dt * k2 - end - γdt = γ * dt - nlsolver.tmp = tmp - - # initial guess - zprev = dt * du₁ - nlsolver.z = z = zprev # Constant extrapolation - - markfirststage!(nlsolver) - z = nlsolve!(nlsolver, integrator, cache, repeat_step) - nlsolvefail(nlsolver) && return - u = nlsolver.tmp + γ * z - - cache.uprev2 = uprev - cache.k2 = du₁ - integrator.fsallast = f1(u, p, t + dt) + f2(u, p, t + dt) - integrator.stats.nf += 1 - integrator.stats.nf2 += 1 - integrator.k[1] = integrator.fsalfirst - integrator.k[2] = integrator.fsallast - integrator.u = u -end - -function initialize!(integrator, cache::CNLF2Cache) - integrator.kshortsize = 2 - integrator.fsalfirst = cache.fsalfirst - integrator.fsallast = du_alias_or_new(cache.nlsolver, integrator.fsalfirst) - resize!(integrator.k, integrator.kshortsize) - integrator.k[1] = integrator.fsalfirst - integrator.k[2] = integrator.fsallast - integrator.f(integrator.fsalfirst, integrator.uprev, integrator.p, integrator.t) - integrator.stats.nf += 1 -end - -function perform_step!(integrator, cache::CNLF2Cache, repeat_step = false) - @unpack t, dt, uprev, u, f, p = integrator - @unpack uprev2, k2, du₁, nlsolver = cache - @unpack z, tmp = nlsolver - @unpack f1 = f - cnt = integrator.iter - - f1(du₁, uprev, p, t) - integrator.stats.nf += 1 - # Explicit part - if cnt == 1 - @.. broadcast=false tmp=uprev + dt * (integrator.fsalfirst - du₁) - else - @.. broadcast=false tmp=uprev2 + 2 // 1 * dt * (integrator.fsalfirst - du₁) - end - # Implicit part - # precalculations - γ = 1 // 1 - if cnt != 1 - @.. broadcast=false tmp+=γ * dt * k2 - end - γdt = γ * dt - - # initial guess - @.. broadcast=false z=dt * du₁ - markfirststage!(nlsolver) - z = nlsolve!(nlsolver, integrator, cache, repeat_step) - nlsolvefail(nlsolver) && return - @.. broadcast=false u=tmp + γ * z - - cache.uprev2 .= uprev - cache.k2 .= du₁ - f(integrator.fsallast, u, p, t + dt) - integrator.stats.nf += 1 end \ No newline at end of file diff --git a/src/OrdinaryDiffEq.jl b/src/OrdinaryDiffEq.jl index ee10215dde..3de1933050 100644 --- a/src/OrdinaryDiffEq.jl +++ b/src/OrdinaryDiffEq.jl @@ -169,6 +169,7 @@ include("perform_step/linear_perform_step.jl") include("perform_step/exponential_rk_perform_step.jl") include("perform_step/explicit_rk_perform_step.jl") include("perform_step/rosenbrock_perform_step.jl") +include("perform_step/imex_multistep_perform_step.jl") include("perform_step/composite_perform_step.jl") include("perform_step/nordsieck_perform_step.jl") diff --git a/src/perform_step/imex_multistep_perform_step.jl b/src/perform_step/imex_multistep_perform_step.jl new file mode 100644 index 0000000000..5a70c3e0a2 --- /dev/null +++ b/src/perform_step/imex_multistep_perform_step.jl @@ -0,0 +1,205 @@ +# CNAB2 + +function initialize!(integrator, cache::CNAB2ConstantCache) + integrator.kshortsize = 2 + integrator.k = typeof(integrator.k)(undef, integrator.kshortsize) + integrator.fsalfirst = integrator.f.f1(integrator.uprev, integrator.p, integrator.t) + + integrator.f.f2(integrator.uprev, integrator.p, integrator.t) # Pre-start fsal + integrator.stats.nf += 1 + integrator.stats.nf2 += 1 + + # Avoid undefined entries if k is an array of arrays + integrator.fsallast = zero(integrator.fsalfirst) + integrator.k[1] = integrator.fsalfirst + integrator.k[2] = integrator.fsallast +end + +function perform_step!(integrator, cache::CNAB2ConstantCache, repeat_step = false) + @unpack t, dt, uprev, u, f, p = integrator + @unpack k2, nlsolver = cache + cnt = integrator.iter + f1 = integrator.f.f1 + f2 = integrator.f.f2 + du₁ = f1(uprev, p, t) + integrator.stats.nf += 1 + k1 = integrator.fsalfirst - du₁ + # Explicit part + if cnt == 1 + tmp = uprev + dt * k1 + else + tmp = uprev + dt * (3 // 2 * k1 - 1 // 2 * k2) + end + nlsolver.tmp = tmp + # Implicit part + # precalculations + γ = 1 // 2 + γdt = γ * dt + + # initial guess + zprev = dt * du₁ + nlsolver.z = z = zprev # Constant extrapolation + + nlsolver.tmp += γ * zprev + markfirststage!(nlsolver) + z = nlsolve!(nlsolver, integrator, cache, repeat_step) + nlsolvefail(nlsolver) && return + u = nlsolver.tmp + 1 // 2 * z + + cache.k2 = k1 + integrator.fsallast = f1(u, p, t + dt) + f2(u, p, t + dt) + integrator.stats.nf += 1 + integrator.stats.nf2 += 1 + integrator.k[1] = integrator.fsalfirst + integrator.k[2] = integrator.fsallast + integrator.u = u +end + +function initialize!(integrator, cache::CNAB2Cache) + integrator.kshortsize = 2 + integrator.fsalfirst = cache.fsalfirst + integrator.fsallast = du_alias_or_new(cache.nlsolver, integrator.fsalfirst) + resize!(integrator.k, integrator.kshortsize) + integrator.k[1] = integrator.fsalfirst + integrator.k[2] = integrator.fsallast + integrator.f(integrator.fsalfirst, integrator.uprev, integrator.p, integrator.t) + integrator.stats.nf += 1 +end + +function perform_step!(integrator, cache::CNAB2Cache, repeat_step = false) + @unpack t, dt, uprev, u, f, p = integrator + @unpack k1, k2, du₁, nlsolver = cache + @unpack z, tmp = nlsolver + @unpack f1 = f + cnt = integrator.iter + + f1(du₁, uprev, p, t) + integrator.stats.nf += 1 + @.. broadcast=false k1=integrator.fsalfirst - du₁ + # Explicit part + if cnt == 1 + @.. broadcast=false tmp=uprev + dt * k1 + else + @.. broadcast=false tmp=uprev + dt * (3 // 2 * k1 - 1 // 2 * k2) + end + # Implicit part + # precalculations + γ = 1 // 2 + γdt = γ * dt + + # initial guess + @.. broadcast=false z=dt * du₁ + @.. broadcast=false tmp+=γ * z + markfirststage!(nlsolver) + z = nlsolve!(nlsolver, integrator, cache, repeat_step) + nlsolvefail(nlsolver) && return + @.. broadcast=false u=tmp + 1 // 2 * z + + cache.k2 .= k1 + f(integrator.fsallast, u, p, t + dt) + integrator.stats.nf += 1 +end + +# CNLF2 + +function initialize!(integrator, cache::CNLF2ConstantCache) + integrator.kshortsize = 2 + integrator.k = typeof(integrator.k)(undef, integrator.kshortsize) + integrator.fsalfirst = integrator.f.f1(integrator.uprev, integrator.p, integrator.t) + + integrator.f.f2(integrator.uprev, integrator.p, integrator.t) # Pre-start fsal + integrator.stats.nf += 1 + integrator.stats.nf2 += 1 + + # Avoid undefined entries if k is an array of arrays + integrator.fsallast = zero(integrator.fsalfirst) + integrator.k[1] = integrator.fsalfirst + integrator.k[2] = integrator.fsallast +end + +function perform_step!(integrator, cache::CNLF2ConstantCache, repeat_step = false) + @unpack t, dt, uprev, u, f, p = integrator + @unpack k2, uprev2, nlsolver = cache + cnt = integrator.iter + f1 = integrator.f.f1 + f2 = integrator.f.f2 + du₁ = f1(uprev, p, t) + integrator.stats.nf += 1 + # Explicit part + if cnt == 1 + tmp = uprev + dt * (integrator.fsalfirst - du₁) + else + tmp = uprev2 + 2 // 1 * dt * (integrator.fsalfirst - du₁) + end + # Implicit part + # precalculations + γ = 1 // 1 + if cnt != 1 + tmp += γ * dt * k2 + end + γdt = γ * dt + nlsolver.tmp = tmp + + # initial guess + zprev = dt * du₁ + nlsolver.z = z = zprev # Constant extrapolation + + markfirststage!(nlsolver) + z = nlsolve!(nlsolver, integrator, cache, repeat_step) + nlsolvefail(nlsolver) && return + u = nlsolver.tmp + γ * z + + cache.uprev2 = uprev + cache.k2 = du₁ + integrator.fsallast = f1(u, p, t + dt) + f2(u, p, t + dt) + integrator.stats.nf += 1 + integrator.stats.nf2 += 1 + integrator.k[1] = integrator.fsalfirst + integrator.k[2] = integrator.fsallast + integrator.u = u +end + +function initialize!(integrator, cache::CNLF2Cache) + integrator.kshortsize = 2 + integrator.fsalfirst = cache.fsalfirst + integrator.fsallast = du_alias_or_new(cache.nlsolver, integrator.fsalfirst) + resize!(integrator.k, integrator.kshortsize) + integrator.k[1] = integrator.fsalfirst + integrator.k[2] = integrator.fsallast + integrator.f(integrator.fsalfirst, integrator.uprev, integrator.p, integrator.t) + integrator.stats.nf += 1 +end + +function perform_step!(integrator, cache::CNLF2Cache, repeat_step = false) + @unpack t, dt, uprev, u, f, p = integrator + @unpack uprev2, k2, du₁, nlsolver = cache + @unpack z, tmp = nlsolver + @unpack f1 = f + cnt = integrator.iter + + f1(du₁, uprev, p, t) + integrator.stats.nf += 1 + # Explicit part + if cnt == 1 + @.. broadcast=false tmp=uprev + dt * (integrator.fsalfirst - du₁) + else + @.. broadcast=false tmp=uprev2 + 2 // 1 * dt * (integrator.fsalfirst - du₁) + end + # Implicit part + # precalculations + γ = 1 // 1 + if cnt != 1 + @.. broadcast=false tmp+=γ * dt * k2 + end + γdt = γ * dt + + # initial guess + @.. broadcast=false z=dt * du₁ + markfirststage!(nlsolver) + z = nlsolve!(nlsolver, integrator, cache, repeat_step) + nlsolvefail(nlsolver) && return + @.. broadcast=false u=tmp + γ * z + + cache.uprev2 .= uprev + cache.k2 .= du₁ + f(integrator.fsallast, u, p, t + dt) + integrator.stats.nf += 1 +end \ No newline at end of file From 6463da2ebf0e7f83d3ba91b5b4cff2e2a70b33a0 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Fri, 2 Aug 2024 18:12:15 +0530 Subject: [PATCH 050/133] Added Nordsieck solvers --- .../Project.toml | 22 ++++++++++++++++- lib/OrdinaryDiffEqNordsieck/Project.toml | 24 +++++++++++++++++++ .../src/OrdinaryDiffEqNordsieck.jl | 15 ++++++++++++ lib/OrdinaryDiffEqNordsieck/src/alg_utils.jl | 13 ++++++++++ lib/OrdinaryDiffEqNordsieck/src/algorithms.jl | 20 ++++++++++++++++ .../src/controllers.jl | 2 ++ .../src}/nordsieck_caches.jl | 2 +- .../src}/nordsieck_perform_step.jl | 2 +- src/OrdinaryDiffEq.jl | 8 +++---- src/alg_utils.jl | 12 ---------- src/algorithms.jl | 21 ---------------- 11 files changed, 101 insertions(+), 40 deletions(-) create mode 100644 lib/OrdinaryDiffEqNordsieck/Project.toml create mode 100644 lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl create mode 100644 lib/OrdinaryDiffEqNordsieck/src/alg_utils.jl create mode 100644 lib/OrdinaryDiffEqNordsieck/src/algorithms.jl create mode 100644 lib/OrdinaryDiffEqNordsieck/src/controllers.jl rename {src/caches => lib/OrdinaryDiffEqNordsieck/src}/nordsieck_caches.jl (99%) rename {src/perform_step => lib/OrdinaryDiffEqNordsieck/src}/nordsieck_perform_step.jl (99%) diff --git a/lib/OrdinaryDiffEqAdamsBashforthMoulton/Project.toml b/lib/OrdinaryDiffEqAdamsBashforthMoulton/Project.toml index 1f0cda1aaf..39b4ef0716 100644 --- a/lib/OrdinaryDiffEqAdamsBashforthMoulton/Project.toml +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/Project.toml @@ -1,4 +1,24 @@ name = "OrdinaryDiffEqAdamsBashforthMoulton" uuid = "89bda076-bce5-4f1c-845f-551c83cdda9a" authors = ["ParamThakkar123 "] -version = "0.1.0" +version = "1.0.0" + +[deps] +FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898" +MuladdMacro = "46d2c3a1-f734-5fdb-9937-b9b9aeba4221" +OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" +Polyester = "f517fe37-dbe3-4b94-8317-1923a5111588" +RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd" +Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3" + +[compat] +julia = "1.10" + +[extras] +DiffEqDevTools = "f3b72e0c-5b89-59e1-b016-84e28bfd966d" +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" +SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[targets] +test = ["DiffEqDevTools", "Random", "SafeTestsets", "Test"] \ No newline at end of file diff --git a/lib/OrdinaryDiffEqNordsieck/Project.toml b/lib/OrdinaryDiffEqNordsieck/Project.toml new file mode 100644 index 0000000000..cd7fce51aa --- /dev/null +++ b/lib/OrdinaryDiffEqNordsieck/Project.toml @@ -0,0 +1,24 @@ +name = "OrdinaryDiffEqNordsieck" +uuid = "c9986a66-5c92-4813-8696-a7ec84c806c8" +authors = ["ParamThakkar123 "] +version = "1.0.0" + +[deps] +FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898" +MuladdMacro = "46d2c3a1-f734-5fdb-9937-b9b9aeba4221" +OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" +Polyester = "f517fe37-dbe3-4b94-8317-1923a5111588" +RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd" +Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3" + +[compat] +julia = "1.10" + +[extras] +DiffEqDevTools = "f3b72e0c-5b89-59e1-b016-84e28bfd966d" +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" +SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[targets] +test = ["DiffEqDevTools", "Random", "SafeTestsets", "Test"] \ No newline at end of file diff --git a/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl b/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl new file mode 100644 index 0000000000..0150b558c2 --- /dev/null +++ b/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl @@ -0,0 +1,15 @@ +module OrdinaryDiffEqNordsieck + +import OrdinaryDiffEq: alg_order, alg_adaptive_order, qsteady_max_default, get_current_alg_order, + AbstractController, OrdinaryDiffEqAdaptiveAlgorithm, OrdinaryDiffEqAdamsVarOrderVarStepAlgorithm, + alg_cache, OrdinaryDiffEqMutableCache, OrdinaryDiffEqConstantCache, initialize!, @unpack, + perform_step! +using MuladdMacro, FastBroadcast, RecursiveArrayTools + +include("algorithms.jl") +include("controllers.jl") +include("alg_utils.jl") +include("nordsieck_caches.jl") +include("nordsieck_perform_step.jl") + +end \ No newline at end of file diff --git a/lib/OrdinaryDiffEqNordsieck/src/alg_utils.jl b/lib/OrdinaryDiffEqNordsieck/src/alg_utils.jl new file mode 100644 index 0000000000..e148b4d742 --- /dev/null +++ b/lib/OrdinaryDiffEqNordsieck/src/alg_utils.jl @@ -0,0 +1,13 @@ +alg_order(alg::AN5) = 5 +alg_order(alg::JVODE) = 1 #dummy value + +alg_adaptive_order(alg::AN5) = 5 + +qsteady_max_default(alg::AN5) = 3 // 2 +qsteady_max_default(alg::JVODE) = 3 // 2 + +get_current_alg_order(alg::JVODE, cache) = get_current_adaptive_order(alg, cache) + +function default_controller(alg::Union{JVODE}, args...) + DummyController() +end \ No newline at end of file diff --git a/lib/OrdinaryDiffEqNordsieck/src/algorithms.jl b/lib/OrdinaryDiffEqNordsieck/src/algorithms.jl new file mode 100644 index 0000000000..9bcc2f61ee --- /dev/null +++ b/lib/OrdinaryDiffEqNordsieck/src/algorithms.jl @@ -0,0 +1,20 @@ +# Adams/BDF methods in Nordsieck forms +""" +AN5: Adaptive step size Adams explicit Method +An adaptive 5th order fixed-leading coefficient Adams method in Nordsieck form. +""" +struct AN5 <: OrdinaryDiffEqAdaptiveAlgorithm end +struct JVODE{bType, aType} <: OrdinaryDiffEqAdamsVarOrderVarStepAlgorithm + algorithm::Symbol + bias1::bType + bias2::bType + bias3::bType + addon::aType +end + +function JVODE(algorithm = :Adams; bias1 = 6, bias2 = 6, bias3 = 10, + addon = 1 // 10^6) + JVODE(algorithm, bias1, bias2, bias3, addon) +end +JVODE_Adams(; kwargs...) = JVODE(:Adams; kwargs...) +JVODE_BDF(; kwargs...) = JVODE(:BDF; kwargs...) \ No newline at end of file diff --git a/lib/OrdinaryDiffEqNordsieck/src/controllers.jl b/lib/OrdinaryDiffEqNordsieck/src/controllers.jl new file mode 100644 index 0000000000..9b338e436b --- /dev/null +++ b/lib/OrdinaryDiffEqNordsieck/src/controllers.jl @@ -0,0 +1,2 @@ +struct DummyController <: AbstractController +end \ No newline at end of file diff --git a/src/caches/nordsieck_caches.jl b/lib/OrdinaryDiffEqNordsieck/src/nordsieck_caches.jl similarity index 99% rename from src/caches/nordsieck_caches.jl rename to lib/OrdinaryDiffEqNordsieck/src/nordsieck_caches.jl index 6b0717a494..cac09eabf8 100644 --- a/src/caches/nordsieck_caches.jl +++ b/lib/OrdinaryDiffEqNordsieck/src/nordsieck_caches.jl @@ -263,4 +263,4 @@ function alg_cache(alg::JVODE, u, rate_prototype, ::Type{uEltypeNoUnits}, z, l, m, c_LTE₊₁, c_LTE, c_LTE₋₁, c_conv, c_𝒟, prev_𝒟, dts, Δ, atmp, tsit5cache, 2, 1, 1, 2, η, η, η, η, η) -end +end \ No newline at end of file diff --git a/src/perform_step/nordsieck_perform_step.jl b/lib/OrdinaryDiffEqNordsieck/src/nordsieck_perform_step.jl similarity index 99% rename from src/perform_step/nordsieck_perform_step.jl rename to lib/OrdinaryDiffEqNordsieck/src/nordsieck_perform_step.jl index 0575a4db5f..26bf11b7ae 100644 --- a/src/perform_step/nordsieck_perform_step.jl +++ b/lib/OrdinaryDiffEqNordsieck/src/nordsieck_perform_step.jl @@ -319,4 +319,4 @@ end nordsieck_prepare_next!(integrator, cache) @.. broadcast=false integrator.k[2]=cache.z[2] / dt return nothing -end +end \ No newline at end of file diff --git a/src/OrdinaryDiffEq.jl b/src/OrdinaryDiffEq.jl index 3de1933050..24c98f8990 100644 --- a/src/OrdinaryDiffEq.jl +++ b/src/OrdinaryDiffEq.jl @@ -153,7 +153,6 @@ include("caches/linear_caches.jl") include("caches/linear_nonlinear_caches.jl") include("caches/imex_multistep_caches.jl") include("caches/rosenbrock_caches.jl") -include("caches/nordsieck_caches.jl") include("tableaus/rosenbrock_tableaus.jl") @@ -171,7 +170,6 @@ include("perform_step/explicit_rk_perform_step.jl") include("perform_step/rosenbrock_perform_step.jl") include("perform_step/imex_multistep_perform_step.jl") include("perform_step/composite_perform_step.jl") -include("perform_step/nordsieck_perform_step.jl") include("dense/rosenbrock_interpolants.jl") include("dense/stiff_addsteps.jl") @@ -303,6 +301,10 @@ using ..OrdinaryDiffEqAdamsBashforthMoulton export AB3, AB4, AB5, ABM32, ABM43, ABM54, VCAB3, VCAB4, VCAB5, VCABM3, VCABM4, VCABM5, VCABM +include("../lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl") +using ..OrdinaryDiffEqNordsieck +export AN5, JVODE, JVODE_Adams, JVODE_BDF + include("dense/generic_dense.jl") include("solve.jl") @@ -455,8 +457,6 @@ export SHLDDRK52, SHLDDRK_2N export CNAB2, CNLF2 -export AN5, JVODE, JVODE_Adams, JVODE_BDF - export AutoSwitch, AutoTsit5, AutoDP5, AutoVern6, AutoVern7, AutoVern8, AutoVern9 diff --git a/src/alg_utils.jl b/src/alg_utils.jl index 12e2284dfc..0873b93388 100644 --- a/src/alg_utils.jl +++ b/src/alg_utils.jl @@ -349,7 +349,6 @@ get_current_alg_order(alg::OrdinaryDiffEqAdamsVarOrderVarStepAlgorithm, cache) = function get_current_adaptive_order(alg::OrdinaryDiffEqAdamsVarOrderVarStepAlgorithm, cache) cache.order end -get_current_alg_order(alg::JVODE, cache) = get_current_adaptive_order(alg, cache) #alg_adaptive_order(alg::OrdinaryDiffEqAdaptiveAlgorithm) = error("Algorithm is adaptive with no order") function get_current_adaptive_order(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm}, @@ -437,9 +436,6 @@ alg_order(alg::Rodas5Pe) = 5 alg_order(alg::CNAB2) = 2 alg_order(alg::CNLF2) = 2 -alg_order(alg::AN5) = 5 -alg_order(alg::JVODE) = 1 #dummy value - alg_maximum_order(alg) = alg_order(alg) alg_maximum_order(alg::CompositeAlgorithm) = maximum(alg_order(x) for x in alg.algs) @@ -456,7 +452,6 @@ alg_adaptive_order(alg::Rosenbrock32) = 2 alg_adaptive_order(alg::Exprb32) = 2 alg_adaptive_order(alg::Exprb43) = 4 -alg_adaptive_order(alg::AN5) = 5 function default_controller(alg, cache, qoldinit, _beta1 = nothing, _beta2 = nothing) if ispredictive(alg) @@ -484,10 +479,6 @@ function _digest_beta1_beta2(alg, cache, ::Val{QT}, _beta1, _beta2) where {QT} end # other special cases in controllers.jl -function default_controller(alg::Union{JVODE}, args...) - DummyController() -end - function beta2_default(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm}) isadaptive(alg) ? 2 // (5alg_order(alg)) : 0 end @@ -508,9 +499,6 @@ qsteady_max_default(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm}) = 1 qsteady_max_default(alg::OrdinaryDiffEqAdaptiveImplicitAlgorithm) = 6 // 5 # But don't re-use Jacobian if not adaptive: too risky and cannot pull back qsteady_max_default(alg::OrdinaryDiffEqImplicitAlgorithm) = isadaptive(alg) ? 1 // 1 : 0 -qsteady_max_default(alg::AN5) = 3 // 2 -qsteady_max_default(alg::JVODE) = 3 // 2 - #TODO #DiffEqBase.nlsolve_default(::QNDF, ::Val{κ}) = 1//2 diff --git a/src/algorithms.jl b/src/algorithms.jl index 2e17664ee9..63ef170e50 100644 --- a/src/algorithms.jl +++ b/src/algorithms.jl @@ -124,27 +124,6 @@ function CNLF2(; chunk_size = Val{0}(), autodiff = Val{true}(), standardtag = Va extrapolant) end -# Adams/BDF methods in Nordsieck forms -""" -AN5: Adaptive step size Adams explicit Method -An adaptive 5th order fixed-leading coefficient Adams method in Nordsieck form. -""" -struct AN5 <: OrdinaryDiffEqAdaptiveAlgorithm end -struct JVODE{bType, aType} <: OrdinaryDiffEqAdamsVarOrderVarStepAlgorithm - algorithm::Symbol - bias1::bType - bias2::bType - bias3::bType - addon::aType -end - -function JVODE(algorithm = :Adams; bias1 = 6, bias2 = 6, bias3 = 10, - addon = 1 // 10^6) - JVODE(algorithm, bias1, bias2, bias3, addon) -end -JVODE_Adams(; kwargs...) = JVODE(:Adams; kwargs...) -JVODE_BDF(; kwargs...) = JVODE(:BDF; kwargs...) - ################################################################################ # Linear Methods From 0ddeccc64df34916cce1b930d869e76eff9f08f5 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Fri, 2 Aug 2024 18:25:33 +0530 Subject: [PATCH 051/133] Added Nordsieck solvers --- .../src/OrdinaryDiffEqNordsieck.jl | 2 +- .../src/controllers.jl | 23 +++++++++++++++++++ .../test}/nordsieck_tests.jl | 2 +- lib/OrdinaryDiffEqNordsieck/test/runtests.jl | 3 +++ src/integrators/controllers.jl | 23 ------------------- test/runtests.jl | 2 +- 6 files changed, 29 insertions(+), 26 deletions(-) rename {test/algconvergence => lib/OrdinaryDiffEqNordsieck/test}/nordsieck_tests.jl (99%) create mode 100644 lib/OrdinaryDiffEqNordsieck/test/runtests.jl diff --git a/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl b/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl index 0150b558c2..f907687348 100644 --- a/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl +++ b/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl @@ -3,7 +3,7 @@ module OrdinaryDiffEqNordsieck import OrdinaryDiffEq: alg_order, alg_adaptive_order, qsteady_max_default, get_current_alg_order, AbstractController, OrdinaryDiffEqAdaptiveAlgorithm, OrdinaryDiffEqAdamsVarOrderVarStepAlgorithm, alg_cache, OrdinaryDiffEqMutableCache, OrdinaryDiffEqConstantCache, initialize!, @unpack, - perform_step! + perform_step!, stepsize_controller!, step_accept_controller!, step_reject_controller! using MuladdMacro, FastBroadcast, RecursiveArrayTools include("algorithms.jl") diff --git a/lib/OrdinaryDiffEqNordsieck/src/controllers.jl b/lib/OrdinaryDiffEqNordsieck/src/controllers.jl index 9b338e436b..8d8d33d193 100644 --- a/lib/OrdinaryDiffEqNordsieck/src/controllers.jl +++ b/lib/OrdinaryDiffEqNordsieck/src/controllers.jl @@ -1,2 +1,25 @@ struct DummyController <: AbstractController +end + +# JVODE +function stepsize_controller!(integrator, alg::JVODE) + if iszero(integrator.EEst) + η = integrator.opts.qmax + else + η = integrator.cache.η + integrator.qold = η + end + η +end + +function step_accept_controller!(integrator, alg::JVODE, η) + q = inv(η) + if q <= integrator.opts.qsteady_max && q >= integrator.opts.qsteady_min + q = one(q) + end + return integrator.dt / q # dtnew +end + +function step_reject_controller!(integrator, alg::JVODE) + integrator.dt *= integrator.qold end \ No newline at end of file diff --git a/test/algconvergence/nordsieck_tests.jl b/lib/OrdinaryDiffEqNordsieck/test/nordsieck_tests.jl similarity index 99% rename from test/algconvergence/nordsieck_tests.jl rename to lib/OrdinaryDiffEqNordsieck/test/nordsieck_tests.jl index 633b47a118..dc93a3e8eb 100644 --- a/test/algconvergence/nordsieck_tests.jl +++ b/lib/OrdinaryDiffEqNordsieck/test/nordsieck_tests.jl @@ -38,4 +38,4 @@ end exact = prob.f.analytic(prob.u0, prob.p, prob.tspan[end]) @test norm(exact - sol[end], Inf) < 3e-3 end -end +end \ No newline at end of file diff --git a/lib/OrdinaryDiffEqNordsieck/test/runtests.jl b/lib/OrdinaryDiffEqNordsieck/test/runtests.jl new file mode 100644 index 0000000000..4cdf24a531 --- /dev/null +++ b/lib/OrdinaryDiffEqNordsieck/test/runtests.jl @@ -0,0 +1,3 @@ +using SafeTestsets + +@time @safetestset "Extrapolation Tests" include("nordsieck_tests.jl") \ No newline at end of file diff --git a/src/integrators/controllers.jl b/src/integrators/controllers.jl index b6998de14a..19a53eba77 100644 --- a/src/integrators/controllers.jl +++ b/src/integrators/controllers.jl @@ -396,29 +396,6 @@ end struct PredictiveController <: AbstractController end -# JVODE -function stepsize_controller!(integrator, alg::JVODE) - if iszero(integrator.EEst) - η = integrator.opts.qmax - else - η = integrator.cache.η - integrator.qold = η - end - η -end - -function step_accept_controller!(integrator, alg::JVODE, η) - q = inv(η) - if q <= integrator.opts.qsteady_max && q >= integrator.opts.qsteady_min - q = one(q) - end - return integrator.dt / q # dtnew -end - -function step_reject_controller!(integrator, alg::JVODE) - integrator.dt *= integrator.qold -end - function post_newton_controller!(integrator, alg) integrator.dt = integrator.dt / integrator.opts.failfactor nothing diff --git a/test/runtests.jl b/test/runtests.jl index 4a8d65cd80..320a3ab061 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -208,7 +208,7 @@ end @time @safetestset "DAE Convergence Tests" include("../lib/OrdinaryDiffEqBDF/test/dae_convergence_tests.jl") @time @safetestset "Non-autonomous Convergence Tests" include("algconvergence/non-autonomous_convergence_tests.jl") @time @safetestset "Adams Variable Coefficients Tests" include("../lib/OrdinaryDiffEqAdamsBashforthMoulton/test/adams_tests.jl") - @time @safetestset "Nordsieck Tests" include("algconvergence/nordsieck_tests.jl") + @time @safetestset "Nordsieck Tests" include("../lib/OrdinaryDiffEqNordsieck/test/nordsieck_tests.jl") end if !is_APPVEYOR && GROUP == "AlgConvergence_II" From 0117bf1391701bb90991f788c2da5b25b86e0c0d Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Fri, 2 Aug 2024 09:55:58 -0400 Subject: [PATCH 052/133] Setup traits to remove FunctionMap from internals --- .../src/OrdinaryDiffEqFunctionMap.jl | 5 +++-- lib/OrdinaryDiffEqFunctionMap/src/alg_utils.jl | 5 ++++- .../src/functionmap_caches.jl | 4 +++- lib/OrdinaryDiffEqFunctionMap/src/interpolants.jl | 2 +- src/OrdinaryDiffEq.jl | 3 ++- src/alg_utils.jl | 5 +++++ src/dense/generic_dense.jl | 8 ++++---- src/integrators/integrator_utils.jl | 6 +++--- src/solve.jl | 13 ++++++------- 9 files changed, 31 insertions(+), 20 deletions(-) diff --git a/lib/OrdinaryDiffEqFunctionMap/src/OrdinaryDiffEqFunctionMap.jl b/lib/OrdinaryDiffEqFunctionMap/src/OrdinaryDiffEqFunctionMap.jl index 5396c1f389..bb92d65fa9 100644 --- a/lib/OrdinaryDiffEqFunctionMap/src/OrdinaryDiffEqFunctionMap.jl +++ b/lib/OrdinaryDiffEqFunctionMap/src/OrdinaryDiffEqFunctionMap.jl @@ -3,7 +3,8 @@ module OrdinaryDiffEqFunctionMap import OrdinaryDiffEq: isfsal, beta2_default, beta1_default, OrdinaryDiffEqAlgorithm, initialize!, perform_step!, @unpack, unwrap_alg, OrdinaryDiffEqMutableCache, alg_cache, @cache, _ode_addsteps!, _ode_interpolant!, _ode_interpolant, - alg_order, OrdinaryDiffEqConstantCache + alg_order, OrdinaryDiffEqConstantCache, dt_required, + isdiscretecache, isdiscretealg using DiffEqBase import RecursiveArrayTools: recursivecopy! import FastBroadcast: @.. @@ -20,4 +21,4 @@ include("fixed_timestep_perform_step.jl") export FunctionMap -end \ No newline at end of file +end diff --git a/lib/OrdinaryDiffEqFunctionMap/src/alg_utils.jl b/lib/OrdinaryDiffEqFunctionMap/src/alg_utils.jl index caf8d67292..353b284fd1 100644 --- a/lib/OrdinaryDiffEqFunctionMap/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqFunctionMap/src/alg_utils.jl @@ -20,4 +20,7 @@ beta1_default(alg::FunctionMap, beta2) = 0 function FunctionMap_scale_by_time(alg::FunctionMap{scale_by_time}) where {scale_by_time} scale_by_time -end \ No newline at end of file +end + +dt_required(alg::FunctionMap) = false +isdiscretealg(alg::FunctionMap) = true diff --git a/lib/OrdinaryDiffEqFunctionMap/src/functionmap_caches.jl b/lib/OrdinaryDiffEqFunctionMap/src/functionmap_caches.jl index cac0e0cab4..67dab2ae37 100644 --- a/lib/OrdinaryDiffEqFunctionMap/src/functionmap_caches.jl +++ b/lib/OrdinaryDiffEqFunctionMap/src/functionmap_caches.jl @@ -20,4 +20,6 @@ function alg_cache(alg::FunctionMap, u, rate_prototype, ::Type{uEltypeNoUnits}, dt, reltol, p, calck, ::Val{false}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits} FunctionMapConstantCache() -end \ No newline at end of file +end + +isdiscretecache(cache::Union{FunctionMapCache, FunctionMapConstantCache}) = true diff --git a/lib/OrdinaryDiffEqFunctionMap/src/interpolants.jl b/lib/OrdinaryDiffEqFunctionMap/src/interpolants.jl index 4f537264bb..233b567fed 100644 --- a/lib/OrdinaryDiffEqFunctionMap/src/interpolants.jl +++ b/lib/OrdinaryDiffEqFunctionMap/src/interpolants.jl @@ -20,4 +20,4 @@ end cache::Union{FunctionMapConstantCache, FunctionMapCache}, idxs, T::Type{Val{0}}, differential_vars::Nothing) @views out[idxs] .= y₀[idxs] -end \ No newline at end of file +end diff --git a/src/OrdinaryDiffEq.jl b/src/OrdinaryDiffEq.jl index 24c98f8990..1b597759b3 100644 --- a/src/OrdinaryDiffEq.jl +++ b/src/OrdinaryDiffEq.jl @@ -131,6 +131,7 @@ import FunctionWrappersWrappers import Preferences DEFAULT_PRECS(W, du, u, p, t, newW, Plprev, Prprev, solverdata) = nothing, nothing +isdiscretecache(cache) = false include("doc_utils.jl") include("misc_utils.jl") @@ -298,7 +299,7 @@ export FunctionMap include("../lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl") using ..OrdinaryDiffEqAdamsBashforthMoulton -export AB3, AB4, AB5, ABM32, ABM43, ABM54, VCAB3, +export AB3, AB4, AB5, ABM32, ABM43, ABM54, VCAB3, VCAB4, VCAB5, VCABM3, VCABM4, VCABM5, VCABM include("../lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl") diff --git a/src/alg_utils.jl b/src/alg_utils.jl index 0873b93388..bf2227195a 100644 --- a/src/alg_utils.jl +++ b/src/alg_utils.jl @@ -41,6 +41,11 @@ isfirk(alg) = false get_current_isfsal(alg, cache) = isfsal(alg) +dt_required(alg) = true +dt_required(alg::LinearExponential) = false + +isdiscretealg(alg) = false + # evaluates f(t[i]) _eval_index(f::F, t::Tuple{A}, _) where {F, A} = f(t[1]) function _eval_index(f::F, t::Tuple{A, Vararg}, i) where {F, A} diff --git a/src/dense/generic_dense.jl b/src/dense/generic_dense.jl index 79acf35844..f8dfa068e2 100644 --- a/src/dense/generic_dense.jl +++ b/src/dense/generic_dense.jl @@ -520,7 +520,7 @@ end function evaluate_interpolant(f, Θ, dt, timeseries, i₋, i₊, cache, idxs, deriv, ks, ts, id, p, differential_vars) - if cache isa (FunctionMapCache) || cache isa FunctionMapConstantCache + if isdiscretecache(cache) return ode_interpolant(Θ, dt, timeseries[i₋], timeseries[i₊], 0, cache, idxs, deriv, differential_vars) elseif !id.dense @@ -619,7 +619,7 @@ function ode_interpolation!(vals, tvals, id::I, idxs, deriv::D, p, dt = ts[i₊] - ts[i₋] Θ = iszero(dt) ? oneunit(t) / oneunit(dt) : (t - ts[i₋]) / dt - if cache isa (FunctionMapCache) || cache isa FunctionMapConstantCache + if isdiscretecache(cache) if eltype(vals) <: AbstractArray ode_interpolant!(vals[j], Θ, dt, timeseries[i₋], timeseries[i₊], 0, cache, idxs, deriv, differential_vars) @@ -768,7 +768,7 @@ function ode_interpolation(tval::Number, id::I, idxs, deriv::D, p, dt = ts[i₊] - ts[i₋] Θ = iszero(dt) ? oneunit(tval) / oneunit(dt) : (tval - ts[i₋]) / dt - if cache isa (FunctionMapCache) || cache isa FunctionMapConstantCache + if isdiscretecache(cache) val = ode_interpolant(Θ, dt, timeseries[i₋], timeseries[i₊], 0, cache, idxs, deriv, differential_vars) elseif !id.dense @@ -850,7 +850,7 @@ function ode_interpolation!(out, tval::Number, id::I, idxs, deriv::D, p, dt = ts[i₊] - ts[i₋] Θ = iszero(dt) ? oneunit(tval) / oneunit(dt) : (tval - ts[i₋]) / dt - if cache isa (FunctionMapCache) || cache isa FunctionMapConstantCache + if isdiscretecache(cache) ode_interpolant!(out, Θ, dt, timeseries[i₋], timeseries[i₊], 0, cache, idxs, deriv, differential_vars) elseif !id.dense diff --git a/src/integrators/integrator_utils.jl b/src/integrators/integrator_utils.jl index a3f45f456a..a7bf28801d 100644 --- a/src/integrators/integrator_utils.jl +++ b/src/integrators/integrator_utils.jl @@ -91,7 +91,7 @@ function _savevalues!(integrator, force_save, reduce_size)::Tuple{Bool, Bool} copyat_or_push!(integrator.sol.u, integrator.saveiter, integrator.u[integrator.opts.save_idxs], false) end - if integrator.alg isa FunctionMap || integrator.opts.dense + if isdiscretealg(integrator.alg) || integrator.opts.dense integrator.saveiter_dense += 1 if integrator.opts.dense if integrator.opts.save_idxs === nothing @@ -124,7 +124,7 @@ function _savevalues!(integrator, force_save, reduce_size)::Tuple{Bool, Bool} integrator.u[integrator.opts.save_idxs], false) end copyat_or_push!(integrator.sol.t, integrator.saveiter, integrator.t) - if integrator.alg isa FunctionMap || integrator.opts.dense + if isdiscretealg(integrator.alg) || integrator.opts.dense integrator.saveiter_dense += 1 if integrator.opts.dense if integrator.opts.save_idxs === nothing @@ -183,7 +183,7 @@ function solution_endpoint_match_cur_integrator!(integrator) copyat_or_push!(integrator.sol.u, integrator.saveiter, integrator.u[integrator.opts.save_idxs], false) end - if integrator.alg isa FunctionMap || integrator.opts.dense + if isdiscretealg(integrator.alg) || integrator.opts.dense integrator.saveiter_dense += 1 if integrator.opts.dense if integrator.opts.save_idxs === nothing diff --git a/src/solve.jl b/src/solve.jl index 65ddb3fdd1..7ca0e02082 100644 --- a/src/solve.jl +++ b/src/solve.jl @@ -27,11 +27,11 @@ function DiffEqBase.__init( save_end = nothing, callback = nothing, dense = save_everystep && - !(alg isa Union{DAEAlgorithm, FunctionMap}) && + !(alg isa DAEAlgorithm) && !(prob isa DiscreteProblem) && isempty(saveat), calck = (callback !== nothing && callback !== CallbackSet()) || (dense) || !isempty(saveat), # and no dense output - dt = alg isa FunctionMap && isempty(tstops) ? + dt = !dt_required(alg) && isempty(tstops) ? eltype(prob.tspan)(1) : eltype(prob.tspan)(0), dtmin = eltype(prob.tspan)(0), dtmax = eltype(prob.tspan)((prob.tspan[end] - prob.tspan[1])), @@ -130,8 +130,7 @@ function DiffEqBase.__init( if (((!(alg isa OrdinaryDiffEqAdaptiveAlgorithm) && !(alg isa OrdinaryDiffEqCompositeAlgorithm) && !(alg isa DAEAlgorithm)) || !adaptive || !isadaptive(alg)) && - dt == tType(0) && isempty(tstops)) && - !(alg isa Union{FunctionMap, LinearExponential}) + dt == tType(0) && isempty(tstops)) && !dt_required(alg) error("Fixed timestep methods require a choice of dt or choosing the tstops") end @@ -186,7 +185,7 @@ function DiffEqBase.__init( uEltypeNoUnits = recursive_unitless_eltype(u) tTypeNoUnits = typeof(one(tType)) - if _alg isa FunctionMap + if prob isa DiscreteProblem abstol_internal = false elseif abstol === nothing if uBottomEltypeNoUnits == uBottomEltype @@ -200,7 +199,7 @@ function DiffEqBase.__init( abstol_internal = real.(abstol) end - if _alg isa FunctionMap + if prob isa DiscreteProblem reltol_internal = false elseif reltol === nothing if uBottomEltypeNoUnits == uBottomEltype @@ -461,7 +460,7 @@ function DiffEqBase.__init( do_error_check = true event_last_time = 0 vector_event_last_time = 1 - last_event_error = _alg isa FunctionMap ? false : zero(uBottomEltypeNoUnits) + last_event_error = prob isa DiscreteProblem ? false : zero(uBottomEltypeNoUnits) dtchangeable = isdtchangeable(_alg) q11 = QT(1) success_iter = 0 From 905291dfacd7e1b07b05fc80368c64050de57412 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Fri, 2 Aug 2024 10:15:29 -0400 Subject: [PATCH 053/133] Update lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl --- lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl index 1703aa9c64..bd16c59db4 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl @@ -6,7 +6,7 @@ import OrdinaryDiffEq: alg_order, isfsal, beta2_default, beta1_default, alg_stab unwrap_alg, @unpack, initialize!, perform_step!, calculate_residuals, calculate_residuals!, _ode_addsteps!, @OnDemandTableauExtract, constvalue, OrdinaryDiffEqMutableCache, uses_uprev, OrdinaryDiffEqConstantCache, @fold, - @cache, CompiledFloats + @cache, CompiledFloats, alg_cache using DiffEqBase, SciMLBase import MuladdMacro: @muladd import FastBroadcast: @.. From 50ac81c25db3cf32473a25e36b51c0e870ba7914 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Fri, 2 Aug 2024 19:49:20 +0530 Subject: [PATCH 054/133] Added Rosenbrock solvers --- .../OrdinaryDiffEqAdamsBashforthMoulton.jl | 3 + .../src/OrdinaryDiffEqNordsieck.jl | 5 +- .../src}/nordsieck_utils.jl | 2 +- lib/OrdinaryDiffEqRosenbrock/Project.toml | 25 + .../src/OrdinaryDiffEqRosenbrock.jl | 29 + lib/OrdinaryDiffEqRosenbrock/src/alg_utils.jl | 53 ++ .../src/algorithms.jl | 206 +++++ .../src}/generic_rosenbrock.jl | 2 +- .../src/interp_func.jl | 18 + .../src}/rosenbrock_caches.jl | 2 +- .../src}/rosenbrock_interpolants.jl | 2 +- .../src}/rosenbrock_perform_step.jl | 2 +- .../src}/rosenbrock_tableaus.jl | 2 +- .../src}/stiff_addsteps.jl | 2 +- .../test/ode_rosenbrock_tests.jl | 706 ++++++++++++++++++ lib/OrdinaryDiffEqRosenbrock/test/runtests.jl | 0 src/OrdinaryDiffEq.jl | 26 +- src/alg_utils.jl | 52 -- src/algorithms.jl | 207 ----- src/interp_func.jl | 18 - test/algconvergence/ode_rosenbrock_tests.jl | 706 ------------------ 21 files changed, 1060 insertions(+), 1008 deletions(-) rename {src => lib/OrdinaryDiffEqNordsieck/src}/nordsieck_utils.jl (99%) create mode 100644 lib/OrdinaryDiffEqRosenbrock/Project.toml create mode 100644 lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl create mode 100644 lib/OrdinaryDiffEqRosenbrock/src/alg_utils.jl create mode 100644 lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl rename {src => lib/OrdinaryDiffEqRosenbrock/src}/generic_rosenbrock.jl (99%) create mode 100644 lib/OrdinaryDiffEqRosenbrock/src/interp_func.jl rename {src/caches => lib/OrdinaryDiffEqRosenbrock/src}/rosenbrock_caches.jl (99%) rename {src/dense => lib/OrdinaryDiffEqRosenbrock/src}/rosenbrock_interpolants.jl (99%) rename {src/perform_step => lib/OrdinaryDiffEqRosenbrock/src}/rosenbrock_perform_step.jl (99%) rename {src/tableaus => lib/OrdinaryDiffEqRosenbrock/src}/rosenbrock_tableaus.jl (99%) rename {src/dense => lib/OrdinaryDiffEqRosenbrock/src}/stiff_addsteps.jl (99%) create mode 100644 lib/OrdinaryDiffEqRosenbrock/test/ode_rosenbrock_tests.jl create mode 100644 lib/OrdinaryDiffEqRosenbrock/test/runtests.jl diff --git a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl index de613bb5d7..8e27483a6f 100644 --- a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl @@ -11,4 +11,7 @@ include("adams_bashforth_moulton_caches.jl") include("adams_utils.jl") include("adams_bashforth_moulton_perform_step.jl") +export AB3, AB4, AB5, ABM32, ABM43, ABM54, VCAB3, + VCAB4, VCAB5, VCABM3, VCABM4, VCABM5, VCABM + end diff --git a/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl b/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl index f907687348..42f3568d39 100644 --- a/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl +++ b/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl @@ -3,7 +3,8 @@ module OrdinaryDiffEqNordsieck import OrdinaryDiffEq: alg_order, alg_adaptive_order, qsteady_max_default, get_current_alg_order, AbstractController, OrdinaryDiffEqAdaptiveAlgorithm, OrdinaryDiffEqAdamsVarOrderVarStepAlgorithm, alg_cache, OrdinaryDiffEqMutableCache, OrdinaryDiffEqConstantCache, initialize!, @unpack, - perform_step!, stepsize_controller!, step_accept_controller!, step_reject_controller! + perform_step!, stepsize_controller!, step_accept_controller!, step_reject_controller!, + calculate_residuals, calculate_residuals! using MuladdMacro, FastBroadcast, RecursiveArrayTools include("algorithms.jl") @@ -12,4 +13,6 @@ include("alg_utils.jl") include("nordsieck_caches.jl") include("nordsieck_perform_step.jl") +export AN5, JVODE, JVODE_Adams, JVODE_BDF + end \ No newline at end of file diff --git a/src/nordsieck_utils.jl b/lib/OrdinaryDiffEqNordsieck/src/nordsieck_utils.jl similarity index 99% rename from src/nordsieck_utils.jl rename to lib/OrdinaryDiffEqNordsieck/src/nordsieck_utils.jl index 4d5df48685..e8766edaea 100644 --- a/src/nordsieck_utils.jl +++ b/lib/OrdinaryDiffEqNordsieck/src/nordsieck_utils.jl @@ -443,4 +443,4 @@ function stepsize_η₋₁!(integrator, cache::T, order) where {T} cache.η₋₁ = inv((bias1 * approx)^inv(order) + addon) end return cache.η₋₁ -end +end \ No newline at end of file diff --git a/lib/OrdinaryDiffEqRosenbrock/Project.toml b/lib/OrdinaryDiffEqRosenbrock/Project.toml new file mode 100644 index 0000000000..697a579868 --- /dev/null +++ b/lib/OrdinaryDiffEqRosenbrock/Project.toml @@ -0,0 +1,25 @@ +name = "OrdinaryDiffEqRosenbrock" +uuid = "43230ef6-c299-4910-a778-202eb28ce4ce" +authors = ["ParamThakkar123 "] +version = "1.0.0" + +[deps] +FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898" +MuladdMacro = "46d2c3a1-f734-5fdb-9937-b9b9aeba4221" +OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" +Polyester = "f517fe37-dbe3-4b94-8317-1923a5111588" +RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd" +Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3" +DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" + +[compat] +julia = "1.10" + +[extras] +DiffEqDevTools = "f3b72e0c-5b89-59e1-b016-84e28bfd966d" +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" +SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[targets] +test = ["DiffEqDevTools", "Random", "SafeTestsets", "Test"] \ No newline at end of file diff --git a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl new file mode 100644 index 0000000000..f07ab9e2d9 --- /dev/null +++ b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl @@ -0,0 +1,29 @@ +module OrdinaryDiffEqRosenbrock + +import OrdinaryDiffEq: alg_order, alg_adaptive_order, isWmethod, isfsal, _unwrap_val, rosenbrock_wanner_docstring, + DEFAULT_PRECS, OrdinaryDiffEqRosenbrockAlgorithm, @cache, alg_cache, initialize!, @unpack, + calc_W, calculate_residuals!, calc_rosenbrock_differentiation!, OrdinaryDiffEqMutableCache, + build_J_W, UJacobianWrapper, OrdinaryDiffEqConstantCache, _ode_interpolant, _ode_interpolant!, + _vec, _reshape, perform_step! +using TruncatedStacktraces, MuladdMacro, FastBroadcast, DiffEqBase, RecursiveArrayTools, step_limiter!, dolinsolve +import DiffEqBase: @def +import LinearAlgebra: mul! + +include("algorithms.jl") +include("alg_utils.jl") +include("rosenbrock_caches.jl") +include("rosenbrock_tableaus.jl") +include("generic_rosenbrock.jl") +include("interp_func.jl") +include("rosenbrock_interpolants.jl") +include("stiff_addsteps.jl") +include("rosenbrock_perform_step.jl") + +export Rosenbrock23, Rosenbrock32, RosShamp4, Veldd4, Velds4, GRK4T, GRK4A, + Ros4LStab, ROS3P, Rodas3, Rodas23W, Rodas3P, Rodas4, Rodas42, Rodas4P, Rodas4P2, + Rodas5, Rodas5P, Rodas5Pe, Rodas5Pr, + RosenbrockW6S4OS, ROS34PW1a, ROS34PW1b, ROS34PW2, ROS34PW3, ROS34PRw, ROS3PRL, + ROS3PRL2, ROK4a, + ROS2, ROS2PR, ROS2S, ROS3, ROS3PR, Scholz4_7 + +end diff --git a/lib/OrdinaryDiffEqRosenbrock/src/alg_utils.jl b/lib/OrdinaryDiffEqRosenbrock/src/alg_utils.jl new file mode 100644 index 0000000000..115f6ab893 --- /dev/null +++ b/lib/OrdinaryDiffEqRosenbrock/src/alg_utils.jl @@ -0,0 +1,53 @@ +alg_order(alg::Rosenbrock23) = 2 +alg_order(alg::Rosenbrock32) = 3 +alg_order(alg::Rodas3P) = 3 +alg_order(alg::ROS3PR) = 3 +alg_order(alg::ROS3PRL) = 3 +alg_order(alg::ROS3PRL2) = 3 +alg_order(alg::ROS3P) = 3 +alg_order(alg::Rodas3) = 3 +alg_order(alg::Rodas23W) = 3 +alg_order(alg::ROS2) = 2 +alg_order(alg::ROS2PR) = 2 +alg_order(alg::ROS2S) = 2 +alg_order(alg::ROS3) = 3 +alg_order(alg::Scholz4_7) = 3 +alg_order(alg::ROS34PW1a) = 3 +alg_order(alg::ROS34PW1b) = 3 +alg_order(alg::ROS34PW2) = 3 +alg_order(alg::ROS34PW3) = 4 +alg_order(alg::ROS34PRw) = 3 +alg_order(alg::ROK4a) = 4 +alg_order(alg::RosShamp4) = 4 +alg_order(alg::Veldd4) = 4 +alg_order(alg::Velds4) = 4 +alg_order(alg::GRK4T) = 4 +alg_order(alg::GRK4A) = 4 +alg_order(alg::Ros4LStab) = 4 +alg_order(alg::RosenbrockW6S4OS) = 4 +alg_order(alg::Rodas4) = 4 +alg_order(alg::Rodas42) = 4 +alg_order(alg::Rodas4P) = 4 +alg_order(alg::Rodas4P2) = 4 +alg_order(alg::Rodas5) = 5 +alg_order(alg::Rodas5P) = 5 +alg_order(alg::Rodas5Pr) = 5 +alg_order(alg::Rodas5Pe) = 5 + +alg_adaptive_order(alg::Rosenbrock32) = 2 +alg_adaptive_order(alg::Rosenbrock23) = 3 + +isWmethod(alg::Rodas23W) = true +isWmethod(alg::Rosenbrock23) = true +isWmethod(alg::Rosenbrock32) = true + +isfsal(alg::Rodas3P) = false +isfsal(alg::Rodas23W) = false +isfsal(alg::Rodas5) = false +isfsal(alg::Rodas5P) = false +isfsal(alg::Rodas5Pr) = false +isfsal(alg::Rodas5Pe) = false +isfsal(alg::Rodas4) = false +isfsal(alg::Rodas42) = false +isfsal(alg::Rodas4P) = false +isfsal(alg::Rodas4P2) = false \ No newline at end of file diff --git a/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl b/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl new file mode 100644 index 0000000000..a618bf8435 --- /dev/null +++ b/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl @@ -0,0 +1,206 @@ +# Rosenbrock Methods + +#= +#### Rosenbrock23, Rosenbrock32, ode23s, ModifiedRosenbrockIntegrator + +- Shampine L.F. and Reichelt M., (1997) The MATLAB ODE Suite, SIAM Journal of +Scientific Computing, 18 (1), pp. 1-22. + +#### ROS2 + +- J. G. Verwer et al. (1999): A second-order Rosenbrock method applied to photochemical dispersion problems + https://doi.org/10.1137/S1064827597326651 + +#### ROS3P + +- Lang, J. & Verwer, ROS3P—An Accurate Third-Order Rosenbrock Solver Designed for + Parabolic Problems J. BIT Numerical Mathematics (2001) 41: 731. doi:10.1023/A:1021900219772 + +#### ROS3, Rodas3, Ros4LStab, Rodas4, Rodas42 + +- E. Hairer, G. Wanner, Solving ordinary differential equations II, stiff and + differential-algebraic problems. Computational mathematics (2nd revised ed.), Springer (1996) + +#### ROS2PR, ROS2S, ROS3PR, Scholz4_7 +-Rang, Joachim (2014): The Prothero and Robinson example: + Convergence studies for Runge-Kutta and Rosenbrock-Wanner methods. + https://doi.org/10.24355/dbbs.084-201408121139-0 + +#### RosShamp4 + +- L. F. Shampine, Implementation of Rosenbrock Methods, ACM Transactions on + Mathematical Software (TOMS), 8: 2, 93-113. doi:10.1145/355993.355994 + +#### Veldd4, Velds4 + +- van Veldhuizen, D-stability and Kaps-Rentrop-methods, M. Computing (1984) 32: 229. + doi:10.1007/BF02243574 + +#### GRK4T, GRK4A + +- Kaps, P. & Rentrop, Generalized Runge-Kutta methods of order four with stepsize control + for stiff ordinary differential equations. P. Numer. Math. (1979) 33: 55. doi:10.1007/BF01396495 + +#### Rodas23W, Rodas3P + +- Steinebach G., Rodas23W / Rodas32P - a Rosenbrock-type method for DAEs with additional error estimate for dense output and Julia implementation, + in progress + +#### Rodas4P + +- Steinebach G. Order-reduction of ROW-methods for DAEs and method of lines + applications. Preprint-Nr. 1741, FB Mathematik, TH Darmstadt; 1995. + +#### Rodas4P2 +- Steinebach G. (2020) Improvement of Rosenbrock-Wanner Method RODASP. + In: Reis T., Grundel S., Schoeps S. (eds) Progress in Differential-Algebraic Equations II. + Differential-Algebraic Equations Forum. Springer, Cham. https://doi.org/10.1007/978-3-030-53905-4_6 + +#### Rodas5 +- Di Marzo G. RODAS5(4) – Méthodes de Rosenbrock d’ordre 5(4) adaptées aux problemes +différentiels-algébriques. MSc mathematics thesis, Faculty of Science, +University of Geneva, Switzerland. + +#### ROS34PRw +-Joachim Rang, Improved traditional Rosenbrock–Wanner methods for stiff ODEs and DAEs, + Journal of Computational and Applied Mathematics, + https://doi.org/10.1016/j.cam.2015.03.010 + +#### ROS3PRL, ROS3PRL2 +-Rang, Joachim (2014): The Prothero and Robinson example: + Convergence studies for Runge-Kutta and Rosenbrock-Wanner methods. + https://doi.org/10.24355/dbbs.084-201408121139-0 + +#### ROK4a +- Tranquilli, Paul and Sandu, Adrian (2014): + Rosenbrock--Krylov Methods for Large Systems of Differential Equations + https://doi.org/10.1137/130923336 + +#### Rodas5P +- Steinebach G. Construction of Rosenbrock–Wanner method Rodas5P and numerical benchmarks within the Julia Differential Equations package. + In: BIT Numerical Mathematics, 63(2), 2023 + + #### Rodas23W, Rodas3P, Rodas5Pe, Rodas5Pr +- Steinebach G. Rosenbrock methods within OrdinaryDiffEq.jl - Overview, recent developments and applications - + Preprint 2024 + https://github.com/hbrs-cse/RosenbrockMethods/blob/main/paper/JuliaPaper.pdf + +=# + +# for Rosenbrock methods with step_limiter +for Alg in [ + :Rosenbrock23, + :Rosenbrock32, + :ROS3P, + :Rodas3, + :Rodas23W, + :Rodas3P, + :Rodas4, + :Rodas42, + :Rodas4P, + :Rodas4P2, + :Rodas5, + :Rodas5P, + :Rodas5Pe, + :Rodas5Pr] + @eval begin + struct $Alg{CS, AD, F, P, FDT, ST, CJ, StepLimiter, StageLimiter} <: + OrdinaryDiffEqRosenbrockAdaptiveAlgorithm{CS, AD, FDT, ST, CJ} + linsolve::F + precs::P + step_limiter!::StepLimiter + stage_limiter!::StageLimiter + end + function $Alg(; chunk_size = Val{0}(), autodiff = Val{true}(), + standardtag = Val{true}(), concrete_jac = nothing, + diff_type = Val{:forward}, linsolve = nothing, + precs = DEFAULT_PRECS, step_limiter! = trivial_limiter!, + stage_limiter! = trivial_limiter!) + $Alg{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + typeof(precs), diff_type, _unwrap_val(standardtag), + _unwrap_val(concrete_jac), typeof(step_limiter!), + typeof(stage_limiter!)}(linsolve, precs, step_limiter!, + stage_limiter!) + end + end + + @eval TruncatedStacktraces.@truncate_stacktrace $Alg 1 2 +end +struct GeneralRosenbrock{CS, AD, F, ST, CJ, TabType} <: + OrdinaryDiffEqRosenbrockAdaptiveAlgorithm{CS, AD, Val{:forward}, ST, CJ} + tableau::TabType + factorization::F +end + +function GeneralRosenbrock(; chunk_size = Val{0}(), autodiff = true, + standardtag = Val{true}(), concrete_jac = nothing, + factorization = lu!, tableau = ROSENBROCK_DEFAULT_TABLEAU) + GeneralRosenbrock{ + _unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(factorization), + _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(tableau)}(tableau, + factorization) +end + +@doc rosenbrock_wanner_docstring( + """ + A 4th order L-stable Rosenbrock-W method (fixed step only). + """, + "RosenbrockW6S4OS", + references = """ + https://doi.org/10.1016/j.cam.2009.09.017 + """) +struct RosenbrockW6S4OS{CS, AD, F, P, FDT, ST, CJ} <: + OrdinaryDiffEqRosenbrockAlgorithm{CS, AD, FDT, ST, CJ} + linsolve::F + precs::P +end +function RosenbrockW6S4OS(; chunk_size = Val{0}(), autodiff = true, + standardtag = Val{true}(), + concrete_jac = nothing, diff_type = Val{:central}, + linsolve = nothing, + precs = DEFAULT_PRECS) + RosenbrockW6S4OS{_unwrap_val(chunk_size), + _unwrap_val(autodiff), typeof(linsolve), typeof(precs), diff_type, + _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, + precs) +end + +for Alg in [ + :ROS2, + :ROS2PR, + :ROS2S, + :ROS3, + :ROS3PR, + :Scholz4_7, + :ROS34PW1a, + :ROS34PW1b, + :ROS34PW2, + :ROS34PW3, + :ROS34PRw, + :ROS3PRL, + :ROS3PRL2, + :ROK4a, + :RosShamp4, + :Veldd4, + :Velds4, + :GRK4T, + :GRK4A, + :Ros4LStab] + @eval begin + struct $Alg{CS, AD, F, P, FDT, ST, CJ} <: + OrdinaryDiffEqRosenbrockAdaptiveAlgorithm{CS, AD, FDT, ST, CJ} + linsolve::F + precs::P + end + function $Alg(; chunk_size = Val{0}(), autodiff = Val{true}(), + standardtag = Val{true}(), concrete_jac = nothing, + diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS) + $Alg{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + typeof(precs), diff_type, _unwrap_val(standardtag), + _unwrap_val(concrete_jac)}(linsolve, + precs) + end + end + + @eval TruncatedStacktraces.@truncate_stacktrace $Alg 1 2 +end \ No newline at end of file diff --git a/src/generic_rosenbrock.jl b/lib/OrdinaryDiffEqRosenbrock/src/generic_rosenbrock.jl similarity index 99% rename from src/generic_rosenbrock.jl rename to lib/OrdinaryDiffEqRosenbrock/src/generic_rosenbrock.jl index 32330c27e1..9cf7420395 100644 --- a/src/generic_rosenbrock.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/generic_rosenbrock.jl @@ -1807,4 +1807,4 @@ You need to change respective places in this file. `gen_initialize()` and special step expressions in macro definitions 2. `caches/rosenbrock_caches.jl` -> `gen_algcache()`, `gen_cache_struct()` 3. `tableaus/rosenbrock_tableaus.jl` -> `gen_tableau_struct()` and `gen_tableau()` -=========================================================================================# +=========================================================================================# \ No newline at end of file diff --git a/lib/OrdinaryDiffEqRosenbrock/src/interp_func.jl b/lib/OrdinaryDiffEqRosenbrock/src/interp_func.jl new file mode 100644 index 0000000000..5037e41991 --- /dev/null +++ b/lib/OrdinaryDiffEqRosenbrock/src/interp_func.jl @@ -0,0 +1,18 @@ +function DiffEqBase.interp_summary(::Type{cacheType}, + dense::Bool) where { + cacheType <: + Union{Rosenbrock23ConstantCache, + Rosenbrock32ConstantCache, + Rosenbrock23Cache, + Rosenbrock32Cache}} + dense ? "specialized 2nd order \"free\" stiffness-aware interpolation" : + "1st order linear" +end +function DiffEqBase.interp_summary(::Type{cacheType}, + dense::Bool) where { + cacheType <: + Union{Rodas4ConstantCache, Rodas23WConstantCache, Rodas3PConstantCache, + Rodas4Cache, Rodas23WCache, Rodas3PCache}} + dense ? "specialized 3rd order \"free\" stiffness-aware interpolation" : + "1st order linear" +end diff --git a/src/caches/rosenbrock_caches.jl b/lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_caches.jl similarity index 99% rename from src/caches/rosenbrock_caches.jl rename to lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_caches.jl index e2eb013809..6076fe7dbb 100644 --- a/src/caches/rosenbrock_caches.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_caches.jl @@ -1140,4 +1140,4 @@ end ### RosenbrockW6S4O -@RosenbrockW6S4OS(:cache) +@RosenbrockW6S4OS(:cache) \ No newline at end of file diff --git a/src/dense/rosenbrock_interpolants.jl b/lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_interpolants.jl similarity index 99% rename from src/dense/rosenbrock_interpolants.jl rename to lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_interpolants.jl index 6f50205cf1..e691619b70 100644 --- a/src/dense/rosenbrock_interpolants.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_interpolants.jl @@ -364,4 +364,4 @@ end @views @.. broadcast=false out=(-6 * k[2][idxs] + 6 * k[3][idxs] - 24 * Θ * k[3][idxs]) / dt^3 out -end +end \ No newline at end of file diff --git a/src/perform_step/rosenbrock_perform_step.jl b/lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_perform_step.jl similarity index 99% rename from src/perform_step/rosenbrock_perform_step.jl rename to lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_perform_step.jl index 2bfdb8b92d..9393c2c573 100644 --- a/src/perform_step/rosenbrock_perform_step.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_perform_step.jl @@ -1986,4 +1986,4 @@ end end @RosenbrockW6S4OS(:init) -@RosenbrockW6S4OS(:performstep) +@RosenbrockW6S4OS(:performstep) \ No newline at end of file diff --git a/src/tableaus/rosenbrock_tableaus.jl b/lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_tableaus.jl similarity index 99% rename from src/tableaus/rosenbrock_tableaus.jl rename to lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_tableaus.jl index 493c67111a..66dc620871 100644 --- a/src/tableaus/rosenbrock_tableaus.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_tableaus.jl @@ -830,4 +830,4 @@ beta3 = 6.8619167645278386e-2 beta4 = 0.8289547562599182 beta5 = 7.9630136489868164e-2 alpha64 = -0.2076823627400282 -=# +=# \ No newline at end of file diff --git a/src/dense/stiff_addsteps.jl b/lib/OrdinaryDiffEqRosenbrock/src/stiff_addsteps.jl similarity index 99% rename from src/dense/stiff_addsteps.jl rename to lib/OrdinaryDiffEqRosenbrock/src/stiff_addsteps.jl index 6e77125e14..5a76baf02e 100644 --- a/src/dense/stiff_addsteps.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/stiff_addsteps.jl @@ -834,4 +834,4 @@ function _ode_addsteps!(k, t, uprev, u, dt, f, p, cache::Rosenbrock5Cache, copyat_or_push!(k, 3, copy(tmp)) end nothing -end +end \ No newline at end of file diff --git a/lib/OrdinaryDiffEqRosenbrock/test/ode_rosenbrock_tests.jl b/lib/OrdinaryDiffEqRosenbrock/test/ode_rosenbrock_tests.jl new file mode 100644 index 0000000000..ce876ae507 --- /dev/null +++ b/lib/OrdinaryDiffEqRosenbrock/test/ode_rosenbrock_tests.jl @@ -0,0 +1,706 @@ +using OrdinaryDiffEq, DiffEqDevTools, Test, LinearAlgebra, LinearSolve +import ODEProblemLibrary: prob_ode_linear, + prob_ode_2Dlinear, + prob_ode_bigfloatlinear, prob_ode_bigfloat2Dlinear +import LinearSolve + +@testset "Rosenbrock Tests" begin + ## Breakout these since no other test of their adaptivity + + dts = (1 / 2) .^ (6:-1:3) + testTol = 0.2 + + ### Rosenbrock23() + + prob = prob_ode_linear + + sim = test_convergence(dts, prob, Rosenbrock23()) + @test sim.𝒪est[:final]≈2 atol=testTol + + sol = solve(prob, Rosenbrock23()) + @test length(sol) < 20 + + prob = prob_ode_2Dlinear + + sim = test_convergence(dts, prob, Rosenbrock23()) + @test sim.𝒪est[:final]≈2 atol=testTol + + sol = solve(prob, Rosenbrock23()) + @test length(sol) < 20 + + prob = prob_ode_bigfloat2Dlinear + + sim = test_convergence(dts, prob, Rosenbrock23(linsolve = QRFactorization())) + @test sim.𝒪est[:final]≈2 atol=testTol + + sol = solve(prob, Rosenbrock23(linsolve = QRFactorization())) + @test length(sol) < 20 + + ### Rosenbrock32() + + prob = prob_ode_linear + + sim = test_convergence(dts, prob, Rosenbrock32()) + @test sim.𝒪est[:final]≈3 atol=testTol + + sol = solve(prob, Rosenbrock32()) + @test length(sol) < 20 + + prob = prob_ode_2Dlinear + + sim = test_convergence(dts, prob, Rosenbrock32()) + @test sim.𝒪est[:final]≈3 atol=testTol + + sol = solve(prob, Rosenbrock32()) + @test length(sol) < 20 + + ### ROS3P() + + prob = prob_ode_linear + + sim = test_convergence(dts, prob, ROS3P()) + @test sim.𝒪est[:final]≈3 atol=testTol + + sol = solve(prob, ROS3P()) + @test length(sol) < 20 + + prob = prob_ode_2Dlinear + + sim = test_convergence(dts, prob, ROS3P()) + @test sim.𝒪est[:final]≈3 atol=testTol + + sol = solve(prob, ROS3P()) + @test length(sol) < 20 + + ### Rodas3() + + prob = prob_ode_linear + + sim = test_convergence(dts, prob, Rodas3()) + @test sim.𝒪est[:final]≈3 atol=testTol + + sol = solve(prob, Rodas3()) + @test length(sol) < 20 + + prob = prob_ode_2Dlinear + + sim = test_convergence(dts, prob, Rodas3()) + @test sim.𝒪est[:final]≈3 atol=testTol + + sol = solve(prob, Rodas3()) + @test length(sol) < 20 + + ### ROS2 + prob = prob_ode_linear + + sim = test_convergence(dts, prob, ROS2()) + @test sim.𝒪est[:final]≈2 atol=testTol + + sol = solve(prob, ROS2()) + @test length(sol) < 61 + + prob = prob_ode_2Dlinear + + sim = test_convergence(dts, prob, ROS2()) + @test sim.𝒪est[:final]≈2 atol=testTol + + sol = solve(prob, ROS2PR()) + @test length(sol) < 60 + + ### ROS2PR + prob = prob_ode_linear + + sim = test_convergence(dts, prob, ROS2PR()) + @test sim.𝒪est[:final]≈2 atol=testTol + + sol = solve(prob, ROS2PR()) + @test length(sol) < 30 + + prob = prob_ode_2Dlinear + + sim = test_convergence(dts, prob, ROS2PR()) + @test sim.𝒪est[:final]≈2 atol=testTol + + sol = solve(prob, ROS2PR()) + @test length(sol) < 30 + + ### ROS2S + prob = prob_ode_linear + + sim = test_convergence(dts, prob, ROS2S()) + @test sim.𝒪est[:final]≈2 atol=testTol + + sol = solve(prob, ROS2S()) + @test length(sol) < 20 + + prob = prob_ode_2Dlinear + + sim = test_convergence(dts, prob, ROS2S()) + @test sim.𝒪est[:final]≈2 atol=testTol + + sol = solve(prob, ROS2S()) + @test length(sol) < 20 + + ### ROS3 + prob = prob_ode_linear + + sim = test_convergence(dts, prob, ROS3()) + @test sim.𝒪est[:final]≈3 atol=testTol + + sol = solve(prob, ROS3()) + @test length(sol) < 20 + + prob = prob_ode_2Dlinear + + sim = test_convergence(dts, prob, ROS3()) + @test sim.𝒪est[:final]≈3 atol=testTol + + sol = solve(prob, ROS3()) + @test length(sol) < 20 + + ### ROS3PR + prob = prob_ode_linear + + sim = test_convergence(dts, prob, ROS3PR()) + @test sim.𝒪est[:final]≈3 atol=testTol + + sol = solve(prob, ROS3PR()) + @test length(sol) < 20 #length(sol) = 4 => Too Small?? + + prob = prob_ode_2Dlinear + + sim = test_convergence(dts, prob, ROS3PR()) + @test sim.𝒪est[:final]≈3 atol=testTol + + sol = solve(prob, ROS3PR()) + @test length(sol) < 20 #length(sol) = 4 => Too Small?? + + ### Scholz4_7 + prob = prob_ode_linear + + sim = test_convergence(dts, prob, Scholz4_7()) + @test sim.𝒪est[:final]≈3 atol=testTol + + sol = solve(prob, Scholz4_7()) + @test length(sol) < 30 + + prob = prob_ode_2Dlinear + + sim = test_convergence(dts, prob, Scholz4_7()) + @test sim.𝒪est[:final]≈3 atol=testTol + + sol = solve(prob, Scholz4_7()) + @test length(sol) < 30 + + println("4th order Rosenbrocks") + + ### RosShamp4 + + prob = prob_ode_linear + + sim = test_convergence(dts, prob, RosShamp4()) + @test sim.𝒪est[:final]≈4 atol=testTol + + sol = solve(prob, RosShamp4()) + @test length(sol) < 20 + + prob = prob_ode_2Dlinear + + sim = test_convergence(dts, prob, RosShamp4()) + @test sim.𝒪est[:final]≈4 atol=testTol + + sol = solve(prob, RosShamp4()) + @test length(sol) < 20 + + ### Veldd4 + + prob = prob_ode_linear + + sim = test_convergence(dts, prob, Veldd4()) + @test sim.𝒪est[:final]≈4 atol=testTol + + sol = solve(prob, Veldd4()) + @test length(sol) < 20 + + prob = prob_ode_2Dlinear + + sim = test_convergence(dts, prob, Veldd4()) + @test sim.𝒪est[:final]≈4 atol=testTol + + sol = solve(prob, Veldd4()) + @test length(sol) < 20 + + ### Velds4 + + prob = prob_ode_linear + + sim = test_convergence(dts, prob, Velds4()) + @test sim.𝒪est[:final]≈4 atol=testTol + + sol = solve(prob, Velds4()) + @test length(sol) < 20 + + prob = prob_ode_2Dlinear + + sim = test_convergence(dts, prob, Velds4()) + @test sim.𝒪est[:final]≈4 atol=testTol + + sol = solve(prob, Velds4()) + @test length(sol) < 20 + + ### GRK4T + + prob = prob_ode_linear + + sim = test_convergence(dts, prob, GRK4T()) + @test sim.𝒪est[:final]≈4 atol=testTol + + sol = solve(prob, GRK4T()) + @test length(sol) < 20 + + prob = prob_ode_2Dlinear + + sim = test_convergence(dts, prob, GRK4T()) + @test sim.𝒪est[:final]≈4 atol=testTol + + sol = solve(prob, GRK4T()) + @test length(sol) < 20 + + ### GRK4A + dts = (1 / 2) .^ (7:-1:4) + + prob = prob_ode_linear + + sim = test_convergence(dts, prob, GRK4A()) + @test sim.𝒪est[:final]≈4 atol=testTol + + sol = solve(prob, GRK4A()) + @test length(sol) < 20 + + prob = prob_ode_2Dlinear + + sim = test_convergence(dts, prob, GRK4A()) + @test sim.𝒪est[:final]≈4 atol=testTol + + sol = solve(prob, GRK4A()) + @test length(sol) < 20 + + ### Ros4LStab + + prob = prob_ode_linear + + sim = test_convergence(dts, prob, Ros4LStab()) + @test sim.𝒪est[:final]≈4 atol=testTol + + sol = solve(prob, Ros4LStab()) + @test length(sol) < 20 + + prob = prob_ode_2Dlinear + + sim = test_convergence(dts, prob, Ros4LStab()) + @test sim.𝒪est[:final]≈4 atol=testTol + + sol = solve(prob, Ros4LStab()) + @test length(sol) < 20 + + ### Rosenbrock-W Algorithms + + println("Rosenbrock-W") + + ### ROS34PW1a + prob = prob_ode_linear + + sim = test_convergence(dts, prob, ROS34PW1a()) + @test sim.𝒪est[:final]≈3 atol=testTol + + sol = solve(prob, ROS34PW1a()) + @test length(sol) < 20 + + prob = prob_ode_2Dlinear + + sim = test_convergence(dts, prob, ROS34PW1a()) + @test sim.𝒪est[:final]≈3 atol=testTol + + sol = solve(prob, ROS34PW1a()) + @test length(sol) < 20 + + ### ROS34PW1b + prob = prob_ode_linear + + sim = test_convergence(dts, prob, ROS34PW1b()) + @test sim.𝒪est[:final]≈3 atol=testTol + + sol = solve(prob, ROS34PW1b()) + @test length(sol) < 20 + + prob = prob_ode_2Dlinear + + sim = test_convergence(dts, prob, ROS34PW1b()) + @test sim.𝒪est[:final]≈3 atol=testTol + + sol = solve(prob, ROS34PW1b()) + @test length(sol) < 20 + + ### ROS34PW2 + prob = prob_ode_linear + + sim = test_convergence(dts, prob, ROS34PW2()) + @test sim.𝒪est[:final]≈3 atol=testTol + + sol = solve(prob, ROS34PW2()) + @test length(sol) < 20 + + prob = prob_ode_2Dlinear + + sim = test_convergence(dts, prob, ROS34PW2()) + @test sim.𝒪est[:final]≈3 atol=testTol + + sol = solve(prob, ROS34PW2()) + @test length(sol) < 20 + + ### ROS34PW3 + prob = prob_ode_linear + + sim = test_convergence(dts, prob, ROS34PW3()) + @test sim.𝒪est[:final]≈4 atol=testTol + + sol = solve(prob, ROS34PW3()) + @test length(sol) < 20 + + prob = prob_ode_2Dlinear + + sim = test_convergence(dts, prob, ROS34PW3()) + @test sim.𝒪est[:final]≈4 atol=testTol + + sol = solve(prob, ROS34PW3()) + @test length(sol) < 20 + + ### ROS34PRw + prob = prob_ode_linear + + sim = test_convergence(dts, prob, ROS34PRw()) + @test sim.𝒪est[:final]≈3 atol=testTol + + sol = solve(prob, ROS34PRw()) + @test length(sol) < 20 + + prob = prob_ode_2Dlinear + + sim = test_convergence(dts, prob, ROS34PRw()) + @test sim.𝒪est[:final]≈3 atol=testTol + + sol = solve(prob, ROS34PRw()) + @test length(sol) < 20 + + ### ROS3PRL + prob = prob_ode_linear + + sim = test_convergence(dts, prob, ROS3PRL()) + @test sim.𝒪est[:final]≈3 atol=testTol + + sol = solve(prob, ROS3PRL()) + @test length(sol) < 20 + + prob = prob_ode_2Dlinear + + sim = test_convergence(dts, prob, ROS3PRL()) + @test sim.𝒪est[:final]≈3 atol=testTol + + sol = solve(prob, ROS3PRL()) + @test length(sol) < 20 + + ### ROS3PRL2 + prob = prob_ode_linear + + sim = test_convergence(dts, prob, ROS3PRL2()) + @test sim.𝒪est[:final]≈3 atol=testTol + + sol = solve(prob, ROS3PRL2()) + @test length(sol) < 20 + + prob = prob_ode_2Dlinear + + sim = test_convergence(dts, prob, ROS3PRL2()) + @test sim.𝒪est[:final]≈3 atol=testTol + + sol = solve(prob, ROS3PRL2()) + @test length(sol) < 20 + + ### ROK4a + prob = prob_ode_linear + + sim = test_convergence(dts, prob, ROK4a()) + @test sim.𝒪est[:final]≈4 atol=testTol + + sol = solve(prob, ROK4a()) + @test length(sol) < 20 + + prob = prob_ode_2Dlinear + + sim = test_convergence(dts, prob, ROK4a()) + @test sim.𝒪est[:final]≈4 atol=testTol + + sol = solve(prob, ROK4a()) + @test length(sol) < 20 + + ### RosenbrockW6S4OS + sim = test_convergence(dts, prob, RosenbrockW6S4OS())#test inplace + @test sim.𝒪est[:final]≈4 atol=testTol + + prob = prob_ode_linear + + sim = test_convergence(dts, prob, RosenbrockW6S4OS())#test non-inplace + @test sim.𝒪est[:final]≈4 atol=testTol + + ### Rodas23W, Rodas3P + + println("Rodas23W") + + prob = prob_ode_linear + + dts = (1 / 2) .^ (6:-1:3) + sim = test_convergence(dts, prob, Rodas23W(), dense_errors = true) + @test sim.𝒪est[:final]≈2 atol=testTol + @test sim.𝒪est[:L2]≈2 atol=testTol + + sol = solve(prob, Rodas23W()) + @test length(sol) < 20 + + prob = prob_ode_2Dlinear + + sim = test_convergence(dts, prob, Rodas23W(), dense_errors = true) + @test sim.𝒪est[:final]≈2 atol=testTol + @test sim.𝒪est[:L2]≈2 atol=testTol + + sol = solve(prob, Rodas23W()) + @test length(sol) < 20 + + println("Rodas3P") + + prob = prob_ode_linear + + sim = test_convergence(dts, prob, Rodas3P(), dense_errors = true) + @test sim.𝒪est[:final]≈3 atol=testTol + @test sim.𝒪est[:L2]≈3 atol=testTol + + sol = solve(prob, Rodas3P()) + @test length(sol) < 20 + + prob = prob_ode_2Dlinear + + sim = test_convergence(dts, prob, Rodas3P(), dense_errors = true) + @test sim.𝒪est[:final]≈3 atol=testTol + @test sim.𝒪est[:L2]≈3 atol=testTol + + sol = solve(prob, Rodas3P()) + @test length(sol) < 20 + + ### Rodas4 Algorithms + + println("RODAS") + + dts = (1 / 2) .^ (7:-1:4) + + prob = prob_ode_linear + + sim = test_convergence(dts, prob, Rodas4(), dense_errors = true) + @test sim.𝒪est[:final]≈4 atol=testTol + @test sim.𝒪est[:L2]≈4 atol=testTol + + sol = solve(prob, Rodas4()) + @test length(sol) < 20 + + sim = test_convergence(dts, prob, Rodas4(autodiff = false), dense_errors = true) + @test sim.𝒪est[:final]≈4 atol=testTol + @test sim.𝒪est[:L2]≈4 atol=testTol + + sol = solve(prob, Rodas4(autodiff = false)) + @test length(sol) < 20 + + sim = test_convergence(dts, prob, Rodas42(), dense_errors = true) + @test sim.𝒪est[:final]≈5.1 atol=testTol + @test sim.𝒪est[:L2]≈4 atol=testTol + + sol = solve(prob, Rodas42()) + @test length(sol) < 20 + + sim = test_convergence(dts, prob, Rodas4P(), dense_errors = true) + @test sim.𝒪est[:final]≈4 atol=testTol + @test sim.𝒪est[:L2]≈4 atol=testTol + + sol = solve(prob, Rodas4P()) + @test length(sol) < 20 + + sim = test_convergence(dts, prob, Rodas4P2(), dense_errors = true) + @test sim.𝒪est[:final]≈4 atol=testTol + @test sim.𝒪est[:L2]≈4 atol=testTol + + sol = solve(prob, Rodas4P2()) + @test length(sol) < 20 + + prob = prob_ode_2Dlinear + + sim = test_convergence(dts, prob, Rodas4(), dense_errors = true) + @test sim.𝒪est[:final]≈4 atol=testTol + @test sim.𝒪est[:L2]≈4 atol=testTol + + sol = solve(prob, Rodas4()) + @test length(sol) < 20 + + println("Rodas4 with finite diff") + + sim = test_convergence(dts, prob, Rodas4(autodiff = false), dense_errors = true) + @test sim.𝒪est[:final]≈4 atol=testTol + @test sim.𝒪est[:L2]≈4 atol=testTol + + sol = solve(prob, Rodas4(autodiff = false)) + @test length(sol) < 20 + + sim = test_convergence(dts, prob, Rodas4(autodiff = false, + diff_type = Val{:forward}), + dense_errors = true) + @test sim.𝒪est[:final]≈4 atol=testTol + @test sim.𝒪est[:L2]≈4 atol=testTol + + sol = solve(prob, Rodas4(autodiff = false, diff_type = Val{:forward})) + @test length(sol) < 20 + + sim = test_convergence(dts, prob, Rodas4(autodiff = false, + diff_type = Val{:complex}), + dense_errors = true) + @test sim.𝒪est[:final]≈4 atol=testTol + @test sim.𝒪est[:L2]≈4 atol=testTol + + sol = solve(prob, Rodas4(autodiff = false, diff_type = Val{:complex})) + @test length(sol) < 20 + + sim = test_convergence(dts, prob, Rodas42(), dense_errors = true) + @test sim.𝒪est[:final]≈5 atol=testTol + @test sim.𝒪est[:L2]≈4 atol=testTol + + sol = solve(prob, Rodas42()) + @test length(sol) < 20 + + sim = test_convergence(dts, prob, Rodas4P(), dense_errors = true) + @test sim.𝒪est[:final]≈4 atol=testTol + @test sim.𝒪est[:L2]≈4 atol=testTol + + sol = solve(prob, Rodas4P()) + @test length(sol) < 20 + + sim = test_convergence(dts, prob, Rodas4P2(), dense_errors = true) + @test sim.𝒪est[:final]≈4 atol=testTol + @test sim.𝒪est[:L2]≈4 atol=testTol + + sol = solve(prob, Rodas4P2()) + @test length(sol) < 20 + + println("Rodas4P2 with finite diff") + + sim = test_convergence(dts, prob, Rodas4P2(autodiff = false), dense_errors = true) + @test sim.𝒪est[:final]≈4 atol=testTol + @test sim.𝒪est[:L2]≈4 atol=testTol + + sol = solve(prob, Rodas4P2(autodiff = false)) + @test length(sol) < 20 + + ### Rodas5 + println("Rodas5") + + prob = prob_ode_linear + + dts = (1 / 2) .^ (6:-1:3) + sim = test_convergence(dts, prob, Rodas5(), dense_errors = true) + @test sim.𝒪est[:final]≈5 atol=testTol + @test sim.𝒪est[:L2]≈5 atol=testTol + + sol = solve(prob, Rodas5()) + @test length(sol) < 20 + + prob = prob_ode_2Dlinear + + sim = test_convergence(dts, prob, Rodas5(), dense_errors = true) + @test sim.𝒪est[:final]≈5 atol=testTol + @test sim.𝒪est[:L2]≈5 atol=testTol + + sol = solve(prob, Rodas5()) + @test length(sol) < 20 + + println("Rodas5P") + + prob = prob_ode_linear + + dts = (1 / 2) .^ (5:-1:2) + sim = test_convergence(dts, prob, Rodas5P(), dense_errors = true) + #@test sim.𝒪est[:final]≈5 atol=testTol #-- observed order > 6 + @test sim.𝒪est[:L2]≈5 atol=testTol + + sol = solve(prob, Rodas5P()) + @test length(sol) < 20 + + prob = prob_ode_2Dlinear + + sim = test_convergence(dts, prob, Rodas5P(), dense_errors = true) + #@test sim.𝒪est[:final]≈5 atol=testTol #-- observed order > 6 + @test sim.𝒪est[:L2]≈5 atol=testTol + + sol = solve(prob, Rodas5P()) + @test length(sol) < 20 + + println("Rodas5Pe") + + prob = prob_ode_linear + + sim = test_convergence(dts, prob, Rodas5Pe(), dense_errors = true) + #@test sim.𝒪est[:final]≈5 atol=testTol #-- observed order > 6 + @test sim.𝒪est[:L2]≈5 atol=testTol + + sol = solve(prob, Rodas5Pe()) + @test length(sol) < 20 + + prob = prob_ode_2Dlinear + + sim = test_convergence(dts, prob, Rodas5Pe(), dense_errors = true) + #@test sim.𝒪est[:final]≈5 atol=testTol #-- observed order > 6 + @test sim.𝒪est[:L2]≈5 atol=testTol + + sol = solve(prob, Rodas5Pe()) + @test length(sol) < 20 + + println("Rodas5Pr") + + prob = prob_ode_linear + + sim = test_convergence(dts, prob, Rodas5Pr(), dense_errors = true) + #@test sim.𝒪est[:final]≈5 atol=testTol #-- observed order > 6 + @test sim.𝒪est[:L2]≈5 atol=testTol + + sol = solve(prob, Rodas5Pr()) + @test length(sol) < 20 + + prob = prob_ode_2Dlinear + + sim = test_convergence(dts, prob, Rodas5Pr(), dense_errors = true) + #@test sim.𝒪est[:final]≈5 atol=testTol #-- observed order > 6 + @test sim.𝒪est[:L2]≈5 atol=testTol + + sol = solve(prob, Rodas5Pr()) + @test length(sol) < 20 + + prob = ODEProblem((u, p, t) -> 0.9u, 0.1, (0.0, 1.0)) + @test_nowarn solve(prob, Rosenbrock23(autodiff = false)) +end + +@testset "Convergence with time-dependent matrix-free Jacobian" begin + time_derivative(du, u, p, t) = (du[1] = t * u[1]) + time_derivative_analytic(u0, p, t) = u0 * exp(t^2 / 2) + ff_time_derivative = ODEFunction(time_derivative, analytic = time_derivative_analytic) + prob = ODEProblem(ff_time_derivative, [1.0], (0.0, 1.0)) + + dts = (1 / 2) .^ (6:-1:3) + testTol = 0.2 + # Check convergence of Rodas3 with time-dependent matrix-free Jacobian. + # Primarily to check that the Jacobian is being updated correctly as t changes. + sim = test_convergence(dts, prob, Rodas3(linsolve = LinearSolve.KrylovJL())) + @test sim.𝒪est[:final]≈3 atol=testTol +end \ No newline at end of file diff --git a/lib/OrdinaryDiffEqRosenbrock/test/runtests.jl b/lib/OrdinaryDiffEqRosenbrock/test/runtests.jl new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/OrdinaryDiffEq.jl b/src/OrdinaryDiffEq.jl index 1b597759b3..2d360e1d7f 100644 --- a/src/OrdinaryDiffEq.jl +++ b/src/OrdinaryDiffEq.jl @@ -147,15 +147,10 @@ include("nlsolve/nlsolve.jl") include("nlsolve/functional.jl") include("nlsolve/newton.jl") -include("generic_rosenbrock.jl") - include("caches/basic_caches.jl") include("caches/linear_caches.jl") include("caches/linear_nonlinear_caches.jl") include("caches/imex_multistep_caches.jl") -include("caches/rosenbrock_caches.jl") - -include("tableaus/rosenbrock_tableaus.jl") include("integrators/type.jl") include("integrators/controllers.jl") @@ -168,15 +163,10 @@ include("wrappers.jl") include("perform_step/linear_perform_step.jl") include("perform_step/exponential_rk_perform_step.jl") include("perform_step/explicit_rk_perform_step.jl") -include("perform_step/rosenbrock_perform_step.jl") include("perform_step/imex_multistep_perform_step.jl") include("perform_step/composite_perform_step.jl") -include("dense/rosenbrock_interpolants.jl") -include("dense/stiff_addsteps.jl") - include("derivative_utils.jl") -include("nordsieck_utils.jl") include("derivative_wrappers.jl") include("iterator_interface.jl") include("constants.jl") @@ -306,6 +296,15 @@ include("../lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl") using ..OrdinaryDiffEqNordsieck export AN5, JVODE, JVODE_Adams, JVODE_BDF +include("../lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl") +using ..OrdinaryDiffEqRosenbrock +export Rosenbrock23, Rosenbrock32, RosShamp4, Veldd4, Velds4, GRK4T, GRK4A, + Ros4LStab, ROS3P, Rodas3, Rodas23W, Rodas3P, Rodas4, Rodas42, Rodas4P, Rodas4P2, + Rodas5, Rodas5P, Rodas5Pe, Rodas5Pr, + RosenbrockW6S4OS, ROS34PW1a, ROS34PW1b, ROS34PW2, ROS34PW3, ROS34PRw, ROS3PRL, + ROS3PRL2, ROK4a, + ROS2, ROS2PR, ROS2S, ROS3, ROS3PR, Scholz4_7 + include("dense/generic_dense.jl") include("solve.jl") @@ -443,13 +442,6 @@ export MagnusMidpoint, LinearExponential, MagnusLeapfrog, LieEuler, CayleyEuler, MagnusGauss4, MagnusNC6, MagnusGL6, MagnusGL8, MagnusNC8, MagnusGL4, MagnusAdapt4, RKMK2, RKMK4, LieRK4, CG2, CG3, CG4a -export Rosenbrock23, Rosenbrock32, RosShamp4, Veldd4, Velds4, GRK4T, GRK4A, - Ros4LStab, ROS3P, Rodas3, Rodas23W, Rodas3P, Rodas4, Rodas42, Rodas4P, Rodas4P2, - Rodas5, Rodas5P, Rodas5Pe, Rodas5Pr, - RosenbrockW6S4OS, ROS34PW1a, ROS34PW1b, ROS34PW2, ROS34PW3, ROS34PRw, ROS3PRL, - ROS3PRL2, ROK4a, - ROS2, ROS2PR, ROS2S, ROS3, ROS3PR, Scholz4_7 - export LawsonEuler, NorsettEuler, ETD1, ETDRK2, ETDRK3, ETDRK4, HochOst4, Exp4, EPIRK4s3A, EPIRK4s3B, EPIRK5s3, EXPRB53s3, EPIRK5P1, EPIRK5P2, ETD2, Exprb32, Exprb43 diff --git a/src/alg_utils.jl b/src/alg_utils.jl index bf2227195a..be7130006c 100644 --- a/src/alg_utils.jl +++ b/src/alg_utils.jl @@ -24,16 +24,6 @@ isfsal(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm}) = true isfsal(tab::DiffEqBase.ExplicitRKTableau) = tab.fsal # isfsal(alg::CompositeAlgorithm) = isfsal(alg.algs[alg.current]) -isfsal(alg::Rodas3P) = false -isfsal(alg::Rodas23W) = false -isfsal(alg::Rodas5) = false -isfsal(alg::Rodas5P) = false -isfsal(alg::Rodas5Pr) = false -isfsal(alg::Rodas5Pe) = false -isfsal(alg::Rodas4) = false -isfsal(alg::Rodas42) = false -isfsal(alg::Rodas4P) = false -isfsal(alg::Rodas4P2) = false # Pseudo Non-FSAL #isfsal(alg::RKM) = false @@ -402,42 +392,6 @@ alg_order(alg::MagnusAdapt4) = 4 alg_order(alg::LinearExponential) = 1 alg_order(alg::MagnusLeapfrog) = 2 -alg_order(alg::ROS2) = 2 -alg_order(alg::ROS2PR) = 2 -alg_order(alg::ROS2S) = 2 -alg_order(alg::ROS3) = 3 -alg_order(alg::ROS3PR) = 3 -alg_order(alg::Scholz4_7) = 3 -alg_order(alg::Rosenbrock23) = 2 -alg_order(alg::Rodas23W) = 3 -alg_order(alg::Rosenbrock32) = 3 -alg_order(alg::ROS3P) = 3 -alg_order(alg::Rodas3) = 3 -alg_order(alg::Rodas3P) = 3 -alg_order(alg::ROS34PW1a) = 3 -alg_order(alg::ROS34PW1b) = 3 -alg_order(alg::ROS34PW2) = 3 -alg_order(alg::ROS34PW3) = 4 -alg_order(alg::ROS34PRw) = 3 -alg_order(alg::ROS3PRL) = 3 -alg_order(alg::ROS3PRL2) = 3 -alg_order(alg::ROK4a) = 4 -alg_order(alg::RosShamp4) = 4 -alg_order(alg::Veldd4) = 4 -alg_order(alg::Velds4) = 4 -alg_order(alg::GRK4T) = 4 -alg_order(alg::GRK4A) = 4 -alg_order(alg::Ros4LStab) = 4 -alg_order(alg::RosenbrockW6S4OS) = 4 -alg_order(alg::Rodas4) = 4 -alg_order(alg::Rodas42) = 4 -alg_order(alg::Rodas4P) = 4 -alg_order(alg::Rodas4P2) = 4 -alg_order(alg::Rodas5) = 5 -alg_order(alg::Rodas5P) = 5 -alg_order(alg::Rodas5Pr) = 5 -alg_order(alg::Rodas5Pe) = 5 - alg_order(alg::CNAB2) = 2 alg_order(alg::CNLF2) = 2 @@ -447,9 +401,6 @@ alg_maximum_order(alg::CompositeAlgorithm) = maximum(alg_order(x) for x in alg.a alg_adaptive_order(alg::ExplicitRK) = alg.tableau.adaptiveorder alg_adaptive_order(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm}) = alg_order(alg) - 1 -alg_adaptive_order(alg::Rosenbrock23) = 3 -alg_adaptive_order(alg::Rosenbrock32) = 2 - # this is actually incorrect and is purposefully decreased as this tends # to track the real error much better # this is actually incorrect and is purposefully decreased as this tends @@ -577,9 +528,6 @@ isstandard(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm}) = false isstandard(alg::OrdinaryDiffEqNewtonAdaptiveAlgorithm) = alg.controller === :Standard isWmethod(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm}) = false -isWmethod(alg::Rosenbrock23) = true -isWmethod(alg::Rosenbrock32) = true -isWmethod(alg::Rodas23W) = true isWmethod(alg::ROS2S) = true isWmethod(alg::ROS34PW1a) = true isWmethod(alg::ROS34PW1b) = true diff --git a/src/algorithms.jl b/src/algorithms.jl index 63ef170e50..c8c25658fd 100644 --- a/src/algorithms.jl +++ b/src/algorithms.jl @@ -169,213 +169,6 @@ struct CayleyEuler <: OrdinaryDiffEqAlgorithm end ################################################################################ -# Rosenbrock Methods - -#= -#### Rosenbrock23, Rosenbrock32, ode23s, ModifiedRosenbrockIntegrator - -- Shampine L.F. and Reichelt M., (1997) The MATLAB ODE Suite, SIAM Journal of -Scientific Computing, 18 (1), pp. 1-22. - -#### ROS2 - -- J. G. Verwer et al. (1999): A second-order Rosenbrock method applied to photochemical dispersion problems - https://doi.org/10.1137/S1064827597326651 - -#### ROS3P - -- Lang, J. & Verwer, ROS3P—An Accurate Third-Order Rosenbrock Solver Designed for - Parabolic Problems J. BIT Numerical Mathematics (2001) 41: 731. doi:10.1023/A:1021900219772 - -#### ROS3, Rodas3, Ros4LStab, Rodas4, Rodas42 - -- E. Hairer, G. Wanner, Solving ordinary differential equations II, stiff and - differential-algebraic problems. Computational mathematics (2nd revised ed.), Springer (1996) - -#### ROS2PR, ROS2S, ROS3PR, Scholz4_7 --Rang, Joachim (2014): The Prothero and Robinson example: - Convergence studies for Runge-Kutta and Rosenbrock-Wanner methods. - https://doi.org/10.24355/dbbs.084-201408121139-0 - -#### RosShamp4 - -- L. F. Shampine, Implementation of Rosenbrock Methods, ACM Transactions on - Mathematical Software (TOMS), 8: 2, 93-113. doi:10.1145/355993.355994 - -#### Veldd4, Velds4 - -- van Veldhuizen, D-stability and Kaps-Rentrop-methods, M. Computing (1984) 32: 229. - doi:10.1007/BF02243574 - -#### GRK4T, GRK4A - -- Kaps, P. & Rentrop, Generalized Runge-Kutta methods of order four with stepsize control - for stiff ordinary differential equations. P. Numer. Math. (1979) 33: 55. doi:10.1007/BF01396495 - -#### Rodas23W, Rodas3P - -- Steinebach G., Rodas23W / Rodas32P - a Rosenbrock-type method for DAEs with additional error estimate for dense output and Julia implementation, - in progress - -#### Rodas4P - -- Steinebach G. Order-reduction of ROW-methods for DAEs and method of lines - applications. Preprint-Nr. 1741, FB Mathematik, TH Darmstadt; 1995. - -#### Rodas4P2 -- Steinebach G. (2020) Improvement of Rosenbrock-Wanner Method RODASP. - In: Reis T., Grundel S., Schoeps S. (eds) Progress in Differential-Algebraic Equations II. - Differential-Algebraic Equations Forum. Springer, Cham. https://doi.org/10.1007/978-3-030-53905-4_6 - -#### Rodas5 -- Di Marzo G. RODAS5(4) – Méthodes de Rosenbrock d’ordre 5(4) adaptées aux problemes -différentiels-algébriques. MSc mathematics thesis, Faculty of Science, -University of Geneva, Switzerland. - -#### ROS34PRw --Joachim Rang, Improved traditional Rosenbrock–Wanner methods for stiff ODEs and DAEs, - Journal of Computational and Applied Mathematics, - https://doi.org/10.1016/j.cam.2015.03.010 - -#### ROS3PRL, ROS3PRL2 --Rang, Joachim (2014): The Prothero and Robinson example: - Convergence studies for Runge-Kutta and Rosenbrock-Wanner methods. - https://doi.org/10.24355/dbbs.084-201408121139-0 - -#### ROK4a -- Tranquilli, Paul and Sandu, Adrian (2014): - Rosenbrock--Krylov Methods for Large Systems of Differential Equations - https://doi.org/10.1137/130923336 - -#### Rodas5P -- Steinebach G. Construction of Rosenbrock–Wanner method Rodas5P and numerical benchmarks within the Julia Differential Equations package. - In: BIT Numerical Mathematics, 63(2), 2023 - - #### Rodas23W, Rodas3P, Rodas5Pe, Rodas5Pr -- Steinebach G. Rosenbrock methods within OrdinaryDiffEq.jl - Overview, recent developments and applications - - Preprint 2024 - https://github.com/hbrs-cse/RosenbrockMethods/blob/main/paper/JuliaPaper.pdf - -=# - -for Alg in [ - :ROS2, - :ROS2PR, - :ROS2S, - :ROS3, - :ROS3PR, - :Scholz4_7, - :ROS34PW1a, - :ROS34PW1b, - :ROS34PW2, - :ROS34PW3, - :ROS34PRw, - :ROS3PRL, - :ROS3PRL2, - :ROK4a, - :RosShamp4, - :Veldd4, - :Velds4, - :GRK4T, - :GRK4A, - :Ros4LStab] - @eval begin - struct $Alg{CS, AD, F, P, FDT, ST, CJ} <: - OrdinaryDiffEqRosenbrockAdaptiveAlgorithm{CS, AD, FDT, ST, CJ} - linsolve::F - precs::P - end - function $Alg(; chunk_size = Val{0}(), autodiff = Val{true}(), - standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS) - $Alg{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), - typeof(precs), diff_type, _unwrap_val(standardtag), - _unwrap_val(concrete_jac)}(linsolve, - precs) - end - end - - @eval TruncatedStacktraces.@truncate_stacktrace $Alg 1 2 -end - -# for Rosenbrock methods with step_limiter -for Alg in [ - :Rosenbrock23, - :Rosenbrock32, - :ROS3P, - :Rodas3, - :Rodas23W, - :Rodas3P, - :Rodas4, - :Rodas42, - :Rodas4P, - :Rodas4P2, - :Rodas5, - :Rodas5P, - :Rodas5Pe, - :Rodas5Pr] - @eval begin - struct $Alg{CS, AD, F, P, FDT, ST, CJ, StepLimiter, StageLimiter} <: - OrdinaryDiffEqRosenbrockAdaptiveAlgorithm{CS, AD, FDT, ST, CJ} - linsolve::F - precs::P - step_limiter!::StepLimiter - stage_limiter!::StageLimiter - end - function $Alg(; chunk_size = Val{0}(), autodiff = Val{true}(), - standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, linsolve = nothing, - precs = DEFAULT_PRECS, step_limiter! = trivial_limiter!, - stage_limiter! = trivial_limiter!) - $Alg{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), - typeof(precs), diff_type, _unwrap_val(standardtag), - _unwrap_val(concrete_jac), typeof(step_limiter!), - typeof(stage_limiter!)}(linsolve, precs, step_limiter!, - stage_limiter!) - end - end - - @eval TruncatedStacktraces.@truncate_stacktrace $Alg 1 2 -end -struct GeneralRosenbrock{CS, AD, F, ST, CJ, TabType} <: - OrdinaryDiffEqRosenbrockAdaptiveAlgorithm{CS, AD, Val{:forward}, ST, CJ} - tableau::TabType - factorization::F -end - -function GeneralRosenbrock(; chunk_size = Val{0}(), autodiff = true, - standardtag = Val{true}(), concrete_jac = nothing, - factorization = lu!, tableau = ROSENBROCK_DEFAULT_TABLEAU) - GeneralRosenbrock{ - _unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(factorization), - _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(tableau)}(tableau, - factorization) -end - -@doc rosenbrock_wanner_docstring( - """ - A 4th order L-stable Rosenbrock-W method (fixed step only). - """, - "RosenbrockW6S4OS", - references = """ - https://doi.org/10.1016/j.cam.2009.09.017 - """) -struct RosenbrockW6S4OS{CS, AD, F, P, FDT, ST, CJ} <: - OrdinaryDiffEqRosenbrockAlgorithm{CS, AD, FDT, ST, CJ} - linsolve::F - precs::P -end -function RosenbrockW6S4OS(; chunk_size = Val{0}(), autodiff = true, - standardtag = Val{true}(), - concrete_jac = nothing, diff_type = Val{:central}, - linsolve = nothing, - precs = DEFAULT_PRECS) - RosenbrockW6S4OS{_unwrap_val(chunk_size), - _unwrap_val(autodiff), typeof(linsolve), typeof(precs), diff_type, - _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, - precs) -end - ###################################### for Alg in [:LawsonEuler, :NorsettEuler, :ETDRK2, :ETDRK3, :ETDRK4, :HochOst4] diff --git a/src/interp_func.jl b/src/interp_func.jl index 8ed016333a..36609b69c7 100644 --- a/src/interp_func.jl +++ b/src/interp_func.jl @@ -30,24 +30,6 @@ function DiffEqBase.interp_summary(interp::OrdinaryDiffEqInterpolation{ } DiffEqBase.interp_summary(cacheType, interp.dense) end -function DiffEqBase.interp_summary(::Type{cacheType}, - dense::Bool) where { - cacheType <: - Union{Rosenbrock23ConstantCache, - Rosenbrock32ConstantCache, - Rosenbrock23Cache, - Rosenbrock32Cache}} - dense ? "specialized 2nd order \"free\" stiffness-aware interpolation" : - "1st order linear" -end -function DiffEqBase.interp_summary(::Type{cacheType}, - dense::Bool) where { - cacheType <: - Union{Rodas4ConstantCache, Rodas23WConstantCache, Rodas3PConstantCache, - Rodas4Cache, Rodas23WCache, Rodas3PCache}} - dense ? "specialized 3rd order \"free\" stiffness-aware interpolation" : - "1st order linear" -end function DiffEqBase.interp_summary(::Type{cacheType}, dense::Bool) where { cacheType <: diff --git a/test/algconvergence/ode_rosenbrock_tests.jl b/test/algconvergence/ode_rosenbrock_tests.jl index e71ec00355..e69de29bb2 100644 --- a/test/algconvergence/ode_rosenbrock_tests.jl +++ b/test/algconvergence/ode_rosenbrock_tests.jl @@ -1,706 +0,0 @@ -using OrdinaryDiffEq, DiffEqDevTools, Test, LinearAlgebra, LinearSolve -import ODEProblemLibrary: prob_ode_linear, - prob_ode_2Dlinear, - prob_ode_bigfloatlinear, prob_ode_bigfloat2Dlinear -import LinearSolve - -@testset "Rosenbrock Tests" begin - ## Breakout these since no other test of their adaptivity - - dts = (1 / 2) .^ (6:-1:3) - testTol = 0.2 - - ### Rosenbrock23() - - prob = prob_ode_linear - - sim = test_convergence(dts, prob, Rosenbrock23()) - @test sim.𝒪est[:final]≈2 atol=testTol - - sol = solve(prob, Rosenbrock23()) - @test length(sol) < 20 - - prob = prob_ode_2Dlinear - - sim = test_convergence(dts, prob, Rosenbrock23()) - @test sim.𝒪est[:final]≈2 atol=testTol - - sol = solve(prob, Rosenbrock23()) - @test length(sol) < 20 - - prob = prob_ode_bigfloat2Dlinear - - sim = test_convergence(dts, prob, Rosenbrock23(linsolve = QRFactorization())) - @test sim.𝒪est[:final]≈2 atol=testTol - - sol = solve(prob, Rosenbrock23(linsolve = QRFactorization())) - @test length(sol) < 20 - - ### Rosenbrock32() - - prob = prob_ode_linear - - sim = test_convergence(dts, prob, Rosenbrock32()) - @test sim.𝒪est[:final]≈3 atol=testTol - - sol = solve(prob, Rosenbrock32()) - @test length(sol) < 20 - - prob = prob_ode_2Dlinear - - sim = test_convergence(dts, prob, Rosenbrock32()) - @test sim.𝒪est[:final]≈3 atol=testTol - - sol = solve(prob, Rosenbrock32()) - @test length(sol) < 20 - - ### ROS3P() - - prob = prob_ode_linear - - sim = test_convergence(dts, prob, ROS3P()) - @test sim.𝒪est[:final]≈3 atol=testTol - - sol = solve(prob, ROS3P()) - @test length(sol) < 20 - - prob = prob_ode_2Dlinear - - sim = test_convergence(dts, prob, ROS3P()) - @test sim.𝒪est[:final]≈3 atol=testTol - - sol = solve(prob, ROS3P()) - @test length(sol) < 20 - - ### Rodas3() - - prob = prob_ode_linear - - sim = test_convergence(dts, prob, Rodas3()) - @test sim.𝒪est[:final]≈3 atol=testTol - - sol = solve(prob, Rodas3()) - @test length(sol) < 20 - - prob = prob_ode_2Dlinear - - sim = test_convergence(dts, prob, Rodas3()) - @test sim.𝒪est[:final]≈3 atol=testTol - - sol = solve(prob, Rodas3()) - @test length(sol) < 20 - - ### ROS2 - prob = prob_ode_linear - - sim = test_convergence(dts, prob, ROS2()) - @test sim.𝒪est[:final]≈2 atol=testTol - - sol = solve(prob, ROS2()) - @test length(sol) < 61 - - prob = prob_ode_2Dlinear - - sim = test_convergence(dts, prob, ROS2()) - @test sim.𝒪est[:final]≈2 atol=testTol - - sol = solve(prob, ROS2PR()) - @test length(sol) < 60 - - ### ROS2PR - prob = prob_ode_linear - - sim = test_convergence(dts, prob, ROS2PR()) - @test sim.𝒪est[:final]≈2 atol=testTol - - sol = solve(prob, ROS2PR()) - @test length(sol) < 30 - - prob = prob_ode_2Dlinear - - sim = test_convergence(dts, prob, ROS2PR()) - @test sim.𝒪est[:final]≈2 atol=testTol - - sol = solve(prob, ROS2PR()) - @test length(sol) < 30 - - ### ROS2S - prob = prob_ode_linear - - sim = test_convergence(dts, prob, ROS2S()) - @test sim.𝒪est[:final]≈2 atol=testTol - - sol = solve(prob, ROS2S()) - @test length(sol) < 20 - - prob = prob_ode_2Dlinear - - sim = test_convergence(dts, prob, ROS2S()) - @test sim.𝒪est[:final]≈2 atol=testTol - - sol = solve(prob, ROS2S()) - @test length(sol) < 20 - - ### ROS3 - prob = prob_ode_linear - - sim = test_convergence(dts, prob, ROS3()) - @test sim.𝒪est[:final]≈3 atol=testTol - - sol = solve(prob, ROS3()) - @test length(sol) < 20 - - prob = prob_ode_2Dlinear - - sim = test_convergence(dts, prob, ROS3()) - @test sim.𝒪est[:final]≈3 atol=testTol - - sol = solve(prob, ROS3()) - @test length(sol) < 20 - - ### ROS3PR - prob = prob_ode_linear - - sim = test_convergence(dts, prob, ROS3PR()) - @test sim.𝒪est[:final]≈3 atol=testTol - - sol = solve(prob, ROS3PR()) - @test length(sol) < 20 #length(sol) = 4 => Too Small?? - - prob = prob_ode_2Dlinear - - sim = test_convergence(dts, prob, ROS3PR()) - @test sim.𝒪est[:final]≈3 atol=testTol - - sol = solve(prob, ROS3PR()) - @test length(sol) < 20 #length(sol) = 4 => Too Small?? - - ### Scholz4_7 - prob = prob_ode_linear - - sim = test_convergence(dts, prob, Scholz4_7()) - @test sim.𝒪est[:final]≈3 atol=testTol - - sol = solve(prob, Scholz4_7()) - @test length(sol) < 30 - - prob = prob_ode_2Dlinear - - sim = test_convergence(dts, prob, Scholz4_7()) - @test sim.𝒪est[:final]≈3 atol=testTol - - sol = solve(prob, Scholz4_7()) - @test length(sol) < 30 - - println("4th order Rosenbrocks") - - ### RosShamp4 - - prob = prob_ode_linear - - sim = test_convergence(dts, prob, RosShamp4()) - @test sim.𝒪est[:final]≈4 atol=testTol - - sol = solve(prob, RosShamp4()) - @test length(sol) < 20 - - prob = prob_ode_2Dlinear - - sim = test_convergence(dts, prob, RosShamp4()) - @test sim.𝒪est[:final]≈4 atol=testTol - - sol = solve(prob, RosShamp4()) - @test length(sol) < 20 - - ### Veldd4 - - prob = prob_ode_linear - - sim = test_convergence(dts, prob, Veldd4()) - @test sim.𝒪est[:final]≈4 atol=testTol - - sol = solve(prob, Veldd4()) - @test length(sol) < 20 - - prob = prob_ode_2Dlinear - - sim = test_convergence(dts, prob, Veldd4()) - @test sim.𝒪est[:final]≈4 atol=testTol - - sol = solve(prob, Veldd4()) - @test length(sol) < 20 - - ### Velds4 - - prob = prob_ode_linear - - sim = test_convergence(dts, prob, Velds4()) - @test sim.𝒪est[:final]≈4 atol=testTol - - sol = solve(prob, Velds4()) - @test length(sol) < 20 - - prob = prob_ode_2Dlinear - - sim = test_convergence(dts, prob, Velds4()) - @test sim.𝒪est[:final]≈4 atol=testTol - - sol = solve(prob, Velds4()) - @test length(sol) < 20 - - ### GRK4T - - prob = prob_ode_linear - - sim = test_convergence(dts, prob, GRK4T()) - @test sim.𝒪est[:final]≈4 atol=testTol - - sol = solve(prob, GRK4T()) - @test length(sol) < 20 - - prob = prob_ode_2Dlinear - - sim = test_convergence(dts, prob, GRK4T()) - @test sim.𝒪est[:final]≈4 atol=testTol - - sol = solve(prob, GRK4T()) - @test length(sol) < 20 - - ### GRK4A - dts = (1 / 2) .^ (7:-1:4) - - prob = prob_ode_linear - - sim = test_convergence(dts, prob, GRK4A()) - @test sim.𝒪est[:final]≈4 atol=testTol - - sol = solve(prob, GRK4A()) - @test length(sol) < 20 - - prob = prob_ode_2Dlinear - - sim = test_convergence(dts, prob, GRK4A()) - @test sim.𝒪est[:final]≈4 atol=testTol - - sol = solve(prob, GRK4A()) - @test length(sol) < 20 - - ### Ros4LStab - - prob = prob_ode_linear - - sim = test_convergence(dts, prob, Ros4LStab()) - @test sim.𝒪est[:final]≈4 atol=testTol - - sol = solve(prob, Ros4LStab()) - @test length(sol) < 20 - - prob = prob_ode_2Dlinear - - sim = test_convergence(dts, prob, Ros4LStab()) - @test sim.𝒪est[:final]≈4 atol=testTol - - sol = solve(prob, Ros4LStab()) - @test length(sol) < 20 - - ### Rosenbrock-W Algorithms - - println("Rosenbrock-W") - - ### ROS34PW1a - prob = prob_ode_linear - - sim = test_convergence(dts, prob, ROS34PW1a()) - @test sim.𝒪est[:final]≈3 atol=testTol - - sol = solve(prob, ROS34PW1a()) - @test length(sol) < 20 - - prob = prob_ode_2Dlinear - - sim = test_convergence(dts, prob, ROS34PW1a()) - @test sim.𝒪est[:final]≈3 atol=testTol - - sol = solve(prob, ROS34PW1a()) - @test length(sol) < 20 - - ### ROS34PW1b - prob = prob_ode_linear - - sim = test_convergence(dts, prob, ROS34PW1b()) - @test sim.𝒪est[:final]≈3 atol=testTol - - sol = solve(prob, ROS34PW1b()) - @test length(sol) < 20 - - prob = prob_ode_2Dlinear - - sim = test_convergence(dts, prob, ROS34PW1b()) - @test sim.𝒪est[:final]≈3 atol=testTol - - sol = solve(prob, ROS34PW1b()) - @test length(sol) < 20 - - ### ROS34PW2 - prob = prob_ode_linear - - sim = test_convergence(dts, prob, ROS34PW2()) - @test sim.𝒪est[:final]≈3 atol=testTol - - sol = solve(prob, ROS34PW2()) - @test length(sol) < 20 - - prob = prob_ode_2Dlinear - - sim = test_convergence(dts, prob, ROS34PW2()) - @test sim.𝒪est[:final]≈3 atol=testTol - - sol = solve(prob, ROS34PW2()) - @test length(sol) < 20 - - ### ROS34PW3 - prob = prob_ode_linear - - sim = test_convergence(dts, prob, ROS34PW3()) - @test sim.𝒪est[:final]≈4 atol=testTol - - sol = solve(prob, ROS34PW3()) - @test length(sol) < 20 - - prob = prob_ode_2Dlinear - - sim = test_convergence(dts, prob, ROS34PW3()) - @test sim.𝒪est[:final]≈4 atol=testTol - - sol = solve(prob, ROS34PW3()) - @test length(sol) < 20 - - ### ROS34PRw - prob = prob_ode_linear - - sim = test_convergence(dts, prob, ROS34PRw()) - @test sim.𝒪est[:final]≈3 atol=testTol - - sol = solve(prob, ROS34PRw()) - @test length(sol) < 20 - - prob = prob_ode_2Dlinear - - sim = test_convergence(dts, prob, ROS34PRw()) - @test sim.𝒪est[:final]≈3 atol=testTol - - sol = solve(prob, ROS34PRw()) - @test length(sol) < 20 - - ### ROS3PRL - prob = prob_ode_linear - - sim = test_convergence(dts, prob, ROS3PRL()) - @test sim.𝒪est[:final]≈3 atol=testTol - - sol = solve(prob, ROS3PRL()) - @test length(sol) < 20 - - prob = prob_ode_2Dlinear - - sim = test_convergence(dts, prob, ROS3PRL()) - @test sim.𝒪est[:final]≈3 atol=testTol - - sol = solve(prob, ROS3PRL()) - @test length(sol) < 20 - - ### ROS3PRL2 - prob = prob_ode_linear - - sim = test_convergence(dts, prob, ROS3PRL2()) - @test sim.𝒪est[:final]≈3 atol=testTol - - sol = solve(prob, ROS3PRL2()) - @test length(sol) < 20 - - prob = prob_ode_2Dlinear - - sim = test_convergence(dts, prob, ROS3PRL2()) - @test sim.𝒪est[:final]≈3 atol=testTol - - sol = solve(prob, ROS3PRL2()) - @test length(sol) < 20 - - ### ROK4a - prob = prob_ode_linear - - sim = test_convergence(dts, prob, ROK4a()) - @test sim.𝒪est[:final]≈4 atol=testTol - - sol = solve(prob, ROK4a()) - @test length(sol) < 20 - - prob = prob_ode_2Dlinear - - sim = test_convergence(dts, prob, ROK4a()) - @test sim.𝒪est[:final]≈4 atol=testTol - - sol = solve(prob, ROK4a()) - @test length(sol) < 20 - - ### RosenbrockW6S4OS - sim = test_convergence(dts, prob, RosenbrockW6S4OS())#test inplace - @test sim.𝒪est[:final]≈4 atol=testTol - - prob = prob_ode_linear - - sim = test_convergence(dts, prob, RosenbrockW6S4OS())#test non-inplace - @test sim.𝒪est[:final]≈4 atol=testTol - - ### Rodas23W, Rodas3P - - println("Rodas23W") - - prob = prob_ode_linear - - dts = (1 / 2) .^ (6:-1:3) - sim = test_convergence(dts, prob, Rodas23W(), dense_errors = true) - @test sim.𝒪est[:final]≈2 atol=testTol - @test sim.𝒪est[:L2]≈2 atol=testTol - - sol = solve(prob, Rodas23W()) - @test length(sol) < 20 - - prob = prob_ode_2Dlinear - - sim = test_convergence(dts, prob, Rodas23W(), dense_errors = true) - @test sim.𝒪est[:final]≈2 atol=testTol - @test sim.𝒪est[:L2]≈2 atol=testTol - - sol = solve(prob, Rodas23W()) - @test length(sol) < 20 - - println("Rodas3P") - - prob = prob_ode_linear - - sim = test_convergence(dts, prob, Rodas3P(), dense_errors = true) - @test sim.𝒪est[:final]≈3 atol=testTol - @test sim.𝒪est[:L2]≈3 atol=testTol - - sol = solve(prob, Rodas3P()) - @test length(sol) < 20 - - prob = prob_ode_2Dlinear - - sim = test_convergence(dts, prob, Rodas3P(), dense_errors = true) - @test sim.𝒪est[:final]≈3 atol=testTol - @test sim.𝒪est[:L2]≈3 atol=testTol - - sol = solve(prob, Rodas3P()) - @test length(sol) < 20 - - ### Rodas4 Algorithms - - println("RODAS") - - dts = (1 / 2) .^ (7:-1:4) - - prob = prob_ode_linear - - sim = test_convergence(dts, prob, Rodas4(), dense_errors = true) - @test sim.𝒪est[:final]≈4 atol=testTol - @test sim.𝒪est[:L2]≈4 atol=testTol - - sol = solve(prob, Rodas4()) - @test length(sol) < 20 - - sim = test_convergence(dts, prob, Rodas4(autodiff = false), dense_errors = true) - @test sim.𝒪est[:final]≈4 atol=testTol - @test sim.𝒪est[:L2]≈4 atol=testTol - - sol = solve(prob, Rodas4(autodiff = false)) - @test length(sol) < 20 - - sim = test_convergence(dts, prob, Rodas42(), dense_errors = true) - @test sim.𝒪est[:final]≈5.1 atol=testTol - @test sim.𝒪est[:L2]≈4 atol=testTol - - sol = solve(prob, Rodas42()) - @test length(sol) < 20 - - sim = test_convergence(dts, prob, Rodas4P(), dense_errors = true) - @test sim.𝒪est[:final]≈4 atol=testTol - @test sim.𝒪est[:L2]≈4 atol=testTol - - sol = solve(prob, Rodas4P()) - @test length(sol) < 20 - - sim = test_convergence(dts, prob, Rodas4P2(), dense_errors = true) - @test sim.𝒪est[:final]≈4 atol=testTol - @test sim.𝒪est[:L2]≈4 atol=testTol - - sol = solve(prob, Rodas4P2()) - @test length(sol) < 20 - - prob = prob_ode_2Dlinear - - sim = test_convergence(dts, prob, Rodas4(), dense_errors = true) - @test sim.𝒪est[:final]≈4 atol=testTol - @test sim.𝒪est[:L2]≈4 atol=testTol - - sol = solve(prob, Rodas4()) - @test length(sol) < 20 - - println("Rodas4 with finite diff") - - sim = test_convergence(dts, prob, Rodas4(autodiff = false), dense_errors = true) - @test sim.𝒪est[:final]≈4 atol=testTol - @test sim.𝒪est[:L2]≈4 atol=testTol - - sol = solve(prob, Rodas4(autodiff = false)) - @test length(sol) < 20 - - sim = test_convergence(dts, prob, Rodas4(autodiff = false, - diff_type = Val{:forward}), - dense_errors = true) - @test sim.𝒪est[:final]≈4 atol=testTol - @test sim.𝒪est[:L2]≈4 atol=testTol - - sol = solve(prob, Rodas4(autodiff = false, diff_type = Val{:forward})) - @test length(sol) < 20 - - sim = test_convergence(dts, prob, Rodas4(autodiff = false, - diff_type = Val{:complex}), - dense_errors = true) - @test sim.𝒪est[:final]≈4 atol=testTol - @test sim.𝒪est[:L2]≈4 atol=testTol - - sol = solve(prob, Rodas4(autodiff = false, diff_type = Val{:complex})) - @test length(sol) < 20 - - sim = test_convergence(dts, prob, Rodas42(), dense_errors = true) - @test sim.𝒪est[:final]≈5 atol=testTol - @test sim.𝒪est[:L2]≈4 atol=testTol - - sol = solve(prob, Rodas42()) - @test length(sol) < 20 - - sim = test_convergence(dts, prob, Rodas4P(), dense_errors = true) - @test sim.𝒪est[:final]≈4 atol=testTol - @test sim.𝒪est[:L2]≈4 atol=testTol - - sol = solve(prob, Rodas4P()) - @test length(sol) < 20 - - sim = test_convergence(dts, prob, Rodas4P2(), dense_errors = true) - @test sim.𝒪est[:final]≈4 atol=testTol - @test sim.𝒪est[:L2]≈4 atol=testTol - - sol = solve(prob, Rodas4P2()) - @test length(sol) < 20 - - println("Rodas4P2 with finite diff") - - sim = test_convergence(dts, prob, Rodas4P2(autodiff = false), dense_errors = true) - @test sim.𝒪est[:final]≈4 atol=testTol - @test sim.𝒪est[:L2]≈4 atol=testTol - - sol = solve(prob, Rodas4P2(autodiff = false)) - @test length(sol) < 20 - - ### Rodas5 - println("Rodas5") - - prob = prob_ode_linear - - dts = (1 / 2) .^ (6:-1:3) - sim = test_convergence(dts, prob, Rodas5(), dense_errors = true) - @test sim.𝒪est[:final]≈5 atol=testTol - @test sim.𝒪est[:L2]≈5 atol=testTol - - sol = solve(prob, Rodas5()) - @test length(sol) < 20 - - prob = prob_ode_2Dlinear - - sim = test_convergence(dts, prob, Rodas5(), dense_errors = true) - @test sim.𝒪est[:final]≈5 atol=testTol - @test sim.𝒪est[:L2]≈5 atol=testTol - - sol = solve(prob, Rodas5()) - @test length(sol) < 20 - - println("Rodas5P") - - prob = prob_ode_linear - - dts = (1 / 2) .^ (5:-1:2) - sim = test_convergence(dts, prob, Rodas5P(), dense_errors = true) - #@test sim.𝒪est[:final]≈5 atol=testTol #-- observed order > 6 - @test sim.𝒪est[:L2]≈5 atol=testTol - - sol = solve(prob, Rodas5P()) - @test length(sol) < 20 - - prob = prob_ode_2Dlinear - - sim = test_convergence(dts, prob, Rodas5P(), dense_errors = true) - #@test sim.𝒪est[:final]≈5 atol=testTol #-- observed order > 6 - @test sim.𝒪est[:L2]≈5 atol=testTol - - sol = solve(prob, Rodas5P()) - @test length(sol) < 20 - - println("Rodas5Pe") - - prob = prob_ode_linear - - sim = test_convergence(dts, prob, Rodas5Pe(), dense_errors = true) - #@test sim.𝒪est[:final]≈5 atol=testTol #-- observed order > 6 - @test sim.𝒪est[:L2]≈5 atol=testTol - - sol = solve(prob, Rodas5Pe()) - @test length(sol) < 20 - - prob = prob_ode_2Dlinear - - sim = test_convergence(dts, prob, Rodas5Pe(), dense_errors = true) - #@test sim.𝒪est[:final]≈5 atol=testTol #-- observed order > 6 - @test sim.𝒪est[:L2]≈5 atol=testTol - - sol = solve(prob, Rodas5Pe()) - @test length(sol) < 20 - - println("Rodas5Pr") - - prob = prob_ode_linear - - sim = test_convergence(dts, prob, Rodas5Pr(), dense_errors = true) - #@test sim.𝒪est[:final]≈5 atol=testTol #-- observed order > 6 - @test sim.𝒪est[:L2]≈5 atol=testTol - - sol = solve(prob, Rodas5Pr()) - @test length(sol) < 20 - - prob = prob_ode_2Dlinear - - sim = test_convergence(dts, prob, Rodas5Pr(), dense_errors = true) - #@test sim.𝒪est[:final]≈5 atol=testTol #-- observed order > 6 - @test sim.𝒪est[:L2]≈5 atol=testTol - - sol = solve(prob, Rodas5Pr()) - @test length(sol) < 20 - - prob = ODEProblem((u, p, t) -> 0.9u, 0.1, (0.0, 1.0)) - @test_nowarn solve(prob, Rosenbrock23(autodiff = false)) -end - -@testset "Convergence with time-dependent matrix-free Jacobian" begin - time_derivative(du, u, p, t) = (du[1] = t * u[1]) - time_derivative_analytic(u0, p, t) = u0 * exp(t^2 / 2) - ff_time_derivative = ODEFunction(time_derivative, analytic = time_derivative_analytic) - prob = ODEProblem(ff_time_derivative, [1.0], (0.0, 1.0)) - - dts = (1 / 2) .^ (6:-1:3) - testTol = 0.2 - # Check convergence of Rodas3 with time-dependent matrix-free Jacobian. - # Primarily to check that the Jacobian is being updated correctly as t changes. - sim = test_convergence(dts, prob, Rodas3(linsolve = LinearSolve.KrylovJL())) - @test sim.𝒪est[:final]≈3 atol=testTol -end From 5691c0ddc7f22d2a640c002cae0a02b188cfe3ea Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Fri, 2 Aug 2024 19:54:15 +0530 Subject: [PATCH 055/133] Fixes --- lib/OrdinaryDiffEqRosenbrock/src/alg_utils.jl | 8 ++++++++ src/alg_utils.jl | 8 -------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/OrdinaryDiffEqRosenbrock/src/alg_utils.jl b/lib/OrdinaryDiffEqRosenbrock/src/alg_utils.jl index 115f6ab893..95f0b1efd8 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/alg_utils.jl @@ -40,6 +40,14 @@ alg_adaptive_order(alg::Rosenbrock23) = 3 isWmethod(alg::Rodas23W) = true isWmethod(alg::Rosenbrock23) = true isWmethod(alg::Rosenbrock32) = true +isWmethod(alg::ROS2S) = true +isWmethod(alg::ROS34PW1a) = true +isWmethod(alg::ROS34PW1b) = true +isWmethod(alg::ROS34PW2) = true +isWmethod(alg::ROS34PW3) = true +isWmethod(alg::ROS34PRw) = true +isWmethod(alg::ROK4a) = true +isWmethod(alg::RosenbrockW6S4OS) = true isfsal(alg::Rodas3P) = false isfsal(alg::Rodas23W) = false diff --git a/src/alg_utils.jl b/src/alg_utils.jl index be7130006c..af6b6823f9 100644 --- a/src/alg_utils.jl +++ b/src/alg_utils.jl @@ -528,14 +528,6 @@ isstandard(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm}) = false isstandard(alg::OrdinaryDiffEqNewtonAdaptiveAlgorithm) = alg.controller === :Standard isWmethod(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm}) = false -isWmethod(alg::ROS2S) = true -isWmethod(alg::ROS34PW1a) = true -isWmethod(alg::ROS34PW1b) = true -isWmethod(alg::ROS34PW2) = true -isWmethod(alg::ROS34PW3) = true -isWmethod(alg::ROS34PRw) = true -isWmethod(alg::ROK4a) = true -isWmethod(alg::RosenbrockW6S4OS) = true isesdirk(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm}) = false From 2ad25d1280e8ab55bad34966bc3391746d768bf1 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Fri, 2 Aug 2024 20:10:38 +0530 Subject: [PATCH 056/133] Fixes and added Explicit RK solvers --- lib/OrdinaryDiffEqExplicitRK/Project.toml | 4 ++ .../src/OrdinaryDiffEqExplicitRK.jl | 14 +++++ lib/OrdinaryDiffEqExplicitRK/src/alg_utils.jl | 5 ++ .../src/algorithms.jl | 8 +++ .../src/explicit_rk_caches.jl | 60 ++++++++++++++++++ .../src}/explicit_rk_perform_step.jl | 2 +- .../src/integrator_interface.jl | 8 +++ src/OrdinaryDiffEq.jl | 6 +- src/alg_utils.jl | 6 -- src/algorithms.jl | 9 --- src/caches/basic_caches.jl | 61 ------------------- src/integrators/integrator_interface.jl | 9 --- 12 files changed, 105 insertions(+), 87 deletions(-) create mode 100644 lib/OrdinaryDiffEqExplicitRK/Project.toml create mode 100644 lib/OrdinaryDiffEqExplicitRK/src/OrdinaryDiffEqExplicitRK.jl create mode 100644 lib/OrdinaryDiffEqExplicitRK/src/alg_utils.jl create mode 100644 lib/OrdinaryDiffEqExplicitRK/src/algorithms.jl create mode 100644 lib/OrdinaryDiffEqExplicitRK/src/explicit_rk_caches.jl rename {src/perform_step => lib/OrdinaryDiffEqExplicitRK/src}/explicit_rk_perform_step.jl (99%) create mode 100644 lib/OrdinaryDiffEqRosenbrock/src/integrator_interface.jl diff --git a/lib/OrdinaryDiffEqExplicitRK/Project.toml b/lib/OrdinaryDiffEqExplicitRK/Project.toml new file mode 100644 index 0000000000..dc14bcda8f --- /dev/null +++ b/lib/OrdinaryDiffEqExplicitRK/Project.toml @@ -0,0 +1,4 @@ +name = "OrdinaryDiffEqExplicitRK" +uuid = "9286f039-9fbf-40e8-bf65-aa933bdc4db0" +authors = ["ParamThakkar123 "] +version = "0.1.0" diff --git a/lib/OrdinaryDiffEqExplicitRK/src/OrdinaryDiffEqExplicitRK.jl b/lib/OrdinaryDiffEqExplicitRK/src/OrdinaryDiffEqExplicitRK.jl new file mode 100644 index 0000000000..fe5b987f09 --- /dev/null +++ b/lib/OrdinaryDiffEqExplicitRK/src/OrdinaryDiffEqExplicitRK.jl @@ -0,0 +1,14 @@ +module OrdinaryDiffEqExplicitRK + +import OrdinaryDiffEq: alg_order, alg_adaptive_order, alg_stability_size, OrdinaryDiffEqAdaptiveAlgorithm, + @cache, alg_cache, OrdinaryDiffEqConstantCache, @unpack, unwrap_alg +using TruncatedStacktraces, RecursiveArrayTools, FastBroadcast, MuladdMacro + +include("algorithms.jl") +include("alg_utils.jl") +include("explicit_rk_caches.jl") +include("explicit_rk_perform_step.jl") + +export ExplicitRK + +end diff --git a/lib/OrdinaryDiffEqExplicitRK/src/alg_utils.jl b/lib/OrdinaryDiffEqExplicitRK/src/alg_utils.jl new file mode 100644 index 0000000000..68bbcafa56 --- /dev/null +++ b/lib/OrdinaryDiffEqExplicitRK/src/alg_utils.jl @@ -0,0 +1,5 @@ +alg_order(alg::ExplicitRK) = alg.tableau.order + +alg_adaptive_order(alg::ExplicitRK) = alg.tableau.adaptiveorder + +alg_stability_size(alg::ExplicitRK) = alg.tableau.stability_size \ No newline at end of file diff --git a/lib/OrdinaryDiffEqExplicitRK/src/algorithms.jl b/lib/OrdinaryDiffEqExplicitRK/src/algorithms.jl new file mode 100644 index 0000000000..b36e517713 --- /dev/null +++ b/lib/OrdinaryDiffEqExplicitRK/src/algorithms.jl @@ -0,0 +1,8 @@ +# RK methods + +struct ExplicitRK{TabType} <: OrdinaryDiffEqAdaptiveAlgorithm + tableau::TabType +end +ExplicitRK(; tableau = ODE_DEFAULT_TABLEAU) = ExplicitRK(tableau) + +TruncatedStacktraces.@truncate_stacktrace ExplicitRK \ No newline at end of file diff --git a/lib/OrdinaryDiffEqExplicitRK/src/explicit_rk_caches.jl b/lib/OrdinaryDiffEqExplicitRK/src/explicit_rk_caches.jl new file mode 100644 index 0000000000..f2234f843c --- /dev/null +++ b/lib/OrdinaryDiffEqExplicitRK/src/explicit_rk_caches.jl @@ -0,0 +1,60 @@ +@cache struct ExplicitRKCache{uType, rateType, uNoUnitsType, TabType} <: + OrdinaryDiffEqMutableCache + u::uType + uprev::uType + tmp::uType + utilde::rateType + atmp::uNoUnitsType + fsalfirst::rateType + fsallast::rateType + kk::Vector{rateType} + tab::TabType +end + +TruncatedStacktraces.@truncate_stacktrace ExplicitRKCache 1 + +function alg_cache(alg::ExplicitRK, u, rate_prototype, ::Type{uEltypeNoUnits}, + ::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t, + dt, reltol, p, calck, + ::Val{true}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits} + kk = Vector{typeof(rate_prototype)}(undef, 0) + for i in 1:(alg.tableau.stages) + push!(kk, zero(rate_prototype)) + end + fsalfirst = kk[1] + if isfsal(alg.tableau) + fsallast = kk[end] + else + fsallast = zero(rate_prototype) + end + utilde = zero(rate_prototype) + tmp = zero(u) + atmp = similar(u, uEltypeNoUnits) + recursivefill!(atmp, false) + tab = ExplicitRKConstantCache(alg.tableau, rate_prototype) + ExplicitRKCache(u, uprev, tmp, utilde, atmp, fsalfirst, fsallast, kk, tab) +end + +struct ExplicitRKConstantCache{MType, VType, KType} <: OrdinaryDiffEqConstantCache + A::MType + c::VType + α::VType + αEEst::VType + stages::Int + kk::KType +end + +function ExplicitRKConstantCache(tableau, rate_prototype) + @unpack A, c, α, αEEst, stages = tableau + A = copy(A') # Transpose A to column major looping + kk = Array{typeof(rate_prototype)}(undef, stages) # Not ks since that's for integrator.opts.dense + αEEst = isempty(αEEst) ? αEEst : α .- αEEst + ExplicitRKConstantCache(A, c, α, αEEst, stages, kk) +end + +function alg_cache(alg::ExplicitRK, u, rate_prototype, ::Type{uEltypeNoUnits}, + ::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t, + dt, reltol, p, calck, + ::Val{false}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits} + ExplicitRKConstantCache(alg.tableau, rate_prototype) +end \ No newline at end of file diff --git a/src/perform_step/explicit_rk_perform_step.jl b/lib/OrdinaryDiffEqExplicitRK/src/explicit_rk_perform_step.jl similarity index 99% rename from src/perform_step/explicit_rk_perform_step.jl rename to lib/OrdinaryDiffEqExplicitRK/src/explicit_rk_perform_step.jl index 08ddee112a..94ea9e4856 100644 --- a/src/perform_step/explicit_rk_perform_step.jl +++ b/lib/OrdinaryDiffEqExplicitRK/src/explicit_rk_perform_step.jl @@ -237,4 +237,4 @@ end f(integrator.fsallast, u, p, t + dt) integrator.stats.nf += 1 end -end +end \ No newline at end of file diff --git a/lib/OrdinaryDiffEqRosenbrock/src/integrator_interface.jl b/lib/OrdinaryDiffEqRosenbrock/src/integrator_interface.jl new file mode 100644 index 0000000000..8b463e5a06 --- /dev/null +++ b/lib/OrdinaryDiffEqRosenbrock/src/integrator_interface.jl @@ -0,0 +1,8 @@ +function resize_non_user_cache!(integrator::ODEIntegrator, + cache::RosenbrockMutableCache, i) + cache.J = similar(cache.J, i, i) + cache.W = similar(cache.W, i, i) + resize_jac_config!(cache.jac_config, i) + resize_grad_config!(cache.grad_config, i) + nothing +end \ No newline at end of file diff --git a/src/OrdinaryDiffEq.jl b/src/OrdinaryDiffEq.jl index 2d360e1d7f..72766d9754 100644 --- a/src/OrdinaryDiffEq.jl +++ b/src/OrdinaryDiffEq.jl @@ -305,6 +305,10 @@ export Rosenbrock23, Rosenbrock32, RosShamp4, Veldd4, Velds4, GRK4T, GRK4A, ROS3PRL2, ROK4a, ROS2, ROS2PR, ROS2S, ROS3, ROS3PR, Scholz4_7 +include("../lib/OrdinaryDiffEqExplicitRK/src/OrdinaryDiffEqExplicitRK.jl") +using ..OrdinaryDiffEqExplicitRK +export ExplicitRK + include("dense/generic_dense.jl") include("solve.jl") @@ -436,7 +440,7 @@ export constructDormandPrince # Reexport the Alg Types -export ExplicitRK, CompositeAlgorithm +export CompositeAlgorithm export MagnusMidpoint, LinearExponential, MagnusLeapfrog, LieEuler, CayleyEuler, MagnusGauss4, MagnusNC6, MagnusGL6, MagnusGL8, MagnusNC8, MagnusGL4, diff --git a/src/alg_utils.jl b/src/alg_utils.jl index af6b6823f9..7284dfe0b8 100644 --- a/src/alg_utils.jl +++ b/src/alg_utils.jl @@ -373,8 +373,6 @@ alg_order(alg::ETD2) = 2 alg_order(alg::Exprb32) = 3 alg_order(alg::Exprb43) = 4 -alg_order(alg::ExplicitRK) = alg.tableau.order - alg_order(alg::RKMK2) = 2 alg_order(alg::RKMK4) = 4 alg_order(alg::LieRK4) = 4 @@ -398,7 +396,6 @@ alg_order(alg::CNLF2) = 2 alg_maximum_order(alg) = alg_order(alg) alg_maximum_order(alg::CompositeAlgorithm) = maximum(alg_order(x) for x in alg.algs) -alg_adaptive_order(alg::ExplicitRK) = alg.tableau.adaptiveorder alg_adaptive_order(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm}) = alg_order(alg) - 1 # this is actually incorrect and is purposefully decreased as this tends @@ -464,9 +461,6 @@ ssp_coefficient(alg) = error("$alg is not a strong stability preserving method." # We shouldn't do this probably. #ssp_coefficient(alg::ImplicitEuler) = Inf -# stability regions -alg_stability_size(alg::ExplicitRK) = alg.tableau.stability_size - alg_can_repeat_jac(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm}) = false alg_can_repeat_jac(alg::OrdinaryDiffEqNewtonAdaptiveAlgorithm) = true diff --git a/src/algorithms.jl b/src/algorithms.jl index c8c25658fd..83a1dda4d2 100644 --- a/src/algorithms.jl +++ b/src/algorithms.jl @@ -68,15 +68,6 @@ end ############################################################################### -# RK methods - -struct ExplicitRK{TabType} <: OrdinaryDiffEqAdaptiveAlgorithm - tableau::TabType -end -ExplicitRK(; tableau = ODE_DEFAULT_TABLEAU) = ExplicitRK(tableau) - -TruncatedStacktraces.@truncate_stacktrace ExplicitRK - ################################################################################ @inline trivial_limiter!(u, integrator, p, t) = nothing diff --git a/src/caches/basic_caches.jl b/src/caches/basic_caches.jl index c6e4757ba5..1609b03fac 100644 --- a/src/caches/basic_caches.jl +++ b/src/caches/basic_caches.jl @@ -100,66 +100,5 @@ end alg_cache(alg::OrdinaryDiffEqAlgorithm, prob, callback::F) where {F} = ODEEmptyCache() -@cache struct ExplicitRKCache{uType, rateType, uNoUnitsType, TabType} <: - OrdinaryDiffEqMutableCache - u::uType - uprev::uType - tmp::uType - utilde::rateType - atmp::uNoUnitsType - fsalfirst::rateType - fsallast::rateType - kk::Vector{rateType} - tab::TabType -end - -TruncatedStacktraces.@truncate_stacktrace ExplicitRKCache 1 - -function alg_cache(alg::ExplicitRK, u, rate_prototype, ::Type{uEltypeNoUnits}, - ::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t, - dt, reltol, p, calck, - ::Val{true}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits} - kk = Vector{typeof(rate_prototype)}(undef, 0) - for i in 1:(alg.tableau.stages) - push!(kk, zero(rate_prototype)) - end - fsalfirst = kk[1] - if isfsal(alg.tableau) - fsallast = kk[end] - else - fsallast = zero(rate_prototype) - end - utilde = zero(rate_prototype) - tmp = zero(u) - atmp = similar(u, uEltypeNoUnits) - recursivefill!(atmp, false) - tab = ExplicitRKConstantCache(alg.tableau, rate_prototype) - ExplicitRKCache(u, uprev, tmp, utilde, atmp, fsalfirst, fsallast, kk, tab) -end - -struct ExplicitRKConstantCache{MType, VType, KType} <: OrdinaryDiffEqConstantCache - A::MType - c::VType - α::VType - αEEst::VType - stages::Int - kk::KType -end - -function ExplicitRKConstantCache(tableau, rate_prototype) - @unpack A, c, α, αEEst, stages = tableau - A = copy(A') # Transpose A to column major looping - kk = Array{typeof(rate_prototype)}(undef, stages) # Not ks since that's for integrator.opts.dense - αEEst = isempty(αEEst) ? αEEst : α .- αEEst - ExplicitRKConstantCache(A, c, α, αEEst, stages, kk) -end - -function alg_cache(alg::ExplicitRK, u, rate_prototype, ::Type{uEltypeNoUnits}, - ::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t, - dt, reltol, p, calck, - ::Val{false}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits} - ExplicitRKConstantCache(alg.tableau, rate_prototype) -end - get_chunksize(cache::DiffEqBase.DECache) = error("This cache does not have a chunksize.") get_chunksize(cache::ODEChunkCache{CS}) where {CS} = CS diff --git a/src/integrators/integrator_interface.jl b/src/integrators/integrator_interface.jl index b2223d419e..c5716b7e02 100644 --- a/src/integrators/integrator_interface.jl +++ b/src/integrators/integrator_interface.jl @@ -298,15 +298,6 @@ function addat_non_user_cache!(integrator::ODEIntegrator, cache::CompositeCache, end end -function resize_non_user_cache!(integrator::ODEIntegrator, - cache::RosenbrockMutableCache, i) - cache.J = similar(cache.J, i, i) - cache.W = similar(cache.W, i, i) - resize_jac_config!(cache.jac_config, i) - resize_grad_config!(cache.grad_config, i) - nothing -end - function deleteat_non_user_cache!(integrator::ODEIntegrator, cache, idxs) # ordering doesn't matter in deterministic cache, so just resize # to match the size of u From a4226ea67da16d4bdf1c95efb78886689821cc54 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Fri, 2 Aug 2024 20:11:59 +0530 Subject: [PATCH 057/133] fixes --- src/OrdinaryDiffEq.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/OrdinaryDiffEq.jl b/src/OrdinaryDiffEq.jl index 72766d9754..7a5bd87da7 100644 --- a/src/OrdinaryDiffEq.jl +++ b/src/OrdinaryDiffEq.jl @@ -162,7 +162,6 @@ include("wrappers.jl") include("perform_step/linear_perform_step.jl") include("perform_step/exponential_rk_perform_step.jl") -include("perform_step/explicit_rk_perform_step.jl") include("perform_step/imex_multistep_perform_step.jl") include("perform_step/composite_perform_step.jl") From 972426f4e853c61f1d89b7687f2d930915de93c4 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Fri, 2 Aug 2024 20:14:24 +0530 Subject: [PATCH 058/133] Updates --- lib/OrdinaryDiffEqRosenbrock/src/interp_func.jl | 9 +++++++++ src/interp_func.jl | 8 -------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/OrdinaryDiffEqRosenbrock/src/interp_func.jl b/lib/OrdinaryDiffEqRosenbrock/src/interp_func.jl index 5037e41991..790d7a2ad2 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/interp_func.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/interp_func.jl @@ -16,3 +16,12 @@ function DiffEqBase.interp_summary(::Type{cacheType}, dense ? "specialized 3rd order \"free\" stiffness-aware interpolation" : "1st order linear" end + +function DiffEqBase.interp_summary(::Type{cacheType}, + dense::Bool) where { + cacheType <: + Union{Rosenbrock5ConstantCache, + Rosenbrock5Cache}} + dense ? "specialized 4rd order \"free\" stiffness-aware interpolation" : + "1st order linear" +end \ No newline at end of file diff --git a/src/interp_func.jl b/src/interp_func.jl index 36609b69c7..8cc95ac156 100644 --- a/src/interp_func.jl +++ b/src/interp_func.jl @@ -30,14 +30,6 @@ function DiffEqBase.interp_summary(interp::OrdinaryDiffEqInterpolation{ } DiffEqBase.interp_summary(cacheType, interp.dense) end -function DiffEqBase.interp_summary(::Type{cacheType}, - dense::Bool) where { - cacheType <: - Union{Rosenbrock5ConstantCache, - Rosenbrock5Cache}} - dense ? "specialized 4rd order \"free\" stiffness-aware interpolation" : - "1st order linear" -end function DiffEqBase.interp_summary(::Type{cacheType}, dense::Bool) where {cacheType} dense ? "3rd order Hermite" : "1st order linear" end From 61732021c4bb62d98f8f32335ebcfdf9d42a04a3 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Fri, 2 Aug 2024 20:20:54 +0530 Subject: [PATCH 059/133] Update --- src/OrdinaryDiffEq.jl | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/OrdinaryDiffEq.jl b/src/OrdinaryDiffEq.jl index 7a5bd87da7..59a6cca68f 100644 --- a/src/OrdinaryDiffEq.jl +++ b/src/OrdinaryDiffEq.jl @@ -250,6 +250,15 @@ include("../lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl") using ..OrdinaryDiffEqTsit5 export Tsit5 +include("../lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl") +using ..OrdinaryDiffEqRosenbrock +export Rosenbrock23, Rosenbrock32, RosShamp4, Veldd4, Velds4, GRK4T, GRK4A, + Ros4LStab, ROS3P, Rodas3, Rodas23W, Rodas3P, Rodas4, Rodas42, Rodas4P, Rodas4P2, + Rodas5, Rodas5P, Rodas5Pe, Rodas5Pr, + RosenbrockW6S4OS, ROS34PW1a, ROS34PW1b, ROS34PW2, ROS34PW3, ROS34PRw, ROS3PRL, + ROS3PRL2, ROK4a, + ROS2, ROS2PR, ROS2S, ROS3, ROS3PR, Scholz4_7 + include("../lib/OrdinaryDiffEqDefault/src/OrdinaryDiffEqDefault.jl") using ..OrdinaryDiffEqDefault export DefaultODEAlgorithm @@ -295,15 +304,6 @@ include("../lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl") using ..OrdinaryDiffEqNordsieck export AN5, JVODE, JVODE_Adams, JVODE_BDF -include("../lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl") -using ..OrdinaryDiffEqRosenbrock -export Rosenbrock23, Rosenbrock32, RosShamp4, Veldd4, Velds4, GRK4T, GRK4A, - Ros4LStab, ROS3P, Rodas3, Rodas23W, Rodas3P, Rodas4, Rodas42, Rodas4P, Rodas4P2, - Rodas5, Rodas5P, Rodas5Pe, Rodas5Pr, - RosenbrockW6S4OS, ROS34PW1a, ROS34PW1b, ROS34PW2, ROS34PW3, ROS34PRw, ROS3PRL, - ROS3PRL2, ROK4a, - ROS2, ROS2PR, ROS2S, ROS3, ROS3PR, Scholz4_7 - include("../lib/OrdinaryDiffEqExplicitRK/src/OrdinaryDiffEqExplicitRK.jl") using ..OrdinaryDiffEqExplicitRK export ExplicitRK From 3f94372d98c949b49c600f6a153deb80742a531f Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Fri, 2 Aug 2024 11:34:55 -0400 Subject: [PATCH 060/133] Update src/OrdinaryDiffEq.jl --- src/OrdinaryDiffEq.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OrdinaryDiffEq.jl b/src/OrdinaryDiffEq.jl index 59a6cca68f..0d8eb6083a 100644 --- a/src/OrdinaryDiffEq.jl +++ b/src/OrdinaryDiffEq.jl @@ -169,6 +169,7 @@ include("derivative_utils.jl") include("derivative_wrappers.jl") include("iterator_interface.jl") include("constants.jl") +include("solve.jl") include("initdt.jl") include("interp_func.jl") From f51491eacda52d9ecf47b9c0cde4ce12d9e06bf8 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Fri, 2 Aug 2024 11:35:56 -0400 Subject: [PATCH 061/133] Update OrdinaryDiffEq.jl --- src/OrdinaryDiffEq.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/OrdinaryDiffEq.jl b/src/OrdinaryDiffEq.jl index 0d8eb6083a..c7dea91d49 100644 --- a/src/OrdinaryDiffEq.jl +++ b/src/OrdinaryDiffEq.jl @@ -165,6 +165,8 @@ include("perform_step/exponential_rk_perform_step.jl") include("perform_step/imex_multistep_perform_step.jl") include("perform_step/composite_perform_step.jl") +include("dense/generic_dense.jl") + include("derivative_utils.jl") include("derivative_wrappers.jl") include("iterator_interface.jl") From de8e503f726b999ca171c8b588f04d35461d9b6a Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Fri, 2 Aug 2024 12:16:31 -0400 Subject: [PATCH 062/133] Update lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl --- lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl index f07ab9e2d9..f2453d684b 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl @@ -4,8 +4,8 @@ import OrdinaryDiffEq: alg_order, alg_adaptive_order, isWmethod, isfsal, _unwrap DEFAULT_PRECS, OrdinaryDiffEqRosenbrockAlgorithm, @cache, alg_cache, initialize!, @unpack, calc_W, calculate_residuals!, calc_rosenbrock_differentiation!, OrdinaryDiffEqMutableCache, build_J_W, UJacobianWrapper, OrdinaryDiffEqConstantCache, _ode_interpolant, _ode_interpolant!, - _vec, _reshape, perform_step! -using TruncatedStacktraces, MuladdMacro, FastBroadcast, DiffEqBase, RecursiveArrayTools, step_limiter!, dolinsolve + _vec, _reshape, perform_step!, trivial_limiter!, dolinsolve +using TruncatedStacktraces, MuladdMacro, FastBroadcast, DiffEqBase, RecursiveArrayTools, import DiffEqBase: @def import LinearAlgebra: mul! From 65e5459356b0f2f200cb7afb49ff34250b0f76ed Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Fri, 2 Aug 2024 22:07:22 +0530 Subject: [PATCH 063/133] Updates --- test/runtests.jl | 58 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 320a3ab061..347ee51c93 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -83,8 +83,62 @@ function activate_dae() Pkg.instantiate() end -function activate_dae() - Pkg.activate("../lib/OrdinaryDiffEqDAE") +function activate_bdf() + Pkg.activate("../lib/OrdinaryDiffEqBDF") + Pkg.develop(PackageSpec(path = dirname(@__DIR__))) + Pkg.instantiate() +end + +function activate_nordsieck() + Pkg.activate("../lib/OrdinaryDiffEqNordsieck") + Pkg.develop(PackageSpec(path = dirname(@__DIR__))) + Pkg.instantiate() +end + +function activate_explicit_rk() + Pkg.activate("../lib/OrdinaryDiffEqExplicitRK") + Pkg.develop(PackageSpec(path = dirname(@__DIR__))) + Pkg.instantiate() +end + +function activate_rosenbrock() + Pkg.activate("../lib/OrdinaryDiffEqRosenbrock") + Pkg.develop(PackageSpec(path = dirname(@__DIR__))) + Pkg.instantiate() +end + +function activate_functionmap() + Pkg.activate("../lib/OrdinaryDiffEqFunctionMap") + Pkg.develop(PackageSpec(path = dirname(@__DIR__))) + Pkg.instantiate() +end + +function activate_high_order__rk() + Pkg.activate("../lib/OrdinaryDiffEqHighOrderRK") + Pkg.develop(PackageSpec(path = dirname(@__DIR__))) + Pkg.instantiate() +end + +function activate_low_order_rk() + Pkg.activate("../lib/OrdinaryDiffEqLowOrderRK") + Pkg.develop(PackageSpec(path = dirname(@__DIR__))) + Pkg.instantiate() +end + +function activate_firk() + Pkg.activate("../lib/OrdinaryDiffEqFIRK") + Pkg.develop(PackageSpec(path = dirname(@__DIR__))) + Pkg.instantiate() +end + +function activate_pdirk() + Pkg.activate("../lib/OrdinaryDiffEqPDIRK") + Pkg.develop(PackageSpec(path = dirname(@__DIR__))) + Pkg.instantiate() +end + +function activate_adams_bashforth_moulton() + Pkg.activate("../lib/OrdinaryDiffEqAdamsBashforthMoulton") Pkg.develop(PackageSpec(path = dirname(@__DIR__))) Pkg.instantiate() end From 72cfebbc5700f7d46e312f0cbc3f3efb90a45440 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Fri, 2 Aug 2024 22:10:51 +0530 Subject: [PATCH 064/133] fixes --- lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl index f2453d684b..28787ced49 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl @@ -5,7 +5,7 @@ import OrdinaryDiffEq: alg_order, alg_adaptive_order, isWmethod, isfsal, _unwrap calc_W, calculate_residuals!, calc_rosenbrock_differentiation!, OrdinaryDiffEqMutableCache, build_J_W, UJacobianWrapper, OrdinaryDiffEqConstantCache, _ode_interpolant, _ode_interpolant!, _vec, _reshape, perform_step!, trivial_limiter!, dolinsolve -using TruncatedStacktraces, MuladdMacro, FastBroadcast, DiffEqBase, RecursiveArrayTools, +using TruncatedStacktraces, MuladdMacro, FastBroadcast, DiffEqBase, RecursiveArrayTools import DiffEqBase: @def import LinearAlgebra: mul! From 2c022ad25ab4896c4182cc226c2a39d86db403c9 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Fri, 2 Aug 2024 22:14:21 +0530 Subject: [PATCH 065/133] OrdinaryDiffEqRosenbrockAlgorithm --- lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl index 28787ced49..a48f6f3948 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl @@ -4,7 +4,8 @@ import OrdinaryDiffEq: alg_order, alg_adaptive_order, isWmethod, isfsal, _unwrap DEFAULT_PRECS, OrdinaryDiffEqRosenbrockAlgorithm, @cache, alg_cache, initialize!, @unpack, calc_W, calculate_residuals!, calc_rosenbrock_differentiation!, OrdinaryDiffEqMutableCache, build_J_W, UJacobianWrapper, OrdinaryDiffEqConstantCache, _ode_interpolant, _ode_interpolant!, - _vec, _reshape, perform_step!, trivial_limiter!, dolinsolve + _vec, _reshape, perform_step!, trivial_limiter!, dolinsolve, OrdinaryDiffEqRosenbrockAdaptiveAlgorithm, + OrdinaryDiffEqRosenbrockAlgorithm using TruncatedStacktraces, MuladdMacro, FastBroadcast, DiffEqBase, RecursiveArrayTools import DiffEqBase: @def import LinearAlgebra: mul! From 6529ee1adf88f124022159b520608cc65fef6356 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Fri, 2 Aug 2024 22:18:35 +0530 Subject: [PATCH 066/133] @ROS2 --- lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl index a48f6f3948..f312fe8df8 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl @@ -12,9 +12,9 @@ import LinearAlgebra: mul! include("algorithms.jl") include("alg_utils.jl") +include("generic_rosenbrock.jl") include("rosenbrock_caches.jl") include("rosenbrock_tableaus.jl") -include("generic_rosenbrock.jl") include("interp_func.jl") include("rosenbrock_interpolants.jl") include("stiff_addsteps.jl") From 26f4067c3aa02971c4ebd092234a3f7b7e38f30d Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Fri, 2 Aug 2024 22:23:54 +0530 Subject: [PATCH 067/133] @capture --- lib/OrdinaryDiffEqRosenbrock/Project.toml | 1 + lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/OrdinaryDiffEqRosenbrock/Project.toml b/lib/OrdinaryDiffEqRosenbrock/Project.toml index 697a579868..7ff5835b3b 100644 --- a/lib/OrdinaryDiffEqRosenbrock/Project.toml +++ b/lib/OrdinaryDiffEqRosenbrock/Project.toml @@ -11,6 +11,7 @@ Polyester = "f517fe37-dbe3-4b94-8317-1923a5111588" RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd" Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3" DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" +MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" [compat] julia = "1.10" diff --git a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl index f312fe8df8..5900af18c6 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl @@ -7,6 +7,7 @@ import OrdinaryDiffEq: alg_order, alg_adaptive_order, isWmethod, isfsal, _unwrap _vec, _reshape, perform_step!, trivial_limiter!, dolinsolve, OrdinaryDiffEqRosenbrockAdaptiveAlgorithm, OrdinaryDiffEqRosenbrockAlgorithm using TruncatedStacktraces, MuladdMacro, FastBroadcast, DiffEqBase, RecursiveArrayTools +import MacroTools: @capture import DiffEqBase: @def import LinearAlgebra: mul! From f8dbed21ab3fea7c01a293485d941c8c2fb1dbc2 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Fri, 2 Aug 2024 20:32:54 -0400 Subject: [PATCH 068/133] a bunch of fixes --- .../src/OrdinaryDiffEqExplicitRK.jl | 3 +- .../src/algorithms.jl | 1 - .../src/OrdinaryDiffEqNordsieck.jl | 2 +- .../src/OrdinaryDiffEqRosenbrock.jl | 73 +++++++++++++++++-- .../src/OrdinaryDiffEqTsit5.jl | 6 +- src/OrdinaryDiffEq.jl | 3 - src/alg_utils.jl | 2 + src/doc_utils.jl | 64 ---------------- 8 files changed, 77 insertions(+), 77 deletions(-) diff --git a/lib/OrdinaryDiffEqExplicitRK/src/OrdinaryDiffEqExplicitRK.jl b/lib/OrdinaryDiffEqExplicitRK/src/OrdinaryDiffEqExplicitRK.jl index fe5b987f09..d4f86ed00c 100644 --- a/lib/OrdinaryDiffEqExplicitRK/src/OrdinaryDiffEqExplicitRK.jl +++ b/lib/OrdinaryDiffEqExplicitRK/src/OrdinaryDiffEqExplicitRK.jl @@ -1,7 +1,8 @@ module OrdinaryDiffEqExplicitRK import OrdinaryDiffEq: alg_order, alg_adaptive_order, alg_stability_size, OrdinaryDiffEqAdaptiveAlgorithm, - @cache, alg_cache, OrdinaryDiffEqConstantCache, @unpack, unwrap_alg + @cache, alg_cache, OrdinaryDiffEqConstantCache, @unpack, unwrap_alg, + OrdinaryDiffEqMutableCache, initialize!, perform_step! using TruncatedStacktraces, RecursiveArrayTools, FastBroadcast, MuladdMacro include("algorithms.jl") diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/algorithms.jl b/lib/OrdinaryDiffEqLowOrderRK/src/algorithms.jl index 8eaeed7d66..72fd423186 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/algorithms.jl @@ -389,7 +389,6 @@ function Stepanov5(stage_limiter!, step_limiter! = trivial_limiter!) Stepanov5(stage_limiter!, step_limiter!, False()) end -@inline trivial_limiter!(u, integrator, p, t) = nothing """ SIR54(; stage_limiter! = OrdinaryDiffEq.trivial_limiter!, step_limiter! = OrdinaryDiffEq.trivial_limiter!, diff --git a/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl b/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl index 42f3568d39..105fb19717 100644 --- a/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl +++ b/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl @@ -3,7 +3,7 @@ module OrdinaryDiffEqNordsieck import OrdinaryDiffEq: alg_order, alg_adaptive_order, qsteady_max_default, get_current_alg_order, AbstractController, OrdinaryDiffEqAdaptiveAlgorithm, OrdinaryDiffEqAdamsVarOrderVarStepAlgorithm, alg_cache, OrdinaryDiffEqMutableCache, OrdinaryDiffEqConstantCache, initialize!, @unpack, - perform_step!, stepsize_controller!, step_accept_controller!, step_reject_controller!, + initialize!, perform_step!, stepsize_controller!, step_accept_controller!, step_reject_controller!, calculate_residuals, calculate_residuals! using MuladdMacro, FastBroadcast, RecursiveArrayTools diff --git a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl index 5900af18c6..86849a419a 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl @@ -1,15 +1,78 @@ module OrdinaryDiffEqRosenbrock -import OrdinaryDiffEq: alg_order, alg_adaptive_order, isWmethod, isfsal, _unwrap_val, rosenbrock_wanner_docstring, +import OrdinaryDiffEq: alg_order, alg_adaptive_order, isWmethod, isfsal, _unwrap_val, DEFAULT_PRECS, OrdinaryDiffEqRosenbrockAlgorithm, @cache, alg_cache, initialize!, @unpack, calc_W, calculate_residuals!, calc_rosenbrock_differentiation!, OrdinaryDiffEqMutableCache, build_J_W, UJacobianWrapper, OrdinaryDiffEqConstantCache, _ode_interpolant, _ode_interpolant!, _vec, _reshape, perform_step!, trivial_limiter!, dolinsolve, OrdinaryDiffEqRosenbrockAdaptiveAlgorithm, - OrdinaryDiffEqRosenbrockAlgorithm + OrdinaryDiffEqRosenbrockAlgorithm, generic_solver_docstring, namify, initialize!, perform_step! using TruncatedStacktraces, MuladdMacro, FastBroadcast, DiffEqBase, RecursiveArrayTools -import MacroTools: @capture -import DiffEqBase: @def -import LinearAlgebra: mul! +import MacroTools +using MacroTools: @capture +using DiffEqBase: @def +using LinearAlgebra: mul!, diag, diagm + +function rosenbrock_wanner_docstring(description::String, + name::String; + references::String = "", + extra_keyword_description = "", + extra_keyword_default = "", + with_step_limiter = false) + keyword_default = """ + autodiff = Val{true}(), + concrete_jac = nothing, + linsolve = nothing, + precs = DEFAULT_PRECS, + """ * extra_keyword_default + + keyword_default_description = """ + - `autodiff`: boolean to control if the Jacobian should be computed via AD or not + - `concrete_jac`: function of the form `jac!(J, u, p, t)` + - `linsolve`: custom solver for the inner linear systems + - `precs`: custom preconditioner for the inner linear solver + """ * extra_keyword_description + + if with_step_limiter + keyword_default *= "step_limiter! = OrdinaryDiffEq.trivial_limiter!,\n" + keyword_default_description *= "- `step_limiter!`: function of the form `limiter!(u, integrator, p, t)`\n" + end + + generic_solver_docstring( + description, name, "Rosenbrock-Wanner Method. ", references, + keyword_default_description, keyword_default + ) +end + +function rosenbrock_docstring(description::String, + name::String; + references::String = "", + extra_keyword_description = "", + extra_keyword_default = "", + with_step_limiter = false) + keyword_default = """ + autodiff = Val{true}(), + concrete_jac = nothing, + linsolve = nothing, + precs = DEFAULT_PRECS, + """ * extra_keyword_default + + keyword_default_description = """ + - `autodiff`: boolean to control if the Jacobian should be computed via AD or not + - `concrete_jac`: function of the form `jac!(J, u, p, t)` + - `linsolve`: custom solver for the inner linear systems + - `precs`: custom preconditioner for the inner linear solver + """ * extra_keyword_description + + if with_step_limiter + keyword_default *= "step_limiter! = OrdinaryDiffEq.trivial_limiter!,\n" + keyword_default_description *= "- `step_limiter!`: function of the form `limiter!(u, integrator, p, t)`\n" + end + + generic_solver_docstring( + description, name, "Rosenbrock Method. ", references, + keyword_default_description, keyword_default + ) +end include("algorithms.jl") include("alg_utils.jl") diff --git a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl index d2272764bb..9ff0769ae7 100644 --- a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl +++ b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl @@ -5,11 +5,13 @@ import OrdinaryDiffEq: alg_order, alg_stability_size, explicit_rk_docstring, OrdinaryDiffEqConstantCache, @fold, trivial_limiter!, constvalue, @unpack, perform_step!, calculate_residuals, @cache, calculate_residuals!, _ode_interpolant, _ode_interpolant!, - CompiledFloats, @OnDemandTableauExtract + CompiledFloats, @OnDemandTableauExtract, initialize!, perform_step!, + CompositeAlgorithm import Static: False import MuladdMacro: @muladd import FastBroadcast: @.. -import RecursiveArrayTools: recursivefill! +import RecursiveArrayTools: recursivefill!, recursive_unitless_bottom_eltype +import LinearAlgebra: norm using DiffEqBase using TruncatedStacktraces diff --git a/src/OrdinaryDiffEq.jl b/src/OrdinaryDiffEq.jl index c7dea91d49..323b73bc1c 100644 --- a/src/OrdinaryDiffEq.jl +++ b/src/OrdinaryDiffEq.jl @@ -311,9 +311,6 @@ include("../lib/OrdinaryDiffEqExplicitRK/src/OrdinaryDiffEqExplicitRK.jl") using ..OrdinaryDiffEqExplicitRK export ExplicitRK -include("dense/generic_dense.jl") -include("solve.jl") - PrecompileTools.@compile_workload begin function lorenz(du, u, p, t) du[1] = 10.0(u[2] - u[1]) diff --git a/src/alg_utils.jl b/src/alg_utils.jl index 7284dfe0b8..0d9b7ca97b 100644 --- a/src/alg_utils.jl +++ b/src/alg_utils.jl @@ -36,6 +36,8 @@ dt_required(alg::LinearExponential) = false isdiscretealg(alg) = false +function alg_stability_size end + # evaluates f(t[i]) _eval_index(f::F, t::Tuple{A}, _) where {F, A} = f(t[1]) function _eval_index(f::F, t::Tuple{A, Vararg}, i) where {F, A} diff --git a/src/doc_utils.jl b/src/doc_utils.jl index e5b5681067..28c4fe64a0 100644 --- a/src/doc_utils.jl +++ b/src/doc_utils.jl @@ -54,37 +54,6 @@ function generic_solver_docstring(description::String, "## References\n" * references end -function rosenbrock_docstring(description::String, - name::String; - references::String = "", - extra_keyword_description = "", - extra_keyword_default = "", - with_step_limiter = false) - keyword_default = """ - autodiff = Val{true}(), - concrete_jac = nothing, - linsolve = nothing, - precs = DEFAULT_PRECS, - """ * extra_keyword_default - - keyword_default_description = """ - - `autodiff`: boolean to control if the Jacobian should be computed via AD or not - - `concrete_jac`: function of the form `jac!(J, u, p, t)` - - `linsolve`: custom solver for the inner linear systems - - `precs`: custom preconditioner for the inner linear solver - """ * extra_keyword_description - - if with_step_limiter - keyword_default *= "step_limiter! = OrdinaryDiffEq.trivial_limiter!,\n" - keyword_default_description *= "- `step_limiter!`: function of the form `limiter!(u, integrator, p, t)`\n" - end - - generic_solver_docstring( - description, name, "Rosenbrock Method. ", references, - keyword_default_description, keyword_default - ) -end - function explicit_rk_docstring(description::String, name::String; references::String = "", @@ -105,36 +74,3 @@ function explicit_rk_docstring(description::String, keyword_default_description, keyword_default ) end - -function rosenbrock_wanner_docstring(description::String, - name::String; - references::String = "", - extra_keyword_description = "", - extra_keyword_default = "", - with_step_limiter = false) - keyword_default = """ - autodiff = Val{true}(), - concrete_jac = nothing, - linsolve = nothing, - precs = DEFAULT_PRECS, - """ * extra_keyword_default - - keyword_default_description = """ - - `autodiff`: boolean to control if the Jacobian should be computed via AD or not - - `concrete_jac`: function of the form `jac!(J, u, p, t)` - - `linsolve`: custom solver for the inner linear systems - - `precs`: custom preconditioner for the inner linear solver - """ * extra_keyword_description - - if with_step_limiter - keyword_default *= "step_limiter! = OrdinaryDiffEq.trivial_limiter!,\n" - keyword_default_description *= "- `step_limiter!`: function of the form `limiter!(u, integrator, p, t)`\n" - end - - generic_solver_docstring( - description, name, "Rosenbrock-Wanner Method. ", references, - keyword_default_description, keyword_default - ) -end - -# TODO other classes From 3aaceb78e497b9c38e676951681efe74b831eb8f Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Fri, 2 Aug 2024 20:41:55 -0400 Subject: [PATCH 069/133] a few more imports --- .../src/OrdinaryDiffEqLowStorageRK.jl | 1 + lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqLowStorageRK/src/OrdinaryDiffEqLowStorageRK.jl b/lib/OrdinaryDiffEqLowStorageRK/src/OrdinaryDiffEqLowStorageRK.jl index 21b2b09ab5..870ef5fb3f 100644 --- a/lib/OrdinaryDiffEqLowStorageRK/src/OrdinaryDiffEqLowStorageRK.jl +++ b/lib/OrdinaryDiffEqLowStorageRK/src/OrdinaryDiffEqLowStorageRK.jl @@ -14,6 +14,7 @@ import OrdinaryDiffEq: alg_order, alg_adaptive_order, calculate_residuals!, using DiffEqBase, FastBroadcast, Polyester, MuladdMacro, RecursiveArrayTools import StaticArrays: SArray, MVector, SVector, @SVector, StaticArray, MMatrix, SA import Static: False +import RecursiveArrayTools: recursive_unitless_bottom_eltype include("algorithms.jl") include("alg_utils.jl") diff --git a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl index 86849a419a..99e0a5f166 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl @@ -5,7 +5,8 @@ import OrdinaryDiffEq: alg_order, alg_adaptive_order, isWmethod, isfsal, _unwrap calc_W, calculate_residuals!, calc_rosenbrock_differentiation!, OrdinaryDiffEqMutableCache, build_J_W, UJacobianWrapper, OrdinaryDiffEqConstantCache, _ode_interpolant, _ode_interpolant!, _vec, _reshape, perform_step!, trivial_limiter!, dolinsolve, OrdinaryDiffEqRosenbrockAdaptiveAlgorithm, - OrdinaryDiffEqRosenbrockAlgorithm, generic_solver_docstring, namify, initialize!, perform_step! + OrdinaryDiffEqRosenbrockAlgorithm, generic_solver_docstring, namify, initialize!, perform_step!, + constvalue, TimeDerivativeWrapper using TruncatedStacktraces, MuladdMacro, FastBroadcast, DiffEqBase, RecursiveArrayTools import MacroTools using MacroTools: @capture From 85e9653d74283aeb6d31822b46f1c1636596eeaa Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Fri, 2 Aug 2024 20:58:09 -0400 Subject: [PATCH 070/133] more imports --- lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl | 2 +- lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl index bd16c59db4..e6e879cd4a 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl @@ -10,7 +10,7 @@ import OrdinaryDiffEq: alg_order, isfsal, beta2_default, beta1_default, alg_stab using DiffEqBase, SciMLBase import MuladdMacro: @muladd import FastBroadcast: @.. -import RecursiveArrayTools: recursivefill! +import RecursiveArrayTools: recursivefill!, recursive_unitless_bottom_eltype import Static: False using DiffEqBase: @def, @tight_loop_macros diff --git a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl index 99e0a5f166..81c9771b6b 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl @@ -6,7 +6,7 @@ import OrdinaryDiffEq: alg_order, alg_adaptive_order, isWmethod, isfsal, _unwrap build_J_W, UJacobianWrapper, OrdinaryDiffEqConstantCache, _ode_interpolant, _ode_interpolant!, _vec, _reshape, perform_step!, trivial_limiter!, dolinsolve, OrdinaryDiffEqRosenbrockAdaptiveAlgorithm, OrdinaryDiffEqRosenbrockAlgorithm, generic_solver_docstring, namify, initialize!, perform_step!, - constvalue, TimeDerivativeWrapper + constvalue, TimeDerivativeWrapper, TimeGradientWrapper, UDerivativeWrapper, UJacobianWrapper using TruncatedStacktraces, MuladdMacro, FastBroadcast, DiffEqBase, RecursiveArrayTools import MacroTools using MacroTools: @capture From efc927984708705eda609c0304ed478d88810dbc Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Fri, 2 Aug 2024 21:09:05 -0400 Subject: [PATCH 071/133] some more imports --- lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl | 2 +- lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl index e6e879cd4a..9f4fe1e194 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl @@ -6,7 +6,7 @@ import OrdinaryDiffEq: alg_order, isfsal, beta2_default, beta1_default, alg_stab unwrap_alg, @unpack, initialize!, perform_step!, calculate_residuals, calculate_residuals!, _ode_addsteps!, @OnDemandTableauExtract, constvalue, OrdinaryDiffEqMutableCache, uses_uprev, OrdinaryDiffEqConstantCache, @fold, - @cache, CompiledFloats, alg_cache + @cache, CompiledFloats, alg_cache, CompositeAlgorithm, alg_autodiff using DiffEqBase, SciMLBase import MuladdMacro: @muladd import FastBroadcast: @.. diff --git a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl index 81c9771b6b..fa91145458 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl @@ -6,7 +6,8 @@ import OrdinaryDiffEq: alg_order, alg_adaptive_order, isWmethod, isfsal, _unwrap build_J_W, UJacobianWrapper, OrdinaryDiffEqConstantCache, _ode_interpolant, _ode_interpolant!, _vec, _reshape, perform_step!, trivial_limiter!, dolinsolve, OrdinaryDiffEqRosenbrockAdaptiveAlgorithm, OrdinaryDiffEqRosenbrockAlgorithm, generic_solver_docstring, namify, initialize!, perform_step!, - constvalue, TimeDerivativeWrapper, TimeGradientWrapper, UDerivativeWrapper, UJacobianWrapper + constvalue, TimeDerivativeWrapper, TimeGradientWrapper, UDerivativeWrapper, UJacobianWrapper, + wrapprecs, alg_autodiff using TruncatedStacktraces, MuladdMacro, FastBroadcast, DiffEqBase, RecursiveArrayTools import MacroTools using MacroTools: @capture From b61de1499df7df8e6616af7b7a6c36f1dec14be0 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Fri, 2 Aug 2024 21:19:22 -0400 Subject: [PATCH 072/133] add missing dep --- lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl index fa91145458..efa8a845d5 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl @@ -12,6 +12,7 @@ using TruncatedStacktraces, MuladdMacro, FastBroadcast, DiffEqBase, RecursiveArr import MacroTools using MacroTools: @capture using DiffEqBase: @def +import LinearSolve using LinearAlgebra: mul!, diag, diagm function rosenbrock_wanner_docstring(description::String, From e610400bf95f7eba7a815720cb84882d9cc1475a Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Fri, 2 Aug 2024 21:29:43 -0400 Subject: [PATCH 073/133] more --- lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl index efa8a845d5..5328e2b00a 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl @@ -7,7 +7,7 @@ import OrdinaryDiffEq: alg_order, alg_adaptive_order, isWmethod, isfsal, _unwrap _vec, _reshape, perform_step!, trivial_limiter!, dolinsolve, OrdinaryDiffEqRosenbrockAdaptiveAlgorithm, OrdinaryDiffEqRosenbrockAlgorithm, generic_solver_docstring, namify, initialize!, perform_step!, constvalue, TimeDerivativeWrapper, TimeGradientWrapper, UDerivativeWrapper, UJacobianWrapper, - wrapprecs, alg_autodiff + wrapprecs, alg_autodiff, calc_tderivative, build_grad_config using TruncatedStacktraces, MuladdMacro, FastBroadcast, DiffEqBase, RecursiveArrayTools import MacroTools using MacroTools: @capture From 02a3bda785d611f0d8ec3559cb9bec6a36a7fafc Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Fri, 2 Aug 2024 21:44:46 -0400 Subject: [PATCH 074/133] more --- lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl index 5328e2b00a..377d8490a6 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl @@ -7,7 +7,7 @@ import OrdinaryDiffEq: alg_order, alg_adaptive_order, isWmethod, isfsal, _unwrap _vec, _reshape, perform_step!, trivial_limiter!, dolinsolve, OrdinaryDiffEqRosenbrockAdaptiveAlgorithm, OrdinaryDiffEqRosenbrockAlgorithm, generic_solver_docstring, namify, initialize!, perform_step!, constvalue, TimeDerivativeWrapper, TimeGradientWrapper, UDerivativeWrapper, UJacobianWrapper, - wrapprecs, alg_autodiff, calc_tderivative, build_grad_config + wrapprecs, alg_autodiff, calc_tderivative, build_grad_config, build_jac_config using TruncatedStacktraces, MuladdMacro, FastBroadcast, DiffEqBase, RecursiveArrayTools import MacroTools using MacroTools: @capture From b35e28e4f8d6a8a9dfd8d88c3202aaf5214085fb Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Fri, 2 Aug 2024 22:00:19 -0400 Subject: [PATCH 075/133] more --- lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl index 377d8490a6..4beb61f27a 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl @@ -7,13 +7,14 @@ import OrdinaryDiffEq: alg_order, alg_adaptive_order, isWmethod, isfsal, _unwrap _vec, _reshape, perform_step!, trivial_limiter!, dolinsolve, OrdinaryDiffEqRosenbrockAdaptiveAlgorithm, OrdinaryDiffEqRosenbrockAlgorithm, generic_solver_docstring, namify, initialize!, perform_step!, constvalue, TimeDerivativeWrapper, TimeGradientWrapper, UDerivativeWrapper, UJacobianWrapper, - wrapprecs, alg_autodiff, calc_tderivative, build_grad_config, build_jac_config + wrapprecs, alg_autodiff, calc_tderivative, build_grad_config, build_jac_config, + issuccess_W using TruncatedStacktraces, MuladdMacro, FastBroadcast, DiffEqBase, RecursiveArrayTools import MacroTools using MacroTools: @capture using DiffEqBase: @def import LinearSolve -using LinearAlgebra: mul!, diag, diagm +using LinearAlgebra: mul!, diag, diagm, I function rosenbrock_wanner_docstring(description::String, name::String; From 09ee69760f3978fd1976ca8e328f721bab042647 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Fri, 2 Aug 2024 22:20:27 -0400 Subject: [PATCH 076/133] should be the last one --- lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl index 4beb61f27a..8e02b45481 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl @@ -8,7 +8,7 @@ import OrdinaryDiffEq: alg_order, alg_adaptive_order, isWmethod, isfsal, _unwrap OrdinaryDiffEqRosenbrockAlgorithm, generic_solver_docstring, namify, initialize!, perform_step!, constvalue, TimeDerivativeWrapper, TimeGradientWrapper, UDerivativeWrapper, UJacobianWrapper, wrapprecs, alg_autodiff, calc_tderivative, build_grad_config, build_jac_config, - issuccess_W + issuccess_W, calculate_residuals using TruncatedStacktraces, MuladdMacro, FastBroadcast, DiffEqBase, RecursiveArrayTools import MacroTools using MacroTools: @capture From e06f6e52117167c531f1e405e606abaf5dab76f2 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Fri, 2 Aug 2024 22:51:23 -0400 Subject: [PATCH 077/133] more imports --- lib/OrdinaryDiffEqExplicitRK/src/OrdinaryDiffEqExplicitRK.jl | 2 +- lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqExplicitRK/src/OrdinaryDiffEqExplicitRK.jl b/lib/OrdinaryDiffEqExplicitRK/src/OrdinaryDiffEqExplicitRK.jl index d4f86ed00c..50fe72b07a 100644 --- a/lib/OrdinaryDiffEqExplicitRK/src/OrdinaryDiffEqExplicitRK.jl +++ b/lib/OrdinaryDiffEqExplicitRK/src/OrdinaryDiffEqExplicitRK.jl @@ -2,7 +2,7 @@ module OrdinaryDiffEqExplicitRK import OrdinaryDiffEq: alg_order, alg_adaptive_order, alg_stability_size, OrdinaryDiffEqAdaptiveAlgorithm, @cache, alg_cache, OrdinaryDiffEqConstantCache, @unpack, unwrap_alg, - OrdinaryDiffEqMutableCache, initialize!, perform_step! + OrdinaryDiffEqMutableCache, initialize!, perform_step!, isfsal using TruncatedStacktraces, RecursiveArrayTools, FastBroadcast, MuladdMacro include("algorithms.jl") diff --git a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl index 8e02b45481..78115f637d 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl @@ -14,6 +14,7 @@ import MacroTools using MacroTools: @capture using DiffEqBase: @def import LinearSolve +import ForwardDiff using LinearAlgebra: mul!, diag, diagm, I function rosenbrock_wanner_docstring(description::String, From 00897fe9d251312c09ac87ad4dff14b54b780d8e Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Fri, 2 Aug 2024 23:23:03 -0400 Subject: [PATCH 078/133] next tests... --- .../src/OrdinaryDiffEqExplicitRK.jl | 3 +- .../src/algorithms.jl | 39 ++++++++++++++++++- .../src/OrdinaryDiffEqRosenbrock.jl | 2 +- src/OrdinaryDiffEq.jl | 1 - src/constants.jl | 38 ------------------ 5 files changed, 41 insertions(+), 42 deletions(-) delete mode 100644 src/constants.jl diff --git a/lib/OrdinaryDiffEqExplicitRK/src/OrdinaryDiffEqExplicitRK.jl b/lib/OrdinaryDiffEqExplicitRK/src/OrdinaryDiffEqExplicitRK.jl index 50fe72b07a..2352c110d6 100644 --- a/lib/OrdinaryDiffEqExplicitRK/src/OrdinaryDiffEqExplicitRK.jl +++ b/lib/OrdinaryDiffEqExplicitRK/src/OrdinaryDiffEqExplicitRK.jl @@ -2,7 +2,8 @@ module OrdinaryDiffEqExplicitRK import OrdinaryDiffEq: alg_order, alg_adaptive_order, alg_stability_size, OrdinaryDiffEqAdaptiveAlgorithm, @cache, alg_cache, OrdinaryDiffEqConstantCache, @unpack, unwrap_alg, - OrdinaryDiffEqMutableCache, initialize!, perform_step!, isfsal + OrdinaryDiffEqMutableCache, initialize!, perform_step!, isfsal, + CompositeAlgorithm using TruncatedStacktraces, RecursiveArrayTools, FastBroadcast, MuladdMacro include("algorithms.jl") diff --git a/lib/OrdinaryDiffEqExplicitRK/src/algorithms.jl b/lib/OrdinaryDiffEqExplicitRK/src/algorithms.jl index b36e517713..b087f4788a 100644 --- a/lib/OrdinaryDiffEqExplicitRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqExplicitRK/src/algorithms.jl @@ -1,4 +1,41 @@ -# RK methods +""" +constructDormandPrince() + +Constructs the tableau object for the Dormand-Prince Order 4/5 method. +""" +function constructDormandPrince(T::Type = Float64) + A = [0 0 0 0 0 0 0 + 1//5 0 0 0 0 0 0 + 3//40 9//40 0 0 0 0 0 + 44//45 -56//15 32//9 0 0 0 0 + 19372//6561 -25360//2187 64448//6561 -212//729 0 0 0 + 9017//3168 -355//33 46732//5247 49//176 -5103//18656 0 0 + 35//384 0 500//1113 125//192 -2187//6784 11//84 0] + c = [0; 1 // 5; 3 // 10; 4 // 5; 8 // 9; 1; 1] + α = [35 // 384; 0; 500 // 1113; 125 // 192; -2187 // 6784; 11 // 84; 0] + αEEst = [ + 5179 // 57600, + 0, + 7571 // 16695, + 393 // 640, + -92097 // 339200, + 187 // 2100, + 1 // 40 + ] + A = map(T, A) + α = map(T, α) + αEEst = map(T, αEEst) + c = map(T, c) + return (DiffEqBase.ExplicitRKTableau(A, c, α, 5, αEEst = αEEst, adaptiveorder = 4, + fsal = true, stability_size = 3.3066)) +end + +""" +ODE_DEFAULT_TABLEAU + +Sets the default tableau for the ODE solver. Currently Dormand-Prince 4/5. +""" +const ODE_DEFAULT_TABLEAU = constructDormandPrince() struct ExplicitRK{TabType} <: OrdinaryDiffEqAdaptiveAlgorithm tableau::TabType diff --git a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl index 78115f637d..7b8f9ab414 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl @@ -15,7 +15,7 @@ using MacroTools: @capture using DiffEqBase: @def import LinearSolve import ForwardDiff -using LinearAlgebra: mul!, diag, diagm, I +using LinearAlgebra: mul!, diag, diagm, I, Diagonal function rosenbrock_wanner_docstring(description::String, name::String; diff --git a/src/OrdinaryDiffEq.jl b/src/OrdinaryDiffEq.jl index 323b73bc1c..9989fc7354 100644 --- a/src/OrdinaryDiffEq.jl +++ b/src/OrdinaryDiffEq.jl @@ -170,7 +170,6 @@ include("dense/generic_dense.jl") include("derivative_utils.jl") include("derivative_wrappers.jl") include("iterator_interface.jl") -include("constants.jl") include("solve.jl") include("initdt.jl") include("interp_func.jl") diff --git a/src/constants.jl b/src/constants.jl deleted file mode 100644 index 78ff7d2d61..0000000000 --- a/src/constants.jl +++ /dev/null @@ -1,38 +0,0 @@ -""" -constructDormandPrince() - -Constructs the tableau object for the Dormand-Prince Order 4/5 method. -""" -function constructDormandPrince(T::Type = Float64) - A = [0 0 0 0 0 0 0 - 1//5 0 0 0 0 0 0 - 3//40 9//40 0 0 0 0 0 - 44//45 -56//15 32//9 0 0 0 0 - 19372//6561 -25360//2187 64448//6561 -212//729 0 0 0 - 9017//3168 -355//33 46732//5247 49//176 -5103//18656 0 0 - 35//384 0 500//1113 125//192 -2187//6784 11//84 0] - c = [0; 1 // 5; 3 // 10; 4 // 5; 8 // 9; 1; 1] - α = [35 // 384; 0; 500 // 1113; 125 // 192; -2187 // 6784; 11 // 84; 0] - αEEst = [ - 5179 // 57600, - 0, - 7571 // 16695, - 393 // 640, - -92097 // 339200, - 187 // 2100, - 1 // 40 - ] - A = map(T, A) - α = map(T, α) - αEEst = map(T, αEEst) - c = map(T, c) - return (DiffEqBase.ExplicitRKTableau(A, c, α, 5, αEEst = αEEst, adaptiveorder = 4, - fsal = true, stability_size = 3.3066)) -end - -""" -ODE_DEFAULT_TABLEAU - -Sets the default tableau for the ODE solver. Currently Dormand-Prince 4/5. -""" -const ODE_DEFAULT_TABLEAU = constructDormandPrince() From 6731f9bade155949ddf8abb162012f6181dec575 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Sat, 3 Aug 2024 09:03:02 +0530 Subject: [PATCH 079/133] update --- lib/OrdinaryDiffEqExplicitRK/Project.toml | 21 ++++++++++++++++++- .../src/OrdinaryDiffEqExplicitRK.jl | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/OrdinaryDiffEqExplicitRK/Project.toml b/lib/OrdinaryDiffEqExplicitRK/Project.toml index dc14bcda8f..091e552e57 100644 --- a/lib/OrdinaryDiffEqExplicitRK/Project.toml +++ b/lib/OrdinaryDiffEqExplicitRK/Project.toml @@ -1,4 +1,23 @@ name = "OrdinaryDiffEqExplicitRK" uuid = "9286f039-9fbf-40e8-bf65-aa933bdc4db0" authors = ["ParamThakkar123 "] -version = "0.1.0" +version = "1.0.0" + +[deps] +FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898" +MuladdMacro = "46d2c3a1-f734-5fdb-9937-b9b9aeba4221" +OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" +RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd" +DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" + +[compat] +julia = "1.10" + +[extras] +DiffEqDevTools = "f3b72e0c-5b89-59e1-b016-84e28bfd966d" +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" +SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[targets] +test = ["DiffEqDevTools", "Random", "SafeTestsets", "Test"] \ No newline at end of file diff --git a/lib/OrdinaryDiffEqExplicitRK/src/OrdinaryDiffEqExplicitRK.jl b/lib/OrdinaryDiffEqExplicitRK/src/OrdinaryDiffEqExplicitRK.jl index 2352c110d6..b4c9a6d45a 100644 --- a/lib/OrdinaryDiffEqExplicitRK/src/OrdinaryDiffEqExplicitRK.jl +++ b/lib/OrdinaryDiffEqExplicitRK/src/OrdinaryDiffEqExplicitRK.jl @@ -4,7 +4,7 @@ import OrdinaryDiffEq: alg_order, alg_adaptive_order, alg_stability_size, Ordina @cache, alg_cache, OrdinaryDiffEqConstantCache, @unpack, unwrap_alg, OrdinaryDiffEqMutableCache, initialize!, perform_step!, isfsal, CompositeAlgorithm -using TruncatedStacktraces, RecursiveArrayTools, FastBroadcast, MuladdMacro +using TruncatedStacktraces, RecursiveArrayTools, FastBroadcast, MuladdMacro, DiffEqBase include("algorithms.jl") include("alg_utils.jl") From cc07cf9ffd4719bea4752255759aad232b7a5f0f Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Sat, 3 Aug 2024 09:07:46 +0530 Subject: [PATCH 080/133] copyat_or_push! --- lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl | 2 +- lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl b/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl index 2d54a3e8cb..5d07b9ca60 100644 --- a/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl +++ b/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl @@ -4,7 +4,7 @@ import OrdinaryDiffEq: alg_order, qmax_default, qmin_default, beta2_default, bet explicit_rk_docstring, OrdinaryDiffEqAdaptiveAlgorithm, trivial_limiter!, _ode_addsteps!, @unpack, @cache, OrdinaryDiffEqMutableCache, constvalue, alg_cache, uses_uprev, initialize!, perform_step!, OrdinaryDiffEqConstantCache, - calculate_residuals!, calculate_residuals, CompiledFloats + calculate_residuals!, calculate_residuals, CompiledFloats, copyat_or_push! import Static: False import MuladdMacro: @muladd using DiffEqBase diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl index 9f4fe1e194..e51b3481b0 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl @@ -6,7 +6,7 @@ import OrdinaryDiffEq: alg_order, isfsal, beta2_default, beta1_default, alg_stab unwrap_alg, @unpack, initialize!, perform_step!, calculate_residuals, calculate_residuals!, _ode_addsteps!, @OnDemandTableauExtract, constvalue, OrdinaryDiffEqMutableCache, uses_uprev, OrdinaryDiffEqConstantCache, @fold, - @cache, CompiledFloats, alg_cache, CompositeAlgorithm, alg_autodiff + @cache, CompiledFloats, alg_cache, CompositeAlgorithm, alg_autodiff, copyat_or_push! using DiffEqBase, SciMLBase import MuladdMacro: @muladd import FastBroadcast: @.. From d5aad61124717c3bc4193368db2024a96cc052fa Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Sat, 3 Aug 2024 09:12:37 +0530 Subject: [PATCH 081/133] calculate_residuals --- lib/OrdinaryDiffEqExplicitRK/src/OrdinaryDiffEqExplicitRK.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqExplicitRK/src/OrdinaryDiffEqExplicitRK.jl b/lib/OrdinaryDiffEqExplicitRK/src/OrdinaryDiffEqExplicitRK.jl index b4c9a6d45a..977923c761 100644 --- a/lib/OrdinaryDiffEqExplicitRK/src/OrdinaryDiffEqExplicitRK.jl +++ b/lib/OrdinaryDiffEqExplicitRK/src/OrdinaryDiffEqExplicitRK.jl @@ -3,7 +3,7 @@ module OrdinaryDiffEqExplicitRK import OrdinaryDiffEq: alg_order, alg_adaptive_order, alg_stability_size, OrdinaryDiffEqAdaptiveAlgorithm, @cache, alg_cache, OrdinaryDiffEqConstantCache, @unpack, unwrap_alg, OrdinaryDiffEqMutableCache, initialize!, perform_step!, isfsal, - CompositeAlgorithm + CompositeAlgorithm, calculate_residuals!, calculate_residuals using TruncatedStacktraces, RecursiveArrayTools, FastBroadcast, MuladdMacro, DiffEqBase include("algorithms.jl") From 032368d024bd33db67ea1c674d11dfe43d3d7826 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Sat, 3 Aug 2024 09:22:50 +0530 Subject: [PATCH 082/133] Update --- lib/OrdinaryDiffEqLowOrderRK/Project.toml | 1 + lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/OrdinaryDiffEqLowOrderRK/Project.toml b/lib/OrdinaryDiffEqLowOrderRK/Project.toml index 2934309198..b696dfce9e 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/Project.toml +++ b/lib/OrdinaryDiffEqLowOrderRK/Project.toml @@ -9,6 +9,7 @@ MuladdMacro = "46d2c3a1-f734-5fdb-9937-b9b9aeba4221" RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd" FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898" Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3" +LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462" diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl index e51b3481b0..e4e7eaa7c9 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl @@ -10,6 +10,7 @@ import OrdinaryDiffEq: alg_order, isfsal, beta2_default, beta1_default, alg_stab using DiffEqBase, SciMLBase import MuladdMacro: @muladd import FastBroadcast: @.. +import LinearAlgebra: norm import RecursiveArrayTools: recursivefill!, recursive_unitless_bottom_eltype import Static: False using DiffEqBase: @def, @tight_loop_macros From 2fb92d687194198b4f71a5e2c080f5ffe10a08d6 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sat, 3 Aug 2024 01:13:25 -0400 Subject: [PATCH 083/133] move around some interface functions --- .../src/integrator_interface.jl | 30 ------------------- .../src/OrdinaryDiffEqRosenbrock.jl | 2 +- lib/OrdinaryDiffEqRosenbrock/src/alg_utils.jl | 6 +++- .../src/algorithms.jl | 2 +- .../src/integrator_interface.jl | 2 +- .../src/interp_func.jl | 2 +- src/alg_utils.jl | 1 + src/integrators/integrator_interface.jl | 27 +++++++++++++++++ 8 files changed, 37 insertions(+), 35 deletions(-) diff --git a/lib/OrdinaryDiffEqFunctionMap/src/integrator_interface.jl b/lib/OrdinaryDiffEqFunctionMap/src/integrator_interface.jl index 092ac3c2e4..e69de29bb2 100644 --- a/lib/OrdinaryDiffEqFunctionMap/src/integrator_interface.jl +++ b/lib/OrdinaryDiffEqFunctionMap/src/integrator_interface.jl @@ -1,30 +0,0 @@ -@inline function DiffEqBase.get_du(integrator::ODEIntegrator) - integrator.cache isa FunctionMapCache || - integrator.cache isa FunctionMapConstantCache && - error("Derivatives are not defined for this stepper.") - return if isdefined(integrator, :fsallast) - integrator.fsallast - else - integrator(integrator.t, Val{1}) - end -end - -@inline function DiffEqBase.get_du!(out, integrator::ODEIntegrator) - integrator.cache isa FunctionMapCache || - integrator.cache isa FunctionMapConstantCache && - error("Derivatives are not defined for this stepper.") - if integrator.cache isa FunctionMapCache - out .= integrator.cache.tmp - else - return if isdefined(integrator, :fsallast) && - !(integrator.alg isa - Union{Rosenbrock23, Rosenbrock32, Rodas23W, - Rodas3P, Rodas4, Rodas4P, Rodas4P2, Rodas5, - Rodas5P, Rodas5Pe, Rodas5Pr}) - # Special stiff interpolations do not store the right value in fsallast - out .= integrator.fsallast - else - integrator(out, integrator.t, Val{1}) - end - end -end \ No newline at end of file diff --git a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl index 7b8f9ab414..0a2ca229ce 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl @@ -8,7 +8,7 @@ import OrdinaryDiffEq: alg_order, alg_adaptive_order, isWmethod, isfsal, _unwrap OrdinaryDiffEqRosenbrockAlgorithm, generic_solver_docstring, namify, initialize!, perform_step!, constvalue, TimeDerivativeWrapper, TimeGradientWrapper, UDerivativeWrapper, UJacobianWrapper, wrapprecs, alg_autodiff, calc_tderivative, build_grad_config, build_jac_config, - issuccess_W, calculate_residuals + issuccess_W, calculate_residuals, has_stiff_interpolation using TruncatedStacktraces, MuladdMacro, FastBroadcast, DiffEqBase, RecursiveArrayTools import MacroTools using MacroTools: @capture diff --git a/lib/OrdinaryDiffEqRosenbrock/src/alg_utils.jl b/lib/OrdinaryDiffEqRosenbrock/src/alg_utils.jl index 95f0b1efd8..80281c3080 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/alg_utils.jl @@ -58,4 +58,8 @@ isfsal(alg::Rodas5Pe) = false isfsal(alg::Rodas4) = false isfsal(alg::Rodas42) = false isfsal(alg::Rodas4P) = false -isfsal(alg::Rodas4P2) = false \ No newline at end of file +isfsal(alg::Rodas4P2) = false + +has_stiff_interpolation(::Union{Rosenbrock23, Rosenbrock32, Rodas23W, + Rodas3P, Rodas4, Rodas4P, Rodas4P2, Rodas5, + Rodas5P, Rodas5Pe, Rodas5Pr}) = true diff --git a/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl b/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl index a618bf8435..4f8e528b8a 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl @@ -203,4 +203,4 @@ for Alg in [ end @eval TruncatedStacktraces.@truncate_stacktrace $Alg 1 2 -end \ No newline at end of file +end diff --git a/lib/OrdinaryDiffEqRosenbrock/src/integrator_interface.jl b/lib/OrdinaryDiffEqRosenbrock/src/integrator_interface.jl index 8b463e5a06..f99dc3a089 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/integrator_interface.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/integrator_interface.jl @@ -5,4 +5,4 @@ function resize_non_user_cache!(integrator::ODEIntegrator, resize_jac_config!(cache.jac_config, i) resize_grad_config!(cache.grad_config, i) nothing -end \ No newline at end of file +end diff --git a/lib/OrdinaryDiffEqRosenbrock/src/interp_func.jl b/lib/OrdinaryDiffEqRosenbrock/src/interp_func.jl index 790d7a2ad2..27bde3e1b7 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/interp_func.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/interp_func.jl @@ -24,4 +24,4 @@ function DiffEqBase.interp_summary(::Type{cacheType}, Rosenbrock5Cache}} dense ? "specialized 4rd order \"free\" stiffness-aware interpolation" : "1st order linear" -end \ No newline at end of file +end diff --git a/src/alg_utils.jl b/src/alg_utils.jl index 0d9b7ca97b..461ef696fc 100644 --- a/src/alg_utils.jl +++ b/src/alg_utils.jl @@ -37,6 +37,7 @@ dt_required(alg::LinearExponential) = false isdiscretealg(alg) = false function alg_stability_size end +has_stiff_interpolation(alg) = false # evaluates f(t[i]) _eval_index(f::F, t::Tuple{A}, _) where {F, A} = f(t[1]) diff --git a/src/integrators/integrator_interface.jl b/src/integrators/integrator_interface.jl index c5716b7e02..2119f4eb3d 100644 --- a/src/integrators/integrator_interface.jl +++ b/src/integrators/integrator_interface.jl @@ -57,6 +57,33 @@ function DiffEqBase.reeval_internals_due_to_modification!( integrator.reeval_fsal = true end +@inline function DiffEqBase.get_du(integrator::ODEIntegrator) + isdiscretecache(integrator.cache) && + error("Derivatives are not defined for this stepper.") + return if isdefined(integrator, :fsallast) + integrator.fsallast + else + integrator(integrator.t, Val{1}) + end +end + +@inline function DiffEqBase.get_du!(out, integrator::ODEIntegrator) + isdiscretecache(integrator.cache) && + error("Derivatives are not defined for this stepper.") + if isdiscretecache(integrator.cache) + out .= integrator.cache.tmp + else + return if isdefined(integrator, :fsallast) && + !has_stiff_interpolation(integrator.alg) + # Special stiff interpolations do not store the + # right value in fsallast + out .= integrator.fsallast + else + integrator(out, integrator.t, Val{1}) + end + end +end + function u_modified!(integrator::ODEIntegrator, bool::Bool) integrator.u_modified = bool end From 57d61e005c2b677714df32edd3ccd73eb45993df Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Sat, 3 Aug 2024 11:31:10 +0530 Subject: [PATCH 084/133] constvalue --- .../src/OrdinaryDiffEqAdamsBashforthMoulton.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl index 8e27483a6f..1728301004 100644 --- a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl @@ -2,7 +2,8 @@ module OrdinaryDiffEqAdamsBashforthMoulton import OrdinaryDiffEq: OrdinaryDiffEqMutableCache, OrdinaryDiffEqConstantCache, @cache, alg_cache, initialize!, @unpack, perform_step!, alg_order, isstandard, OrdinaryDiffEqAlgorithm, - OrdinaryDiffEqAdaptiveAlgorithm, OrdinaryDiffEqAdamsVarOrderVarStepAlgorithm + OrdinaryDiffEqAdaptiveAlgorithm, OrdinaryDiffEqAdamsVarOrderVarStepAlgorithm, + constvalue using MuladdMacro, FastBroadcast include("algorithms.jl") From 19ffbaf7622e3fdcb6a5738054cd1b326ca8864b Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sat, 3 Aug 2024 02:32:01 -0400 Subject: [PATCH 085/133] a few more --- lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl | 3 ++- lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl b/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl index 5d07b9ca60..7252cefab0 100644 --- a/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl +++ b/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl @@ -4,7 +4,8 @@ import OrdinaryDiffEq: alg_order, qmax_default, qmin_default, beta2_default, bet explicit_rk_docstring, OrdinaryDiffEqAdaptiveAlgorithm, trivial_limiter!, _ode_addsteps!, @unpack, @cache, OrdinaryDiffEqMutableCache, constvalue, alg_cache, uses_uprev, initialize!, perform_step!, OrdinaryDiffEqConstantCache, - calculate_residuals!, calculate_residuals, CompiledFloats, copyat_or_push! + calculate_residuals!, calculate_residuals, CompiledFloats, copyat_or_push!, + unwrap_alg import Static: False import MuladdMacro: @muladd using DiffEqBase diff --git a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl index 0a2ca229ce..ae56e2d2bb 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl @@ -8,7 +8,8 @@ import OrdinaryDiffEq: alg_order, alg_adaptive_order, isWmethod, isfsal, _unwrap OrdinaryDiffEqRosenbrockAlgorithm, generic_solver_docstring, namify, initialize!, perform_step!, constvalue, TimeDerivativeWrapper, TimeGradientWrapper, UDerivativeWrapper, UJacobianWrapper, wrapprecs, alg_autodiff, calc_tderivative, build_grad_config, build_jac_config, - issuccess_W, calculate_residuals, has_stiff_interpolation + issuccess_W, calculate_residuals, has_stiff_interpolation, + resize_non_user_cache!, _ode_addsteps! using TruncatedStacktraces, MuladdMacro, FastBroadcast, DiffEqBase, RecursiveArrayTools import MacroTools using MacroTools: @capture From a0821ff9f72095d0d0d7ba031509c47266ddec47 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sat, 3 Aug 2024 02:37:30 -0400 Subject: [PATCH 086/133] Update src/solve.jl --- src/solve.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/solve.jl b/src/solve.jl index 7ca0e02082..7b90d8d3dd 100644 --- a/src/solve.jl +++ b/src/solve.jl @@ -31,7 +31,7 @@ function DiffEqBase.__init( isempty(saveat), calck = (callback !== nothing && callback !== CallbackSet()) || (dense) || !isempty(saveat), # and no dense output - dt = !dt_required(alg) && isempty(tstops) ? + dt = isdiscretealg(alg) && isempty(tstops) ? eltype(prob.tspan)(1) : eltype(prob.tspan)(0), dtmin = eltype(prob.tspan)(0), dtmax = eltype(prob.tspan)((prob.tspan[end] - prob.tspan[1])), From 59e4a268394ea497059dbd04cff631a3ecdde154 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Sat, 3 Aug 2024 12:32:03 +0530 Subject: [PATCH 087/133] jacobian2W! --- lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl index ae56e2d2bb..c598b40b45 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl @@ -9,7 +9,7 @@ import OrdinaryDiffEq: alg_order, alg_adaptive_order, isWmethod, isfsal, _unwrap constvalue, TimeDerivativeWrapper, TimeGradientWrapper, UDerivativeWrapper, UJacobianWrapper, wrapprecs, alg_autodiff, calc_tderivative, build_grad_config, build_jac_config, issuccess_W, calculate_residuals, has_stiff_interpolation, - resize_non_user_cache!, _ode_addsteps! + resize_non_user_cache!, _ode_addsteps!, jacobian2W! using TruncatedStacktraces, MuladdMacro, FastBroadcast, DiffEqBase, RecursiveArrayTools import MacroTools using MacroTools: @capture From 3fcefb1a5d90213348c68978993f4f6cad54da16 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sat, 3 Aug 2024 03:08:40 -0400 Subject: [PATCH 088/133] more --- lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl | 2 +- lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl index ae56e2d2bb..c598b40b45 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl @@ -9,7 +9,7 @@ import OrdinaryDiffEq: alg_order, alg_adaptive_order, isWmethod, isfsal, _unwrap constvalue, TimeDerivativeWrapper, TimeGradientWrapper, UDerivativeWrapper, UJacobianWrapper, wrapprecs, alg_autodiff, calc_tderivative, build_grad_config, build_jac_config, issuccess_W, calculate_residuals, has_stiff_interpolation, - resize_non_user_cache!, _ode_addsteps! + resize_non_user_cache!, _ode_addsteps!, jacobian2W! using TruncatedStacktraces, MuladdMacro, FastBroadcast, DiffEqBase, RecursiveArrayTools import MacroTools using MacroTools: @capture diff --git a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl index 9ff0769ae7..0754f77fa3 100644 --- a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl +++ b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl @@ -6,7 +6,7 @@ import OrdinaryDiffEq: alg_order, alg_stability_size, explicit_rk_docstring, constvalue, @unpack, perform_step!, calculate_residuals, @cache, calculate_residuals!, _ode_interpolant, _ode_interpolant!, CompiledFloats, @OnDemandTableauExtract, initialize!, perform_step!, - CompositeAlgorithm + CompositeAlgorithm, _ode_addsteps! import Static: False import MuladdMacro: @muladd import FastBroadcast: @.. @@ -24,4 +24,4 @@ include("tsit_perform_step.jl") export Tsit5 -end \ No newline at end of file +end From 6648d8ad00becb944b3e85d739b51afda60e5ecb Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sat, 3 Aug 2024 03:44:54 -0400 Subject: [PATCH 089/133] another --- lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl index 0754f77fa3..3aee3ef319 100644 --- a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl +++ b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl @@ -6,7 +6,7 @@ import OrdinaryDiffEq: alg_order, alg_stability_size, explicit_rk_docstring, constvalue, @unpack, perform_step!, calculate_residuals, @cache, calculate_residuals!, _ode_interpolant, _ode_interpolant!, CompiledFloats, @OnDemandTableauExtract, initialize!, perform_step!, - CompositeAlgorithm, _ode_addsteps! + CompositeAlgorithm, _ode_addsteps!, copyat_or_push! import Static: False import MuladdMacro: @muladd import FastBroadcast: @.. From 8df87e64a2366fa87e264e151dbb0b4ebb4493e6 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sat, 3 Aug 2024 04:15:30 -0400 Subject: [PATCH 090/133] deps in ABM --- .../src/OrdinaryDiffEqAdamsBashforthMoulton.jl | 4 +++- src/OrdinaryDiffEq.jl | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl index 1728301004..d0edaaf4c5 100644 --- a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl @@ -4,6 +4,8 @@ import OrdinaryDiffEq: OrdinaryDiffEqMutableCache, OrdinaryDiffEqConstantCache, initialize!, @unpack, perform_step!, alg_order, isstandard, OrdinaryDiffEqAlgorithm, OrdinaryDiffEqAdaptiveAlgorithm, OrdinaryDiffEqAdamsVarOrderVarStepAlgorithm, constvalue +import OrdinaryDiffEq: BS3ConstantCache, BS3Cache, RK4ConstantCache, RK4Cache + using MuladdMacro, FastBroadcast include("algorithms.jl") @@ -12,7 +14,7 @@ include("adams_bashforth_moulton_caches.jl") include("adams_utils.jl") include("adams_bashforth_moulton_perform_step.jl") -export AB3, AB4, AB5, ABM32, ABM43, ABM54, VCAB3, +export AB3, AB4, AB5, ABM32, ABM43, ABM54, VCAB3, VCAB4, VCAB5, VCABM3, VCABM4, VCABM5, VCABM end diff --git a/src/OrdinaryDiffEq.jl b/src/OrdinaryDiffEq.jl index 9989fc7354..177ceb652d 100644 --- a/src/OrdinaryDiffEq.jl +++ b/src/OrdinaryDiffEq.jl @@ -260,6 +260,7 @@ export Rosenbrock23, Rosenbrock32, RosShamp4, Veldd4, Velds4, GRK4T, GRK4A, RosenbrockW6S4OS, ROS34PW1a, ROS34PW1b, ROS34PW2, ROS34PW3, ROS34PRw, ROS3PRL, ROS3PRL2, ROK4a, ROS2, ROS2PR, ROS2S, ROS3, ROS3PR, Scholz4_7 +import OrdinaryDiffEqRosenbrock: RosenbrockMutableCache include("../lib/OrdinaryDiffEqDefault/src/OrdinaryDiffEqDefault.jl") using ..OrdinaryDiffEqDefault From 4752f1805022184b96cc76f77272494f1cc62994 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sat, 3 Aug 2024 04:27:20 -0400 Subject: [PATCH 091/133] import correctly --- src/OrdinaryDiffEq.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OrdinaryDiffEq.jl b/src/OrdinaryDiffEq.jl index 177ceb652d..171eda9230 100644 --- a/src/OrdinaryDiffEq.jl +++ b/src/OrdinaryDiffEq.jl @@ -260,7 +260,7 @@ export Rosenbrock23, Rosenbrock32, RosShamp4, Veldd4, Velds4, GRK4T, GRK4A, RosenbrockW6S4OS, ROS34PW1a, ROS34PW1b, ROS34PW2, ROS34PW3, ROS34PRw, ROS3PRL, ROS3PRL2, ROK4a, ROS2, ROS2PR, ROS2S, ROS3, ROS3PR, Scholz4_7 -import OrdinaryDiffEqRosenbrock: RosenbrockMutableCache +import ..OrdinaryDiffEqRosenbrock: RosenbrockMutableCache include("../lib/OrdinaryDiffEqDefault/src/OrdinaryDiffEqDefault.jl") using ..OrdinaryDiffEqDefault From 4ff49d930982b70926abcf9d4ab3d0c2fb4b1e90 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sat, 3 Aug 2024 04:54:03 -0400 Subject: [PATCH 092/133] Fix ABM import --- src/OrdinaryDiffEq.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OrdinaryDiffEq.jl b/src/OrdinaryDiffEq.jl index 171eda9230..e0e5fd342e 100644 --- a/src/OrdinaryDiffEq.jl +++ b/src/OrdinaryDiffEq.jl @@ -293,6 +293,7 @@ export Euler, SplitEuler, Heun, Ralston, Midpoint, RK4, DP5, Anas5, RKO65, FRK65, RKM, MSRK5, MSRK6, PSRK4p7q6, PSRK3p5q4, PSRK3p6q5, Stepanov5, SIR54, Alshina2, Alshina3, Alshina6 +using ..OrdinaryDiffEqLowOrderRK: BS3Cache, BS3ConstantCache include("../lib/OrdinaryDiffEqFunctionMap/src/OrdinaryDiffEqFunctionMap.jl") using ..OrdinaryDiffEqFunctionMap From dd497b86e600e2d38d7ba2fd1a50fb091992aa67 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Sat, 3 Aug 2024 14:31:11 +0530 Subject: [PATCH 093/133] RK4Cache --- src/OrdinaryDiffEq.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OrdinaryDiffEq.jl b/src/OrdinaryDiffEq.jl index e0e5fd342e..d504b7bbfe 100644 --- a/src/OrdinaryDiffEq.jl +++ b/src/OrdinaryDiffEq.jl @@ -293,7 +293,7 @@ export Euler, SplitEuler, Heun, Ralston, Midpoint, RK4, DP5, Anas5, RKO65, FRK65, RKM, MSRK5, MSRK6, PSRK4p7q6, PSRK3p5q4, PSRK3p6q5, Stepanov5, SIR54, Alshina2, Alshina3, Alshina6 -using ..OrdinaryDiffEqLowOrderRK: BS3Cache, BS3ConstantCache +using ..OrdinaryDiffEqLowOrderRK: BS3Cache, BS3ConstantCache, RK4ConstantCache, RK4Cache include("../lib/OrdinaryDiffEqFunctionMap/src/OrdinaryDiffEqFunctionMap.jl") using ..OrdinaryDiffEqFunctionMap From 2c5e7290e8e2952210458b679bf972942ed909e0 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sat, 3 Aug 2024 05:04:34 -0400 Subject: [PATCH 094/133] Update src/solve.jl --- src/solve.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/solve.jl b/src/solve.jl index 7b90d8d3dd..8b1dc8b36c 100644 --- a/src/solve.jl +++ b/src/solve.jl @@ -130,7 +130,7 @@ function DiffEqBase.__init( if (((!(alg isa OrdinaryDiffEqAdaptiveAlgorithm) && !(alg isa OrdinaryDiffEqCompositeAlgorithm) && !(alg isa DAEAlgorithm)) || !adaptive || !isadaptive(alg)) && - dt == tType(0) && isempty(tstops)) && !dt_required(alg) + dt == tType(0) && isempty(tstops)) && dt_required(alg) error("Fixed timestep methods require a choice of dt or choosing the tstops") end From c7223809b8007f48020c9e2ff396ec5c08e3e124 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sat, 3 Aug 2024 05:35:49 -0400 Subject: [PATCH 095/133] add missing imports --- lib/OrdinaryDiffEqExplicitRK/src/OrdinaryDiffEqExplicitRK.jl | 3 ++- lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqExplicitRK/src/OrdinaryDiffEqExplicitRK.jl b/lib/OrdinaryDiffEqExplicitRK/src/OrdinaryDiffEqExplicitRK.jl index 977923c761..16399a3835 100644 --- a/lib/OrdinaryDiffEqExplicitRK/src/OrdinaryDiffEqExplicitRK.jl +++ b/lib/OrdinaryDiffEqExplicitRK/src/OrdinaryDiffEqExplicitRK.jl @@ -1,10 +1,11 @@ module OrdinaryDiffEqExplicitRK import OrdinaryDiffEq: alg_order, alg_adaptive_order, alg_stability_size, OrdinaryDiffEqAdaptiveAlgorithm, - @cache, alg_cache, OrdinaryDiffEqConstantCache, @unpack, unwrap_alg, + @cache, alg_cache, OrdinaryDiffEqConstantCache, @unpack, unwrap_alg, OrdinaryDiffEqMutableCache, initialize!, perform_step!, isfsal, CompositeAlgorithm, calculate_residuals!, calculate_residuals using TruncatedStacktraces, RecursiveArrayTools, FastBroadcast, MuladdMacro, DiffEqBase +import LinearAlgebra: norm include("algorithms.jl") include("alg_utils.jl") diff --git a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl index 3aee3ef319..dea9a3d3c4 100644 --- a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl +++ b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl @@ -20,6 +20,7 @@ include("alg_utils.jl") include("tsit_caches.jl") include("tsit_tableaus.jl") include("interp_func.jl") +include("interpolants.jl") include("tsit_perform_step.jl") export Tsit5 From ec264c0997b5b0236f73134b7e0daef9db1fd9b5 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Sat, 3 Aug 2024 15:09:52 +0530 Subject: [PATCH 096/133] @def --- lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl index dea9a3d3c4..7485424bad 100644 --- a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl +++ b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl @@ -14,6 +14,7 @@ import RecursiveArrayTools: recursivefill!, recursive_unitless_bottom_eltype import LinearAlgebra: norm using DiffEqBase using TruncatedStacktraces +import DiffEqBase: @def include("algorithms.jl") include("alg_utils.jl") From f7e492f09aff6d2c7b0f3549e8acf194b1c50a5f Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sat, 3 Aug 2024 06:03:40 -0400 Subject: [PATCH 097/133] some clean up --- Project.toml | 2 -- .../src/OrdinaryDiffEqAdamsBashforthMoulton.jl | 4 ++-- .../src/adams_bashforth_moulton_caches.jl | 2 +- .../src/adams_bashforth_moulton_perform_step.jl | 2 +- .../src/OrdinaryDiffEqLowOrderRK.jl | 4 ++-- lib/OrdinaryDiffEqLowOrderRK/src/algorithms.jl | 4 +++- .../src/OrdinaryDiffEqLowStorageRK.jl | 3 ++- .../OrdinaryDiffEqLowStorageRK/src/arrayfuse.jl | 0 lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl | 2 +- lib/OrdinaryDiffEqTsit5/src/algorithms.jl | 4 +++- src/OrdinaryDiffEq.jl | 8 ++------ src/algorithms.jl | 2 +- src/composite_algs.jl | 3 --- src/initdt.jl | 2 +- test/interface/ode_numbertype_tests.jl | 2 +- 15 files changed, 20 insertions(+), 24 deletions(-) rename src/wrappers.jl => lib/OrdinaryDiffEqLowStorageRK/src/arrayfuse.jl (100%) diff --git a/Project.toml b/Project.toml index 10bb3e24fd..bb6def4837 100644 --- a/Project.toml +++ b/Project.toml @@ -10,7 +10,6 @@ ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9" DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" -EnumX = "4e289a0a-7415-4d19-859d-a7e5c4648b56" ExponentialUtilities = "d4d017d3-3776-5f7e-afef-a10c40355c18" FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898" FastClosures = "9aa1b823-49e4-5ca5-8b0f-3971ec8bab6a" @@ -18,7 +17,6 @@ FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b" FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41" ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" FunctionWrappersWrappers = "77dc65aa-8811-40c2-897b-53d922fa7daf" -IfElse = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173" InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" LineSearches = "d3d80556-e9d4-5f37-9878-2ab0fcc64255" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" diff --git a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl index d0edaaf4c5..6900c49edb 100644 --- a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl @@ -3,9 +3,9 @@ module OrdinaryDiffEqAdamsBashforthMoulton import OrdinaryDiffEq: OrdinaryDiffEqMutableCache, OrdinaryDiffEqConstantCache, @cache, alg_cache, initialize!, @unpack, perform_step!, alg_order, isstandard, OrdinaryDiffEqAlgorithm, OrdinaryDiffEqAdaptiveAlgorithm, OrdinaryDiffEqAdamsVarOrderVarStepAlgorithm, - constvalue + constvalue, calculate_residuals, calculate_residuals! import OrdinaryDiffEq: BS3ConstantCache, BS3Cache, RK4ConstantCache, RK4Cache - +import RecursiveArrayTools: recursivefill! using MuladdMacro, FastBroadcast include("algorithms.jl") diff --git a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_bashforth_moulton_caches.jl b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_bashforth_moulton_caches.jl index e842455393..29a021f0ca 100644 --- a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_bashforth_moulton_caches.jl +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_bashforth_moulton_caches.jl @@ -1018,4 +1018,4 @@ function alg_cache(alg::VCABM, u, rate_prototype, ::Type{uEltypeNoUnits}, u, uprev, fsalfirst, k4, ϕstar_nm1, dts, c, g, ϕ_n, ϕ_np1, ϕstar_n, β, order, max_order, atmp, tmp, ξ, ξ0, utilde, utildem1, utildem2, utildep1, atmpm1, atmpm2, atmpp1, 1) -end \ No newline at end of file +end diff --git a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_bashforth_moulton_perform_step.jl b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_bashforth_moulton_perform_step.jl index eaba2d6193..a000e9f714 100644 --- a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_bashforth_moulton_perform_step.jl +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_bashforth_moulton_perform_step.jl @@ -1539,4 +1539,4 @@ end cache.ϕstar_nm1, cache.ϕstar_n = ϕstar_n, ϕstar_nm1 return nothing end # inbounds -end \ No newline at end of file +end diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl index e4e7eaa7c9..778dbb6e51 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl @@ -29,6 +29,6 @@ export Euler, SplitEuler, Heun, Ralston, Midpoint, RK4, BS3, OwrenZen3, OwrenZen4, OwrenZen5, BS5, DP5, Anas5, RKO65, FRK65, RKM, MSRK5, MSRK6, PSRK4p7q6, PSRK3p5q4, PSRK3p6q5, Stepanov5, SIR54, - Alshina2, Alshina3, Alshina6 + Alshina2, Alshina3, Alshina6, AutoDP5 -end \ No newline at end of file +end diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/algorithms.jl b/lib/OrdinaryDiffEqLowOrderRK/src/algorithms.jl index 72fd423186..9792b438e0 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/algorithms.jl @@ -225,6 +225,8 @@ function DP5(stage_limiter!, step_limiter! = trivial_limiter!) DP5(stage_limiter!, step_limiter!, False()) end +AutoDP5(alg; kwargs...) = AutoAlgSwitch(DP5(), alg; kwargs...) + @doc explicit_rk_docstring("4th order Runge-Kutta method designed for periodic problems.", "Anas5", extra_keyword_description = """- `w`: a periodicity estimate, which when accurate the method becomes 5th order @@ -611,4 +613,4 @@ function Base.show(io::IO, alg::Alshina6) print(io, "Alshina6(stage_limiter! = ", alg.stage_limiter!, ", step_limiter! = ", alg.step_limiter!, ", thread = ", alg.thread, ")") -end \ No newline at end of file +end diff --git a/lib/OrdinaryDiffEqLowStorageRK/src/OrdinaryDiffEqLowStorageRK.jl b/lib/OrdinaryDiffEqLowStorageRK/src/OrdinaryDiffEqLowStorageRK.jl index 870ef5fb3f..cf67877b02 100644 --- a/lib/OrdinaryDiffEqLowStorageRK/src/OrdinaryDiffEqLowStorageRK.jl +++ b/lib/OrdinaryDiffEqLowStorageRK/src/OrdinaryDiffEqLowStorageRK.jl @@ -9,13 +9,14 @@ import OrdinaryDiffEq: alg_order, alg_adaptive_order, calculate_residuals!, OrdinaryDiffEqAdaptiveAlgorithm, uses_uprev, default_controller, PIDController, alg_cache, _vec, _reshape, @cache, isfsal, full_cache, - constvalue, _unwrap_val, du_alias_or_new, ArrayFuse, + constvalue, _unwrap_val, du_alias_or_new, trivial_limiter!, perform_step!, initialize!, explicit_rk_docstring using DiffEqBase, FastBroadcast, Polyester, MuladdMacro, RecursiveArrayTools import StaticArrays: SArray, MVector, SVector, @SVector, StaticArray, MMatrix, SA import Static: False import RecursiveArrayTools: recursive_unitless_bottom_eltype +include("arrayfuse.jl") include("algorithms.jl") include("alg_utils.jl") include("low_storage_rk_caches.jl") diff --git a/src/wrappers.jl b/lib/OrdinaryDiffEqLowStorageRK/src/arrayfuse.jl similarity index 100% rename from src/wrappers.jl rename to lib/OrdinaryDiffEqLowStorageRK/src/arrayfuse.jl diff --git a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl index 7485424bad..e1cf436aa5 100644 --- a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl +++ b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl @@ -24,6 +24,6 @@ include("interp_func.jl") include("interpolants.jl") include("tsit_perform_step.jl") -export Tsit5 +export Tsit5, AutoTsit5 end diff --git a/lib/OrdinaryDiffEqTsit5/src/algorithms.jl b/lib/OrdinaryDiffEqTsit5/src/algorithms.jl index 6da2a58444..45cfbcc5a1 100644 --- a/lib/OrdinaryDiffEqTsit5/src/algorithms.jl +++ b/lib/OrdinaryDiffEqTsit5/src/algorithms.jl @@ -21,4 +21,6 @@ TruncatedStacktraces.@truncate_stacktrace Tsit5 3 # for backwards compatibility function Tsit5(stage_limiter!, step_limiter! = trivial_limiter!) Tsit5(stage_limiter!, step_limiter!, False()) -end \ No newline at end of file +end + +AutoTsit5(alg; kwargs...) = AutoAlgSwitch(Tsit5(), alg; kwargs...) diff --git a/src/OrdinaryDiffEq.jl b/src/OrdinaryDiffEq.jl index d504b7bbfe..8f49871764 100644 --- a/src/OrdinaryDiffEq.jl +++ b/src/OrdinaryDiffEq.jl @@ -28,8 +28,6 @@ using LinearSolve, SimpleNonlinearSolve using LineSearches -import EnumX - import FillArrays: Trues, Falses # Interfaces @@ -85,8 +83,6 @@ using DiffEqBase: check_error!, @def, _vec, _reshape using FastBroadcast: @.., True, False -using IfElse - using SciMLBase: NoInit, _unwrap_val import SciMLBase: alg_order @@ -250,7 +246,7 @@ export ABDF2, QNDF1, QBDF1, QNDF2, QBDF2, QNDF, QBDF, FBDF, include("../lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl") using ..OrdinaryDiffEqTsit5 -export Tsit5 +export Tsit5, AutoTsit5 include("../lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl") using ..OrdinaryDiffEqRosenbrock @@ -292,7 +288,7 @@ export Euler, SplitEuler, Heun, Ralston, Midpoint, RK4, BS3, OwrenZen3, OwrenZen4, OwrenZen5, BS5, Tsit5, DP5, Anas5, RKO65, FRK65, RKM, MSRK5, MSRK6, PSRK4p7q6, PSRK3p5q4, PSRK3p6q5, Stepanov5, SIR54, - Alshina2, Alshina3, Alshina6 + Alshina2, Alshina3, Alshina6, AutoDP5 using ..OrdinaryDiffEqLowOrderRK: BS3Cache, BS3ConstantCache, RK4ConstantCache, RK4Cache include("../lib/OrdinaryDiffEqFunctionMap/src/OrdinaryDiffEqFunctionMap.jl") diff --git a/src/algorithms.jl b/src/algorithms.jl index 83a1dda4d2..6d3579b2ad 100644 --- a/src/algorithms.jl +++ b/src/algorithms.jl @@ -295,4 +295,4 @@ struct AutoSwitch{nAlg, sAlg, tolType, T} dtfac::T stiffalgfirst::Bool switch_max::Int -end \ No newline at end of file +end diff --git a/src/composite_algs.jl b/src/composite_algs.jl index a48873547c..dfc6ad0f5f 100644 --- a/src/composite_algs.jl +++ b/src/composite_algs.jl @@ -71,6 +71,3 @@ function AutoAlgSwitch(nonstiffalg::Tuple, stiffalg::Tuple; kwargs...) AS = AutoSwitch(nonstiffalg, stiffalg; kwargs...) CompositeAlgorithm((nonstiffalg..., stiffalg...), AS) end - -AutoTsit5(alg; kwargs...) = AutoAlgSwitch(Tsit5(), alg; kwargs...) -AutoDP5(alg; kwargs...) = AutoAlgSwitch(DP5(), alg; kwargs...) diff --git a/src/initdt.jl b/src/initdt.jl index d8777e898a..3612331909 100644 --- a/src/initdt.jl +++ b/src/initdt.jl @@ -132,7 +132,7 @@ return tdir * dtmin end - dt₀ = IfElse.ifelse((d₀ < 1 // 10^(5)) | + dt₀ = ifelse((d₀ < 1 // 10^(5)) | (d₁ < 1 // 10^(5)), smalldt, convert(_tType, oneunit_tType * DiffEqBase.value((d₀ / d₁) / diff --git a/test/interface/ode_numbertype_tests.jl b/test/interface/ode_numbertype_tests.jl index 6740442e08..9471c6cb90 100644 --- a/test/interface/ode_numbertype_tests.jl +++ b/test/interface/ode_numbertype_tests.jl @@ -27,7 +27,7 @@ sol4 = solve(prob, DP5(), dt = BigInt(1) // BigInt(2)^(3), adaptive = false) @test eltype(sol4.u) == Rational{BigInt} -tabalg = ExplicitRK(tableau = constructDormandPrince(Rational{BigInt})) +tabalg = ExplicitRK(tableau = OrdinaryDiffEq.OrdinaryDiffEqExplicitRK.constructDormandPrince(Rational{BigInt})) integrator = init(prob, tabalg, dt = BigInt(1) // BigInt(2)^(3), abstol = 1, reltol = 0, adaptive = false) From 2c8515214f41285c1df870d2536253baf20fb901 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sat, 3 Aug 2024 06:22:19 -0400 Subject: [PATCH 098/133] fix project toml --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index bb6def4837..f804b5652a 100644 --- a/Project.toml +++ b/Project.toml @@ -10,6 +10,7 @@ ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9" DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" +EnumX = "4e289a0a-7415-4d19-859d-a7e5c4648b56" ExponentialUtilities = "d4d017d3-3776-5f7e-afef-a10c40355c18" FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898" FastClosures = "9aa1b823-49e4-5ca5-8b0f-3971ec8bab6a" @@ -58,7 +59,6 @@ FillArrays = "1.9" FiniteDiff = "2" ForwardDiff = "0.10.3" FunctionWrappersWrappers = "0.1" -IfElse = "0.1" InteractiveUtils = "1.9" LineSearches = "7" LinearAlgebra = "1.9" From 947a76c29fe8441cc4c0e1d7e4e84f9af0aa34ea Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sat, 3 Aug 2024 06:58:36 -0400 Subject: [PATCH 099/133] remove extra file --- src/OrdinaryDiffEq.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/OrdinaryDiffEq.jl b/src/OrdinaryDiffEq.jl index 8f49871764..7b2d1c383c 100644 --- a/src/OrdinaryDiffEq.jl +++ b/src/OrdinaryDiffEq.jl @@ -154,7 +154,6 @@ include("integrators/integrator_interface.jl") include("integrators/integrator_utils.jl") include("cache_utils.jl") include("initialize_dae.jl") -include("wrappers.jl") include("perform_step/linear_perform_step.jl") include("perform_step/exponential_rk_perform_step.jl") From eb425a127c7e682687600021e9c34e5a2716fcef Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Sat, 3 Aug 2024 16:50:13 +0530 Subject: [PATCH 100/133] Adapt --- lib/OrdinaryDiffEqLowStorageRK/Project.toml | 1 + .../src/OrdinaryDiffEqLowStorageRK.jl | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqLowStorageRK/Project.toml b/lib/OrdinaryDiffEqLowStorageRK/Project.toml index e418603292..50de54d8e7 100644 --- a/lib/OrdinaryDiffEqLowStorageRK/Project.toml +++ b/lib/OrdinaryDiffEqLowStorageRK/Project.toml @@ -10,6 +10,7 @@ OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" Polyester = "f517fe37-dbe3-4b94-8317-1923a5111588" RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd" Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3" +Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" [compat] julia = "1.10" diff --git a/lib/OrdinaryDiffEqLowStorageRK/src/OrdinaryDiffEqLowStorageRK.jl b/lib/OrdinaryDiffEqLowStorageRK/src/OrdinaryDiffEqLowStorageRK.jl index cf67877b02..c1c31f9021 100644 --- a/lib/OrdinaryDiffEqLowStorageRK/src/OrdinaryDiffEqLowStorageRK.jl +++ b/lib/OrdinaryDiffEqLowStorageRK/src/OrdinaryDiffEqLowStorageRK.jl @@ -11,7 +11,7 @@ import OrdinaryDiffEq: alg_order, alg_adaptive_order, calculate_residuals!, alg_cache, _vec, _reshape, @cache, isfsal, full_cache, constvalue, _unwrap_val, du_alias_or_new, trivial_limiter!, perform_step!, initialize!, explicit_rk_docstring -using DiffEqBase, FastBroadcast, Polyester, MuladdMacro, RecursiveArrayTools +using DiffEqBase, FastBroadcast, Polyester, MuladdMacro, RecursiveArrayTools, Adapt import StaticArrays: SArray, MVector, SVector, @SVector, StaticArray, MMatrix, SA import Static: False import RecursiveArrayTools: recursive_unitless_bottom_eltype From ba7d0439e97ef65f4a2aa4c292c2b4d385f21d5f Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Sat, 3 Aug 2024 16:53:38 +0530 Subject: [PATCH 101/133] AutoAlgSwitch --- lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl index e1cf436aa5..0bad7aaeeb 100644 --- a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl +++ b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl @@ -6,7 +6,7 @@ import OrdinaryDiffEq: alg_order, alg_stability_size, explicit_rk_docstring, constvalue, @unpack, perform_step!, calculate_residuals, @cache, calculate_residuals!, _ode_interpolant, _ode_interpolant!, CompiledFloats, @OnDemandTableauExtract, initialize!, perform_step!, - CompositeAlgorithm, _ode_addsteps!, copyat_or_push! + CompositeAlgorithm, _ode_addsteps!, copyat_or_push!, AutoAlgSwitch import Static: False import MuladdMacro: @muladd import FastBroadcast: @.. From f123e4fa54c3f904f072093452c984eefaef5496 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Sat, 3 Aug 2024 17:01:51 +0530 Subject: [PATCH 102/133] trivial_limiter! --- .../src/OrdinaryDiffEqAdamsBashforthMoulton.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl index 6900c49edb..d5a1c38d79 100644 --- a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl @@ -3,7 +3,7 @@ module OrdinaryDiffEqAdamsBashforthMoulton import OrdinaryDiffEq: OrdinaryDiffEqMutableCache, OrdinaryDiffEqConstantCache, @cache, alg_cache, initialize!, @unpack, perform_step!, alg_order, isstandard, OrdinaryDiffEqAlgorithm, OrdinaryDiffEqAdaptiveAlgorithm, OrdinaryDiffEqAdamsVarOrderVarStepAlgorithm, - constvalue, calculate_residuals, calculate_residuals! + constvalue, calculate_residuals, calculate_residuals!, trivial_limiter! import OrdinaryDiffEq: BS3ConstantCache, BS3Cache, RK4ConstantCache, RK4Cache import RecursiveArrayTools: recursivefill! using MuladdMacro, FastBroadcast From 13a415099b966e00493b5e6e31260cee5ea90feb Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Sat, 3 Aug 2024 17:13:18 +0530 Subject: [PATCH 103/133] AutoAlgSwitch --- lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl index 778dbb6e51..1b4e7e5201 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl @@ -6,7 +6,8 @@ import OrdinaryDiffEq: alg_order, isfsal, beta2_default, beta1_default, alg_stab unwrap_alg, @unpack, initialize!, perform_step!, calculate_residuals, calculate_residuals!, _ode_addsteps!, @OnDemandTableauExtract, constvalue, OrdinaryDiffEqMutableCache, uses_uprev, OrdinaryDiffEqConstantCache, @fold, - @cache, CompiledFloats, alg_cache, CompositeAlgorithm, alg_autodiff, copyat_or_push! + @cache, CompiledFloats, alg_cache, CompositeAlgorithm, alg_autodiff, copyat_or_push!, + AutoAlgSwitch using DiffEqBase, SciMLBase import MuladdMacro: @muladd import FastBroadcast: @.. From 9db7b757dc002c7d0c50b988e699b1aed1ff572f Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Sat, 3 Aug 2024 17:23:02 +0530 Subject: [PATCH 104/133] Static --- .../src/OrdinaryDiffEqAdamsBashforthMoulton.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl index d5a1c38d79..3f522ac74b 100644 --- a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl @@ -7,6 +7,7 @@ import OrdinaryDiffEq: OrdinaryDiffEqMutableCache, OrdinaryDiffEqConstantCache, import OrdinaryDiffEq: BS3ConstantCache, BS3Cache, RK4ConstantCache, RK4Cache import RecursiveArrayTools: recursivefill! using MuladdMacro, FastBroadcast +import Static: False include("algorithms.jl") include("alg_utils.jl") From 4e32260ed578e15c85778fced172765b6aab648d Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Sat, 3 Aug 2024 17:35:30 +0530 Subject: [PATCH 105/133] ADTypes --- lib/OrdinaryDiffEqAdamsBashforthMoulton/Project.toml | 1 + .../src/OrdinaryDiffEqAdamsBashforthMoulton.jl | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/OrdinaryDiffEqAdamsBashforthMoulton/Project.toml b/lib/OrdinaryDiffEqAdamsBashforthMoulton/Project.toml index 39b4ef0716..991c7f6454 100644 --- a/lib/OrdinaryDiffEqAdamsBashforthMoulton/Project.toml +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/Project.toml @@ -10,6 +10,7 @@ OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" Polyester = "f517fe37-dbe3-4b94-8317-1923a5111588" RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd" Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3" +ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" [compat] julia = "1.10" diff --git a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl index 3f522ac74b..64732b8458 100644 --- a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl @@ -8,6 +8,7 @@ import OrdinaryDiffEq: BS3ConstantCache, BS3Cache, RK4ConstantCache, RK4Cache import RecursiveArrayTools: recursivefill! using MuladdMacro, FastBroadcast import Static: False +import ADTypes: AutoForwardDiff include("algorithms.jl") include("alg_utils.jl") From 41349aa80d12b3f50bb66c7ddca535151e44c037 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Sat, 3 Aug 2024 18:51:55 +0530 Subject: [PATCH 106/133] ADTypes --- lib/OrdinaryDiffEqRosenbrock/Project.toml | 1 + lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/OrdinaryDiffEqRosenbrock/Project.toml b/lib/OrdinaryDiffEqRosenbrock/Project.toml index 7ff5835b3b..9c315a9599 100644 --- a/lib/OrdinaryDiffEqRosenbrock/Project.toml +++ b/lib/OrdinaryDiffEqRosenbrock/Project.toml @@ -11,6 +11,7 @@ Polyester = "f517fe37-dbe3-4b94-8317-1923a5111588" RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd" Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3" DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" +ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" [compat] diff --git a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl index c598b40b45..644754e804 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl @@ -17,6 +17,7 @@ using DiffEqBase: @def import LinearSolve import ForwardDiff using LinearAlgebra: mul!, diag, diagm, I, Diagonal +import ADTypes: AutoForwardDiff function rosenbrock_wanner_docstring(description::String, name::String; From e25583f394142a2acfac11773a0ac3e830747d88 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Sat, 3 Aug 2024 19:23:28 +0530 Subject: [PATCH 107/133] Tsit5ConstantCache --- lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl | 2 +- src/OrdinaryDiffEq.jl | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl b/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl index 105fb19717..5b5e1d3a5c 100644 --- a/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl +++ b/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl @@ -4,7 +4,7 @@ import OrdinaryDiffEq: alg_order, alg_adaptive_order, qsteady_max_default, get_c AbstractController, OrdinaryDiffEqAdaptiveAlgorithm, OrdinaryDiffEqAdamsVarOrderVarStepAlgorithm, alg_cache, OrdinaryDiffEqMutableCache, OrdinaryDiffEqConstantCache, initialize!, @unpack, initialize!, perform_step!, stepsize_controller!, step_accept_controller!, step_reject_controller!, - calculate_residuals, calculate_residuals! + calculate_residuals, calculate_residuals!, Tsit5ConstantCache using MuladdMacro, FastBroadcast, RecursiveArrayTools include("algorithms.jl") diff --git a/src/OrdinaryDiffEq.jl b/src/OrdinaryDiffEq.jl index 7b2d1c383c..b699012e6f 100644 --- a/src/OrdinaryDiffEq.jl +++ b/src/OrdinaryDiffEq.jl @@ -246,6 +246,7 @@ export ABDF2, QNDF1, QBDF1, QNDF2, QBDF2, QNDF, QBDF, FBDF, include("../lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl") using ..OrdinaryDiffEqTsit5 export Tsit5, AutoTsit5 +import .OrdinaryDiffEqTsit5: Tsit5ConstantCache include("../lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl") using ..OrdinaryDiffEqRosenbrock From 1b8afa4e0ccdc1ed4103c7ef1f108f7cde5d140e Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Sat, 3 Aug 2024 19:32:44 +0530 Subject: [PATCH 108/133] full_cache --- lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl index 0bad7aaeeb..9168c6f646 100644 --- a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl +++ b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl @@ -6,7 +6,8 @@ import OrdinaryDiffEq: alg_order, alg_stability_size, explicit_rk_docstring, constvalue, @unpack, perform_step!, calculate_residuals, @cache, calculate_residuals!, _ode_interpolant, _ode_interpolant!, CompiledFloats, @OnDemandTableauExtract, initialize!, perform_step!, - CompositeAlgorithm, _ode_addsteps!, copyat_or_push!, AutoAlgSwitch + CompositeAlgorithm, _ode_addsteps!, copyat_or_push!, AutoAlgSwitch, + full_cache import Static: False import MuladdMacro: @muladd import FastBroadcast: @.. From 10a9a1e5ce6d180a15c978a3a37aeab9a96d6141 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Sat, 3 Aug 2024 19:55:07 +0530 Subject: [PATCH 109/133] norm --- lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl index 644754e804..2614bfa648 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl @@ -16,7 +16,7 @@ using MacroTools: @capture using DiffEqBase: @def import LinearSolve import ForwardDiff -using LinearAlgebra: mul!, diag, diagm, I, Diagonal +using LinearAlgebra: mul!, diag, diagm, I, Diagonal, norm import ADTypes: AutoForwardDiff function rosenbrock_wanner_docstring(description::String, From b1ca7d8e87275585f27f551a5fcf55dc699de312 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Sat, 3 Aug 2024 20:07:01 +0530 Subject: [PATCH 110/133] full_cache --- lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl index 2614bfa648..a12fc68986 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl @@ -9,7 +9,7 @@ import OrdinaryDiffEq: alg_order, alg_adaptive_order, isWmethod, isfsal, _unwrap constvalue, TimeDerivativeWrapper, TimeGradientWrapper, UDerivativeWrapper, UJacobianWrapper, wrapprecs, alg_autodiff, calc_tderivative, build_grad_config, build_jac_config, issuccess_W, calculate_residuals, has_stiff_interpolation, - resize_non_user_cache!, _ode_addsteps!, jacobian2W! + resize_non_user_cache!, _ode_addsteps!, jacobian2W!, full_cache using TruncatedStacktraces, MuladdMacro, FastBroadcast, DiffEqBase, RecursiveArrayTools import MacroTools using MacroTools: @capture From 984bce70764b0d5cb779d91d316e873518bc68a9 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sat, 3 Aug 2024 11:01:26 -0400 Subject: [PATCH 111/133] Update lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl --- lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl b/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl index 5b5e1d3a5c..675f5b48e6 100644 --- a/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl +++ b/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl @@ -4,7 +4,7 @@ import OrdinaryDiffEq: alg_order, alg_adaptive_order, qsteady_max_default, get_c AbstractController, OrdinaryDiffEqAdaptiveAlgorithm, OrdinaryDiffEqAdamsVarOrderVarStepAlgorithm, alg_cache, OrdinaryDiffEqMutableCache, OrdinaryDiffEqConstantCache, initialize!, @unpack, initialize!, perform_step!, stepsize_controller!, step_accept_controller!, step_reject_controller!, - calculate_residuals, calculate_residuals!, Tsit5ConstantCache + calculate_residuals, calculate_residuals!, Tsit5ConstantCache, get_current_adaptive_order, ode_interpolant, ode_interpolant! using MuladdMacro, FastBroadcast, RecursiveArrayTools include("algorithms.jl") From 913b9eeb2a4dfb1b2741d2b11cbc0992668be1b0 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sat, 3 Aug 2024 11:02:24 -0400 Subject: [PATCH 112/133] Update src/OrdinaryDiffEq.jl --- src/OrdinaryDiffEq.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OrdinaryDiffEq.jl b/src/OrdinaryDiffEq.jl index b699012e6f..7486ccd607 100644 --- a/src/OrdinaryDiffEq.jl +++ b/src/OrdinaryDiffEq.jl @@ -306,6 +306,7 @@ export AN5, JVODE, JVODE_Adams, JVODE_BDF include("../lib/OrdinaryDiffEqExplicitRK/src/OrdinaryDiffEqExplicitRK.jl") using ..OrdinaryDiffEqExplicitRK +using ..OrdinaryDiffEqExplicitRK: constructDormandPrince export ExplicitRK PrecompileTools.@compile_workload begin From 032ee4dcda11f45cbd8f98a616146b1ed05208ef Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sat, 3 Aug 2024 11:36:32 -0400 Subject: [PATCH 113/133] a few more missing bits --- lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl | 2 +- lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl index 1b4e7e5201..10cfae06ad 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl @@ -7,7 +7,7 @@ import OrdinaryDiffEq: alg_order, isfsal, beta2_default, beta1_default, alg_stab calculate_residuals!, _ode_addsteps!, @OnDemandTableauExtract, constvalue, OrdinaryDiffEqMutableCache, uses_uprev, OrdinaryDiffEqConstantCache, @fold, @cache, CompiledFloats, alg_cache, CompositeAlgorithm, alg_autodiff, copyat_or_push!, - AutoAlgSwitch + AutoAlgSwitch, _ode_interpolant, _ode_interpolant! using DiffEqBase, SciMLBase import MuladdMacro: @muladd import FastBroadcast: @.. diff --git a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl index a12fc68986..6c0e508f1d 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl @@ -90,6 +90,7 @@ include("interp_func.jl") include("rosenbrock_interpolants.jl") include("stiff_addsteps.jl") include("rosenbrock_perform_step.jl") +include("integrator_interface.jl") export Rosenbrock23, Rosenbrock32, RosShamp4, Veldd4, Velds4, GRK4T, GRK4A, Ros4LStab, ROS3P, Rodas3, Rodas23W, Rodas3P, Rodas4, Rodas42, Rodas4P, Rodas4P2, From 1cf0be4ee507efdfd87c61cb82d55d399d151595 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Sat, 3 Aug 2024 21:40:11 +0530 Subject: [PATCH 114/133] ODEIntegrator --- lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl index 6c0e508f1d..d52183fbef 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl @@ -8,7 +8,7 @@ import OrdinaryDiffEq: alg_order, alg_adaptive_order, isWmethod, isfsal, _unwrap OrdinaryDiffEqRosenbrockAlgorithm, generic_solver_docstring, namify, initialize!, perform_step!, constvalue, TimeDerivativeWrapper, TimeGradientWrapper, UDerivativeWrapper, UJacobianWrapper, wrapprecs, alg_autodiff, calc_tderivative, build_grad_config, build_jac_config, - issuccess_W, calculate_residuals, has_stiff_interpolation, + issuccess_W, calculate_residuals, has_stiff_interpolation, ODEIntegrator, resize_non_user_cache!, _ode_addsteps!, jacobian2W!, full_cache using TruncatedStacktraces, MuladdMacro, FastBroadcast, DiffEqBase, RecursiveArrayTools import MacroTools From 03093acea5ce9ecc25512639e99190574118b3eb Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Sat, 3 Aug 2024 22:16:23 +0530 Subject: [PATCH 115/133] perform_predict! --- lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl b/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl index 675f5b48e6..6757ad9582 100644 --- a/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl +++ b/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl @@ -4,7 +4,8 @@ import OrdinaryDiffEq: alg_order, alg_adaptive_order, qsteady_max_default, get_c AbstractController, OrdinaryDiffEqAdaptiveAlgorithm, OrdinaryDiffEqAdamsVarOrderVarStepAlgorithm, alg_cache, OrdinaryDiffEqMutableCache, OrdinaryDiffEqConstantCache, initialize!, @unpack, initialize!, perform_step!, stepsize_controller!, step_accept_controller!, step_reject_controller!, - calculate_residuals, calculate_residuals!, Tsit5ConstantCache, get_current_adaptive_order, ode_interpolant, ode_interpolant! + calculate_residuals, calculate_residuals!, Tsit5ConstantCache, get_current_adaptive_order, + ode_interpolant, ode_interpolant!, perform_predict! using MuladdMacro, FastBroadcast, RecursiveArrayTools include("algorithms.jl") From 0bb766e4c7083299c6c028a425fc266d8675ab7a Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Sun, 4 Aug 2024 00:10:08 +0530 Subject: [PATCH 116/133] full_cache --- lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl index 10cfae06ad..6b9a7ba668 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl @@ -7,7 +7,7 @@ import OrdinaryDiffEq: alg_order, isfsal, beta2_default, beta1_default, alg_stab calculate_residuals!, _ode_addsteps!, @OnDemandTableauExtract, constvalue, OrdinaryDiffEqMutableCache, uses_uprev, OrdinaryDiffEqConstantCache, @fold, @cache, CompiledFloats, alg_cache, CompositeAlgorithm, alg_autodiff, copyat_or_push!, - AutoAlgSwitch, _ode_interpolant, _ode_interpolant! + AutoAlgSwitch, _ode_interpolant, _ode_interpolant!, full_cache using DiffEqBase, SciMLBase import MuladdMacro: @muladd import FastBroadcast: @.. From 439fad12b7b7e39c2e22b92c63edd613b7daa4a3 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sat, 3 Aug 2024 15:37:15 -0400 Subject: [PATCH 117/133] Fix prediction import --- lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl b/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl index 6757ad9582..5476c3fc9a 100644 --- a/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl +++ b/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl @@ -5,12 +5,13 @@ import OrdinaryDiffEq: alg_order, alg_adaptive_order, qsteady_max_default, get_c alg_cache, OrdinaryDiffEqMutableCache, OrdinaryDiffEqConstantCache, initialize!, @unpack, initialize!, perform_step!, stepsize_controller!, step_accept_controller!, step_reject_controller!, calculate_residuals, calculate_residuals!, Tsit5ConstantCache, get_current_adaptive_order, - ode_interpolant, ode_interpolant!, perform_predict! + ode_interpolant, ode_interpolant! using MuladdMacro, FastBroadcast, RecursiveArrayTools include("algorithms.jl") include("controllers.jl") include("alg_utils.jl") +include("nordsieck_utils.jl") include("nordsieck_caches.jl") include("nordsieck_perform_step.jl") From b269441b651bee6675c94161ee10a5b5eae06474 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sat, 3 Aug 2024 15:50:27 -0400 Subject: [PATCH 118/133] add missing custom interpolations --- lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl index 6b9a7ba668..871d81f7e2 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl @@ -21,6 +21,7 @@ include("alg_utils.jl") include("low_order_rk_caches.jl") include("low_order_rk_tableaus.jl") include("interp_func.jl") +include("interpolants.jl") include("low_order_rk_perform_step.jl") include("low_order_rk_addsteps.jl") include("split_perform_step.jl") From fc502771bf6055592f4afa3f903c0917958300a7 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Sun, 4 Aug 2024 01:28:30 +0530 Subject: [PATCH 119/133] DP8ConstantCache --- lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl | 2 +- src/OrdinaryDiffEq.jl | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl index 871d81f7e2..87e266878a 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl @@ -7,7 +7,7 @@ import OrdinaryDiffEq: alg_order, isfsal, beta2_default, beta1_default, alg_stab calculate_residuals!, _ode_addsteps!, @OnDemandTableauExtract, constvalue, OrdinaryDiffEqMutableCache, uses_uprev, OrdinaryDiffEqConstantCache, @fold, @cache, CompiledFloats, alg_cache, CompositeAlgorithm, alg_autodiff, copyat_or_push!, - AutoAlgSwitch, _ode_interpolant, _ode_interpolant!, full_cache + AutoAlgSwitch, _ode_interpolant, _ode_interpolant!, full_cache, DP8ConstantCache using DiffEqBase, SciMLBase import MuladdMacro: @muladd import FastBroadcast: @.. diff --git a/src/OrdinaryDiffEq.jl b/src/OrdinaryDiffEq.jl index 7486ccd607..5ece1c0059 100644 --- a/src/OrdinaryDiffEq.jl +++ b/src/OrdinaryDiffEq.jl @@ -281,6 +281,7 @@ export KuttaPRK2p5 include("../lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl") using ..OrdinaryDiffEqHighOrderRK export TanYam7, DP8, PFRK87, TsitPap8 +using ..OrdinaryDiffEqHighOrderRK: DP8ConstantCache include("../lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl") using ..OrdinaryDiffEqLowOrderRK From b1d993e41506a0e5cb4b9cec3dd8e12f2ba7dd0d Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sat, 3 Aug 2024 18:03:43 -0400 Subject: [PATCH 120/133] move high order interpolant --- .../src/OrdinaryDiffEqHighOrderRK.jl | 3 +- .../src/interpolants.jl | 140 +++++++++++++++++ .../src/OrdinaryDiffEqLowOrderRK.jl | 2 +- .../src/interpolants.jl | 146 +----------------- 4 files changed, 144 insertions(+), 147 deletions(-) create mode 100644 lib/OrdinaryDiffEqHighOrderRK/src/interpolants.jl diff --git a/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl b/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl index 7252cefab0..6e0f5918cc 100644 --- a/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl +++ b/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl @@ -5,7 +5,7 @@ import OrdinaryDiffEq: alg_order, qmax_default, qmin_default, beta2_default, bet _ode_addsteps!, @unpack, @cache, OrdinaryDiffEqMutableCache, constvalue, alg_cache, uses_uprev, initialize!, perform_step!, OrdinaryDiffEqConstantCache, calculate_residuals!, calculate_residuals, CompiledFloats, copyat_or_push!, - unwrap_alg + unwrap_alg, _ode_interpolant, _ode_interpolant! import Static: False import MuladdMacro: @muladd using DiffEqBase @@ -18,6 +18,7 @@ include("alg_utils.jl") include("high_order_rk_caches.jl") include("high_order_rk_tableaus.jl") include("interp_func.jl") +include("interpolants.jl") include("high_order_rk_addsteps.jl") include("high_order_rk_perform_step.jl") diff --git a/lib/OrdinaryDiffEqHighOrderRK/src/interpolants.jl b/lib/OrdinaryDiffEqHighOrderRK/src/interpolants.jl new file mode 100644 index 0000000000..7076eedb7a --- /dev/null +++ b/lib/OrdinaryDiffEqHighOrderRK/src/interpolants.jl @@ -0,0 +1,140 @@ +""" +""" +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{DP8ConstantCache, DP8Cache}, idxs::Nothing, + T::Type{Val{0}}, differential_vars::Nothing) + Θ1 = 1 - Θ + # return @.. broadcast=false y₀ + dt*Θ*(k[1] + Θ1*(k[2] + Θ*(k[3]+Θ1*(k[4] + Θ*(k[5] + Θ1*(k[6]+Θ*k[7])))))) + return @inbounds y₀ + + dt * Θ * + (k[1] + + Θ1 * (k[2] + + Θ * (k[3] + Θ1 * (k[4] + Θ * (k[5] + Θ1 * (k[6] + Θ * k[7])))))) +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{DP8ConstantCache, DP8Cache}, idxs, + T::Type{Val{0}}, differential_vars::Nothing) + Θ1 = 1 - Θ + # return @.. broadcast=false y₀[idxs] + dt*Θ*(k[1][idxs] + Θ1*(k[2][idxs] + Θ*(k[3][idxs]+Θ1*(k[4][idxs] + Θ*(k[5][idxs] + Θ1*(k[6][idxs]+Θ*k[7][idxs])))))) + return y₀[idxs] + + dt * Θ * + (k[1][idxs] + + Θ1 * (k[2][idxs] + + Θ * (k[3][idxs] + + Θ1 * (k[4][idxs] + Θ * (k[5][idxs] + Θ1 * (k[6][idxs] + Θ * k[7][idxs])))))) +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{DP8ConstantCache, DP8Cache}, idxs::Nothing, + T::Type{Val{0}}, differential_vars::Nothing) + Θ1 = 1 - Θ + @inbounds @.. broadcast=false out=y₀ + + dt * Θ * + (k[1] + + Θ1 * (k[2] + + Θ * (k[3] + + Θ1 * + (k[4] + Θ * (k[5] + Θ1 * (k[6] + Θ * k[7])))))) + #@inbounds for i in eachindex(out) + # out[i] = y₀[i] + dt*Θ*(k[1][i] + Θ1*(k[2][i] + Θ*(k[3][i]+Θ1*(k[4][i] + Θ*(k[5][i] + Θ1*(k[6][i]+Θ*k[7][i])))))) + #end + out +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{DP8ConstantCache, DP8Cache}, idxs, + T::Type{Val{0}}, differential_vars::Nothing) + Θ1 = 1 - Θ + @views @.. broadcast=false out=y₀[idxs] + + dt * Θ * + (k[1][idxs] + + Θ1 * (k[2][idxs] + + Θ * (k[3][idxs] + + Θ1 * (k[4][idxs] + + Θ * + (k[5][idxs] + Θ1 * (k[6][idxs] + Θ * k[7][idxs])))))) + #@inbounds for (j,i) in enumerate(idxs) + # out[j] = y₀[i] + dt*Θ*(k[1][i] + Θ1*(k[2][i] + Θ*(k[3][i]+Θ1*(k[4][i] + Θ*(k[5][i] + Θ1*(k[6][i]+Θ*k[7][i])))))) + #end + out +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{DP8ConstantCache, DP8Cache}, idxs::Nothing, + T::Type{Val{1}}, differential_vars::Nothing) + @inbounds b1diff = @.. broadcast=false k[1]+k[2] + @inbounds b2diff = @.. broadcast=false -2*k[2]+2*k[3]+2*k[4] + @inbounds b3diff = @.. broadcast=false -3 * k[3]-6 * k[4]+3*k[5]+3*k[6] + @inbounds b4diff = @.. broadcast=false 4 * k[4] - 8 * k[5] - 12 * k[6]+4 * k[7] + @inbounds b5diff = @.. broadcast=false 5 * k[5] + 15 * k[6]-15 * k[7] + @inbounds b6diff = @.. broadcast=false -6 * k[6]+18 * k[7] + @inbounds b7diff = @.. broadcast=false -7*k[7] + # return @.. broadcast=false b1diff + Θ*(b2diff + Θ*(b3diff + Θ*(b4diff + Θ*(b5diff + Θ*(b6diff + Θ*b7diff))))) + return b1diff + + Θ * + (b2diff + Θ * (b3diff + Θ * (b4diff + Θ * (b5diff + Θ * (b6diff + Θ * b7diff))))) +end + +@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{DP8ConstantCache, DP8Cache}, idxs, + T::Type{Val{1}}, differential_vars::Nothing) + b1diff = @.. broadcast=false k[1][idxs]+k[2][idxs] + b2diff = @.. broadcast=false -2*k[2][idxs]+2*k[3][idxs]+2*k[4][idxs] + b3diff = @.. broadcast=false -3 * k[3][idxs]-6 * k[4][idxs]+3*k[5][idxs]+3*k[6][idxs] + b4diff = @.. broadcast=false 4 * k[4][idxs] - 8 * k[5][idxs] - + 12 * k[6][idxs]+4 * k[7][idxs] + b5diff = @.. broadcast=false 5 * k[5][idxs] + 15 * k[6][idxs]-15 * k[7][idxs] + b6diff = @.. broadcast=false -6 * k[6][idxs]+18 * k[7][idxs] + b7diff = @.. broadcast=false -7*k[7][idxs] + # return @.. broadcast=false b1diff + Θ*(b2diff + Θ*(b3diff + Θ*(b4diff + Θ*(b5diff + Θ*(b6diff + Θ*b7diff))))) + return b1diff + + Θ * + (b2diff + Θ * (b3diff + Θ * (b4diff + Θ * (b5diff + Θ * (b6diff + Θ * b7diff))))) +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{DP8ConstantCache, DP8Cache}, idxs::Nothing, + T::Type{Val{1}}, differential_vars::Nothing) + # b1diff = k[1] + k[2] + # b2diff = -2*k[2] + 2*k[3] + 2*k[4] + # b3diff = -3*k[3] - 6*k[4] + 3*k[5] + 3*k[6] + # b4diff = 4*k[4] - 8*k[5] - 12*k[6] + 4*k[7] + # b5diff = 5*k[5] + 15*k[6] - 15*k[7] + # b6diff = -6*k[6] + 18*k[7] + # @.. broadcast=false out = b1diff + Θ*(b2diff + Θ*(b3diff + Θ*(b4diff + + # Θ*(b5diff + Θ*(b6diff - 7*k[7]*Θ))))) + @views @.. broadcast=false out=k[1] + k[2] + + Θ * (-2 * k[2] + 2 * k[3] + 2 * k[4] + + Θ * (-3 * k[3] - 6 * k[4] + 3 * k[5] + 3 * k[6] + + Θ * (4 * k[4] - 8 * k[5] - 12 * k[6] + 4 * k[7] + + Θ * (5 * k[5] + 15 * k[6] - 15 * k[7] + + Θ * (-6 * k[6] + 18 * k[7] - 7 * k[7] * Θ))))) + out +end + +@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{DP8ConstantCache, DP8Cache}, idxs, + T::Type{Val{1}}, differential_vars::Nothing) + # b1diff = k[1][idxs] + k[2][idxs] + # b2diff = -2*k[2][idxs] + 2*k[3][idxs] + 2*k[4][idxs] + # b3diff = -3*k[3][idxs] - 6*k[4][idxs] + 3*k[5][idxs] + 3*k[6][idxs] + # b4diff = 4*k[4][idxs] - 8*k[5][idxs] - 12*k[6][idxs] + 4*k[7][idxs] + # b5diff = 5*k[5][idxs] + 15*k[6][idxs] - 15*k[7][idxs] + # b6diff = -6*k[6][idxs] + 18*k[7][idxs] + #@views @.. broadcast=false out = b1diff + Θ*(b2diff + Θ*(b3diff + Θ*(b4diff + + # Θ*(b5diff + Θ*(b6diff - 7*k[7][idxs]*Θ))))) + @views @.. broadcast=false out=k[1][idxs] + k[2][idxs] + + Θ * (-2 * k[2][idxs] + 2 * k[3][idxs] + 2 * k[4][idxs] + + Θ * + (-3 * k[3][idxs] - 6 * k[4][idxs] + 3 * k[5][idxs] + + 3 * k[6][idxs] + + Θ * + (4 * k[4][idxs] - 8 * k[5][idxs] - 12 * k[6][idxs] + + 4 * k[7][idxs] + + Θ * + (5 * k[5][idxs] + 15 * k[6][idxs] - 15 * k[7][idxs] + + Θ * (-6 * k[6][idxs] + 18 * k[7][idxs] - + 7 * k[7][idxs] * Θ))))) + out +end \ No newline at end of file diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl index 87e266878a..871d81f7e2 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl @@ -7,7 +7,7 @@ import OrdinaryDiffEq: alg_order, isfsal, beta2_default, beta1_default, alg_stab calculate_residuals!, _ode_addsteps!, @OnDemandTableauExtract, constvalue, OrdinaryDiffEqMutableCache, uses_uprev, OrdinaryDiffEqConstantCache, @fold, @cache, CompiledFloats, alg_cache, CompositeAlgorithm, alg_autodiff, copyat_or_push!, - AutoAlgSwitch, _ode_interpolant, _ode_interpolant!, full_cache, DP8ConstantCache + AutoAlgSwitch, _ode_interpolant, _ode_interpolant!, full_cache using DiffEqBase, SciMLBase import MuladdMacro: @muladd import FastBroadcast: @.. diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/interpolants.jl b/lib/OrdinaryDiffEqLowOrderRK/src/interpolants.jl index d6df06413e..ccc53c1e8b 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/interpolants.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/interpolants.jl @@ -1188,148 +1188,4 @@ end # out[j] = k[1][i] + k[1][i]*b1Θdiff + k[3][i]*b3Θdiff + k[4][i]*b4Θdiff + k[5][i]*b5Θdiff + k[6][i]*b6Θdiff + k[7][i]*b7Θdiff + k[8][i]*b8Θdiff + k[9][i]*b9Θdiff + k[10][i]*b10Θdiff + k[11][i]*b11Θdiff #end out -end - -""" -""" -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{DP8ConstantCache, DP8Cache}, idxs::Nothing, - T::Type{Val{0}}, differential_vars::Nothing) - Θ1 = 1 - Θ - # return @.. broadcast=false y₀ + dt*Θ*(k[1] + Θ1*(k[2] + Θ*(k[3]+Θ1*(k[4] + Θ*(k[5] + Θ1*(k[6]+Θ*k[7])))))) - return @inbounds y₀ + - dt * Θ * - (k[1] + - Θ1 * (k[2] + - Θ * (k[3] + Θ1 * (k[4] + Θ * (k[5] + Θ1 * (k[6] + Θ * k[7])))))) -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{DP8ConstantCache, DP8Cache}, idxs, - T::Type{Val{0}}, differential_vars::Nothing) - Θ1 = 1 - Θ - # return @.. broadcast=false y₀[idxs] + dt*Θ*(k[1][idxs] + Θ1*(k[2][idxs] + Θ*(k[3][idxs]+Θ1*(k[4][idxs] + Θ*(k[5][idxs] + Θ1*(k[6][idxs]+Θ*k[7][idxs])))))) - return y₀[idxs] + - dt * Θ * - (k[1][idxs] + - Θ1 * (k[2][idxs] + - Θ * (k[3][idxs] + - Θ1 * (k[4][idxs] + Θ * (k[5][idxs] + Θ1 * (k[6][idxs] + Θ * k[7][idxs])))))) -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{DP8ConstantCache, DP8Cache}, idxs::Nothing, - T::Type{Val{0}}, differential_vars::Nothing) - Θ1 = 1 - Θ - @inbounds @.. broadcast=false out=y₀ + - dt * Θ * - (k[1] + - Θ1 * (k[2] + - Θ * (k[3] + - Θ1 * - (k[4] + Θ * (k[5] + Θ1 * (k[6] + Θ * k[7])))))) - #@inbounds for i in eachindex(out) - # out[i] = y₀[i] + dt*Θ*(k[1][i] + Θ1*(k[2][i] + Θ*(k[3][i]+Θ1*(k[4][i] + Θ*(k[5][i] + Θ1*(k[6][i]+Θ*k[7][i])))))) - #end - out -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{DP8ConstantCache, DP8Cache}, idxs, - T::Type{Val{0}}, differential_vars::Nothing) - Θ1 = 1 - Θ - @views @.. broadcast=false out=y₀[idxs] + - dt * Θ * - (k[1][idxs] + - Θ1 * (k[2][idxs] + - Θ * (k[3][idxs] + - Θ1 * (k[4][idxs] + - Θ * - (k[5][idxs] + Θ1 * (k[6][idxs] + Θ * k[7][idxs])))))) - #@inbounds for (j,i) in enumerate(idxs) - # out[j] = y₀[i] + dt*Θ*(k[1][i] + Θ1*(k[2][i] + Θ*(k[3][i]+Θ1*(k[4][i] + Θ*(k[5][i] + Θ1*(k[6][i]+Θ*k[7][i])))))) - #end - out -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{DP8ConstantCache, DP8Cache}, idxs::Nothing, - T::Type{Val{1}}, differential_vars::Nothing) - @inbounds b1diff = @.. broadcast=false k[1]+k[2] - @inbounds b2diff = @.. broadcast=false -2*k[2]+2*k[3]+2*k[4] - @inbounds b3diff = @.. broadcast=false -3 * k[3]-6 * k[4]+3*k[5]+3*k[6] - @inbounds b4diff = @.. broadcast=false 4 * k[4] - 8 * k[5] - 12 * k[6]+4 * k[7] - @inbounds b5diff = @.. broadcast=false 5 * k[5] + 15 * k[6]-15 * k[7] - @inbounds b6diff = @.. broadcast=false -6 * k[6]+18 * k[7] - @inbounds b7diff = @.. broadcast=false -7*k[7] - # return @.. broadcast=false b1diff + Θ*(b2diff + Θ*(b3diff + Θ*(b4diff + Θ*(b5diff + Θ*(b6diff + Θ*b7diff))))) - return b1diff + - Θ * - (b2diff + Θ * (b3diff + Θ * (b4diff + Θ * (b5diff + Θ * (b6diff + Θ * b7diff))))) -end - -@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{DP8ConstantCache, DP8Cache}, idxs, - T::Type{Val{1}}, differential_vars::Nothing) - b1diff = @.. broadcast=false k[1][idxs]+k[2][idxs] - b2diff = @.. broadcast=false -2*k[2][idxs]+2*k[3][idxs]+2*k[4][idxs] - b3diff = @.. broadcast=false -3 * k[3][idxs]-6 * k[4][idxs]+3*k[5][idxs]+3*k[6][idxs] - b4diff = @.. broadcast=false 4 * k[4][idxs] - 8 * k[5][idxs] - - 12 * k[6][idxs]+4 * k[7][idxs] - b5diff = @.. broadcast=false 5 * k[5][idxs] + 15 * k[6][idxs]-15 * k[7][idxs] - b6diff = @.. broadcast=false -6 * k[6][idxs]+18 * k[7][idxs] - b7diff = @.. broadcast=false -7*k[7][idxs] - # return @.. broadcast=false b1diff + Θ*(b2diff + Θ*(b3diff + Θ*(b4diff + Θ*(b5diff + Θ*(b6diff + Θ*b7diff))))) - return b1diff + - Θ * - (b2diff + Θ * (b3diff + Θ * (b4diff + Θ * (b5diff + Θ * (b6diff + Θ * b7diff))))) -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{DP8ConstantCache, DP8Cache}, idxs::Nothing, - T::Type{Val{1}}, differential_vars::Nothing) - # b1diff = k[1] + k[2] - # b2diff = -2*k[2] + 2*k[3] + 2*k[4] - # b3diff = -3*k[3] - 6*k[4] + 3*k[5] + 3*k[6] - # b4diff = 4*k[4] - 8*k[5] - 12*k[6] + 4*k[7] - # b5diff = 5*k[5] + 15*k[6] - 15*k[7] - # b6diff = -6*k[6] + 18*k[7] - # @.. broadcast=false out = b1diff + Θ*(b2diff + Θ*(b3diff + Θ*(b4diff + - # Θ*(b5diff + Θ*(b6diff - 7*k[7]*Θ))))) - @views @.. broadcast=false out=k[1] + k[2] + - Θ * (-2 * k[2] + 2 * k[3] + 2 * k[4] + - Θ * (-3 * k[3] - 6 * k[4] + 3 * k[5] + 3 * k[6] + - Θ * (4 * k[4] - 8 * k[5] - 12 * k[6] + 4 * k[7] + - Θ * (5 * k[5] + 15 * k[6] - 15 * k[7] + - Θ * (-6 * k[6] + 18 * k[7] - 7 * k[7] * Θ))))) - out -end - -@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{DP8ConstantCache, DP8Cache}, idxs, - T::Type{Val{1}}, differential_vars::Nothing) - # b1diff = k[1][idxs] + k[2][idxs] - # b2diff = -2*k[2][idxs] + 2*k[3][idxs] + 2*k[4][idxs] - # b3diff = -3*k[3][idxs] - 6*k[4][idxs] + 3*k[5][idxs] + 3*k[6][idxs] - # b4diff = 4*k[4][idxs] - 8*k[5][idxs] - 12*k[6][idxs] + 4*k[7][idxs] - # b5diff = 5*k[5][idxs] + 15*k[6][idxs] - 15*k[7][idxs] - # b6diff = -6*k[6][idxs] + 18*k[7][idxs] - #@views @.. broadcast=false out = b1diff + Θ*(b2diff + Θ*(b3diff + Θ*(b4diff + - # Θ*(b5diff + Θ*(b6diff - 7*k[7][idxs]*Θ))))) - @views @.. broadcast=false out=k[1][idxs] + k[2][idxs] + - Θ * (-2 * k[2][idxs] + 2 * k[3][idxs] + 2 * k[4][idxs] + - Θ * - (-3 * k[3][idxs] - 6 * k[4][idxs] + 3 * k[5][idxs] + - 3 * k[6][idxs] + - Θ * - (4 * k[4][idxs] - 8 * k[5][idxs] - 12 * k[6][idxs] + - 4 * k[7][idxs] + - Θ * - (5 * k[5][idxs] + 15 * k[6][idxs] - 15 * k[7][idxs] + - Θ * (-6 * k[6][idxs] + 18 * k[7][idxs] - - 7 * k[7][idxs] * Θ))))) - out -end - -""" -""" \ No newline at end of file +end \ No newline at end of file From b8a9bd34264e3d7d224fc48a9f464abc52362dc7 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sat, 3 Aug 2024 18:25:04 -0400 Subject: [PATCH 121/133] a bit more --- .../src/OrdinaryDiffEqHighOrderRK.jl | 3 ++- lib/OrdinaryDiffEqHighOrderRK/src/interpolants.jl | 12 ++++++++++++ .../src/OrdinaryDiffEqLowOrderRK.jl | 3 ++- .../src/OrdinaryDiffEqRosenbrock.jl | 3 ++- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl b/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl index 6e0f5918cc..c1349c3c4e 100644 --- a/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl +++ b/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl @@ -5,7 +5,8 @@ import OrdinaryDiffEq: alg_order, qmax_default, qmin_default, beta2_default, bet _ode_addsteps!, @unpack, @cache, OrdinaryDiffEqMutableCache, constvalue, alg_cache, uses_uprev, initialize!, perform_step!, OrdinaryDiffEqConstantCache, calculate_residuals!, calculate_residuals, CompiledFloats, copyat_or_push!, - unwrap_alg, _ode_interpolant, _ode_interpolant! + unwrap_alg, _ode_interpolant, _ode_interpolant!, + DerivativeOrderNotPossibleError import Static: False import MuladdMacro: @muladd using DiffEqBase diff --git a/lib/OrdinaryDiffEqHighOrderRK/src/interpolants.jl b/lib/OrdinaryDiffEqHighOrderRK/src/interpolants.jl index 7076eedb7a..4556a5e9cd 100644 --- a/lib/OrdinaryDiffEqHighOrderRK/src/interpolants.jl +++ b/lib/OrdinaryDiffEqHighOrderRK/src/interpolants.jl @@ -1,3 +1,15 @@ +function _ode_interpolant(Θ, dt, y₀, y₁, k, + cache::Union{DP8ConstantCache, DP8Cache}, + idxs, T::Type{Val{D}}, differential_vars) where {D} + throw(DerivativeOrderNotPossibleError()) +end + +function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, + cache::Union{DP8ConstantCache, DP8Cache}, + idxs, T::Type{Val{D}}, differential_vars) where {D} + throw(DerivativeOrderNotPossibleError()) +end + """ """ @muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl index 871d81f7e2..4cc5c051f3 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl @@ -7,7 +7,8 @@ import OrdinaryDiffEq: alg_order, isfsal, beta2_default, beta1_default, alg_stab calculate_residuals!, _ode_addsteps!, @OnDemandTableauExtract, constvalue, OrdinaryDiffEqMutableCache, uses_uprev, OrdinaryDiffEqConstantCache, @fold, @cache, CompiledFloats, alg_cache, CompositeAlgorithm, alg_autodiff, copyat_or_push!, - AutoAlgSwitch, _ode_interpolant, _ode_interpolant!, full_cache + AutoAlgSwitch, _ode_interpolant, _ode_interpolant!, full_cache, + accept_step_controller using DiffEqBase, SciMLBase import MuladdMacro: @muladd import FastBroadcast: @.. diff --git a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl index d52183fbef..25604e563c 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl @@ -9,7 +9,8 @@ import OrdinaryDiffEq: alg_order, alg_adaptive_order, isWmethod, isfsal, _unwrap constvalue, TimeDerivativeWrapper, TimeGradientWrapper, UDerivativeWrapper, UJacobianWrapper, wrapprecs, alg_autodiff, calc_tderivative, build_grad_config, build_jac_config, issuccess_W, calculate_residuals, has_stiff_interpolation, ODEIntegrator, - resize_non_user_cache!, _ode_addsteps!, jacobian2W!, full_cache + resize_non_user_cache!, _ode_addsteps!, jacobian2W!, full_cache, + resize_jac_config!, resize_grad_config! using TruncatedStacktraces, MuladdMacro, FastBroadcast, DiffEqBase, RecursiveArrayTools import MacroTools using MacroTools: @capture From 7fb10377c9a8fd46f9d7428820d934a5c0231371 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sat, 3 Aug 2024 19:52:30 -0400 Subject: [PATCH 122/133] getting close --- lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl | 2 +- test/interface/interpolation_derivative_error_tests.jl | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl b/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl index 5476c3fc9a..96ef875b48 100644 --- a/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl +++ b/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl @@ -5,7 +5,7 @@ import OrdinaryDiffEq: alg_order, alg_adaptive_order, qsteady_max_default, get_c alg_cache, OrdinaryDiffEqMutableCache, OrdinaryDiffEqConstantCache, initialize!, @unpack, initialize!, perform_step!, stepsize_controller!, step_accept_controller!, step_reject_controller!, calculate_residuals, calculate_residuals!, Tsit5ConstantCache, get_current_adaptive_order, - ode_interpolant, ode_interpolant! + ode_interpolant, ode_interpolant!, trivial_limiter! using MuladdMacro, FastBroadcast, RecursiveArrayTools include("algorithms.jl") diff --git a/test/interface/interpolation_derivative_error_tests.jl b/test/interface/interpolation_derivative_error_tests.jl index f447f84fbd..9e7a5c5906 100644 --- a/test/interface/interpolation_derivative_error_tests.jl +++ b/test/interface/interpolation_derivative_error_tests.jl @@ -13,6 +13,7 @@ out = rand(3) for alg in [Rosenbrock23(), Rodas4(), Rodas5P(), Tsit5(), DP5(), BS5(), OwrenZen3(), OwrenZen4(), OwrenZen5(), Vern6(), Vern7(), Vern8(), Vern9(), BS3()] + @show alg sol = solve(prob, alg) @test_throws OrdinaryDiffEq.DerivativeOrderNotPossibleError sol(0.5, Val{10}) @test_throws OrdinaryDiffEq.DerivativeOrderNotPossibleError sol(out, 0.5, Val{10}) From a69313a1df1e7f86cabb60dfe558a8a0bc9d05da Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sat, 3 Aug 2024 20:52:46 -0400 Subject: [PATCH 123/133] some imports --- lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl | 1 + lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl b/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl index 96ef875b48..019ce33433 100644 --- a/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl +++ b/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl @@ -7,6 +7,7 @@ import OrdinaryDiffEq: alg_order, alg_adaptive_order, qsteady_max_default, get_c calculate_residuals, calculate_residuals!, Tsit5ConstantCache, get_current_adaptive_order, ode_interpolant, ode_interpolant!, trivial_limiter! using MuladdMacro, FastBroadcast, RecursiveArrayTools +import Static: False include("algorithms.jl") include("controllers.jl") diff --git a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl index 25604e563c..9a99b54c2c 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl @@ -10,7 +10,7 @@ import OrdinaryDiffEq: alg_order, alg_adaptive_order, isWmethod, isfsal, _unwrap wrapprecs, alg_autodiff, calc_tderivative, build_grad_config, build_jac_config, issuccess_W, calculate_residuals, has_stiff_interpolation, ODEIntegrator, resize_non_user_cache!, _ode_addsteps!, jacobian2W!, full_cache, - resize_jac_config!, resize_grad_config! + resize_jac_config!, resize_grad_config!, DerivativeOrderNotPossibleError using TruncatedStacktraces, MuladdMacro, FastBroadcast, DiffEqBase, RecursiveArrayTools import MacroTools using MacroTools: @capture From 52d58bb1ac9c41404429d99319ed6d4723560825 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sat, 3 Aug 2024 20:59:08 -0400 Subject: [PATCH 124/133] more --- lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl index 9168c6f646..b7856a89bc 100644 --- a/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl +++ b/lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl @@ -7,7 +7,7 @@ import OrdinaryDiffEq: alg_order, alg_stability_size, explicit_rk_docstring, calculate_residuals!, _ode_interpolant, _ode_interpolant!, CompiledFloats, @OnDemandTableauExtract, initialize!, perform_step!, CompositeAlgorithm, _ode_addsteps!, copyat_or_push!, AutoAlgSwitch, - full_cache + full_cache, DerivativeOrderNotPossibleError import Static: False import MuladdMacro: @muladd import FastBroadcast: @.. From 19423aeb6838003cab4a1fffbae08b8cfb44ec44 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sat, 3 Aug 2024 21:06:20 -0400 Subject: [PATCH 125/133] one more --- lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl index 4cc5c051f3..6f997fcf85 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl @@ -8,7 +8,7 @@ import OrdinaryDiffEq: alg_order, isfsal, beta2_default, beta1_default, alg_stab OrdinaryDiffEqMutableCache, uses_uprev, OrdinaryDiffEqConstantCache, @fold, @cache, CompiledFloats, alg_cache, CompositeAlgorithm, alg_autodiff, copyat_or_push!, AutoAlgSwitch, _ode_interpolant, _ode_interpolant!, full_cache, - accept_step_controller + accept_step_controller, DerivativeOrderNotPossibleError using DiffEqBase, SciMLBase import MuladdMacro: @muladd import FastBroadcast: @.. From c4d48f1e2f5067bc7a56abf4dbd94f9883ed942a Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sat, 3 Aug 2024 21:38:14 -0400 Subject: [PATCH 126/133] missing cache piece --- lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl b/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl index c1349c3c4e..601124da72 100644 --- a/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl +++ b/lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl @@ -6,7 +6,7 @@ import OrdinaryDiffEq: alg_order, qmax_default, qmin_default, beta2_default, bet alg_cache, uses_uprev, initialize!, perform_step!, OrdinaryDiffEqConstantCache, calculate_residuals!, calculate_residuals, CompiledFloats, copyat_or_push!, unwrap_alg, _ode_interpolant, _ode_interpolant!, - DerivativeOrderNotPossibleError + DerivativeOrderNotPossibleError, full_cache import Static: False import MuladdMacro: @muladd using DiffEqBase From b3f2f3ac3bff7f0475d29b058032200792ed7a6d Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sat, 3 Aug 2024 21:54:51 -0400 Subject: [PATCH 127/133] add missing cache --- lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl b/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl index 019ce33433..d41fdcd771 100644 --- a/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl +++ b/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl @@ -4,8 +4,8 @@ import OrdinaryDiffEq: alg_order, alg_adaptive_order, qsteady_max_default, get_c AbstractController, OrdinaryDiffEqAdaptiveAlgorithm, OrdinaryDiffEqAdamsVarOrderVarStepAlgorithm, alg_cache, OrdinaryDiffEqMutableCache, OrdinaryDiffEqConstantCache, initialize!, @unpack, initialize!, perform_step!, stepsize_controller!, step_accept_controller!, step_reject_controller!, - calculate_residuals, calculate_residuals!, Tsit5ConstantCache, get_current_adaptive_order, - ode_interpolant, ode_interpolant!, trivial_limiter! + calculate_residuals, calculate_residuals!, Tsit5ConstantCache, get_current_adaptive_order, + ode_interpolant, ode_interpolant!, trivial_limiter!, Tsit5Cache using MuladdMacro, FastBroadcast, RecursiveArrayTools import Static: False @@ -18,4 +18,4 @@ include("nordsieck_perform_step.jl") export AN5, JVODE, JVODE_Adams, JVODE_BDF -end \ No newline at end of file +end From 5d8b121aa3a1683b81601d6df89e83d8df1cfa26 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Sun, 4 Aug 2024 09:08:52 +0530 Subject: [PATCH 128/133] Update --- .../src/OrdinaryDiffEqLowOrderRK.jl | 1 + lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl | 2 ++ src/OrdinaryDiffEq.jl | 6 +++--- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl index 6f997fcf85..25fb623e73 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl @@ -9,6 +9,7 @@ import OrdinaryDiffEq: alg_order, isfsal, beta2_default, beta1_default, alg_stab @cache, CompiledFloats, alg_cache, CompositeAlgorithm, alg_autodiff, copyat_or_push!, AutoAlgSwitch, _ode_interpolant, _ode_interpolant!, full_cache, accept_step_controller, DerivativeOrderNotPossibleError + AutoAlgSwitch, _ode_interpolant, _ode_interpolant!, full_cache, DP8ConstantCache, DP8Cache using DiffEqBase, SciMLBase import MuladdMacro: @muladd import FastBroadcast: @.. diff --git a/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl b/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl index d41fdcd771..7752a08595 100644 --- a/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl +++ b/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl @@ -6,6 +6,8 @@ import OrdinaryDiffEq: alg_order, alg_adaptive_order, qsteady_max_default, get_c initialize!, perform_step!, stepsize_controller!, step_accept_controller!, step_reject_controller!, calculate_residuals, calculate_residuals!, Tsit5ConstantCache, get_current_adaptive_order, ode_interpolant, ode_interpolant!, trivial_limiter!, Tsit5Cache + calculate_residuals, calculate_residuals!, Tsit5ConstantCache, get_current_adaptive_order, + ode_interpolant, ode_interpolant!, Tsit5Cache using MuladdMacro, FastBroadcast, RecursiveArrayTools import Static: False diff --git a/src/OrdinaryDiffEq.jl b/src/OrdinaryDiffEq.jl index 5ece1c0059..fb96cb7ab7 100644 --- a/src/OrdinaryDiffEq.jl +++ b/src/OrdinaryDiffEq.jl @@ -246,7 +246,7 @@ export ABDF2, QNDF1, QBDF1, QNDF2, QBDF2, QNDF, QBDF, FBDF, include("../lib/OrdinaryDiffEqTsit5/src/OrdinaryDiffEqTsit5.jl") using ..OrdinaryDiffEqTsit5 export Tsit5, AutoTsit5 -import .OrdinaryDiffEqTsit5: Tsit5ConstantCache +import .OrdinaryDiffEqTsit5: Tsit5ConstantCache, Tsit5Cache include("../lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl") using ..OrdinaryDiffEqRosenbrock @@ -281,12 +281,12 @@ export KuttaPRK2p5 include("../lib/OrdinaryDiffEqHighOrderRK/src/OrdinaryDiffEqHighOrderRK.jl") using ..OrdinaryDiffEqHighOrderRK export TanYam7, DP8, PFRK87, TsitPap8 -using ..OrdinaryDiffEqHighOrderRK: DP8ConstantCache +using ..OrdinaryDiffEqHighOrderRK: DP8ConstantCache, DP8Cache include("../lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl") using ..OrdinaryDiffEqLowOrderRK export Euler, SplitEuler, Heun, Ralston, Midpoint, RK4, - BS3, OwrenZen3, OwrenZen4, OwrenZen5, BS5, Tsit5, + BS3, OwrenZen3, OwrenZen4, OwrenZen5, BS5, DP5, Anas5, RKO65, FRK65, RKM, MSRK5, MSRK6, PSRK4p7q6, PSRK3p5q4, PSRK3p6q5, Stepanov5, SIR54, Alshina2, Alshina3, Alshina6, AutoDP5 From 743eb978f518c50fa16de9531a11016dca16f29d Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Sun, 4 Aug 2024 09:15:59 +0530 Subject: [PATCH 129/133] Update --- lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl index 25fb623e73..077486196d 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl @@ -9,7 +9,7 @@ import OrdinaryDiffEq: alg_order, isfsal, beta2_default, beta1_default, alg_stab @cache, CompiledFloats, alg_cache, CompositeAlgorithm, alg_autodiff, copyat_or_push!, AutoAlgSwitch, _ode_interpolant, _ode_interpolant!, full_cache, accept_step_controller, DerivativeOrderNotPossibleError - AutoAlgSwitch, _ode_interpolant, _ode_interpolant!, full_cache, DP8ConstantCache, DP8Cache + AutoAlgSwitch, _ode_interpolant, _ode_interpolant!, full_cache using DiffEqBase, SciMLBase import MuladdMacro: @muladd import FastBroadcast: @.. From 9f452f24f3023ad22d5f04994c2c96150d738141 Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Sun, 4 Aug 2024 09:19:57 +0530 Subject: [PATCH 130/133] Removed --- lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl index 077486196d..6f997fcf85 100644 --- a/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl +++ b/lib/OrdinaryDiffEqLowOrderRK/src/OrdinaryDiffEqLowOrderRK.jl @@ -9,7 +9,6 @@ import OrdinaryDiffEq: alg_order, isfsal, beta2_default, beta1_default, alg_stab @cache, CompiledFloats, alg_cache, CompositeAlgorithm, alg_autodiff, copyat_or_push!, AutoAlgSwitch, _ode_interpolant, _ode_interpolant!, full_cache, accept_step_controller, DerivativeOrderNotPossibleError - AutoAlgSwitch, _ode_interpolant, _ode_interpolant!, full_cache using DiffEqBase, SciMLBase import MuladdMacro: @muladd import FastBroadcast: @.. From 454389cba34983ec0ab67739709a017dc7bd7aad Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Sun, 4 Aug 2024 09:45:17 +0530 Subject: [PATCH 131/133] LinearAlgebra --- lib/OrdinaryDiffEqNordsieck/Project.toml | 1 + lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/OrdinaryDiffEqNordsieck/Project.toml b/lib/OrdinaryDiffEqNordsieck/Project.toml index cd7fce51aa..19e2c9b060 100644 --- a/lib/OrdinaryDiffEqNordsieck/Project.toml +++ b/lib/OrdinaryDiffEqNordsieck/Project.toml @@ -10,6 +10,7 @@ OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" Polyester = "f517fe37-dbe3-4b94-8317-1923a5111588" RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd" Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3" +LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" [compat] julia = "1.10" diff --git a/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl b/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl index 7752a08595..cc688a26e7 100644 --- a/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl +++ b/lib/OrdinaryDiffEqNordsieck/src/OrdinaryDiffEqNordsieck.jl @@ -9,6 +9,7 @@ import OrdinaryDiffEq: alg_order, alg_adaptive_order, qsteady_max_default, get_c calculate_residuals, calculate_residuals!, Tsit5ConstantCache, get_current_adaptive_order, ode_interpolant, ode_interpolant!, Tsit5Cache using MuladdMacro, FastBroadcast, RecursiveArrayTools +import LinearAlgebra: rmul! import Static: False include("algorithms.jl") From d12501433d8c98d45724889508db70a5cf4ed5aa Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sun, 4 Aug 2024 00:33:07 -0400 Subject: [PATCH 132/133] Revert "Merge remote-tracking branch 'origin/master'" This reverts commit 2dc43eced4c76dcdcd4b28dabe307692a64a350b, reversing changes made to 26f4067c3aa02971c4ebd092234a3f7b7e38f30d. --- .../src/rosenbrock_perform_step.jl | 112 +++++++++--------- 1 file changed, 54 insertions(+), 58 deletions(-) diff --git a/lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_perform_step.jl b/lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_perform_step.jl index f48379782a..9393c2c573 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_perform_step.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_perform_step.jl @@ -35,8 +35,7 @@ end mass_matrix = integrator.f.mass_matrix # Precalculations - dtγ = dt * d - neginvdtγ = -inv(dtγ) + γ = dt * d dto2 = dt / 2 dto6 = dt / 6 @@ -45,7 +44,7 @@ end integrator.stats.nf += 1 end - calc_rosenbrock_differentiation!(integrator, cache, dtγ, dtγ, repeat_step, true) + calc_rosenbrock_differentiation!(integrator, cache, γ, γ, repeat_step, false) calculate_residuals!(weight, fill!(weight, one(eltype(u))), uprev, uprev, integrator.opts.abstol, integrator.opts.reltol, @@ -55,17 +54,17 @@ end linres = dolinsolve( integrator, cache.linsolve; A = nothing, b = _vec(linsolve_tmp), du = integrator.fsalfirst, u = u, p = p, t = t, weight = weight, - solverdata = (; gamma = dtγ)) + solverdata = (; gamma = γ)) else linres = dolinsolve(integrator, cache.linsolve; A = W, b = _vec(linsolve_tmp), du = integrator.fsalfirst, u = u, p = p, t = t, weight = weight, - solverdata = (; gamma = dtγ)) + solverdata = (; gamma = γ)) end vecu = _vec(linres.u) veck₁ = _vec(k₁) - @.. veck₁ = vecu * neginvdtγ + @.. broadcast=false veck₁=-vecu integrator.stats.nsolve += 1 @.. broadcast=false u=uprev + dto2 * k₁ @@ -85,7 +84,7 @@ end vecu = _vec(linres.u) veck2 = _vec(k₂) - @.. veck2 = vecu * neginvdtγ + @.. broadcast=false veck2=-vecu integrator.stats.nsolve += 1 @.. broadcast=false k₂+=k₁ @@ -110,7 +109,7 @@ end linres = dolinsolve(integrator, linres.cache; b = _vec(linsolve_tmp)) vecu = _vec(linres.u) veck3 = _vec(k₃) - @.. veck3 = vecu * neginvdtγ + @.. broadcast=false veck3=-vecu integrator.stats.nsolve += 1 @@ -130,8 +129,8 @@ end if mass_matrix !== I algvar = reshape(cache.algebraic_vars, size(u)) - invatol = inv(integrator.opts.abstol) - @.. atmp = ifelse(algvar, fsallast, false) * invatol + @.. broadcast=false atmp=ifelse(algvar, fsallast, false) / + integrator.opts.abstol integrator.EEst += integrator.opts.internalnorm(atmp, t) end end @@ -148,8 +147,7 @@ end mass_matrix = integrator.f.mass_matrix # Precalculations - dtγ = dt * d - neginvdtγ = -inv(dtγ) + γ = dt * d dto2 = dt / 2 dto6 = dt / 6 @@ -158,7 +156,7 @@ end integrator.stats.nf += 1 end - calc_rosenbrock_differentiation!(integrator, cache, dtγ, dtγ, repeat_step, true) + calc_rosenbrock_differentiation!(integrator, cache, γ, γ, repeat_step, false) calculate_residuals!(weight, fill!(weight, one(eltype(u))), uprev, uprev, integrator.opts.abstol, integrator.opts.reltol, @@ -168,17 +166,17 @@ end linres = dolinsolve( integrator, cache.linsolve; A = nothing, b = _vec(linsolve_tmp), du = integrator.fsalfirst, u = u, p = p, t = t, weight = weight, - solverdata = (; gamma = dtγ)) + solverdata = (; gamma = γ)) else linres = dolinsolve(integrator, cache.linsolve; A = W, b = _vec(linsolve_tmp), du = integrator.fsalfirst, u = u, p = p, t = t, weight = weight, - solverdata = (; gamma = dtγ)) + solverdata = (; gamma = γ)) end vecu = _vec(linres.u) veck₁ = _vec(k₁) - @.. veck₁ = vecu * neginvdtγ + @.. broadcast=false veck₁=-vecu integrator.stats.nsolve += 1 @.. broadcast=false u=uprev + dto2 * k₁ @@ -198,7 +196,7 @@ end vecu = _vec(linres.u) veck2 = _vec(k₂) - @.. veck2 = vecu * neginvdtγ + @.. broadcast=false veck2=-vecu integrator.stats.nsolve += 1 @.. broadcast=false k₂+=k₁ @@ -220,7 +218,7 @@ end vecu = _vec(linres.u) veck3 = _vec(k₃) - @.. veck3 = vecu * neginvdtγ + @.. broadcast=false veck3=-vecu integrator.stats.nsolve += 1 @.. broadcast=false u=uprev + dto6 * (k₁ + 4k₂ + k₃) @@ -234,8 +232,8 @@ end integrator.EEst = integrator.opts.internalnorm(atmp, t) if mass_matrix !== I - invatol = inv(integrator.opts.abstol) - @.. atmp=ifelse(cache.algebraic_vars, fsallast, false) * invatol + @.. broadcast=false atmp=ifelse(cache.algebraic_vars, fsallast, false) / + integrator.opts.abstol integrator.EEst += integrator.opts.internalnorm(atmp, t) end end @@ -248,8 +246,7 @@ end @unpack c₃₂, d, tf, uf = cache # Precalculations - dtγ = dt * d - neginvdtγ = -inv(dtγ) + γ = dt * d dto2 = dt / 2 dto6 = dt / 6 @@ -263,24 +260,22 @@ end # Time derivative dT = calc_tderivative(integrator, cache) - W = calc_W(integrator, cache, dtγ, repeat_step, true) + W = calc_W(integrator, cache, γ, repeat_step) if !issuccess_W(W) integrator.EEst = 2 return nothing end - k₁ = _reshape(W \ _vec((integrator.fsalfirst + dtγ * dT)), axes(uprev)) * neginvdtγ + k₁ = _reshape(W \ -_vec((integrator.fsalfirst + γ * dT)), axes(uprev)) integrator.stats.nsolve += 1 - tmp = @.. uprev + dto2 * k₁ - f₁ = f(tmp, p, t + dto2) + f₁ = f(uprev + dto2 * k₁, p, t + dto2) integrator.stats.nf += 1 if mass_matrix === I - k₂ = _reshape(W \ _vec(f₁ - k₁), axes(uprev)) + k₂ = _reshape(W \ -_vec(f₁ - k₁), axes(uprev)) + k₁ else - k₂ = _reshape(W \ _vec(f₁ - mass_matrix * k₁), axes(uprev)) + k₂ = _reshape(W \ -_vec(f₁ - mass_matrix * k₁), axes(uprev)) + k₁ end - k₂ = @.. k₂ * neginvdtγ + k₁ integrator.stats.nsolve += 1 u = uprev + dt * k₂ @@ -289,28 +284,30 @@ end integrator.stats.nf += 1 if mass_matrix === I - linsolve_tmp = @.. (integrator.fsallast - c₃₂ * (k₂ - f₁) - - 2 * (k₁ - integrator.fsalfirst) + dt * dT) + k₃ = _reshape( + W \ + -_vec((integrator.fsallast - c₃₂ * (k₂ - f₁) - + 2 * (k₁ - integrator.fsalfirst) + dt * dT)), + axes(uprev)) else - linsolve_tmp = mass_matrix * (@.. c₃₂ * k₂ + 2 * k₁) - linsolve_tmp = @.. (integrator.fsallast - linsolve_tmp + - c₃₂ * f₁ + 2 * integrator.fsalfirst + dt * dT) + linsolve_tmp = integrator.fsallast - mass_matrix * (c₃₂ * k₂ + 2 * k₁) + + c₃₂ * f₁ + 2 * integrator.fsalfirst + dt * dT + k₃ = _reshape(W \ -_vec(linsolve_tmp), axes(uprev)) end - k₃ = _reshape(W \ _vec(linsolve_tmp), axes(uprev)) * neginvdtγ integrator.stats.nsolve += 1 if u isa Number utilde = dto6 * f.mass_matrix[1, 1] * (k₁ - 2 * k₂ + k₃) else - utilde = f.mass_matrix * (@.. dto6 * (k₁ - 2 * k₂ + k₃)) + utilde = dto6 * f.mass_matrix * (k₁ - 2 * k₂ + k₃) end atmp = calculate_residuals(utilde, uprev, u, integrator.opts.abstol, integrator.opts.reltol, integrator.opts.internalnorm, t) integrator.EEst = integrator.opts.internalnorm(atmp, t) if mass_matrix !== I - invatol = inv(integrator.opts.abstol) - atmp = ifelse(!integrator.differential_vars, integrator.fsallast, false) .* invatol + atmp = @. ifelse(!integrator.differential_vars, integrator.fsallast, false) ./ + integrator.opts.abstol integrator.EEst += integrator.opts.internalnorm(atmp, t) end end @@ -326,8 +323,7 @@ end @unpack c₃₂, d, tf, uf = cache # Precalculations - dtγ = dt * d - neginvdtγ = -inv(dtγ) + γ = dt * d dto2 = dt / 2 dto6 = dt / 6 @@ -341,52 +337,52 @@ end # Time derivative dT = calc_tderivative(integrator, cache) - W = calc_W(integrator, cache, dtγ, repeat_step, true) + W = calc_W(integrator, cache, γ, repeat_step) if !issuccess_W(W) integrator.EEst = 2 return nothing end - k₁ = _reshape(W \ -_vec((integrator.fsalfirst + dtγ * dT)), axes(uprev))/dtγ + k₁ = _reshape(W \ -_vec((integrator.fsalfirst + γ * dT)), axes(uprev)) integrator.stats.nsolve += 1 - tmp = @.. uprev + dto2 * k₁ - f₁ = f(tmp, p, t + dto2) + f₁ = f(uprev + dto2 * k₁, p, t + dto2) integrator.stats.nf += 1 if mass_matrix === I - k₂ = _reshape(W \ _vec(f₁ - k₁), axes(uprev)) + k₂ = _reshape(W \ -_vec(f₁ - k₁), axes(uprev)) + k₁ else linsolve_tmp = f₁ - mass_matrix * k₁ - k₂ = _reshape(W \ _vec(linsolve_tmp), axes(uprev)) + k₂ = _reshape(W \ -_vec(linsolve_tmp), axes(uprev)) + k₁ end - k₂ = @.. k₂ * neginvdtγ + k₁ integrator.stats.nsolve += 1 - tmp = @.. uprev + dt * k₂ + tmp = uprev + dt * k₂ integrator.fsallast = f(tmp, p, t + dt) integrator.stats.nf += 1 if mass_matrix === I - linsolve_tmp = @.. (integrator.fsallast - c₃₂ * (k₂ - f₁) - - 2(k₁ - integrator.fsalfirst) + dt * dT) + k₃ = _reshape( + W \ + -_vec((integrator.fsallast - c₃₂ * (k₂ - f₁) - + 2(k₁ - integrator.fsalfirst) + dt * dT)), + axes(uprev)) else - linsolve_tmp = mass_matrix * (@.. c₃₂ * k₂ + 2 * k₁) - linsolve_tmp = @.. (integrator.fsallast - linsolve_tmp + - c₃₂ * f₁ + 2 * integrator.fsalfirst + dt * dT) + linsolve_tmp = integrator.fsallast - mass_matrix * (c₃₂ * k₂ + 2k₁) + c₃₂ * f₁ + + 2 * integrator.fsalfirst + dt * dT + k₃ = _reshape(W \ -_vec(linsolve_tmp), axes(uprev)) end - k₃ = _reshape(W \ _vec(linsolve_tmp), axes(uprev)) * neginvdtγ integrator.stats.nsolve += 1 - u = @.. uprev + dto6 * (k₁ + 4k₂ + k₃) + u = uprev + dto6 * (k₁ + 4k₂ + k₃) if integrator.opts.adaptive - utilde = @.. dto6 * (k₁ - 2k₂ + k₃) + utilde = dto6 * (k₁ - 2k₂ + k₃) atmp = calculate_residuals(utilde, uprev, u, integrator.opts.abstol, integrator.opts.reltol, integrator.opts.internalnorm, t) integrator.EEst = integrator.opts.internalnorm(atmp, t) if mass_matrix !== I - invatol = inv(integrator.opts.abstol) - atmp = ifelse(!integrator.differential_vars, integrator.fsallast, false) .* invatol + atmp = @. ifelse(!integrator.differential_vars, integrator.fsallast, false) ./ + integrator.opts.abstol integrator.EEst += integrator.opts.internalnorm(atmp, t) end end From 6073819255b251262560e54cc6e6d5231f01234d Mon Sep 17 00:00:00 2001 From: ParamThakkar123 Date: Sun, 4 Aug 2024 10:27:24 +0530 Subject: [PATCH 133/133] FiniteDiff --- lib/OrdinaryDiffEqRosenbrock/Project.toml | 1 + lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/OrdinaryDiffEqRosenbrock/Project.toml b/lib/OrdinaryDiffEqRosenbrock/Project.toml index 9c315a9599..8a5a2cdf78 100644 --- a/lib/OrdinaryDiffEqRosenbrock/Project.toml +++ b/lib/OrdinaryDiffEqRosenbrock/Project.toml @@ -13,6 +13,7 @@ Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3" DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" +FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41" [compat] julia = "1.10" diff --git a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl index 9a99b54c2c..42d2585347 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl @@ -17,6 +17,7 @@ using MacroTools: @capture using DiffEqBase: @def import LinearSolve import ForwardDiff +using FiniteDiff using LinearAlgebra: mul!, diag, diagm, I, Diagonal, norm import ADTypes: AutoForwardDiff