Skip to content

Commit

Permalink
update for difftools v0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisRackauckas committed Nov 21, 2017
1 parent 6ae90c6 commit 9fc8937
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ julia 0.6
DiffEqBase
Reexport
NLsolve
DiffEqDiffTools 0.1.0
DiffEqDiffTools 0.2.0
BandedMatrices
22 changes: 11 additions & 11 deletions src/jacobian.jl
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import DiffEqDiffTools, NLsolve

mutable struct BVPJacobianWrapper{LossType,CacheType} <: Function
mutable struct BVPJacobianWrapper{LossType} <: Function
loss::LossType
x1::CacheType
fx1::CacheType
end

(p::BVPJacobianWrapper)(resid,u) = p.loss(u,resid)

(p::BVPJacobianWrapper)(u) = (resid = similar(u); p.loss(u,resid); resid)

function ConstructSparseJacobian(f!::BVPJacobianWrapper, S::BVPSystem)
function ConstructSparseJacobian(f!::BVPJacobianWrapper, S::BVPSystem, y)
RealOrComplex = (eltype(y) <: Complex) ? Val{:Complex} : Val{:Real}
jac_cache = DiffEqDiffTools.JacobianCache(Val{:central},RealOrComplex,
similar(y),similar(y),similar(y))
function fg!(x::Vector, fx::Vector, gx)
RealOrComplex = (eltype(fx) <: Complex) ? Val{:Complex} : Val{:Real}
DiffEqDiffTools.finite_difference_jacobian!(gx, f!, x, Val{:central},
RealOrComplex, Val{:JacobianWrapper}, fx)
DiffEqDiffTools.finite_difference_jacobian!(gx, f!, x, jac_cache)
end
g!(x::Vector, gx::Array) = (fx = similar(x); fg!(x, fx, gx))
J = bzeros(eltype(S.y[1]), S.M*S.N, S.M*S.N, S.M-1, S.M-1)
NLsolve.DifferentiableMultivariateFunction(f!.loss, g!, fg!, sparse(J))
end

function ConstructJacobian(f!::BVPJacobianWrapper, S::BVPSystem)
function ConstructJacobian(f!::BVPJacobianWrapper, S::BVPSystem, y)
RealOrComplex = (eltype(y) <: Complex) ? Val{:Complex} : Val{:Real}
jac_cache = DiffEqDiffTools.JacobianCache(Val{:central},RealOrComplex,
similar(y),similar(y),similar(y))
function fg!(x::Vector, fx::Vector, gx)
RealOrComplex = (eltype(fx) <: Complex) ? Val{:Complex} : Val{:Real}
DiffEqDiffTools.finite_difference_jacobian!(gx, f!, x, Val{:central},
RealOrComplex, Val{:JacobianWrapper}, fx)
DiffEqDiffTools.finite_difference_jacobian!(gx, f!, x, jac_cache)
end
g!(x::Vector, gx::Array) = (fx = similar(x); fg!(x, fx, gx))
NLsolve.DifferentiableMultivariateFunction(f!.loss, g!, fg!)
Expand Down
4 changes: 2 additions & 2 deletions src/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ function solve(prob::BVProblem, alg::Union{GeneralMIRK,MIRK}; dt=0.0, kwargs...)
nothing
end

jac_wrapper = BVPJacobianWrapper(loss, similar(vec_y), similar(vec_y))
jac_wrapper = BVPJacobianWrapper(loss)

flatten_vector!(vec_y, S.y)
opt = isa(prob.problem_type, TwoPointBVProblem) ? alg.nlsolve(ConstructJacobian(jac_wrapper, S), vec_y) : alg.nlsolve(ConstructJacobian(jac_wrapper, S), vec_y) # Sparse matrix is broken
opt = isa(prob.problem_type, TwoPointBVProblem) ? alg.nlsolve(ConstructJacobian(jac_wrapper, S, vec_y), vec_y) : alg.nlsolve(ConstructJacobian(jac_wrapper, S, vec_y), vec_y) # Sparse matrix is broken
nest_vector!(S.y, opt[1])

retcode = opt[2] ? :Success : :Failure
Expand Down

0 comments on commit 9fc8937

Please sign in to comment.