-
-
Notifications
You must be signed in to change notification settings - Fork 259
Replace Hairer-Wanner initdt with CVODE CVHin for deterministic solvers #3161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ChrisRackauckas-Claude
wants to merge
21
commits into
SciML:master
Choose a base branch
from
ChrisRackauckas-Claude:stiff-initdt-v2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
c48b2fc
Replace Hairer-Wanner initdt with CVODE CVHin for deterministic solvers
ChrisRackauckas 6a2d606
Fix backward integration, GPU compatibility, and Runic formatting in …
ChrisRackauckas 358b6c7
Always use order-dependent formula in CVHin, clamp to hub
ChrisRackauckas 51efd35
Fix stats.nf tracking and GPU compatibility in CVHin
ChrisRackauckas 7220abc
Fix ForwardDiff.Dual compatibility in CVHin initdt
ChrisRackauckas ba4a99c
Revert SUNDIALS curvature threshold, use formula-always approach
ChrisRackauckas 07494a7
Fix Unitful, zero-length vector, and mixed-unit ArrayPartition compat…
ChrisRackauckas 3222037
Fix ComplexF64 compatibility and rename numers to nums for spell check
ChrisRackauckas 44a9d44
Fix GPU ComplexF64 bug and update test tolerances for CVHin initdt
ChrisRackauckas 396f09e
Fix Runic formatting: use 1.0e-6 instead of 1e-6
ChrisRackauckas 95f2497
Fix remaining CI failures: update test tolerances for CVHin initdt
ChrisRackauckas ebff656
Fix ODEInterface atol and extrapolation cross-precision comparison
ChrisRackauckas 82884b1
Fix DelayDiffEq rosenbrock and parameters test tolerances for CVHin
ChrisRackauckas e843df1
Fix Unitful DimensionError in CVHin OOP path and widen rosenbrock rtol
ChrisRackauckas 83160a7
Fix DelayDiffEq rosenbrock and multi_algorithm tests for CVHin
ChrisRackauckas f391274
Fix RKN adaptive IIP-vs-OOP tests and Rosenbrock32 DDE tolerance
ChrisRackauckas 166b27a
Widen RKN endpoint atol and Vern7 DDE error threshold for CVHin
ChrisRackauckas c49c38a
Replace RKN adaptive IIP-vs-OOP endpoint comparison with retcode check
ChrisRackauckas 27f35c0
Fix Runic formatting and typo in inference.jl from PR #3202
ChrisRackauckas f06e102
Fix Runic formatting in alg_utils.jl files from PR #3202
ChrisRackauckas f169f21
Guard AutoVern7+Rodas5P inference test for Julia >= 1.11
ChrisRackauckas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| using Test | ||
| using OrdinaryDiffEqBDF | ||
| using OrdinaryDiffEqSDIRK | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would be good to add some tests for Rosenbrock also. |
||
| @testset "CVHin Initial Step Size Algorithm" begin | ||
|
|
||
| @testset "Simple exponential decay (in-place)" begin | ||
| function f_exp!(du, u, p, t) | ||
| du[1] = -u[1] | ||
| end | ||
| prob = ODEProblem(f_exp!, [1.0], (0.0, 10.0)) | ||
| sol = solve(prob, FBDF()) | ||
| @test sol.retcode == ReturnCode.Success | ||
| @test isapprox(sol.u[end][1], exp(-10.0), rtol = 1.0e-2) | ||
| end | ||
|
|
||
| @testset "Simple exponential decay (out-of-place)" begin | ||
| f_exp(u, p, t) = [-u[1]] | ||
| prob = ODEProblem(f_exp, [1.0], (0.0, 10.0)) | ||
| sol = solve(prob, FBDF()) | ||
| @test sol.retcode == ReturnCode.Success | ||
| @test isapprox(sol.u[end][1], exp(-10.0), rtol = 1.0e-2) | ||
| end | ||
|
|
||
| @testset "Multi-scale with zero states and tiny abstol (in-place)" begin | ||
| # This is the pathological case from issue #1496: | ||
| # Some species start at 0 with tiny abstol, causing the Hairer algorithm | ||
| # to produce catastrophically small initial dt. | ||
| function f_ms!(du, u, p, t) | ||
| du[1] = -100.0 * u[1] + 1.0 | ||
| du[2] = 0.1 * u[1] | ||
| du[3] = 1.84 # mimics TH2S | ||
| end | ||
| u0 = [1.0, 0.0, 0.0] | ||
| prob = ODEProblem(f_ms!, u0, (0.0, 100.0)) | ||
|
|
||
| # With FBDF - should succeed efficiently | ||
| sol_fbdf = solve(prob, FBDF(), abstol = 1.0e-15, reltol = 1.0e-8) | ||
| @test sol_fbdf.retcode == ReturnCode.Success | ||
| @test sol_fbdf.t[end] == 100.0 | ||
|
|
||
| # The CVHin algorithm should produce an initial dt much larger than the | ||
| # catastrophically small ~5e-25 that the old Hairer algorithm would give. | ||
| # With abstol=1e-15 and u0=0, it computes ~3.5e-15 | ||
| # (10 orders of magnitude larger). | ||
| dt_fbdf = sol_fbdf.t[2] - sol_fbdf.t[1] | ||
| @test dt_fbdf > 1.0e-20 # Much larger than the ~5e-25 Hairer would give | ||
| end | ||
|
|
||
| @testset "Multi-scale with zero states and tiny abstol (out-of-place)" begin | ||
| function f_ms(u, p, t) | ||
| return [-100.0 * u[1] + 1.0, 0.1 * u[1], 1.84] | ||
| end | ||
| u0 = [1.0, 0.0, 0.0] | ||
| prob = ODEProblem(f_ms, u0, (0.0, 100.0)) | ||
|
|
||
| sol = solve(prob, FBDF(), abstol = 1.0e-15, reltol = 1.0e-8) | ||
| @test sol.retcode == ReturnCode.Success | ||
| @test sol.t[end] == 100.0 | ||
| end | ||
|
|
||
| @testset "Stiff Robertson problem" begin | ||
| # Classic stiff test problem | ||
| function robertson!(du, u, p, t) | ||
| du[1] = -0.04 * u[1] + 1.0e4 * u[2] * u[3] | ||
| du[2] = 0.04 * u[1] - 1.0e4 * u[2] * u[3] - 3.0e7 * u[2]^2 | ||
| du[3] = 3.0e7 * u[2]^2 | ||
| end | ||
| u0 = [1.0, 0.0, 0.0] | ||
| prob = ODEProblem(robertson!, u0, (0.0, 1.0e5)) | ||
|
|
||
| sol = solve(prob, FBDF(), abstol = 1.0e-8, reltol = 1.0e-8) | ||
| @test sol.retcode == ReturnCode.Success | ||
| @test sol.t[end] == 1.0e5 | ||
|
|
||
| # Conservation law: u1 + u2 + u3 = 1 | ||
| @test isapprox(sum(sol.u[end]), 1.0, atol = 1.0e-6) | ||
| end | ||
|
|
||
| @testset "Backward integration" begin | ||
| function f_back!(du, u, p, t) | ||
| du[1] = -u[1] | ||
| end | ||
| prob = ODEProblem(f_back!, [exp(-10.0)], (10.0, 0.0)) | ||
| sol = solve(prob, FBDF()) | ||
| @test sol.retcode == ReturnCode.Success | ||
| @test isapprox(sol.u[end][1], 1.0, rtol = 2.0e-2) | ||
| end | ||
|
|
||
| @testset "User-specified dt still works" begin | ||
| function f_dt!(du, u, p, t) | ||
| du[1] = -u[1] | ||
| end | ||
| prob = ODEProblem(f_dt!, [1.0], (0.0, 1.0)) | ||
| # When user specifies dt, initdt should not be called | ||
| sol = solve(prob, FBDF(), dt = 0.01) | ||
| @test sol.retcode == ReturnCode.Success | ||
| end | ||
|
|
||
| @testset "QNDF with multi-scale problem" begin | ||
| function f_qndf!(du, u, p, t) | ||
| du[1] = -100.0 * u[1] + 1.0 | ||
| du[2] = 0.0 # starts at 0, stays at 0 | ||
| end | ||
| u0 = [1.0, 0.0] | ||
| prob = ODEProblem(f_qndf!, u0, (0.0, 1.0)) | ||
|
|
||
| sol = solve(prob, QNDF(), abstol = 1.0e-12, reltol = 1.0e-8) | ||
| @test sol.retcode == ReturnCode.Success | ||
| @test sol.t[end] == 1.0 | ||
| end | ||
|
|
||
| @testset "ImplicitEuler initial step size" begin | ||
| function f_ie!(du, u, p, t) | ||
| du[1] = -100.0 * u[1] + 1.0 | ||
| du[2] = 0.0 | ||
| end | ||
| u0 = [1.0, 0.0] | ||
| prob = ODEProblem(f_ie!, u0, (0.0, 1.0)) | ||
|
|
||
| sol = solve(prob, ImplicitEuler(), abstol = 1.0e-12, reltol = 1.0e-8) | ||
| @test sol.retcode == ReturnCode.Success | ||
| @test sol.t[end] == 1.0 | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems pretty bad... no?