I have been trying to debug this error the last few days I wondered if anybody has advice on how to proceed.
I am solving the Poisson equation for a step charge distribution (a common problem in electrostatics/semiconductor physics) on a non-uniform finite volume mesh where the unknown are defined on cell centres and the fluxes on the cell faces.
$$ 0 = (\phi_x)_x + \rho(x) $$
the charge profile (the source term) is given by,
$$ \rho(x)= \begin{cases} -1,& \text{if } -1 \leq x \leq 0\\ 1,& \text{if } 0 \leq x \leq 1\\ 0, & \text{otherwise} \end{cases} $$
and the boundary conditions are,
$$ \phi(x_L)=0 \\ \frac{\partial\phi}{\partial x}\bigg|_{x_R}=0 $$
and the domain is $[-10,10]$.
I am using code developed to solve the advection-diffusion-reaction equation (I have written myself see my notes here, http://danieljfarrell.github.io/FVM). The advection-diffusion-reaction equation is a more general case of the Poisson equation. Indeed the Poisson equation can be recovered by setting the advection velocity to zero and removing the transient term.
The code has been tested against a number of situations for uniform, nonuniform and random grids and always produces a reasonable solutions (http://danieljfarrell.github.io/FVM/examples.html) for the advection-diffusion-reaction equation.
To show where the code breaks down I have made the following example. I setup a uniform mesh of 20 cells and then make it nonuniform by removing a single cell. In the left figure I have removed cell $\Omega_8$ and in the right $\Omega_9$ has been removed. The 9th cell covers the region where the source term (i.e. the charge) changes sign. The bug appears when the grid is nonuniform in a region where the reaction term changes sign. As you can see below.
Any ideas what could possibility be causing this issue? Let me know if more information regarding the discretisation would be helpful (I didn't want to pack too much detail into this question).