Skip to content

Commit 81563c4

Browse files
Merge pull request #139 from SciML/symbolic_constructors
Properly use symbolic constructors
2 parents 89dcf9b + 4a7bd47 commit 81563c4

File tree

2 files changed

+19
-25
lines changed

2 files changed

+19
-25
lines changed

lib/ODEProblemLibrary/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ODEProblemLibrary"
22
uuid = "fdc4e326-1af4-4b90-96e7-779fcce2daa5"
3-
version = "0.1.8"
3+
version = "0.1.9"
44

55
[deps]
66
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"

lib/ODEProblemLibrary/src/ode_simple_nonlinear_prob.jl

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +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-
de = ODESystem(eqs, t; name = :van_der_pol) |> structural_simplify |> complete
58-
van = ODEFunction(de, [y, x], [μ], jac = true, eval_module = @__MODULE__)
57+
van = ODESystem(eqs, t; name = :van_der_pol) |> structural_simplify |> complete
5958

6059
"""
6160
Van der Pol Equations
@@ -67,11 +66,11 @@ Van der Pol Equations
6766
\\frac{dy}{dt} = μ((1-x^2)y -x)
6867
```
6968
70-
with ``μ=1.0`` and ``u_0=[0,\\sqrt{3}]``
69+
with ``μ=1.0`` and ``u_0=[x => \\sqrt{3}, y => 0]``
7170
7271
Non-stiff parameters.
7372
"""
74-
prob_ode_vanderpol = ODEProblem(van, [0; sqrt(3)], (0.0, 1.0), 1.0)
73+
prob_ode_vanderpol = ODEProblem(van, [y => 0, x => sqrt(3)], (0.0, 1.0), => 1.0], jac=true, eval_module = @__MODULE__)
7574

7675
"""
7776
Van der Pol Equations
@@ -83,11 +82,11 @@ Van der Pol Equations
8382
\\frac{dy}{dt} = μ((1-x^2)y -x)
8483
```
8584
86-
with ``μ=10^6`` and ``u_0=[0,\\sqrt{3}]``
85+
with ``μ=10^6`` and ``u_0=[x => \\sqrt{3}, y => 0]``
8786
8887
Stiff parameters.
8988
"""
90-
prob_ode_vanderpol_stiff = ODEProblem(van, [0; sqrt(3)], (0.0, 1.0), 1e6)
89+
prob_ode_vanderpol_stiff = ODEProblem(van, [y => 0, x => sqrt(3)], (0.0, 1.0), => 1e6], jac=true, eval_module = @__MODULE__)
9190

9291
# ROBER
9392
@parameters k₁ k₂ k₃
@@ -96,8 +95,7 @@ prob_ode_vanderpol_stiff = ODEProblem(van, [0; sqrt(3)], (0.0, 1.0), 1e6)
9695
eqs = [D(y₁) ~ -k₁ * y₁ + k₃ * y₂ * y₃,
9796
D(y₂) ~ k₁ * y₁ - k₂ * y₂^2 - k₃ * y₂ * y₃,
9897
D(y₃) ~ k₂ * y₂^2]
99-
de = ODESystem(eqs, t; name = :rober) |> structural_simplify |> complete
100-
rober = ODEFunction(de, [y₁, y₂, y₃], [k₁, k₂, k₃], jac = true, eval_module = @__MODULE__)
98+
rober = ODESystem(eqs, t; name = :rober) |> structural_simplify |> complete
10199

102100
"""
103101
The Robertson biochemical reactions: (Stiff)
@@ -118,7 +116,7 @@ Hairer Norsett Wanner Solving Ordinary Differential Equations I - Nonstiff Probl
118116
119117
Usually solved on ``[0,1e11]``
120118
"""
121-
prob_ode_rober = ODEProblem(rober, [1.0; 0.0; 0.0], (0.0, 1e11), (0.04, 3e7, 1e4))
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__)
122120

123121
# Three Body
124122
const threebody_μ = big(0.012277471);
@@ -177,8 +175,7 @@ prob_ode_threebody = ODEProblem(threebody,
177175
eqs = [D(y₁) ~ I₁ * y₂ * y₃,
178176
D(y₂) ~ I₂ * y₁ * y₃,
179177
D(y₃) ~ I₃ * y₁ * y₂]
180-
de = ODESystem(eqs, t; name = :rigid_body) |> structural_simplify |> complete
181-
rigid = ODEFunction(de, [y₁, y₂, y₃], [I₁, I₂, I₃], jac = true, eval_module = @__MODULE__)
178+
rigid = ODESystem(eqs, t; name = :rigid_body) |> structural_simplify |> complete
182179

183180
"""
184181
Rigid Body Equations (Non-stiff)
@@ -203,7 +200,9 @@ or Hairer Norsett Wanner Solving Ordinary Differential Equations I - Nonstiff Pr
203200
204201
Usually solved from 0 to 20.
205202
"""
206-
prob_ode_rigidbody = ODEProblem(rigid, [1.0, 0.0, 0.9], (0.0, 20.0), (-2.0, 1.25, -0.5))
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__)
207206

208207
# Pleiades Problem
209208

@@ -360,10 +359,7 @@ eqs = [D(y1) ~ -p1 * y1 + p2 * y2 + p3 * y3 + p4,
360359
p2 * y6 + p11 * y7,
361360
D(y7) ~ p10 * y6 * y8 - p12 * y7,
362361
D(y8) ~ -p10 * y6 * y8 + p12 * y7]
363-
de = ODESystem(eqs, t; name = :hires) |> structural_simplify |> complete
364-
hires = ODEFunction(de, [y1, y2, y3, y4, y5, y6, y7, y8],
365-
[p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12],
366-
jac = true)
362+
hires = ODESystem(eqs, t; name = :hires) |> structural_simplify |> complete
367363

368364
u0 = zeros(8)
369365
u0[1] = 1
@@ -391,20 +387,18 @@ where ``f`` is defined by
391387
Reference: [demohires.pdf](http://www.radford.edu/~thompson/vodef90web/problems/demosnodislin/Demos_Pitagora/DemoHires/demohires.pdf)
392388
Notebook: [Hires.ipynb](http://nbviewer.jupyter.org/github/JuliaDiffEq/DiffEqBenchmarks.jl/blob/master/StiffODE/Hires.ipynb)
393389
"""
394-
prob_ode_hires = ODEProblem(hires, u0, (0.0, 321.8122),
395-
(1.71, 0.43, 8.32, 0.0007, 8.75,
396-
10.03, 0.035, 1.12, 1.745, 280.0,
397-
0.69, 1.81))
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__)
398394

399395
@parameters p1 p2 p3
400396
@variables y1(t) y2(t) y3(t)
401397

402398
eqs = [D(y1) ~ p1 * (y2 + y1 * (1 - p2 * y1 - y2)),
403399
D(y2) ~ (y3 - (1 + y1) * y2) / p1,
404400
D(y3) ~ p3 * (y1 - y3)]
405-
de = ODESystem(eqs, t; name = :orego) |> structural_simplify |> complete
406-
jac = calculate_jacobian(de)
407-
orego = ODEFunction(de, [y1, y2, y3], [p1, p2, p3], jac = true, eval_module = @__MODULE__)
401+
orego = ODESystem(eqs, t; name = :orego) |> structural_simplify |> complete
408402

409403
"""
410404
Orego Problem (Stiff)
@@ -424,4 +418,4 @@ where ``s=77.27``, ``w=0.161`` and ``q=8.375⋅10^{-6}``.
424418
Reference: [demoorego.pdf](http://www.radford.edu/~thompson/vodef90web/problems/demosnodislin/Demos_Pitagora/DemoOrego/demoorego.pdf)
425419
Notebook: [Orego.ipynb](http://nbviewer.jupyter.org/github/JuliaDiffEq/DiffEqBenchmarks.jl/blob/master/StiffODE/Orego.ipynb)
426420
"""
427-
prob_ode_orego = ODEProblem(orego, [1.0, 2.0, 3.0], (0.0, 30.0), [77.27, 8.375e-6, 0.161])
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__)

0 commit comments

Comments
 (0)