I am trying to solve complex valued Poisson equation $$(C + \nabla. D \nabla )u = f \text{ ;where C, D, u and f are complex numbers.} $$
I am breaking this eqn into real valued problem, which is of the form
$$ \underbrace{\begin{pmatrix} C_r + \nabla. D_r \nabla & -C_i - \nabla. D_i \nabla \\ C_i + \nabla. D_i \nabla & C_r + \nabla. D_r \nabla \end{pmatrix} }_{A} \begin{pmatrix} u_r \\ u_i \end{pmatrix} = \begin{pmatrix} f_r \\ f_i \end{pmatrix} $$
where 'r' and 'i' denote the real and imaginary parts. I wrote a Preconditioner (PC) which has the same form as the above equation by defining MAT A
and Vec. I verified the PC was working fine by solving the above equation for an example.
I have also defined a shell matrix operator which computes the action of A
operator on the vector and registered the shell matrix and PC with ksp. When I try to solve
equations using shell matrix and PC I am getting wrong solution. I am using Dirichlet boundary conditions(bcs) for $u_r$ and $u_i$ and homogeneous bcs for residual equation passed to PC. As a sanity check I did -ksp_type preonly
with Dirichlet bcs for PC and I do get a correct solution. The ksp for both PC and Shell matrix is gmres
.
Any suggestions on what could be going wrong?