Skip to content
This repository was archived by the owner on Mar 30, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ authors = ["Chris Rackauckas <accounts@chrisrackauckas.com>"]
version = "2.50.0"

[deps]
BracketingNonlinearSolve = "70df07ce-3d50-431d-a3e7-ca6ddb60ac1e"
CommonSolve = "38540f10-b2f7-11e9-35d8-d573e4eb0ff2"
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
DiffEqNoiseProcess = "77a26b50-5914-5dd7-bc55-306e6241c503"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
ExplicitImports = "7d51a73a-1435-4ff3-83d9-f097790105c7"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
NLsolve = "2774e3e8-f4cf-5e23-947b-6d7e65073b56"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
RootedTrees = "47965b36-3f3e-11e9-0dcf-4570dfd42a8c"
Expand All @@ -22,6 +22,7 @@ StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
[compat]
BVProblemLibrary = "0.1"
BoundaryValueDiffEq = "5"
BracketingNonlinearSolve = "1"
CommonSolve = "0.2"
DDEProblemLibrary = "0.1"
DelayDiffEq = "5.20"
Expand All @@ -31,7 +32,6 @@ Distributed = "1.9"
ExplicitImports = "1.14.0"
LinearAlgebra = "1.9"
Logging = "1.9"
NLsolve = "4.5"
NonlinearSolve = "3.13, 4"
ODEProblemLibrary = "0.1"
OrdinaryDiffEq = "6"
Expand Down
6 changes: 3 additions & 3 deletions src/DiffEqDevTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ using RecipesBase: RecipesBase, @recipe, @series
using RecursiveArrayTools: RecursiveArrayTools, recursive_mean, vecvecapply
using DiffEqNoiseProcess: DiffEqNoiseProcess, NoiseGrid, NoiseWrapper
using StructArrays: StructArrays, StructArray
using NLsolve: NLsolve, nlsolve
using BracketingNonlinearSolve: BracketingNonlinearSolve, Bisection
using LinearAlgebra: LinearAlgebra, norm, I, /, \
using RootedTrees: RootedTrees, RootedTreeIterator, RungeKuttaMethod, residual_order_condition
using Distributed: Distributed
using Statistics: Statistics, mean, std
using SciMLBase: SciMLBase, DAEProblem, DESolution, EnsembleProblem, EnsembleSolution,
EnsembleThreads, NonlinearProblem, ODEProblem, ReturnCode, SDDEProblem,
SDEProblem, remake
EnsembleThreads, IntervalNonlinearProblem, NonlinearProblem,
ODEProblem, ReturnCode, SDDEProblem, SDEProblem, remake
using CommonSolve: init, solve, step!

import Base: length, convert, transpose
Expand Down
43 changes: 29 additions & 14 deletions src/tableau_info.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,22 @@ function stability_region(
tab_or_alg::Union{ODERKTableau, AbstractODEAlgorithm};
initial_guess = -3.0, kw...
)
residual! = function (resid, x)
return resid[1] = abs(stability_region(x[1], tab_or_alg)) - 1
f = (x, p) -> abs(stability_region(x, tab_or_alg)) - 1
T = typeof(initial_guess)
# Bracket between a point near 0 (inside stability region) and a point
# far from 0 (outside stability region). Solvers are 0-stable (|r(0)|=1)
# and not ∞-stable, so a sign change must exist between these points.
near_zero = sign(initial_guess) * one(T) / T(10)
far = initial_guess * T(10)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is 10 big enough to actually find a root?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only method that this doesn't work on is Chebyshev methods, which would fail for other reasons because of its adaptivity of building its tableau. So it's good enough, we can make this open ended another way in the future if someone actually cares, but as a dev tool, good enough.

left, right = minmax(near_zero, far)
if f(left, nothing) * f(right, nothing) >= 0
# No sign change on same side of 0 (e.g. A-stable methods).
# Try bracket spanning 0: boundary is at z=0 for A-stable methods.
left, right = minmax(far, -near_zero)
end
sol = nlsolve(residual!, [initial_guess]; kw...)
return sol.zero[1]
prob = IntervalNonlinearProblem{false}(f, (left, right))
sol = solve(prob, Bisection(); kw...)
return sol.u
end

"""
Expand All @@ -90,11 +101,13 @@ function imaginary_stability_interval(
initial_guess = length(tab) - one(eltype(tab.A)),
kw...
)
residual! = function (resid, x)
return resid[1] = abs(stability_region(im * x[1], tab)) - 1
end
sol = nlsolve(residual!, [initial_guess]; kw...)
return sol.zero[1]
f = (x, p) -> abs(stability_region(im * x, tab)) - 1
T = typeof(initial_guess)
near_zero = one(T) / T(10)
far = initial_guess * T(10)
prob = IntervalNonlinearProblem{false}(f, (near_zero, far))
sol = solve(prob, Bisection(); kw...)
return sol.u
end

"""
Expand All @@ -110,11 +123,13 @@ function imaginary_stability_interval(
initial_guess = 20.0,
kw...
)
residual! = function (resid, x)
return resid[1] = abs(stability_region(im * x[1], alg)) - 1
end
sol = nlsolve(residual!, [initial_guess]; kw...)
return sol.zero[1]
f = (x, p) -> abs(stability_region(im * x, alg)) - 1
T = typeof(initial_guess)
near_zero = one(T) / T(10)
far = initial_guess * T(10)
prob = IntervalNonlinearProblem{false}(f, (near_zero, far))
sol = solve(prob, Bisection(); kw...)
return sol.u
end

function RootedTrees.residual_order_condition(
Expand Down
Loading