Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix warning: update vars to idxs #736

Merged
merged 3 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ ModelingToolkit = "8"
ODEProblemLibrary = "0.1"
Optimization = "3"
OptimizationNLopt = "0.1, 0.2"
OrdinaryDiffEq = "6.31"
OrdinaryDiffEq = "6.76"
Plots = "1"
RecursiveArrayTools = "2, 3"
SDEProblemLibrary = "0.1"
Expand Down
22 changes: 11 additions & 11 deletions docs/src/examples/classical_physics.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ prob = SecondOrderODEProblem(harmonicoscillator, dx₀, x₀, tspan, ω)
sol = solve(prob, DPRKN6())

#Plot
plot(sol, vars = [2, 1], linewidth = 2, title = "Simple Harmonic Oscillator",
plot(sol, idxs = [2, 1], linewidth = 2, title = "Simple Harmonic Oscillator",
xaxis = "Time", yaxis = "Elongation", label = ["x" "dx"])
plot!(t -> A * cos(ω * t - ϕ), lw = 3, ls = :dash, label = "Analytical Solution x")
plot!(t -> -A * ω * sin(ω * t - ϕ), lw = 3, ls = :dash, label = "Analytical Solution dx")
Expand Down Expand Up @@ -147,12 +147,12 @@ plot(sol, linewidth = 2, title = "Simple Pendulum Problem", xaxis = "Time",
So now we know that behaviour of the position versus time. However, it will be useful to us to look at the phase space of the pendulum, i.e., and representation of all possible states of the system in question (the pendulum) by looking at its velocity and position. Phase space analysis is ubiquitous in the analysis of dynamical systems, and thus we will provide a few facilities for it.

```@example physics
p = plot(sol, vars = (1, 2), xlims = (-9, 9), title = "Phase Space Plot",
p = plot(sol, idxs = (1, 2), xlims = (-9, 9), title = "Phase Space Plot",
xaxis = "Velocity", yaxis = "Position", leg = false)
function phase_plot(prob, u0, p, tspan = 2pi)
_prob = ODEProblem(prob.f, u0, (0.0, tspan))
sol = solve(_prob, Vern9()) # Use Vern9 solver for higher accuracy
plot!(p, sol, vars = (1, 2), xlims = nothing, ylims = nothing)
plot!(p, sol, idxs = (1, 2), xlims = nothing, ylims = nothing)
end
for i in (-4pi):(pi / 2):(4π)
for j in (-4pi):(pi / 2):(4π)
Expand Down Expand Up @@ -267,13 +267,13 @@ function poincare_map(prob, u₀, p; callback = cb)
_prob = ODEProblem(prob.f, u₀, prob.tspan)
sol = solve(_prob, Vern9(), save_everystep = false, save_start = false,
save_end = false, callback = cb, abstol = 1e-16, reltol = 1e-16)
scatter!(p, sol, vars = (3, 4), markersize = 3, msw = 0)
scatter!(p, sol, idxs = (3, 4), markersize = 3, msw = 0)
end
```

```@example physics
lβrange = -0.02:0.0025:0.02
p = scatter(sol2, vars = (3, 4), leg = false, markersize = 3, msw = 0)
p = scatter(sol2, idxs = (3, 4), leg = false, markersize = 3, msw = 0)
for lβ in lβrange
poincare_map(poincare, [0.01, 0.01, 0.01, lβ], p)
end
Expand Down Expand Up @@ -334,7 +334,7 @@ sol = solve(prob, Vern9(), abstol = 1e-16, reltol = 1e-16);

```@example physics
# Plot the orbit
plot(sol, vars = (1, 2), title = "The orbit of the Hénon-Heiles system", xaxis = "x",
plot(sol, idxs = (1, 2), title = "The orbit of the Hénon-Heiles system", xaxis = "x",
yaxis = "y", leg = false)
```

Expand All @@ -343,9 +343,9 @@ plot(sol, vars = (1, 2), title = "The orbit of the Hénon-Heiles system", xaxis
@show sol.retcode

#Plot -
plot(sol, vars = (1, 3), title = "Phase space for the Hénon-Heiles system",
plot(sol, idxs = (1, 3), title = "Phase space for the Hénon-Heiles system",
xaxis = "Position", yaxis = "Velocity")
plot!(sol, vars = (2, 4), leg = false)
plot!(sol, idxs = (2, 4), leg = false)
```

```@example physics
Expand Down Expand Up @@ -382,14 +382,14 @@ Notice that we get the same results:

```@example physics
# Plot the orbit
plot(sol2, vars = (3, 4), title = "The orbit of the Hénon-Heiles system", xaxis = "x",
plot(sol2, idxs = (3, 4), title = "The orbit of the Hénon-Heiles system", xaxis = "x",
yaxis = "y", leg = false)
```

```@example physics
plot(sol2, vars = (3, 1), title = "Phase space for the Hénon-Heiles system",
plot(sol2, idxs = (3, 1), title = "Phase space for the Hénon-Heiles system",
xaxis = "Position", yaxis = "Velocity")
plot!(sol2, vars = (4, 2), leg = false)
plot!(sol2, idxs = (4, 2), leg = false)
```

but now the energy change is essentially zero:
Expand Down
9 changes: 4 additions & 5 deletions docs/src/examples/kepler_problem.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ Also, we know that
$${\displaystyle {\frac {\mathrm {d} {\boldsymbol {p}}}{\mathrm {d} t}}=-{\frac {\partial {\mathcal {H}}}{\partial {\boldsymbol {q}}}}\quad ,\quad {\frac {\mathrm {d} {\boldsymbol {q}}}{\mathrm {d} t}}=+{\frac {\partial {\mathcal {H}}}{\partial {\boldsymbol {p}}}}}$$

```@example kepler
using OrdinaryDiffEq, LinearAlgebra, ForwardDiff, Plots;
gr();
using OrdinaryDiffEq, LinearAlgebra, ForwardDiff, Plots
H(q, p) = norm(p)^2 / 2 - inv(norm(q))
L(q, p) = q[1] * p[2] - p[1] * q[2]

Expand All @@ -30,12 +29,12 @@ sol = solve(prob, KahanLi6(), dt = 1 // 10);
Let's plot the orbit and check the energy and angular momentum variation. We know that energy and angular momentum should be constant, and they are also called first integrals.

```@example kepler
plot_orbit(sol) = plot(sol, vars = (3, 4), lab = "Orbit", title = "Kepler Problem Solution")
plot_orbit(sol) = plot(sol, idxs = (3, 4), lab = "Orbit", title = "Kepler Problem Solution")

function plot_first_integrals(sol, H, L)
plot(initial_first_integrals[1] .- map(u -> H(u[2, :], u[1, :]), sol.u),
plot(initial_first_integrals[1] .- map(u -> H(u.x[2], u.x[1]), sol.u),
lab = "Energy variation", title = "First Integrals")
plot!(initial_first_integrals[2] .- map(u -> L(u[2, :], u[1, :]), sol.u),
plot!(initial_first_integrals[2] .- map(u -> L(u.x[2], u.x[1]), sol.u),
lab = "Angular momentum variation")
end
analysis_plot(sol, H, L) = plot(plot_orbit(sol), plot_first_integrals(sol, H, L))
Expand Down
12 changes: 5 additions & 7 deletions docs/src/solvers/ode_solve.md
Original file line number Diff line number Diff line change
Expand Up @@ -556,20 +556,18 @@ to be thread safe. It parallelizes the `nlsolve` calls inside the method.
- `ROS2PR` - A 2nd order stiffly accurate Rosenbrock-Wanner method with 3 internal stages with Rinf=0.
For problems with medium stiffness the convergence behaviour is very poor
and it is recommended to use `ROS2S` instead.
- `ROS3PR` - A 3nd order stiffly accurate Rosenbrock-Wanner method
- `ROS3PR` - A 3nd order stiffly accurate Rosenbrock-Wanner method
with 3 internal stages and B_PR consistent of order 3, which is strongly A-stable with Rinf~=-0.73.
- `Scholz47` - A 3nd order stiffly accurate Rosenbrock-Wanner method
- `Scholz47` - A 3nd order stiffly accurate Rosenbrock-Wanner method
with 3 internal stages and B_PR consistent of order 3, which is strongly A-stable with Rinf~=-0.73.
Convergence with order 4 for the stiff case, but has a poor accuracy.
- `ROS3PRL` - A 3nd order stiffly accurate Rosenbrock-Wanner method with 4 internal stages
with B_PR consistent of order 2 with Rinf=0. The order of convergence decreases if medium stiff problems
are considered, but it has good results for very stiff cases.
- `ROS3PRL2` - A 3nd order stiffly accurate Rosenbrock-Wanner method with 4 internal stages
with B_PR consistent of order 3. The order of convergence does NOT decreases if
with B_PR consistent of order 3. The order of convergence does NOT decreases if
medium stiff problems are considered as it does for ROS3PRL.



#### Rosenbrock-W Methods

- `Rosenbrock23` - An Order 2/3 L-Stable Rosenbrock-W method which is good for very
Expand All @@ -588,9 +586,9 @@ to be thread safe. It parallelizes the `nlsolve` calls inside the method.
- `ROS34PW2` - A 4th order stiffy accurate Rosenbrock-W method for PDAEs.
- `ROS34PW3` - A 4th order strongly A-stable (Rinf~0.63) Rosenbrock-W method.
- `ROS34PRw` - A 3nd order stiffly accurate Rosenbrock-Wanner W-method with 4 internal stages with B_PR consistent of order 2
- `ROS2S` - A 2nd order stiffly accurate Rosenbrock-Wanner W-method
- `ROS2S` - A 2nd order stiffly accurate Rosenbrock-Wanner W-method
with 3 internal stages with B_PR consistent of order 2 with Rinf=0.

#### Stabilized Explicit Methods

- `ROCK2` - Second order stabilized Runge-Kutta method. Exhibits high stability
Expand Down
Loading