Skip to content

Commit

Permalink
Merge pull request #200 from avik-pal/ap/jac_prototype
Browse files Browse the repository at this point in the history
Newton Raphson used to ignore jac-prototype
  • Loading branch information
ChrisRackauckas authored Aug 19, 2023
2 parents cb80ed2 + 503d579 commit e93fc58
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ docs/site/
# environment.
Manifest.toml
docs/src/assets/Project.toml

.vscode
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "NonlinearSolve"
uuid = "8913a72c-1f9b-4ce2-8d82-65094dcecaec"
authors = ["SciML"]
version = "1.9.0"
version = "1.10.0"

[deps]
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
Expand Down
6 changes: 5 additions & 1 deletion src/raphson.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ end

function jacobian_caches(alg::NewtonRaphson, f, u, p, ::Val{true})
uf = JacobianWrapper(f, p)
J = ArrayInterface.undefmatrix(u)
J = if f.jac_prototype === nothing
ArrayInterface.undefmatrix(u)
else
f.jac_prototype
end

linprob = LinearProblem(J, _vec(zero(u)); u0 = _vec(zero(u)))
weight = similar(u)
Expand Down
6 changes: 5 additions & 1 deletion test/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,15 @@ sol = solve(prob_brusselator_2d, NewtonRaphson())
du0 = copy(u0)
jac_sparsity = Symbolics.jacobian_sparsity((du, u) -> brusselator_2d_loop(du, u, p), du0,
u0)
jac_prototype = float.(jac_sparsity)
fill!(jac_prototype, 0)
@test all(iszero, jac_prototype)

ff = NonlinearFunction(brusselator_2d_loop; jac_prototype = float.(jac_sparsity))
ff = NonlinearFunction(brusselator_2d_loop; jac_prototype)
prob_brusselator_2d = NonlinearProblem(ff, u0, p)
sol = solve(prob_brusselator_2d, NewtonRaphson())
@test norm(sol.resid) < 1e-8
@test !all(iszero, jac_prototype)

sol = solve(prob_brusselator_2d, NewtonRaphson(autodiff = false))
@test norm(sol.resid) < 1e-6
Expand Down

0 comments on commit e93fc58

Please sign in to comment.