I've recently started looking into writing a finite-differences-based solver for the Poisson equation of the form $$\nabla\left(\varepsilon\nabla\varphi\right)=\rho$$ in 2D for arbitrary geometries (some additional details can be found here). However, I've soon discovered that upon imposing pure Neumann boundaries the system no longer can be solved in a straight forward manner, as the problem becomes ill-posed. First I thought the failure to solve the system arises perhaps due to some kind of a limitation of the solver I use (successive relaxation method), but from answer here I learned that the compatibility conditions are not satisfied in my problem (in particular the discrete compatibility condition), on top of the fact that the all Neumann boundaries make it an ill-posed problem (Edit: not sure about the nomenclature here, but the lack of satisfied compatibility condition could be classified as an ill-conditioned problem).
Now, how I understood one can impose the compatibility condition is just to modify the right-hand side (RHS) of the Poisson equation (including both the original $\rho$ and the Neumann boundary conditions that are stored in the RHS vector) by subtracting its mean as: $$\rho_{h}=\rho-mean(\rho),$$ where mean is calculated over all points in the vector $\rho$. This should be trivial enough, right? Well, my implementation of this in C++ did not yield any results and the convergence issues continued. In fact, the solvers I tried out with this (SOR, biCGstat, CG, CGsquare) all failed to converge as their respective residuals either diverged or just get stuck at a particular value and looped around it until the iteration reached maximal allowed iteration count.
I have recently encountered this post, where a user complains about a similar issue. He, luckily, managed to resolve it, but did not go too much into the details (he only explained that something was incorrect with the counter for the mean value calculation/subtraction).
Thus I wanted to ask if somebody can explain the practical implementation details of the discrete compatibility condition. What needs to be taken into account when calculating the average of the RHS vector, and what needs to be taken into account when subtracting the said average from the original RHS?