Skip to content

Commit eacac4c

Browse files
Merge pull request #141 from AayushSabharwal/as/mtkv10
refactor: update to MTKv10
2 parents 8fec5c0 + e49a441 commit eacac4c

File tree

4 files changed

+33
-26
lines changed

4 files changed

+33
-26
lines changed

lib/ODEProblemLibrary/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ RuntimeGeneratedFunctions = "7e49a35a-f44a-4d26-94aa-eba1b4ca6b47"
1515
Aqua = "0.5"
1616
DiffEqBase = "6"
1717
Latexify = "0.16"
18-
ModelingToolkit = "9"
18+
ModelingToolkit = "9, 10"
1919
RuntimeGeneratedFunctions = "0.5"
2020
julia = "1.10"
2121

lib/ODEProblemLibrary/src/ODEProblemLibrary.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ export prob_ode_linear, prob_ode_bigfloatlinear, prob_ode_2Dlinear,
3030
prob_ode_chen, prob_ode_rossler, prob_ode_rabinovich_fabrikant, prob_ode_sprott,
3131
prob_ode_hindmarsh_rose
3232

33+
# For MTKv9 compatibility
34+
@static if !isdefined(ModelingToolkit, :mtkcompile)
35+
function mtkcompile(args...; kwargs...)
36+
structural_simplify(args...; kwargs...)
37+
end
38+
end
39+
3340
include("ode_linear_prob.jl")
3441
include("ode_simple_nonlinear_prob.jl")
3542
include("brusselator_prob.jl")

lib/ODEProblemLibrary/src/ode_simple_nonlinear_prob.jl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ prob_ode_fitzhughnagumo = ODEProblem(fitz, [1.0; 1.0], (0.0, 1.0),
5454

5555
eqs = [D(y) ~ μ * ((1 - x^2) * y - x),
5656
D(x) ~ y]
57-
van = ODESystem(eqs, t; name = :van_der_pol) |> structural_simplify |> complete
57+
van = System(eqs, t; name = :van_der_pol) |> mtkcompile
5858

5959
"""
6060
Van der Pol Equations
@@ -70,7 +70,7 @@ with ``μ=1.0`` and ``u_0=[x => \\sqrt{3}, y => 0]``
7070
7171
Non-stiff parameters.
7272
"""
73-
prob_ode_vanderpol = ODEProblem(van, [y => 0, x => sqrt(3)], (0.0, 1.0), [μ => 1.0], jac=true, eval_module = @__MODULE__)
73+
prob_ode_vanderpol = ODEProblem(van, [y => 0, x => sqrt(3), μ => 1.0], (0.0, 1.0), jac=true, eval_module = @__MODULE__)
7474

7575
"""
7676
Van der Pol Equations
@@ -86,7 +86,7 @@ with ``μ=10^6`` and ``u_0=[x => \\sqrt{3}, y => 0]``
8686
8787
Stiff parameters.
8888
"""
89-
prob_ode_vanderpol_stiff = ODEProblem(van, [y => 0, x => sqrt(3)], (0.0, 1.0), [μ => 1e6], jac=true, eval_module = @__MODULE__)
89+
prob_ode_vanderpol_stiff = ODEProblem(van, [y => 0, x => sqrt(3), μ => 1e6], (0.0, 1.0), jac=true, eval_module = @__MODULE__)
9090

9191
# ROBER
9292
@parameters k₁ k₂ k₃
@@ -95,7 +95,7 @@ prob_ode_vanderpol_stiff = ODEProblem(van, [y => 0, x => sqrt(3)], (0.0, 1.0), [
9595
eqs = [D(y₁) ~ -k₁ * y₁ + k₃ * y₂ * y₃,
9696
D(y₂) ~ k₁ * y₁ - k₂ * y₂^2 - k₃ * y₂ * y₃,
9797
D(y₃) ~ k₂ * y₂^2]
98-
rober = ODESystem(eqs, t; name = :rober) |> structural_simplify |> complete
98+
rober = System(eqs, t; name = :rober) |> mtkcompile
9999

100100
"""
101101
The Robertson biochemical reactions: (Stiff)
@@ -116,7 +116,7 @@ Hairer Norsett Wanner Solving Ordinary Differential Equations I - Nonstiff Probl
116116
117117
Usually solved on ``[0,1e11]``
118118
"""
119-
prob_ode_rober = ODEProblem(rober, [y₁, y₂, y₃] .=> [1.0; 0.0; 0.0], (0.0, 1e11), [k₁, k₂, k₃] .=> (0.04, 3e7, 1e4), jac = true, eval_module = @__MODULE__)
119+
prob_ode_rober = ODEProblem(rober, [[y₁, y₂, y₃] .=> [1.0; 0.0; 0.0]; [k₁, k₂, k₃] .=> (0.04, 3e7, 1e4)], (0.0, 1e11), jac = true, eval_module = @__MODULE__)
120120

121121
# Three Body
122122
const threebody_μ = big(0.012277471);
@@ -175,7 +175,7 @@ prob_ode_threebody = ODEProblem(threebody,
175175
eqs = [D(y₁) ~ I₁ * y₂ * y₃,
176176
D(y₂) ~ I₂ * y₁ * y₃,
177177
D(y₃) ~ I₃ * y₁ * y₂]
178-
rigid = ODESystem(eqs, t; name = :rigid_body) |> structural_simplify |> complete
178+
rigid = System(eqs, t; name = :rigid_body) |> mtkcompile
179179

180180
"""
181181
Rigid Body Equations (Non-stiff)
@@ -200,9 +200,8 @@ or Hairer Norsett Wanner Solving Ordinary Differential Equations I - Nonstiff Pr
200200
201201
Usually solved from 0 to 20.
202202
"""
203-
prob_ode_rigidbody = ODEProblem(rigid, [y₁, y₂, y₃] .=> [1.0, 0.0, 0.9], (0.0, 20.0),
204-
[I₁, I₂, I₃] .=> (-2.0, 1.25, -0.5), jac = true,
205-
eval_module = @__MODULE__)
203+
prob_ode_rigidbody = ODEProblem(rigid, [[y₁, y₂, y₃] .=> [1.0, 0.0, 0.9]; [I₁, I₂, I₃] .=> (-2.0, 1.25, -0.5)], (0.0, 20.0),
204+
jac = true, eval_module = @__MODULE__)
206205

207206
# Pleiades Problem
208207

@@ -359,12 +358,16 @@ eqs = [D(y1) ~ -p1 * y1 + p2 * y2 + p3 * y3 + p4,
359358
p2 * y6 + p11 * y7,
360359
D(y7) ~ p10 * y6 * y8 - p12 * y7,
361360
D(y8) ~ -p10 * y6 * y8 + p12 * y7]
362-
hires = ODESystem(eqs, t; name = :hires) |> structural_simplify |> complete
361+
hires = System(eqs, t; name = :hires) |> mtkcompile
363362

364363
u0 = zeros(8)
365364
u0[1] = 1
366365
u0[8] = 0.0057
367366

367+
u0 = [y1, y2, y3, y4, y5, y6, y7, y8] .=> u0
368+
p = [p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12] .=> (1.71, 0.43, 8.32, 0.0007, 8.75,
369+
10.03, 0.035, 1.12, 1.745, 280.0, 0.69, 1.81)
370+
368371
"""
369372
Hires Problem (Stiff)
370373
@@ -387,18 +390,15 @@ where ``f`` is defined by
387390
Reference: [demohires.pdf](http://www.radford.edu/~thompson/vodef90web/problems/demosnodislin/Demos_Pitagora/DemoHires/demohires.pdf)
388391
Notebook: [Hires.ipynb](http://nbviewer.jupyter.org/github/JuliaDiffEq/DiffEqBenchmarks.jl/blob/master/StiffODE/Hires.ipynb)
389392
"""
390-
prob_ode_hires = ODEProblem(hires, [y1, y2, y3, y4, y5, y6, y7, y8] .=> u0, (0.0, 321.8122),
391-
[p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12] .=> (1.71, 0.43, 8.32, 0.0007, 8.75,
392-
10.03, 0.035, 1.12, 1.745, 280.0,
393-
0.69, 1.81), jac = true, eval_module = @__MODULE__)
393+
prob_ode_hires = ODEProblem(hires, [u0; p], (0.0, 321.8122), jac = true, eval_module = @__MODULE__)
394394

395395
@parameters p1 p2 p3
396396
@variables y1(t) y2(t) y3(t)
397397

398398
eqs = [D(y1) ~ p1 * (y2 + y1 * (1 - p2 * y1 - y2)),
399399
D(y2) ~ (y3 - (1 + y1) * y2) / p1,
400400
D(y3) ~ p3 * (y1 - y3)]
401-
orego = ODESystem(eqs, t; name = :orego) |> structural_simplify |> complete
401+
orego = System(eqs, t; name = :orego) |> mtkcompile
402402

403403
"""
404404
Orego Problem (Stiff)
@@ -418,4 +418,4 @@ where ``s=77.27``, ``w=0.161`` and ``q=8.375⋅10^{-6}``.
418418
Reference: [demoorego.pdf](http://www.radford.edu/~thompson/vodef90web/problems/demosnodislin/Demos_Pitagora/DemoOrego/demoorego.pdf)
419419
Notebook: [Orego.ipynb](http://nbviewer.jupyter.org/github/JuliaDiffEq/DiffEqBenchmarks.jl/blob/master/StiffODE/Orego.ipynb)
420420
"""
421-
prob_ode_orego = ODEProblem(orego, [y1, y2, y3] .=> [1.0, 2.0, 3.0], (0.0, 30.0), [p1, p2, p3] .=> [77.27, 8.375e-6, 0.161], jac = true, eval_module = @__MODULE__)
421+
prob_ode_orego = ODEProblem(orego, [[y1, y2, y3] .=> [1.0, 2.0, 3.0]; [p1, p2, p3] .=> [77.27, 8.375e-6, 0.161]], (0.0, 30.0), jac = true, eval_module = @__MODULE__)

lib/ODEProblemLibrary/src/strange_attractors.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ eqs = [D(x) ~ sin(y) - b * x,
1010
D(y) ~ sin(z) - b * y,
1111
D(z) ~ sin(x) - b * z]
1212

13-
@mtkbuild thomas = ODESystem(eqs, t)
13+
@mtkbuild thomas = System(eqs, t)
1414

1515
"""
1616
Thomas' cyclically symmetric attractor equations
@@ -33,7 +33,7 @@ eqs = [D(x) ~ σ * (y - x),
3333
D(y) ~ x *- z) - y,
3434
D(z) ~ x * y - β * z]
3535

36-
@mtkbuild lorenz = ODESystem(eqs, t)
36+
@mtkbuild lorenz = System(eqs, t)
3737

3838
"""
3939
Lorenz equations
@@ -56,7 +56,7 @@ eqs = [D(x) ~ (z - b) * x - d * y,
5656
D(y) ~ d * x + (z - b) * y,
5757
D(z) ~ c + a * z - z^3 / 3 - (x^2 + y^2) * (1 + e * z) + f * z * x^3]
5858

59-
@mtkbuild aizawa = ODESystem(eqs, t)
59+
@mtkbuild aizawa = System(eqs, t)
6060

6161
"""
6262
Aizawa equations
@@ -78,7 +78,7 @@ eqs = [D(x) ~ y - a * x + b * y * z,
7878
D(y) ~ c * y - x * z + z,
7979
D(z) ~ d * x * y - e * z]
8080

81-
@mtkbuild dadras = ODESystem(eqs, t)
81+
@mtkbuild dadras = System(eqs, t)
8282

8383
"""
8484
Dadras equations
@@ -100,7 +100,7 @@ eqs = [D(x) ~ a * (y - x),
100100
D(y) ~ (c - a) * x - x * z + c * y,
101101
D(z) ~ x * y - b * z]
102102

103-
@mtkbuild chen = ODESystem(eqs, t)
103+
@mtkbuild chen = System(eqs, t)
104104

105105
"""
106106
chen equations
@@ -122,7 +122,7 @@ eqs = [D(x) ~ -(y + z),
122122
D(y) ~ x + a * y,
123123
D(z) ~ b + z * (x - c)]
124124

125-
@mtkbuild rossler = ODESystem(eqs, t)
125+
@mtkbuild rossler = System(eqs, t)
126126

127127
"""
128128
rossler equations
@@ -145,7 +145,7 @@ eqs = [D(x) ~ y * (z - 1 + x^2) + b * x,
145145
D(y) ~ x * (3 * z + 1 - x^2) + b * y,
146146
D(z) ~ -2 * z * (a + x * y)]
147147

148-
@mtkbuild rabinovich_fabrikant = ODESystem(eqs, t)
148+
@mtkbuild rabinovich_fabrikant = System(eqs, t)
149149

150150
"""
151151
rabinovich_fabrikant equations
@@ -167,7 +167,7 @@ eqs = [D(x) ~ y + a * x * y + x * z,
167167
D(y) ~ 1 - b * x^2 + y * z,
168168
D(z) ~ x - x^2 - y^2]
169169

170-
@mtkbuild sprott = ODESystem(eqs, t)
170+
@mtkbuild sprott = System(eqs, t)
171171

172172
"""
173173
sprott equations
@@ -189,7 +189,7 @@ eqs = [D(x) ~ y - a * x^3 + b * x^2 - z + i,
189189
D(y) ~ c - d * x^2 - y,
190190
D(z) ~ r * (s * (x - xr) - z)]
191191

192-
@mtkbuild hindmarsh_rose = ODESystem(eqs, t)
192+
@mtkbuild hindmarsh_rose = System(eqs, t)
193193

194194
"""
195195
hindmarsh_rose equations

0 commit comments

Comments
 (0)