diff --git a/src/nonlinear/abstract_newton_solver.jl b/src/nonlinear/abstract_newton_solver.jl index ce11b79..a08dda7 100644 --- a/src/nonlinear/abstract_newton_solver.jl +++ b/src/nonlinear/abstract_newton_solver.jl @@ -71,6 +71,8 @@ cache(solver::AbstractNewtonSolver) = solver.cache config(solver::AbstractNewtonSolver) = solver.config status(solver::AbstractNewtonSolver) = solver.status jacobian(solver::AbstractNewtonSolver) = solver.jacobian +linearsolver(solver::AbstractNewtonSolver) = solver.linear +linesearch(solver::AbstractNewtonSolver) = solver.linesearch compute_jacobian!(s::AbstractNewtonSolver, x, f::Callable) = compute_jacobian!(s, x, f, missing) compute_jacobian!(s::AbstractNewtonSolver, x, f::Callable, ::Missing) = s.jacobian(s.cache.J, x, f) diff --git a/src/nonlinear/newton_solver.jl b/src/nonlinear/newton_solver.jl index ce8b8f3..b4b064a 100644 --- a/src/nonlinear/newton_solver.jl +++ b/src/nonlinear/newton_solver.jl @@ -20,8 +20,8 @@ end function solver_step!(x, f, forj, s::NewtonSolver) # shortcuts - rhs = s.cache.rhs - δ = s.cache.δx + rhs = cache(s).rhs + δ = cache(s).δx # update Newton solver cache update!(s, x) @@ -30,14 +30,14 @@ function solver_step!(x, f, forj, s::NewtonSolver) compute_jacobian!(s, x, forj) # factorize linear solver - factorize!(s.linear, s.cache.J) + factorize!(linearsolver(s), cache(s).J) # compute RHS f(rhs, x) rmul!(rhs, -1) # solve J δx = -f(x) - ldiv!(δ, s.linear, rhs) + ldiv!(δ, linearsolver(s), rhs) # apply line search α = s.linesearch(linesearch_objective(f, jacobian(s), cache(s))) diff --git a/src/nonlinear/quasi_newton_solver.jl b/src/nonlinear/quasi_newton_solver.jl index 15e3cfe..3b1ad94 100644 --- a/src/nonlinear/quasi_newton_solver.jl +++ b/src/nonlinear/quasi_newton_solver.jl @@ -22,16 +22,16 @@ end function solver_step!(x, f, forj, s::QuasiNewtonSolver) # shortcuts - rhs = s.cache.rhs - δ = s.cache.δx + rhs = cache(s).rhs + δ = cache(s).δx # update Newton solver cache update!(s, x) # compute Jacobian and factorize - if mod(s.status.i-1, s.refactorize) == 0 + if mod(status(s).i-1, s.refactorize) == 0 compute_jacobian!(s, x, forj) - factorize!(s.linear, s.cache.J) + factorize!(linearsolver(s), cache(s).J) end # compute RHS @@ -39,7 +39,7 @@ function solver_step!(x, f, forj, s::QuasiNewtonSolver) rmul!(rhs, -1) # solve J δx = -f(x) - ldiv!(δ, s.linear, rhs) + ldiv!(δ, linearsolver(s), rhs) # apply line search α = s.linesearch(linesearch_objective(f, jacobian(s), cache(s)))