Solution (source code)

= Solution

For two solutions of the <Poisson equation> with the same <Dirichlet boundary condition>, let $w=u_1-u_2$. Then $\nabla^2w=0$ in $V$ and $w=0$ on its boundary. By <Green's first identity>,
$$
\int_V|\nabla w|^2\,dV
=\int_Sw\,\partial_nw\,dS-\int_Vw\nabla^2w\,dV=0.
$$
Thus $w$ is constant on each connected component, and the zero boundary values make each constant zero. \b[The Dirichlet solution is unique whenever it exists.] This argument requires the regularity needed for the displayed integration by parts; it does not assert existence for arbitrary rough data.

With a <Neumann boundary condition>, integrating the <Poisson equation> and using the <divergence theorem> instead gives the necessary compatibility condition
$$
\boxed{\int_V\rho\,dV=\int_Sg\,dS.}
$$
On a disconnected region this condition must hold on each connected component separately. If two solutions have the same normal derivative, their difference is harmonic with $\partial_nw=0$. The same <Green's first identity> again forces $\nabla w=0$. Thus \b[Neumann solutions are unique only up to an additive constant on each connected component]. Adding a constant preserves both the equation and normal derivative, so uniqueness without a normalization cannot hold. On a connected region, prescribing the mean value removes this one-dimensional freedom.