Implementing discrete Poisson equation wtih Neumann boundary condition

I understand how to implement a discrete 2D poisson solution with Dirchlet boundary conditions. Using http://en.wikipedia.org/wiki/Discrete_Poisson_equation#On_a_two-dimensional_rectangular_grid , you just replace any of the u_i,j that are on the source side of the boundary with the boundary values that you have. However, I don't understand how to implement the Neumann boundary condition. If you want to "match" the external derivative, wouldn't you have to just set the nodes that are on the target side of the boundary to a value that makes the derivative between the source boundary pixel and the target boundary pixel equal the derivative outside the boundary? If you do this, haven't you just simply "filled in" one node around the boundary and provided a slightly smaller version of the Dirchlet problem?

Can anyone explain this?

-

1 Answer

Well, not exactly.

For Neumann BCs, you don't fill in any values, you just supply a relation between the values of the points on the boundary and the points right next to them. Think of this as having 2 different governing equations, one of them which is valid inside the boundary, and the other is valid only on the boundary.

When you discretize your system, you get a relation between the values $u_{ij}, u_{i+1j}, u_{i-1j}, u_{ij+1},u_{ij-1}$, etc..., that depends on your governing equation, now, this relation is valid INSIDE the domain only.

If for instance, you want to enforce the first derivative with respect to x to be equal to q, you write .

$u_{0j} - u_{1j} = q\delta_x$, this is itself a governing equation but is only valid between the values $i = 0$ and $1$.

So in your system, you have to alter the equations you are solving so that you have two equations instead of one, this is very simple to implement because the BC equation is always simpler than the governing equation.

In fact, the same thing holds for Dirichlet BCs, but in that case, your boundary equation is even simpler, it does not involve u at $i = 1$ at all, it is simply

$u_{0j} = p$

where $p$ is the prescribed Dirichlet condition, you can choose that your implementation solves this "second kind of equation" along with the governing equation as well, but this is trivial because it will try to solve $u_{0j} = p$ just to give you $u_{0j} = p$.

-