Skip to content

Commit 2942615

Browse files
committed
undo Rosenbrock23 changes
1 parent acd2414 commit 2942615

File tree

2 files changed

+132
-0
lines changed

2 files changed

+132
-0
lines changed

lib/OrdinaryDiffEqRosenbrock/src/interp_func.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
function DiffEqBase.interp_summary(::Type{cacheType},
2+
dense::Bool) where {
3+
cacheType <:
4+
Union{Rosenbrock23ConstantCache,
5+
Rosenbrock32ConstantCache,
6+
Rosenbrock23Cache,
7+
Rosenbrock32Cache}}
8+
dense ? "specialized 2nd order \"free\" stiffness-aware interpolation" :
9+
"1st order linear"
10+
end
11+
112
function DiffEqBase.interp_summary(::Type{cacheType},
213
dense::Bool) where {
314
cacheType <:

lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_interpolants.jl

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,124 @@
1+
### Fallbacks to capture
2+
ROSENBROCKS_WITH_INTERPOLATIONS = Union{Rosenbrock23ConstantCache, Rosenbrock23Cache,
3+
Rosenbrock32ConstantCache, Rosenbrock32Cache,
4+
RosenbrockCombinedConstantCache,
5+
RosenbrockCache}
6+
7+
function _ode_interpolant(Θ, dt, y₀, y₁, k,
8+
cache::ROSENBROCKS_WITH_INTERPOLATIONS,
9+
idxs, T::Type{Val{D}}, differential_vars) where {D}
10+
throw(DerivativeOrderNotPossibleError())
11+
end
12+
13+
function _ode_interpolant!(out, Θ, dt, y₀, y₁, k,
14+
cache::ROSENBROCKS_WITH_INTERPOLATIONS,
15+
idxs, T::Type{Val{D}}, differential_vars) where {D}
16+
throw(DerivativeOrderNotPossibleError())
17+
end
18+
19+
"""
20+
From MATLAB ODE Suite by Shampine
21+
"""
22+
@def rosenbrock2332unpack begin
23+
if cache isa OrdinaryDiffEqMutableCache
24+
d = cache.tab.d
25+
else
26+
d = cache.d
27+
end
28+
end
29+
30+
@def rosenbrock2332pre0 begin
31+
@rosenbrock2332unpack
32+
c1 = Θ * (1 - Θ) / (1 - 2d)
33+
c2 = Θ *- 2d) / (1 - 2d)
34+
end
35+
36+
@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k,
37+
cache::Union{Rosenbrock23ConstantCache,
38+
Rosenbrock32ConstantCache}, idxs::Nothing,
39+
T::Type{Val{0}}, differential_vars)
40+
@rosenbrock2332pre0
41+
@inbounds y₀ + dt * (c1 * k[1] + c2 * k[2])
42+
end
43+
44+
@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k,
45+
cache::Union{Rosenbrock23Cache, Rosenbrock32Cache},
46+
idxs::Nothing, T::Type{Val{0}}, differential_vars)
47+
@rosenbrock2332pre0
48+
@inbounds @.. y₀+dt * (c1 * k[1] + c2 * k[2])
49+
end
50+
51+
@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k,
52+
cache::Union{Rosenbrock23ConstantCache, Rosenbrock23Cache,
53+
Rosenbrock32ConstantCache, Rosenbrock32Cache
54+
}, idxs, T::Type{Val{0}}, differential_vars)
55+
@rosenbrock2332pre0
56+
@.. y₀[idxs]+dt * (c1 * k[1][idxs] + c2 * k[2][idxs])
57+
end
58+
59+
@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k,
60+
cache::Union{Rosenbrock23ConstantCache,
61+
Rosenbrock23Cache,
62+
Rosenbrock32ConstantCache, Rosenbrock32Cache
63+
}, idxs::Nothing, T::Type{Val{0}}, differential_vars)
64+
@rosenbrock2332pre0
65+
@inbounds @.. out=y₀ + dt * (c1 * k[1] + c2 * k[2])
66+
out
67+
end
68+
69+
@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k,
70+
cache::Union{Rosenbrock23ConstantCache,
71+
Rosenbrock23Cache,
72+
Rosenbrock32ConstantCache, Rosenbrock32Cache
73+
}, idxs, T::Type{Val{0}}, differential_vars)
74+
@rosenbrock2332pre0
75+
@views @.. out=y₀[idxs] + dt * (c1 * k[1][idxs] + c2 * k[2][idxs])
76+
out
77+
end
78+
79+
# First Derivative of the dense output
80+
@def rosenbrock2332pre1 begin
81+
@rosenbrock2332unpack
82+
c1diff = (1 - 2 * Θ) / (1 - 2 * d)
83+
c2diff = (2 * Θ - 2 * d) / (1 - 2 * d)
84+
end
85+
86+
@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k,
87+
cache::Union{Rosenbrock23ConstantCache, Rosenbrock23Cache,
88+
Rosenbrock32ConstantCache, Rosenbrock32Cache
89+
}, idxs::Nothing, T::Type{Val{1}}, differential_vars)
90+
@rosenbrock2332pre1
91+
@.. c1diff * k[1]+c2diff * k[2]
92+
end
93+
94+
@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k,
95+
cache::Union{Rosenbrock23ConstantCache, Rosenbrock23Cache,
96+
Rosenbrock32ConstantCache, Rosenbrock32Cache
97+
}, idxs, T::Type{Val{1}}, differential_vars)
98+
@rosenbrock2332pre1
99+
@.. c1diff * k[1][idxs]+c2diff * k[2][idxs]
100+
end
101+
102+
@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k,
103+
cache::Union{Rosenbrock23ConstantCache,
104+
Rosenbrock23Cache,
105+
Rosenbrock32ConstantCache, Rosenbrock32Cache
106+
}, idxs::Nothing, T::Type{Val{1}}, differential_vars)
107+
@rosenbrock2332pre1
108+
@.. out=c1diff * k[1] + c2diff * k[2]
109+
out
110+
end
111+
112+
@muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k,
113+
cache::Union{Rosenbrock23ConstantCache,
114+
Rosenbrock23Cache,
115+
Rosenbrock32ConstantCache, Rosenbrock32Cache
116+
}, idxs, T::Type{Val{1}}, differential_vars)
117+
@rosenbrock2332pre1
118+
@views @.. out=c1diff * k[1][idxs] + c2diff * k[2][idxs]
119+
out
120+
end
121+
1122
"""
2123
From MATLAB ODE Suite by Shampine
3124
"""

0 commit comments

Comments
 (0)