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,

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

  def Mult(self, x, y): = 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:

1 Like