Skip to content

Commit 486bc1e

Browse files
fix sparse test
1 parent 8b74b25 commit 486bc1e

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

src/jacobian.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,14 @@ function jacobian!(J::AbstractMatrix{<:Number}, cache)
3838
else
3939
isforward = alg_difftype(alg) === Val{:forward}
4040
if isforward
41-
forwardcache = get_tmp_cache(cache, alg, unwrap_cache(cache, true))[2]
42-
uf(forwardcache, x)
41+
uf(fx, x)
4342
#cache.destats.nf += 1
44-
tmp = jacobian_finitediff_forward!(J, uf, x, jac_config, forwardcache,
43+
tmp = jacobian_finitediff_forward!(J, uf, x, jac_config, fx,
4544
cache)
4645
else # not forward difference
4746
tmp = jacobian_finitediff!(J, uf, x, jac_config, cache)
4847
end
49-
cache.destats.nf += tmp
48+
#cache.destats.nf += tmp
5049
end
5150
nothing
5251
end

src/raphson.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ function perform_step!(cache::NewtonRaphsonCache{true})
110110
jacobian!(J, cache)
111111

112112
# u = u - J \ fu
113-
linres = dolinsolve(alg.precs, linsolve, A = J, b = fu, linu = du1,
113+
linres = dolinsolve(alg.precs, linsolve, A = J, b = _vec(fu), linu = _vec(du1),
114114
p = p, reltol = cache.abstol)
115115
cache.linsolve = linres.cache
116116
@. u = u - du1

test/sparse.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using NonlinearSolve, LinearAlgebra, SparseArrays
1+
using NonlinearSolve, LinearAlgebra, SparseArrays, Symbolics
22

33
const N = 32
44
const xyd_brusselator = range(0,stop=1,length=N)
@@ -34,10 +34,16 @@ u0 = init_brusselator_2d(xyd_brusselator)
3434
prob_brusselator_2d = NonlinearProblem(brusselator_2d_loop,u0,p)
3535
sol = solve(prob_brusselator_2d, NewtonRaphson())
3636

37-
using Symbolics
3837
du0 = copy(u0)
3938
jac_sparsity = Symbolics.jacobian_sparsity((du,u)->brusselator_2d_loop(du,u,p),du0,u0)
4039

41-
f = NonlinearFunction(brusselator_2d_loop;jac_prototype=float.(jac_sparsity))
42-
prob_brusselator_2d = NonlinearProblem(f,u0,p)
40+
ff = NonlinearFunction(brusselator_2d_loop;jac_prototype=float.(jac_sparsity))
41+
prob_brusselator_2d = NonlinearProblem(ff,u0,p)
4342
sol = solve(prob_brusselator_2d, NewtonRaphson())
43+
@test norm(sol.resid) < 1e-8
44+
45+
sol = solve(prob_brusselator_2d, NewtonRaphson(autodiff=false))
46+
@test norm(sol.resid) < 1e-6
47+
48+
cache = init(prob_brusselator_2d, NewtonRaphson())
49+
@test maximum(cache.jac_config.colorvec) == 12

0 commit comments

Comments
 (0)