Skip to content

Commit

Permalink
Refactoring: move ContinuationOptions to euler_newton.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Jun 18, 2018
1 parent 4f404b3 commit 1e90247
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
33 changes: 26 additions & 7 deletions src/continuations/euler_newton.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Parameters: @with_kw
using StaticArrays: SMatrix, SVector

# TODO: Cleanup! The code is the very ugly at the moment because I
Expand Down Expand Up @@ -62,6 +63,24 @@ ContinuationCache(prob::AbstractContinuationProblem, args...) =
ContinuationCache(get_prob_cache(prob), args...)


@with_kw struct ContinuationOptions
direction::Int = 1
h0::Float64 = 1.0
h_min::Float64 = 1e-6
h_zero::Float64 = 1e-6
rtol::Float64 = 0.01
atol::Float64 = 1e-6
max_samples::Int = 100
max_adaptations::Int = 100
max_corrector_steps::Int = 100
max_branches::Int = 10
max_misc_steps::Int = 100 # TODO: remove
nominal_contraction::Float64 = 0.8
nominal_distance::Float64 = 0.1
nominal_angle_rad::Float64 = 2π * (30 / 360)
end


function tangent(L, Q)
tJ = Q[:, end]
if det(Q) * det(@view L[1:end-1, 1:end-1]) < 0
Expand All @@ -70,7 +89,8 @@ function tangent(L, Q)
return tJ
end

function current_tangent(cache, opts)
function current_tangent(cache::ContinuationCache,
opts::ContinuationOptions)
prob_cache = cache.prob_cache
u = cache.u
H = cache.H
Expand All @@ -93,15 +113,18 @@ function corrector_step!(H, J, Q, v, prob_cache)
return (w, dv, H, L, Q, J)
end

function predictor_corrector_step!(cache, opts)
function predictor_corrector_step!(cache::ContinuationCache,
opts::ContinuationOptions)
predictor_corrector_step!(cache, opts,
cache.u,
current_tangent(cache, opts),
cache.h,
cache.direction)
end

function predictor_corrector_step!(cache, opts, u, tJ, h, direction)
function predictor_corrector_step!(cache::ContinuationCache,
opts::ContinuationOptions,
u, tJ, h, direction)
prob_cache = cache.prob_cache
H = cache.H
J = cache.J
Expand Down Expand Up @@ -170,7 +193,3 @@ function predictor_corrector_step!(cache, opts, u, tJ, h, direction)
return v, h
end
end

function record!(sol, cache)
push_point!(sol, cache)
end
25 changes: 4 additions & 21 deletions src/continuations/interface.jl
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
using Parameters: @with_kw


@with_kw struct ContinuationOptions
direction::Int = 1
h0::Float64 = 1.0
h_min::Float64 = 1e-6
h_zero::Float64 = 1e-6
rtol::Float64 = 0.01
atol::Float64 = 1e-6
max_samples::Int = 100
max_adaptations::Int = 100
max_corrector_steps::Int = 100
max_branches::Int = 10
max_misc_steps::Int = 100 # TODO: remove
nominal_contraction::Float64 = 0.8
nominal_distance::Float64 = 0.1
nominal_angle_rad::Float64 = 2π * (30 / 360)
end


mutable struct ContinuationSolver{P <: AbstractContinuationProblem,
C <: ContinuationCache,
S <: ContinuationSolution}
Expand Down Expand Up @@ -53,6 +32,10 @@ function step!(solver::ContinuationSolver)
solver.i += 1
end

function record!(sol, cache)
push_point!(sol, cache)
end

function step!(solver::ContinuationSolver, max_steps)
cache = solver.cache
for _ in 1:max_steps
Expand Down

0 comments on commit 1e90247

Please sign in to comment.