Skip to content
This repository was archived by the owner on Jun 21, 2024. It is now read-only.

Commit f57be8f

Browse files
authored
update to dynamicalsystems v3 (#130)
* use Dt and not diffeq * rename pinteg to pds * update trajectory animator * repalce integ with ds * fix orbit diagram * fix psos scan * fix cobweb * give up on Poincare map for now * `bump version
1 parent 960393d commit f57be8f

12 files changed

Lines changed: 140 additions & 122 deletions

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "InteractiveDynamics"
22
uuid = "ec714cd0-5f51-11eb-0b6e-452e7367ff84"
33
repo = "https://github.com/JuliaDynamics/InteractiveDynamics.jl.git"
4-
version = "0.21.12"
4+
version = "0.22.0"
55

66
[deps]
77
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"

examples/dynamicalsystems/brainscan.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ using OrdinaryDiffEq
33

44
ds = Systems.henonheiles()
55
diffeq = (alg = Vern9(), abstol = 1e-9, reltol = 1e-9)
6+
ds = CoupledODEs(ds, diffeq)
7+
68
u0s = [
79
[0.0, -0.25, 0.42081, 0.0],
810
[0.0, 0.1, 0.5, 0.0],
9-
[0.0, -0.31596, 0.354461, 0.0591255]
11+
[0.0, -0.31596, 0.354461, 0.0591255],
1012
]
11-
trs = [trajectory(ds, 10000, u0; diffeq)[:, SVector(1,2,3)] for u0 u0s]
13+
trs = [trajectory(ds, 10000, u0)[1][:, SVector(1,2,3)] for u0 u0s]
1214
j = 2 # the dimension of the plane
1315

1416
brainscan_poincaresos(trs, j; linekw = (transparency = true,))
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
using InteractiveDynamics, GLMakie, DynamicalSystems
1+
using DynamicalSystems
2+
using InteractiveDynamics, GLMakie
23

34
# the second range is a convenience for intermittency example of logistic
45
rrange = 1:0.001:4.0
56
# rrange = (rc = 1 + sqrt(8); [rc, rc - 1e-5, rc - 1e-3])
67

78
lo = Systems.logistic(0.4; r=rrange[1])
89

9-
interactive_cobweb(lo, rrange, 5)
10+
interactive_cobweb(lo, rrange, 5);

examples/dynamicalsystems/orbitdiagram.jl

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
using InteractiveDynamics, GLMakie
21
using DynamicalSystems
2+
using InteractiveDynamics, GLMakie
33

44
i = 1
5-
p_index = 1
65

7-
systems = [(Systems.logistic(), 2.5, 4.0, "r", "logistic map"),
8-
(Systems.henon(), 0.8, 1.4, "a", "Hénon map"),
9-
(Systems.standardmap(), 0.0, 1.2, "k", "standard map")]
6+
ds = Systems.lorenz()
7+
pmap = PoincareMap(ds, (2, 0.0); rootkw = (xrtol = 1e-8, atol = 1e-9))
8+
9+
systems = [(Systems.logistic(), 2.5, 4.0, "r", "logistic map", 1),
10+
(Systems.henon(), 0.8, 1.4, "a", "Hénon map", 1),
11+
(Systems.standardmap(), 0.0, 1.2, "k", "standard map", 1),
12+
# Poincare map
13+
(pmap, 100.0, 200.0, "ρ", "Lorenz Poincare map", 2),
14+
# Stroboscopic map of duffing
15+
16+
]
1017

11-
ds, p_min, p_max, parname, t = systems[2]
18+
ds, p_min, p_max, parname, t, p_index = systems[4]
1219
t = "orbit diagram for the "*t
1320

1421
fig, oddata = interactive_orbitdiagram(ds, p_index, p_min, p_max, i;

examples/dynamicalsystems/psos.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
using InteractiveDynamics, GLMakie, OrdinaryDiffEq, DynamicalSystems
2-
diffeq = (alg = Vern9(), abstol = 1e-9, reltol = 1e-9)
32

43
hh = Systems.henonheiles()
4+
diffeq = (alg = Vern9(), abstol = 1e-9, reltol = 1e-9)
5+
hh = CoupledODEs(hh, diffeq)
56

67
potential(x, y) = 0.5(x^2 + y^2) + (x^2*y - (y^3)/3)
78
energy(x,y,px,py) = 0.5(px^2 + py^2) + potential(x,y)
@@ -21,7 +22,7 @@ plane = (1, 0.0) # first variable crossing 0
2122
# Interactive PSOS with random colors
2223
scene, state = interactive_poincaresos(
2324
hh, plane, (2, 4), complete;
24-
labels = ("q₂" , "p₂"), diffeq
25+
labels = ("q₂" , "p₂")
2526
);
2627

2728
# %% Coloring points using a custom function

examples/dynamicalsystems/trajectory_animator.jl

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
using InteractiveDynamics
21
using DynamicalSystems, GLMakie
3-
using OrdinaryDiffEq
2+
using InteractiveDynamics
43

54
F, G, a, b = 6.886, 1.347, 0.255, 4.0
6-
ds = Systems.lorenz84(; F, G, a, b)
7-
diffeq = (alg = Tsit5(), adaptive = false, dt = 0.01)
5+
ds = PredefinedDynamicalSystems.lorenz84(; F, G, a, b)
86

97
u1 = [0.1, 0.1, 0.1] # periodic
108
u2 = u1 .+ 1e-3 # fixed point
@@ -13,13 +11,12 @@ u4 = [-1.5, 1.2, 1.3] .+ 21e-9 # chaotic 2
1311
u0s = [u1, u2, u3, u4]
1412

1513
interactive_evolution(
16-
ds, u0s; tail = 1000, diffeq, fade = true,
14+
ds, u0s; tail = 1000, fade = true,
1715
tsidxs = [1,2],
1816
# tsidxs = nothing, # comment/uncomment this line to remove timeseries
1917
)
2018

2119
# %% Lorenz63 with parameters and additional plotted elements
22-
diffeq = (alg = Tsit5(), adaptive = false, dt = 0.01)
2320
ps = Dict(
2421
1 => 1:0.1:30,
2522
2 => 10:0.1:50,
@@ -40,10 +37,9 @@ u3 = [20,10,40.0]
4037
u0s = [u1, u3]
4138

4239
idxs = [1,2,3]
43-
diffeq = (alg = Tsit5(), dt = 0.01, adaptive = false)
4440

4541
figure, obs, step, slidervals = interactive_evolution(
46-
ds, u0s; ps, idxs, tail = 1000, diffeq, pnames, lims
42+
ds, u0s; ps, idxs, tail = 1000, pnames, lims
4743
)
4844

4945
# Use the `slidervals` observable to plot fixed points
@@ -58,16 +54,14 @@ scatter!(ax, fpobs; markersize = 15, marker = :diamond, color = :black)
5854

5955
# %% Custom animation
6056
using DynamicalSystems, InteractiveDynamics, GLMakie
61-
using OrdinaryDiffEq: Tsit5
6257
using LinearAlgebra: dot, norm
63-
6458
ds = Systems.thomas_cyclical(b = 0.2)
6559
u0s = ([3, 1, 1.], [1, 3, 1.], [1, 1, 3.])
66-
diffeq = (alg = Tsit5(), adaptive = false, dt = 0.05)
60+
Δt = 0.05
6761

6862
fig, obs, step, = interactive_evolution(
69-
ds, u0s; tail = 1000, diffeq, add_controls = false, tsidxs = nothing,
70-
idxs = [1, 2, 3],
63+
ds, u0s; tail = 1000, add_controls = false, tsidxs = nothing,
64+
idxs = [1, 2, 3], Δt,
7165
figure = (resolution = (1200, 600),),
7266
)
7367
axss = content(fig[1,1][1,1])

src/chaos/brainscan.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ function brainscan_poincaresos(
5555
for i in 1:length(As)
5656
A = As[i]
5757
# plot 3D trajectories
58-
lines!(ax, A.data; color = colors[i], transparency = false, linekw...)
58+
lines!(ax, vec(A); color = colors[i], transparency = false, linekw...)
5959

6060
# Poincare sos
6161
psos = lift(y) do y
6262
DynamicalSystems.poincaresos(A, (j, y); direction, warning = false)
6363
end
64-
psos2d = lift(p -> p[:, otheridxs].data, psos)
65-
psos3d = lift(p -> p.data, psos)
64+
psos2d = lift(p -> vec(p[:, otheridxs]), psos)
65+
psos3d = lift(p -> vec(p), psos)
6666
Makie.scatter!(axp, psos2d; color = colors[i], scatterkw...)
6767
Makie.scatter!(ax, psos3d; color = colors[i], markersize = 5, scatterkw...)
6868
end

src/chaos/cobweb.jl

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ function interactive_cobweb(
3636

3737
@assert O 1
3838
@assert DynamicalSystems.dimension(ds) == 1
39+
@assert !DynamicalSystems.isinplace(ds)
3940

4041
figure = Figure(resolution = (1000, 800))
4142
axts = figure[1, :] = Axis(figure)
@@ -44,7 +45,7 @@ axmap = figure[2, :] = Axis(figure)
4445
sg = SliderGrid(figure[3, :],
4546
(label = pname, range = prange),
4647
(label = "n", range = 1:Tmax, startvalue = 20),
47-
(label = "x₀", range = x0s, startvalue = ds.u0),
48+
(label = "x₀", range = x0s, startvalue = DynamicalSystems.initial_state(ds)[1]),
4849
)
4950
r_observable, L, x0 = [sg.sliders[i].value for i in 1:3]
5051

@@ -54,7 +55,14 @@ function seriespoints(x)
5455
return [Point2f(n[i], x[i]) for i in 1:length(x)]
5556
end
5657

57-
x = Observable(DynamicalSystems.trajectory(ds, L[], x0[]))
58+
function get_float_trajectory(ds, L, x0)
59+
y = x0 isa Real ? DynamicalSystems.SVector(x0) : x0
60+
z = DynamicalSystems.trajectory(ds, L, y)[1]
61+
w = reinterpret(Float64, vec(z))
62+
return Float32.(w)
63+
end
64+
65+
x = Observable(get_float_trajectory(ds, L[], x0[]))
5866
xn = lift(a -> seriespoints(a), x)
5967
lines!(axts, xn; color = trajcolor, lw = 2.0)
6068
scatter!(axts, xn; color = trajcolor, markersize = 10)
@@ -64,9 +72,14 @@ ylims!(axts, xmin, xmax)
6472
# Cobweb diagram
6573
DynamicalSystems.set_parameter!(ds, pindex, prange[1])
6674

67-
fobs = Any[Observable(ds.f.(xs, Ref(ds.p), 0))]
75+
fobs = Any[Observable(
76+
map(x -> DynamicalSystems.dynamic_rule(ds)(x, DynamicalSystems.current_parameters(ds), 0)[1], xs)
77+
)]
6878
for order in 2:O
69-
push!(fobs, Observable(ds.f.(fobs[end][], Ref(ds.p), 0)))
79+
push!(fobs, Observable(
80+
map(x -> DynamicalSystems.dynamic_rule(ds)(x, DynamicalSystems.current_parameters(ds), 0)[1], fobs[end][])
81+
# DynamicalSystems.dynamic_rule(ds).(fobs[end][], Ref(DynamicalSystems.current_parameters(ds)), 0)
82+
))
7083
end
7184

7285
# plot diagonal and fⁿ
@@ -87,20 +100,23 @@ ylims!(axmap, xmin, xmax)
87100
# On trigger r-slider update all plots:
88101
on(r_observable) do r
89102
DynamicalSystems.set_parameter!(ds, pindex, r)
90-
x[] = DynamicalSystems.trajectory(ds, L[], x0[])
91-
fobs[1][] = ds.f.(xs, Ref(ds.p), 0)
103+
x[] = get_float_trajectory(ds, L[], x0[])
104+
fobs[1][] = map(x -> DynamicalSystems.dynamic_rule(ds)(x, DynamicalSystems.current_parameters(ds), 0)[1], xs)
92105
for order in 2:O
93-
fobs[order][] = ds.f.(fobs[order-1][], Ref(ds.p), 0)
106+
fobs[order][] = map(
107+
x -> DynamicalSystems.dynamic_rule(ds)(x, DynamicalSystems.current_parameters(ds), 0)[1], fobs[order-1][]
108+
)
94109
end
95110
end
96111

97112
on(L) do l
98-
x[] = DynamicalSystems.trajectory(ds, l, x0[])
113+
res = get_float_trajectory(ds, l, x0[])
114+
x[] = res
99115
xlims!(axts, 0, l) # this is better than autolimits
100116
end
101117

102118
on(x0) do u
103-
x[] = DynamicalSystems.trajectory(ds, L[], u)
119+
x[] = get_float_trajectory(ds, L[], u)
104120
end
105121

106122
# Finally add buttons to hide/show elements of the plot

0 commit comments

Comments
 (0)