Scale the inverse of matrix

Dear all,

I have tried implementing the MHSS preconditioner for the CG solver in NGSolve.

P = (1 + j)(B + C) where B is the real part and C is the imaginary part.
I could calculate
a_pre_inv = a_pre.Inverse(fes_pre.FreeDofs(), inverse="sparsecholesky") where a_pre is B + C.
Is there any way to scale this inverse with 1/(1-1j) and use this matrix as a preconditioner for the CG solver of the complex system?

Any help is highly appreciated.

Best regards,
VC

Maybe there is even an easier way, but one way is to derive from BaseMatrix and implement the scaling there. Something like this:

class ScaledBaseMat(BaseMatrix):
  def __init__(self, mat):
    self.mat = mat
    super().__init__()

  def Mult(self, x, y):
    y.data = self.mat * x
    y[:] *= 1/(1-1j)

and then use this matrix in your preconditioner.

See here for an example of such a BaseMatrix overload:
https://docu.ngsolve.org/latest/i-tutorials/unit-2.1.2-blockjacobi/blockjacobi.html#Implement-a-forward-backward-GS-preconditioner

1 Like