Skip to content

Commit

Permalink
Fix docs build (#31)
Browse files Browse the repository at this point in the history
* modify so that alg converges

* probably a bug

* decrease tolerance

* decrease tolerance

* change the tolerances

* remove the constant redef warning

* increase the period

* use the same initial guess twice

* increase period guess a lot

* warn user

* just keep the guess that works
  • Loading branch information
JonasKoziorek authored Jan 15, 2025
1 parent 11063cb commit b148ec1
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/src/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ end
ig = InitialGuess(SVector(2.0, 5.0, 10.0), 10.2)
OSalg = OptimizedShooting(Δt=0.01, n=3)
ds = CoupledODEs(roessler_rule, [1.0, -2.0, 0.1], [0.15, 0.2, 3.5])
ds = CoupledODEs(roessler_rule, [1.0, -2.0, 0.1], [0.15, 0.2, 3.5]; diffeq=(abstol=1e-10, reltol=1e-10))
res = periodic_orbit(ds, OSalg, ig)
plot_result(res, ds; azimuth = 1.3pi, elevation=0.1pi)
```
Expand Down
6 changes: 3 additions & 3 deletions docs/src/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ system itself.
using PeriodicOrbits
function lorenz(u0=[0.0, 10.0, 0.0]; σ = 10.0, ρ = 28.0, β = 8/3)
return CoupledODEs(lorenz_rule, u0, [σ, ρ, β])
return CoupledODEs(lorenz_rule, u0, [σ, ρ, β]; diffeq=(abstol=1e-10, reltol=1e-10))
end
@inbounds function lorenz_rule(u, p, t)
du1 = p[1]*(u[2]-u[1])
Expand All @@ -22,8 +22,8 @@ ds = lorenz()
Next, we give initial guess of the location of the periodic orbit and its period.

```@example MAIN
u0_guess = SVector(3.5, 3.0, 0.0)
T_guess = 5.2
u0_guess = SVector(1.0, 2.0, 5.0)
T_guess = 4.2
ig = InitialGuess(u0_guess, T_guess)
```
Then we pick an appropriate algorithm that will detect the PO. In this case we can use
Expand Down
3 changes: 3 additions & 0 deletions src/algorithms/continuous_time/optimized_shooting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ is optimized by the Levenberg-Marquardt algorithm.
In our implementation, the keyword argument `n` corresponds to ``n`` in the residual ``R``.
The keyword argument `Δt` corresponds to ``\\Delta t`` in the residual ``R``.
Note that for the algorithm to converge to a periodic orbit, the initial guess has to be
close to an existing periodic orbit.
"""
@kwdef struct OptimizedShooting{T} <: PeriodicOrbitFinder
Δt::Float64 = 1e-6
Expand Down
2 changes: 1 addition & 1 deletion src/pretty_printing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ end
function Base.summary(ig::InitialGuess)
digits = 5
u0 = round.(ig.u0, digits=digits)
T = isnothing(ig.T) ? "nothing" : round(ig.T, digits=ig_round_digits)
T = isnothing(ig.T) ? "nothing" : round(ig.T, digits=digits)
return "$(typeof(ig))($(u0), $(T))"
end

Expand Down
6 changes: 3 additions & 3 deletions test/algorithms/continuous_time/optimized_shooting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ using LinearAlgebra: norm
end

@testset "Optimized shooting" begin
igs = [InitialGuess(SVector(1.0, 2.0, 5.0), 4.2), InitialGuess(SVector(1.0, 2.0, 5.0), 5.2)]
igs = [InitialGuess(SVector(1.0, 2.0, 5.0), 4.2), InitialGuess(SVector(1.0, 2.0, 5.0), 4.2)]
ig = igs[1]
alg = OptimizedShooting(Δt=1e-3, n=3, nonlinear_solve_kwargs=(abstol=1e-6, reltol=1e-6))
ds = CoupledODEs(lorenz_rule, [0.0, 10.0, 0.0], [10.0, 28.0, 8 / 3]; diffeq=(abstol=1e-10, reltol=1e-10))
alg = OptimizedShooting(Δt=1e-4, n=3, nonlinear_solve_kwargs=(abstol=1e-7, reltol=1e-7))
ds = CoupledODEs(lorenz_rule, [0.0, 10.0, 0.0], [10.0, 28.0, 8 / 3]; diffeq=(abstol=1e-11, reltol=1e-11))

res = periodic_orbit(ds, alg, ig)

Expand Down
6 changes: 3 additions & 3 deletions test/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ end
return SVector{3}(du1, du2, du3)
end

const logistic_ = logistic()
const lorenz_ = lorenz()
const period3window = StateSpaceSet([SVector{1}(x) for x in [0.15933615523767342, 0.5128107111364378, 0.9564784814729845]])
logistic_ = logistic()
period3window = StateSpaceSet([SVector{1}(x) for x in [0.15933615523767342, 0.5128107111364378, 0.9564784814729845]])

@testset "constructors of InitialGuess" begin
# TODO
Expand Down Expand Up @@ -66,6 +65,7 @@ end
po = PeriodicOrbit(logistic_, SVector{1}([(r-1)/r]), 1)
@test isdiscretetime(po) == true

lorenz_ = lorenz()
po = PeriodicOrbit(lorenz_, current_state(lorenz_), 1.0)
@test isdiscretetime(po) == false
end
4 changes: 2 additions & 2 deletions test/minimal_period.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ function logistic(x0=0.4; r = 4.0)
end
logistic_rule(x, p, n) = @inbounds SVector(p[1]*x[1]*(1 - x[1]))

const logistic_ = logistic()
const period3window = StateSpaceSet([SVector{1}(x) for x in [0.15933615523767342, 0.5128107111364378, 0.9564784814729845]])
logistic_ = logistic()
period3window = StateSpaceSet([SVector{1}(x) for x in [0.15933615523767342, 0.5128107111364378, 0.9564784814729845]])

@testset "minimal_period discrete" begin
r = 1+sqrt(8)
Expand Down

0 comments on commit b148ec1

Please sign in to comment.