Skip to content

Commit 0f81d2e

Browse files
Merge pull request #3140 from ChrisRackauckas-Claude/add-dde-sublibrary
Add DelayDiffEq as a sublibrary
2 parents 509f956 + bdc4601 commit 0f81d2e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+6184
-8
lines changed

lib/DelayDiffEq/LICENSE.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The DelayDiffEq.jl package is licensed under the MIT "Expat" License:
2+
3+
> Copyright (c) 2017: ChrisRackauckas.
4+
>
5+
> Permission is hereby granted, free of charge, to any person obtaining a copy
6+
> of this software and associated documentation files (the "Software"), to deal
7+
> in the Software without restriction, including without limitation the rights
8+
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
> copies of the Software, and to permit persons to whom the Software is
10+
> furnished to do so, subject to the following conditions:
11+
>
12+
> The above copyright notice and this permission notice shall be included in all
13+
> copies or substantial portions of the Software.
14+
>
15+
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
> SOFTWARE.
22+
>

lib/DelayDiffEq/Project.toml

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
name = "DelayDiffEq"
2+
uuid = "c7a87de4-83fd-43d3-ac6b-85200c5401ec"
3+
authors = ["Chris Rackauckas <accounts@chrisrackauckas.com>"]
4+
version = "1.0.0"
5+
6+
[deps]
7+
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
8+
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
9+
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
10+
FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898"
11+
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
12+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
13+
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
14+
OrdinaryDiffEqCore = "bbf590c4-e513-4bbe-9b18-05decba2e5d8"
15+
OrdinaryDiffEqDefault = "50262376-6c5a-4cf5-baba-aaf4f84d72d7"
16+
OrdinaryDiffEqDifferentiation = "4302a76b-040a-498a-8c04-15b101fed76b"
17+
OrdinaryDiffEqFunctionMap = "d3585ca7-f5d3-4ba6-8057-292ed1abd90f"
18+
OrdinaryDiffEqNonlinearSolve = "127b3ac7-2247-4354-8eb6-78cf4e7c58e8"
19+
OrdinaryDiffEqRosenbrock = "43230ef6-c299-4910-a778-202eb28ce4ce"
20+
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
21+
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
22+
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
23+
SciMLLogging = "a6db7da4-7206-11f0-1eab-35f2a5dbe1d1"
24+
SimpleNonlinearSolve = "727e6d20-b764-4bd8-a329-72de5adea6c7"
25+
SymbolicIndexingInterface = "2efcf032-c050-4f8e-a9bb-153293bab1f5"
26+
27+
[extras]
28+
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
29+
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
30+
DDEProblemLibrary = "f42792ee-6ffc-4e2a-ae83-8ee2f22de800"
31+
DiffEqCallbacks = "459566f4-90b8-5000-8ac3-15dfb0a30def"
32+
DiffEqDevTools = "f3b72e0c-5b89-59e1-b016-84e28bfd966d"
33+
ExplicitImports = "7d51a73a-1435-4ff3-83d9-f097790105c7"
34+
FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41"
35+
LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae"
36+
OrdinaryDiffEqBDF = "6ad6398a-0878-4a85-9266-38940aa047c8"
37+
OrdinaryDiffEqFeagin = "101fe9f7-ebb6-4678-b671-3a81e7194747"
38+
OrdinaryDiffEqHighOrderRK = "d28bc4f8-55e1-4f49-af69-84c1a99f0f58"
39+
OrdinaryDiffEqLowOrderRK = "1344f307-1e59-4825-a18e-ace9aa3fa4c6"
40+
OrdinaryDiffEqLowStorageRK = "b0944070-b475-4768-8dec-fb6eb410534d"
41+
OrdinaryDiffEqSDIRK = "2d112036-d095-4a1e-ab9a-08536f3ecdbf"
42+
OrdinaryDiffEqSSPRK = "669c94d9-1f4b-4b64-b377-1aa079aa2388"
43+
OrdinaryDiffEqTsit5 = "b1df2697-797e-41e3-8120-5422d3b24e4a"
44+
OrdinaryDiffEqVerner = "79d7bb75-1356-48c1-b8c0-6832512096c2"
45+
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
46+
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
47+
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
48+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
49+
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
50+
51+
[compat]
52+
ADTypes = "1.16"
53+
Aqua = "0.8.11"
54+
ArrayInterface = "7"
55+
DDEProblemLibrary = "0.1"
56+
DataStructures = "0.18, 0.19"
57+
DiffEqBase = "6.209"
58+
DiffEqCallbacks = "4"
59+
DiffEqDevTools = "2.44.4"
60+
ExplicitImports = "1.13.1"
61+
FastBroadcast = "0.3.5"
62+
FiniteDiff = "2.27"
63+
ForwardDiff = "0.10.38, 1"
64+
LinearAlgebra = "1"
65+
LinearSolve = "3.54"
66+
Logging = "1"
67+
OrdinaryDiffEqBDF = "1.16.0"
68+
OrdinaryDiffEqCore = "3"
69+
OrdinaryDiffEqDefault = "1.9"
70+
OrdinaryDiffEqDifferentiation = "2.2.1"
71+
OrdinaryDiffEqFeagin = "1.3.0"
72+
OrdinaryDiffEqFunctionMap = "1.6"
73+
OrdinaryDiffEqHighOrderRK = "1.4.0"
74+
OrdinaryDiffEqLowOrderRK = "1.5.0"
75+
OrdinaryDiffEqLowStorageRK = "1.12.0"
76+
OrdinaryDiffEqNonlinearSolve = "1.16"
77+
OrdinaryDiffEqRosenbrock = "1.19"
78+
OrdinaryDiffEqSDIRK = "1.6.0"
79+
OrdinaryDiffEqSSPRK = "1.5.0"
80+
OrdinaryDiffEqTsit5 = "1.4.0"
81+
OrdinaryDiffEqVerner = "1.5.0"
82+
Random = "<0.0.1, 1"
83+
RecursiveArrayTools = "3"
84+
Reexport = "1.0"
85+
SafeTestsets = "0.1.0"
86+
SciMLBase = "2.115.0"
87+
SciMLLogging = "1.4.0"
88+
SimpleNonlinearSolve = "2"
89+
SymbolicIndexingInterface = "0.3.36"
90+
Test = "<0.0.1, 1"
91+
Unitful = "1"
92+
julia = "1.10"
93+
94+
[targets]
95+
test = ["ADTypes", "Aqua", "DDEProblemLibrary", "DiffEqCallbacks", "DiffEqDevTools", "ExplicitImports", "FiniteDiff", "LinearSolve", "OrdinaryDiffEqBDF", "OrdinaryDiffEqFeagin", "OrdinaryDiffEqHighOrderRK", "OrdinaryDiffEqLowOrderRK", "OrdinaryDiffEqLowStorageRK", "OrdinaryDiffEqSDIRK", "OrdinaryDiffEqSSPRK", "OrdinaryDiffEqTsit5", "OrdinaryDiffEqVerner", "Random", "RecursiveArrayTools", "SafeTestsets", "Test", "Unitful"]
96+
97+
[sources.OrdinaryDiffEqCore]
98+
path = "../OrdinaryDiffEqCore"
99+
100+
[sources.OrdinaryDiffEqDefault]
101+
path = "../OrdinaryDiffEqDefault"
102+
103+
[sources.OrdinaryDiffEqDifferentiation]
104+
path = "../OrdinaryDiffEqDifferentiation"
105+
106+
[sources.OrdinaryDiffEqFunctionMap]
107+
path = "../OrdinaryDiffEqFunctionMap"
108+
109+
[sources.OrdinaryDiffEqNonlinearSolve]
110+
path = "../OrdinaryDiffEqNonlinearSolve"
111+
112+
[sources.OrdinaryDiffEqRosenbrock]
113+
path = "../OrdinaryDiffEqRosenbrock"
114+
115+
[sources.OrdinaryDiffEqBDF]
116+
path = "../OrdinaryDiffEqBDF"
117+
118+
[sources.OrdinaryDiffEqFeagin]
119+
path = "../OrdinaryDiffEqFeagin"
120+
121+
[sources.OrdinaryDiffEqHighOrderRK]
122+
path = "../OrdinaryDiffEqHighOrderRK"
123+
124+
[sources.OrdinaryDiffEqLowOrderRK]
125+
path = "../OrdinaryDiffEqLowOrderRK"
126+
127+
[sources.OrdinaryDiffEqLowStorageRK]
128+
path = "../OrdinaryDiffEqLowStorageRK"
129+
130+
[sources.OrdinaryDiffEqSDIRK]
131+
path = "../OrdinaryDiffEqSDIRK"
132+
133+
[sources.OrdinaryDiffEqSSPRK]
134+
path = "../OrdinaryDiffEqSSPRK"
135+
136+
[sources.OrdinaryDiffEqTsit5]
137+
path = "../OrdinaryDiffEqTsit5"
138+
139+
[sources.OrdinaryDiffEqVerner]
140+
path = "../OrdinaryDiffEqVerner"

lib/DelayDiffEq/src/DelayDiffEq.jl

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
module DelayDiffEq
2+
3+
import Reexport: @reexport, Reexport
4+
@reexport using SciMLBase
5+
import OrdinaryDiffEqCore, OrdinaryDiffEqNonlinearSolve, OrdinaryDiffEqDifferentiation,
6+
OrdinaryDiffEqRosenbrock
7+
import OrdinaryDiffEqDefault: OrdinaryDiffEqDefault
8+
import OrdinaryDiffEqFunctionMap: OrdinaryDiffEqFunctionMap
9+
10+
using DataStructures: BinaryMinHeap
11+
using LinearAlgebra: opnorm, I
12+
using Logging: @logmsg
13+
using RecursiveArrayTools: copyat_or_push!, recursivecopy, recursivecopy!,
14+
recursive_bottom_eltype, recursive_unitless_bottom_eltype,
15+
recursive_unitless_eltype
16+
using ForwardDiff: ForwardDiff
17+
18+
import ArrayInterface
19+
import SimpleNonlinearSolve
20+
import SymbolicIndexingInterface as SII
21+
22+
using SciMLBase: AbstractDDEAlgorithm, AbstractDDEIntegrator, AbstractODEIntegrator,
23+
DEIntegrator
24+
25+
using Base: deleteat!
26+
import FastBroadcast: @..
27+
28+
using OrdinaryDiffEqNonlinearSolve: NLAnderson, NLFunctional
29+
using OrdinaryDiffEqCore: AbstractNLSolverCache, SlowConvergence,
30+
alg_extrapolates, alg_maximum_order, initialize!, DEVerbosity
31+
using OrdinaryDiffEqRosenbrock: RosenbrockMutableCache
32+
using OrdinaryDiffEqFunctionMap: FunctionMap
33+
# using OrdinaryDiffEqDifferentiation: resize_grad_config!, resize_jac_config!
34+
35+
# Explicit imports for functions
36+
using OrdinaryDiffEqCore: AutoSwitch, CompositeAlgorithm
37+
using OrdinaryDiffEqDefault: DefaultODEAlgorithm
38+
using SciMLBase: CallbackSet, DAEProblem, DDEProblem, DESolution, ODEProblem, ReturnCode,
39+
VectorContinuousCallback, addat!, addat_non_user_cache!,
40+
deleteat_non_user_cache!,
41+
du_cache, full_cache, get_tmp_cache, isinplace,
42+
reeval_internals_due_to_modification!,
43+
reinit!, resize_non_user_cache!, savevalues!, u_cache, user_cache,
44+
step!, terminate!, u_modified!, get_proposed_dt, set_proposed_dt!,
45+
auto_dt_reset!,
46+
add_tstop!, add_saveat!, get_du, get_du!, addsteps!,
47+
change_t_via_interpolation!, isadaptive
48+
using DiffEqBase: initialize!
49+
import DiffEqBase
50+
using SciMLLogging: AbstractVerbosityPreset, None, @SciMLMessage
51+
52+
import SciMLBase
53+
54+
export Discontinuity, MethodOfSteps
55+
56+
include("discontinuity_type.jl")
57+
include("functionwrapper.jl")
58+
59+
include("integrators/type.jl")
60+
include("integrators/utils.jl")
61+
include("integrators/interface.jl")
62+
63+
include("fpsolve/type.jl")
64+
include("fpsolve/fpsolve.jl")
65+
include("fpsolve/utils.jl")
66+
include("fpsolve/functional.jl")
67+
include("cache_utils.jl")
68+
include("interpolants.jl")
69+
include("history_function.jl")
70+
include("algorithms.jl")
71+
include("track.jl")
72+
include("alg_utils.jl")
73+
include("solve.jl")
74+
include("utils.jl")
75+
76+
# Default solver for DDEProblems
77+
function SciMLBase.__solve(prob::DDEProblem; kwargs...)
78+
return SciMLBase.solve(prob, MethodOfSteps(DefaultODEAlgorithm()); kwargs...)
79+
end
80+
function SciMLBase.__init(prob::DDEProblem; kwargs...)
81+
return DiffEqBase.init(prob, MethodOfSteps(DefaultODEAlgorithm()); kwargs...)
82+
end
83+
84+
end # module

lib/DelayDiffEq/src/alg_utils.jl

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
## SciMLBase Trait Definitions
2+
3+
function SciMLBase.isautodifferentiable(alg::AbstractMethodOfStepsAlgorithm)
4+
return SciMLBase.isautodifferentiable(alg.alg)
5+
end
6+
function SciMLBase.allows_arbitrary_number_types(alg::AbstractMethodOfStepsAlgorithm)
7+
return SciMLBase.allows_arbitrary_number_types(alg.alg)
8+
end
9+
function SciMLBase.allowscomplex(alg::AbstractMethodOfStepsAlgorithm)
10+
return SciMLBase.allowscomplex(alg.alg)
11+
end
12+
SciMLBase.isdiscrete(alg::AbstractMethodOfStepsAlgorithm) = SciMLBase.isdiscrete(alg.alg)
13+
SciMLBase.isadaptive(alg::AbstractMethodOfStepsAlgorithm) = SciMLBase.isadaptive(alg.alg)
14+
15+
## DelayDiffEq Internal Traits
16+
17+
function isconstrained(alg::AbstractMethodOfStepsAlgorithm{constrained}) where {constrained}
18+
return constrained
19+
end
20+
OrdinaryDiffEqCore.uses_uprev(alg::AbstractMethodOfStepsAlgorithm, adaptive) = true
21+
22+
function OrdinaryDiffEqCore.isimplicit(alg::AbstractMethodOfStepsAlgorithm)
23+
return OrdinaryDiffEqCore.isimplicit(alg.alg)
24+
end
25+
function OrdinaryDiffEqCore.isdtchangeable(alg::AbstractMethodOfStepsAlgorithm)
26+
return OrdinaryDiffEqCore.isdtchangeable(alg.alg)
27+
end
28+
function OrdinaryDiffEqCore.ismultistep(alg::AbstractMethodOfStepsAlgorithm)
29+
return OrdinaryDiffEqCore.ismultistep(alg.alg)
30+
end
31+
function OrdinaryDiffEqCore.isautoswitch(alg::AbstractMethodOfStepsAlgorithm)
32+
return OrdinaryDiffEqCore.isautoswitch(alg.alg)
33+
end
34+
function OrdinaryDiffEqCore.get_chunksize(alg::AbstractMethodOfStepsAlgorithm)
35+
return OrdinaryDiffEqCore.get_chunksize(alg.alg)
36+
end
37+
function OrdinaryDiffEqCore.get_chunksize_int(alg::AbstractMethodOfStepsAlgorithm)
38+
return OrdinaryDiffEqCore.get_chunksize_int(alg.alg)
39+
end
40+
function OrdinaryDiffEqCore.alg_autodiff(alg::AbstractMethodOfStepsAlgorithm)
41+
return OrdinaryDiffEqCore.alg_autodiff(alg.alg)
42+
end
43+
function OrdinaryDiffEqCore.alg_difftype(alg::AbstractMethodOfStepsAlgorithm)
44+
return OrdinaryDiffEqCore.alg_difftype(alg.alg)
45+
end
46+
function OrdinaryDiffEqCore.standardtag(alg::AbstractMethodOfStepsAlgorithm)
47+
return OrdinaryDiffEqCore.standardtag(alg.alg)
48+
end
49+
function OrdinaryDiffEqCore.concrete_jac(alg::AbstractMethodOfStepsAlgorithm)
50+
return OrdinaryDiffEqCore.concrete_jac(alg.alg)
51+
end
52+
function OrdinaryDiffEqCore.alg_extrapolates(alg::AbstractMethodOfStepsAlgorithm)
53+
return OrdinaryDiffEqCore.alg_extrapolates(alg.alg)
54+
end
55+
function SciMLBase.alg_order(alg::AbstractMethodOfStepsAlgorithm)
56+
return SciMLBase.alg_order(alg.alg)
57+
end
58+
function OrdinaryDiffEqCore.alg_maximum_order(alg::AbstractMethodOfStepsAlgorithm)
59+
return OrdinaryDiffEqCore.alg_maximum_order(alg.alg)
60+
end
61+
function OrdinaryDiffEqCore.alg_adaptive_order(alg::AbstractMethodOfStepsAlgorithm)
62+
return OrdinaryDiffEqCore.alg_adaptive_order(alg.alg)
63+
end
64+
65+
"""
66+
iscomposite(alg)
67+
68+
Return if algorithm `alg` is a composite algorithm.
69+
"""
70+
iscomposite(alg) = false
71+
iscomposite(::OrdinaryDiffEqCore.OrdinaryDiffEqCompositeAlgorithm) = true
72+
iscomposite(alg::AbstractMethodOfStepsAlgorithm) = iscomposite(alg.alg)
73+
74+
function DiffEqBase.prepare_alg(alg::MethodOfSteps, u0, p, prob)
75+
return MethodOfSteps(
76+
DiffEqBase.prepare_alg(alg.alg, u0, p, prob);
77+
constrained = isconstrained(alg),
78+
fpsolve = alg.fpsolve
79+
)
80+
end

lib/DelayDiffEq/src/algorithms.jl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
abstract type DelayDiffEqAlgorithm <: AbstractDDEAlgorithm end
2+
abstract type AbstractMethodOfStepsAlgorithm{constrained} <: DelayDiffEqAlgorithm end
3+
4+
struct MethodOfSteps{algType, F, constrained} <: AbstractMethodOfStepsAlgorithm{constrained}
5+
alg::algType
6+
fpsolve::F
7+
end
8+
9+
"""
10+
MethodOfSteps(alg; constrained = false, fpsolve = NLFunctional())
11+
12+
Construct an algorithm that solves delay differential equations by the method of steps,
13+
where `alg` is an ODE algorithm from OrdinaryDiffEq.jl upon which the calculation of
14+
steps is based.
15+
16+
If the algorithm is `constrained` only steps of size at most the minimal delay will be
17+
taken. If it is unconstrained, fixed-point iteration `fpsolve` is applied for step sizes
18+
that exceed the minimal delay.
19+
20+
21+
Citations:
22+
23+
General Approach
24+
25+
Zivari-Piran, Hossein, and Wayne H. Enright. "An efficient unified approach for the numerical
26+
solution of delay differential equations." Numerical Algorithms 53.2-3 (2010): 397-417.
27+
28+
State-Dependent Delays
29+
30+
S. P. Corwin, D. Sarafyan and S. Thompson in "DKLAG6: a code based on continuously embedded
31+
sixth-order Runge-Kutta methods for the solution of state-dependent functional differential
32+
equations", Applied Numerical Mathematics, 1997.
33+
"""
34+
function MethodOfSteps(alg; constrained = false, fpsolve = NLFunctional())
35+
return MethodOfSteps{typeof(alg), typeof(fpsolve), constrained}(alg, fpsolve)
36+
end

lib/DelayDiffEq/src/cache_utils.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function SciMLBase.unwrap_cache(integrator::DDEIntegrator, is_stiff)
2+
alg = integrator.alg
3+
cache = integrator.cache
4+
iscomp = alg isa CompositeAlgorithm
5+
if !iscomp
6+
return cache
7+
elseif alg.choice_function isa AutoSwitch
8+
num = is_stiff ? 2 : 1
9+
return get_current_cache(cache, num)
10+
else
11+
return get_current_cache(cache, integrator.cache.current)
12+
end
13+
end

0 commit comments

Comments
 (0)