I have written Poisson solvers using two different methods:
A classic Jacobi scheme and one using the multigrid solver Hypre. I made up a couple of test cases ensuring the validity of those solvers.
For both cases the domain is defined as $(x,y) \in [-1,1]^2$ with periodic boundary conditions. Also, the grids first and last point are the same:
$$p(0,y) = p(N_x-1,y)$$
$$p(x,0) = p(x,N_y-1)$$
Test case 1
- $f_{rhs} = -8 \pi^2 \sin(2\pi x) \sin(2\pi y)$
- $p_{exact} = \sin(2\pi x) \sin(2\pi y)$
For both solvers, the solution is 2$^{\mathrm{nd}}$ order accurate is space. No problems here so far.
Test Case 2
- $p_{rhs} = e^{-10 (x^2 + y^2)}$
- $p_{exact}:$ No analytical solution, and therefore the numerical solution is differentiated using a high-order compact scheme and compared to $p_{rhs}$
Note that in this case, $\int_V p_{rhs}dV \neq 0$ and therefore the problem is ill defined. Therefore, the $rhs$ must be modified:
$p_{rhs} = e^{-10 (x^2 + y^2)} - \dfrac{\int_D e^{-10 (x^2 + y^2)} dx dy}{V}$
where $V$ is the domain volume. The integral is computed using the Trapezoidal rule.
This is where things get tricky. No matter how fine my grid is, $\left(p_{num}\right)_{xx} + \left(p_{num}\right)_{yy}$ never converge to $p_{rhs}$. When the grid is fine enough, the solvers converge, but the solution is off by ~20% while the overall profiles are relatively correct. When the grid is coarse, the Hypre solver simply diverges.
Question
Have I missed anything? Is my approach inconsistent/wrong?