@@ -46,6 +46,9 @@ mutable struct KrylovSPD{T, F, Tv, Ta} <: AbstractKrylovSolver{T}
4646 atol:: T # absolute tolerance
4747 rtol:: T # relative tolerance
4848
49+ P:: Tp # Preconditioner
50+ nitertot:: Int # Total number of Krylov iterations
51+
4952 # Problem data
5053 A:: Ta # Constraint matrix
5154 θ:: Tv # scaling
@@ -54,14 +57,26 @@ mutable struct KrylovSPD{T, F, Tv, Ta} <: AbstractKrylovSolver{T}
5457
5558 function KrylovSPD (f:: Function , A:: Ta ;
5659 atol:: T = eps (T)^ (3 // 4 ),
57- rtol:: T = eps (T)^ (3 // 4 )
60+ rtol:: T = eps (T)^ (3 // 4 ),
61+ preconditioner:: Symbol = :Identity
5862 ) where {T, Ta <: AbstractMatrix{T} }
5963 F = typeof (f)
6064 m, n = size (A)
6165
62- return new {T, F, Vector{T}, Ta} (
66+ if preconditioner == :Jacobi
67+ P = JacobiPreconditioner (ones (T, m))
68+ elseif preconditioner == :Identity
69+ P = IdentityPreconditioner ()
70+ else
71+ @error " Unknown preconditioner: $preconditioner , using identity instead"
72+ P = IdentityPreconditioner ()
73+ end
74+
75+ return new {T, F, Vector{T}, Ta, typeof(P)} (
6376 m, n,
6477 f, atol, rtol,
78+ P,
79+ 0 ,
6580 A, ones (T, n), ones (T, n), ones (T, m)
6681 )
6782 end
@@ -101,6 +116,9 @@ function update!(
101116 kkt. regP .= regP
102117 kkt. regD .= regD
103118
119+ # Update Jacobi preconditioner
120+ update_preconditioner (kkt)
121+
104122 return nothing
105123end
106124
@@ -137,17 +155,22 @@ function solve!(
137155 end
138156 )
139157
158+ opM = op (kkt. P)
159+ # @info typeof(opM) extrema(kkt.P.d)
160+
140161 # Solve normal equations
141- _dy, stats = kkt. f (opS, ξ_, atol= kkt. atol, rtol= kkt. rtol)
142- dy .= _dy
162+ _dy, stats = kkt. f (opS, ξ_, M = opM, atol= kkt. atol, rtol= kkt. rtol)
143163
144- # Recover dx
164+ # Book-keeping
165+ kkt. nitertot += length (stats. residuals) - 1
166+
167+ # Recover dy, dx
168+ dy .= _dy
145169 dx .= D * (kkt. A' * dy - ξd)
146170
147171 return nothing
148172end
149173
150-
151174# ==============================================================================
152175# KrylovSID:
153176# ==============================================================================
@@ -424,4 +447,7 @@ function solve!(
424447 dy .= _dy
425448
426449 return nothing
427- end
450+ end
451+
452+ # Code for pre-conditioners
453+ include (" preconditioners.jl" )
0 commit comments