@@ -121,6 +121,8 @@ default_alias_b(::Any, ::Any, ::Any) = false
121
121
default_alias_A (:: AbstractKrylovSubspaceMethod , :: Any , :: Any ) = true
122
122
default_alias_b (:: AbstractKrylovSubspaceMethod , :: Any , :: Any ) = true
123
123
124
+ DEFAULT_PRECS (A, p) = IdentityOperator (size (A)[1 ]), IdentityOperator (size (A)[2 ])
125
+
124
126
function __init_u0_from_Ab (A, b)
125
127
u0 = similar (b, size (A, 2 ))
126
128
fill! (u0, false )
@@ -136,12 +138,12 @@ function SciMLBase.init(prob::LinearProblem, alg::SciMLLinearSolveAlgorithm,
136
138
reltol = default_tol (real (eltype (prob. b))),
137
139
maxiters:: Int = length (prob. b),
138
140
verbose:: Bool = false ,
139
- Pl = IdentityOperator ( size (prob . A)[ 1 ]) ,
140
- Pr = IdentityOperator ( size (prob . A)[ 2 ]) ,
141
+ Pl = nothing ,
142
+ Pr = nothing ,
141
143
assumptions = OperatorAssumptions (issquare (prob. A)),
142
144
sensealg = LinearSolveAdjoint (),
143
145
kwargs... )
144
- @unpack A, b, u0, p = prob
146
+ (; A, b, u0, p) = prob
145
147
146
148
A = if alias_A || A isa SMatrix
147
149
A
@@ -167,6 +169,18 @@ function SciMLBase.init(prob::LinearProblem, alg::SciMLLinearSolveAlgorithm,
167
169
reltol = real (eltype (prob. b))(reltol)
168
170
abstol = real (eltype (prob. b))(abstol)
169
171
172
+ precs = hasproperty (alg, :precs ) ? alg. precs : DEFAULT_PRECS
173
+ _Pl, _Pr = precs (A, p)
174
+ if isnothing (Pl)
175
+ Pl = _Pl
176
+ else
177
+ @warn " passing Preconditioners at `init`/`solve` time is deprecated. Instead add a `precs` function to your algorithm."
178
+ end
179
+ if isnothing (Pr)
180
+ Pr = _Pr
181
+ else
182
+ @warn " passing Preconditioners at `init`/`solve` time is deprecated. Instead add a `precs` function to your algorithm."
183
+ end
170
184
cacheval = init_cacheval (alg, A, b, u0_, Pl, Pr, maxiters, abstol, reltol, verbose,
171
185
assumptions)
172
186
isfresh = true
@@ -179,6 +193,33 @@ function SciMLBase.init(prob::LinearProblem, alg::SciMLLinearSolveAlgorithm,
179
193
return cache
180
194
end
181
195
196
+
197
+ function SciMLBase. reinit! (cache:: LinearCache ;
198
+ A = nothing ,
199
+ b = cache. b,
200
+ u = cache. u,
201
+ p = nothing ,)
202
+ (; alg, cacheval, isfresh, abstol, reltol, maxiters, verbose, assumptions, sensealg) = cache
203
+
204
+ precs = hasproperty (alg, :precs ) ? alg. precs : DEFAULT_PRECS
205
+ Pl, Pr = if isnothing (A) || isnothing (p)
206
+ (cache. Pl, cache. Pr)
207
+ else
208
+ if isnothing (A)
209
+ A = cache. A
210
+ end
211
+ if isnothing (p)
212
+ p = cache. p
213
+ end
214
+ precs (A, p)
215
+ end
216
+
217
+ return LinearCache{typeof (A), typeof (b), typeof (u), typeof (p), typeof (alg), typeof (cacheval),
218
+ typeof (Pl), typeof (Pr), typeof (reltol), typeof (assumptions. issq),
219
+ typeof (sensealg)}(A, b, u, p, alg, cacheval, isfresh, Pl, Pr, abstol, reltol,
220
+ maxiters, verbose, assumptions, sensealg)
221
+ end
222
+
182
223
function SciMLBase. solve (prob:: LinearProblem , args... ; kwargs... )
183
224
return solve (prob, nothing , args... ; kwargs... )
184
225
end
0 commit comments