@@ -73,6 +73,7 @@ mutable struct LinearCache{TA, Tb, Tu, Tp, Talg, Tc, Tl, Tr, Ttol, issq, S}
73
73
alg:: Talg
74
74
cacheval:: Tc # store alg cache here
75
75
isfresh:: Bool # false => cacheval is set wrt A, true => update cacheval wrt A
76
+ precsisfresh:: Bool # false => PR,PL is set wrt A, true => update PR,PL wrt A
76
77
Pl:: Tl # preconditioners
77
78
Pr:: Tr
78
79
abstol:: Ttol
85
86
86
87
function Base. setproperty! (cache:: LinearCache , name:: Symbol , x)
87
88
if name === :A
88
- if hasproperty (cache. alg, :precs ) && ! isnothing (cache. alg. precs)
89
- Pl, Pr = cache. alg. precs (x, cache. p)
90
- setfield! (cache, :Pl , Pl)
91
- setfield! (cache, :Pr , Pr)
92
- end
93
89
setfield! (cache, :isfresh , true )
90
+ setfield! (cache, :precsisfresh , true )
94
91
elseif name === :p
95
- if hasproperty (cache. alg, :precs ) && ! isnothing (cache. alg. precs)
96
- Pl, Pr = cache. alg. precs (cache. A, x)
97
- setfield! (cache, :Pl , Pl)
98
- setfield! (cache, :Pr , Pr)
99
- end
92
+ setfield! (cache, :precsisfresh , true )
100
93
elseif name === :b
101
94
# In case there is something that needs to be done when b is updated
102
95
update_cacheval! (cache, :b , x)
@@ -208,11 +201,12 @@ function SciMLBase.init(prob::LinearProblem, alg::SciMLLinearSolveAlgorithm,
208
201
cacheval = init_cacheval (alg, A, b, u0_, Pl, Pr, maxiters, abstol, reltol, verbose,
209
202
assumptions)
210
203
isfresh = true
204
+ precsisfresh = false
211
205
Tc = typeof (cacheval)
212
206
213
207
cache = LinearCache{typeof (A), typeof (b), typeof (u0_), typeof (p), typeof (alg), Tc,
214
208
typeof (Pl), typeof (Pr), typeof (reltol), typeof (assumptions. issq),
215
- typeof (sensealg)}(A, b, u0_, p, alg, cacheval, isfresh, Pl, Pr, abstol, reltol,
209
+ typeof (sensealg)}(A, b, u0_, p, alg, cacheval, isfresh, precsisfresh, Pl, Pr, abstol, reltol,
216
210
maxiters, verbose, assumptions, sensealg)
217
211
return cache
218
212
end
@@ -223,27 +217,26 @@ function SciMLBase.reinit!(cache::LinearCache;
223
217
b = cache. b,
224
218
u = cache. u,
225
219
p = nothing ,
226
- reinit_cache = false ,)
220
+ reinit_cache = false ,
221
+ reuse_precs = false )
227
222
(; alg, cacheval, abstol, reltol, maxiters, verbose, assumptions, sensealg) = cache
228
223
229
- precs = (hasproperty (alg, :precs ) && ! isnothing (alg. precs)) ? alg. precs : DEFAULT_PRECS
230
- Pl, Pr = if isnothing (A) || isnothing (p)
231
- if isnothing (A)
232
- A = cache. A
233
- end
234
- if isnothing (p)
235
- p = cache. p
236
- end
237
- precs (A, p)
238
- else
239
- (cache. Pl, cache. Pr)
240
- end
241
- isfresh = true
242
224
225
+ isfresh = ! isnothing (A)
226
+ precsisfresh = ! reuse_precs && (isfresh || ! isnothing (p))
227
+ isfresh |= cache. isfresh
228
+ precsisfresh |= cache. precsisfresh
229
+
230
+ A = isnothing (A) ? cache. A : A
231
+ b = isnothing (b) ? cache. b : b
232
+ u = isnothing (u) ? cache. u : u
233
+ p = isnothing (p) ? cache. p : p
234
+ Pl = cache. Pl
235
+ Pr = cache. Pr
243
236
if reinit_cache
244
237
return LinearCache{typeof (A), typeof (b), typeof (u), typeof (p), typeof (alg), typeof (cacheval),
245
238
typeof (Pl), typeof (Pr), typeof (reltol), typeof (assumptions. issq),
246
- typeof (sensealg)}(A, b, u, p, alg, cacheval, isfresh, Pl, Pr, abstol, reltol,
239
+ typeof (sensealg)}(A, b, u, p, alg, cacheval, precsisfresh, isfresh, Pl, Pr, abstol, reltol,
247
240
maxiters, verbose, assumptions, sensealg)
248
241
else
249
242
cache. A = A
@@ -253,6 +246,7 @@ function SciMLBase.reinit!(cache::LinearCache;
253
246
cache. Pl = Pl
254
247
cache. Pr = Pr
255
248
cache. isfresh = true
249
+ cache. precsisfresh = precsisfresh
256
250
end
257
251
end
258
252
0 commit comments