@@ -63,7 +63,8 @@ function DFSane(; σ_min = 1e-10, σ_max = 1e+10, σ_1 = 1.0, M = 10, γ = 1e-4,
63
63
n_exp, η_strategy, max_inner_iterations)
64
64
end
65
65
66
- @concrete mutable struct DFSaneCache{iip}
66
+ # FIXME : Someone please make this code conform to the style of the remaining solvers
67
+ @concrete mutable struct DFSaneCache{iip} <: AbstractNonlinearSolveCache{iip}
67
68
alg
68
69
uₙ
69
70
uₙ₋₁
91
92
reltol
92
93
prob
93
94
stats:: NLStats
94
- termination_condition
95
- tc_storage
95
+ tc_cache
96
96
end
97
97
98
+ get_fu (cache:: DFSaneCache ) = cache. fuₙ
99
+ set_fu! (cache:: DFSaneCache , fu) = (cache. fuₙ = fu)
100
+ get_u (cache:: DFSaneCache ) = cache. uₙ
101
+
98
102
function SciMLBase. __init (prob:: NonlinearProblem{uType, iip} , alg:: DFSane , args... ;
99
103
alias_u0 = false , maxiters = 1000 , abstol = nothing , reltol = nothing ,
100
104
termination_condition = nothing , internalnorm:: F = DEFAULT_NORM,
@@ -124,24 +128,18 @@ function SciMLBase.__init(prob::NonlinearProblem{uType, iip}, alg::DFSane, args.
124
128
125
129
ℋ = fill (f₍ₙₒᵣₘ₎ₙ₋₁, M)
126
130
127
- abstol, reltol, termination_condition = _init_termination_elements (abstol, reltol,
128
- termination_condition, T)
129
-
130
- mode = DiffEqBase. get_termination_mode (termination_condition)
131
-
132
- storage = mode ∈ DiffEqBase. SAFE_TERMINATION_MODES ? NLSolveSafeTerminationResult () :
133
- nothing
131
+ abstol, reltol, tc_cache = init_termination_cache (abstol, reltol, fuₙ₋₁, uₙ₋₁,
132
+ termination_condition)
134
133
135
134
return DFSaneCache {iip} (alg, uₙ, uₙ₋₁, fuₙ, fuₙ₋₁, 𝒹, ℋ, f₍ₙₒᵣₘ₎ₙ₋₁, f₍ₙₒᵣₘ₎₀,
136
135
M, σₙ, σₘᵢₙ, σₘₐₓ, α₁, γ, τₘᵢₙ, τₘₐₓ, nₑₓₚ, p, false , maxiters,
137
136
internalnorm, ReturnCode. Default, abstol, reltol, prob, NLStats (1 , 0 , 0 , 0 , 0 ),
138
- termination_condition, storage )
137
+ tc_cache )
139
138
end
140
139
141
140
function perform_step! (cache:: DFSaneCache{true} )
142
- @unpack alg, f₍ₙₒᵣₘ₎ₙ₋₁, f₍ₙₒᵣₘ₎₀, σₙ, σₘᵢₙ, σₘₐₓ, α₁, γ, τₘᵢₙ, τₘₐₓ, nₑₓₚ, M, tc_storage = cache
141
+ @unpack alg, f₍ₙₒᵣₘ₎ₙ₋₁, f₍ₙₒᵣₘ₎₀, σₙ, σₘᵢₙ, σₘₐₓ, α₁, γ, τₘᵢₙ, τₘₐₓ, nₑₓₚ, M = cache
143
142
144
- termination_condition = cache. termination_condition (tc_storage)
145
143
f = (dx, x) -> cache. prob. f (dx, x, cache. p)
146
144
147
145
T = eltype (cache. uₙ)
@@ -184,9 +182,7 @@ function perform_step!(cache::DFSaneCache{true})
184
182
f₍ₙₒᵣₘ₎ₙ = norm (cache. fuₙ)^ nₑₓₚ
185
183
end
186
184
187
- if termination_condition (cache. fuₙ, cache. uₙ, cache. uₙ₋₁, cache. abstol, cache. reltol)
188
- cache. force_stop = true
189
- end
185
+ check_and_update! (cache, cache. fuₙ, cache. uₙ, cache. uₙ₋₁)
190
186
191
187
# Update spectral parameter
192
188
@. cache. uₙ₋₁ = cache. uₙ - cache. uₙ₋₁
@@ -215,9 +211,8 @@ function perform_step!(cache::DFSaneCache{true})
215
211
end
216
212
217
213
function perform_step! (cache:: DFSaneCache{false} )
218
- @unpack alg, f₍ₙₒᵣₘ₎ₙ₋₁, f₍ₙₒᵣₘ₎₀, σₙ, σₘᵢₙ, σₘₐₓ, α₁, γ, τₘᵢₙ, τₘₐₓ, nₑₓₚ, M, tc_storage = cache
214
+ @unpack alg, f₍ₙₒᵣₘ₎ₙ₋₁, f₍ₙₒᵣₘ₎₀, σₙ, σₘᵢₙ, σₘₐₓ, α₁, γ, τₘᵢₙ, τₘₐₓ, nₑₓₚ, M = cache
219
215
220
- termination_condition = cache. termination_condition (tc_storage)
221
216
f = x -> cache. prob. f (x, cache. p)
222
217
223
218
T = eltype (cache. uₙ)
@@ -260,9 +255,7 @@ function perform_step!(cache::DFSaneCache{false})
260
255
f₍ₙₒᵣₘ₎ₙ = norm (cache. fuₙ)^ nₑₓₚ
261
256
end
262
257
263
- if termination_condition (cache. fuₙ, cache. uₙ, cache. uₙ₋₁, cache. abstol, cache. reltol)
264
- cache. force_stop = true
265
- end
258
+ check_and_update! (cache, cache. fuₙ, cache. uₙ, cache. uₙ₋₁)
266
259
267
260
# Update spectral parameter
268
261
cache. uₙ₋₁ = @. cache. uₙ - cache. uₙ₋₁
@@ -290,26 +283,9 @@ function perform_step!(cache::DFSaneCache{false})
290
283
return nothing
291
284
end
292
285
293
- function SciMLBase. solve! (cache:: DFSaneCache )
294
- while ! cache. force_stop && cache. stats. nsteps < cache. maxiters
295
- cache. stats. nsteps += 1
296
- perform_step! (cache)
297
- end
298
-
299
- if cache. stats. nsteps == cache. maxiters
300
- cache. retcode = ReturnCode. MaxIters
301
- else
302
- cache. retcode = ReturnCode. Success
303
- end
304
-
305
- return SciMLBase. build_solution (cache. prob, cache. alg, cache. uₙ, cache. fuₙ;
306
- retcode = cache. retcode, stats = cache. stats)
307
- end
308
-
309
286
function SciMLBase. reinit! (cache:: DFSaneCache{iip} , u0 = cache. uₙ; p = cache. p,
310
- abstol = cache. abstol, reltol = cache. reltol,
311
- termination_condition = cache. termination_condition,
312
- maxiters = cache. maxiters) where {iip}
287
+ abstol = cache. abstol, reltol = cache. reltol, maxiters = cache. maxiters,
288
+ termination_condition = get_termination_mode (cache. tc_cache)) where {iip}
313
289
cache. p = p
314
290
if iip
315
291
recursivecopy! (cache. uₙ, u0)
@@ -330,12 +306,12 @@ function SciMLBase.reinit!(cache::DFSaneCache{iip}, u0 = cache.uₙ; p = cache.p
330
306
T = eltype (cache. uₙ)
331
307
cache. σₙ = T (cache. alg. σ_1)
332
308
333
- termination_condition = _get_reinit_termination_condition (cache, abstol, reltol,
309
+ abstol, reltol, tc_cache = init_termination_cache ( abstol, reltol, cache . fuₙ, cache . uₙ ,
334
310
termination_condition)
335
311
336
312
cache. abstol = abstol
337
313
cache. reltol = reltol
338
- cache. termination_condition = termination_condition
314
+ cache. tc_cache = tc_cache
339
315
cache. maxiters = maxiters
340
316
cache. stats. nf = 1
341
317
cache. stats. nsteps = 1
0 commit comments