Skip to content

Commit

Permalink
Sweep/point indices in show(::SimpleBifurcationInterval)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Jun 24, 2018
1 parent 0df70d9 commit 249f5eb
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/base/display.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using ..Continuations: set_if_not

aliasof(x) = nameof(typeof(x))

tkindstr(x) = tkindstr(timekind(x))
Expand All @@ -18,8 +20,6 @@ function print_header(io::IO, ctx::Union{BifurcationSweep,
print(io, aliasof(ctx), " <", tkindstr(ctx), ">")
end

set_if_not(io, key, val) = haskey(io, key) ? io : IOContext(io, key => val)

function Base.show(io::IO, point::SpecialPoint)
print_header(io, point)
println(io)
Expand Down
26 changes: 26 additions & 0 deletions src/continuations/display.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,33 @@
set_if_not(io, key, val) = haskey(io, key) ? io : IOContext(io, key => val)

function print_header(io::IO, x)
print(io, nameof(typeof(x)))
end

function print_header(io::IO, point::SimpleBifurcationInterval)
i_sweep = try
point.sweep.value.i
catch
'?'
end
h = @sprintf "%.4g" norm(point.h)
print(io, nameof(typeof(point)),
" u0=sweeps[$i_sweep].u[$(point.i)]",
" h=", h,
" dir=", point.direction)
end

function Base.show(io::IO, point::SimpleBifurcationInterval)
print_header(io, point)
println(io)
if ! get(io, :compact, false)
io = set_if_not(io, :compact, true) # reduce number of digits shown
println(io, "happened between:")
println(io, " u0 = ", point.u0)
println(io, " u1 = ", point.u1)
end
end

function Base.show(io::IO, sweep::ContinuationSweep)
print_header(io, sweep)

Expand Down
18 changes: 14 additions & 4 deletions src/continuations/solution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,24 @@ struct SimpleBifurcationInterval{uType}
u1::uType
h::Float64 # hType?
direction::Int
sweep::WeakRef
end


struct ContinuationSweep{uType <: AbstractVector}
i::Int
direction::Int
u::Vector{uType}
simple_bifurcation::Vector{SimpleBifurcationInterval{uType}}
sol::WeakRef
end

ContinuationSweep(uType::Type{<: AbstractArray}, direction) =
ContinuationSweep(direction,
ContinuationSweep(uType::Type{<: AbstractArray}, i, direction, sol) =
ContinuationSweep(i,
direction,
Vector{uType}(),
Vector{SimpleBifurcationInterval{uType}}())
Vector{SimpleBifurcationInterval{uType}}(),
sol)

Base.eltype(::Type{<: ContinuationSweep{uType}}) where uType = uType
Base.length(sweep::ContinuationSweep) = length(sweep.u)
Expand All @@ -39,6 +44,7 @@ function push_point!(sweep::ContinuationSweep, cache)
u1,
cache.h,
-cache.direction, # re-flip to save direction at u0
WeakRef(sweep),
))
end
end
Expand All @@ -53,7 +59,11 @@ end

function new_sweep!(sol::ContinuationSolution{uType},
direction) where uType
push!(sol.sweeps, ContinuationSweep(uType, direction))
push!(sol.sweeps, ContinuationSweep(
uType,
length(sol.sweeps) + 1,
direction,
WeakRef(sol)))
end

function sweeps_as_vectors(sol::ContinuationSolution{uType}, i) where uType
Expand Down

0 comments on commit 249f5eb

Please sign in to comment.