Skip to content

Commit 1f0e158

Browse files
Merge pull request #2196 from oscardssmith/os/fix-NonlinearSolveAlg-convergence-criteria
I think this fixes a few minor bugs with nonlinear convergence
2 parents 3e9e98d + fd37f75 commit 1f0e158

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

src/nlsolve/newton.jl

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,12 @@ end
8383
nlcache = nlsolver.cache.cache
8484
step!(nlcache)
8585
nlsolver.ztmp = nlcache.u
86-
ndz = opts.internalnorm(nlcache.fu, t)
86+
87+
ustep = compute_ustep(tmp, γ, z, method)
88+
atmp = calculate_residuals(nlcache.fu, uprev, ustep, opts.abstol, opts.reltol,
89+
opts.internalnorm, t)
90+
ndz = opts.internalnorm(atmp, t)
91+
#ndz = opts.internalnorm(nlcache.fu, t)
8792
# NDF and BDF are special because the truncation error is directly
8893
# proportional to the total displacement.
8994
if integrator.alg isa QNDF
@@ -95,12 +100,17 @@ end
95100
@muladd function compute_step!(nlsolver::NLSolver{<:NonlinearSolveAlg, true}, integrator)
96101
@unpack uprev, t, p, dt, opts = integrator
97102
@unpack z, tmp, ztmp, γ, α, cache, method = nlsolver
98-
@unpack tstep, invγdt, ustep = cache
103+
@unpack tstep, invγdt, atmp, ustep = cache
99104

100105
nlcache = nlsolver.cache.cache
101106
step!(nlcache)
102107
@.. broadcast=false ztmp=nlcache.u
103-
ndz = opts.internalnorm(nlcache.fu, t)
108+
109+
ustep = compute_ustep!(ustep, tmp, γ, z, method)
110+
calculate_residuals!(atmp, nlcache.fu, uprev, ustep, opts.abstol, opts.reltol,
111+
opts.internalnorm, t)
112+
ndz = opts.internalnorm(atmp, t)
113+
#ndz = opts.internalnorm(nlcache.fu, t)
104114
# NDF and BDF are special because the truncation error is directly
105115
# proportional to the total displacement.
106116
if integrator.alg isa QNDF

src/nlsolve/type.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ mutable struct NonlinearSolveCache{uType, tType, rateType, tType2, P, C} <:
237237
ustep::uType
238238
tstep::tType
239239
k::rateType
240+
atmp::uType
240241
invγdt::tType2
241242
prob::P
242243
cache::C

src/nlsolve/utils.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ function build_nlsolver(
224224
end
225225
prob = NonlinearProblem(NonlinearFunction(nlf), ztmp, nlp_params)
226226
cache = init(prob, nlalg.alg)
227-
nlcache = NonlinearSolveCache(ustep, tstep, k, invγdt, prob, cache)
227+
nlcache = NonlinearSolveCache(ustep, tstep, k, atmp, invγdt, prob, cache)
228228
else
229229
nlcache = NLNewtonCache(ustep, tstep, k, atmp, dz, J, W, true,
230230
true, true, tType(dt), du1, uf, jac_config,
@@ -308,7 +308,7 @@ function build_nlsolver(
308308
end
309309
prob = NonlinearProblem(NonlinearFunction(nlf), copy(ztmp), nlp_params)
310310
cache = init(prob, nlalg.alg)
311-
nlcache = NonlinearSolveCache(nothing, tstep, nothing, invγdt, prob, cache)
311+
nlcache = NonlinearSolveCache(nothing, tstep, nothing, nothing, invγdt, prob, cache)
312312
else
313313
nlcache = NLNewtonConstantCache(tstep, J, W, true, true, true, tType(dt), uf,
314314
invγdt, tType(nlalg.new_W_dt_cutoff), t)

0 commit comments

Comments
 (0)