Given 3D Poisson equation$$\nabla^2 \phi(x, y, z) = f(x, y, z)$$and the right hand side and the domain, am I free to impose any boundary conditions (BC) on the function $\phi$, or do they have to be somehow consistent with the right hand side? In particular, if I impose periodic BC, will there be exactly one solution for any right hand side?For example, let:$$f(x, y, z) = - 3 \pi^{2} \sin{\left (\pi x \right )} \sin{\left (\pi y \right )} \sin{\left (\pi z \right )}$$and I solve on a box $(0, 1)\times (0, 1) \times (0, 1)$.Now any solution must be a sum of $\phi_0+\phi_1$ where:$$\phi_0(x, y, z) = \sin{\left (\pi x \right )} \sin{\left (\pi y \right )} \sin{\left (\pi z \right )}\,,$$because $\nabla^2\phi_0 = f$, and $\phi_1$ is any harmonic function (i.e. $\nabla^2\phi_1 = 0$). Correct?If I impose zero Dirichlet BC, then $\phi_0$ is the only solution, because it satisfies the BC, satisfies the equation and the solution must be unique. Correct?What if I impose periodic BC? Does it mean that there will be some harmonic function $\phi_1$ such that $\phi_0+\phi_1$ satisfies the periodic BC and solves the equation? What is this $\phi_1$ explicitly in this case?
Role of boundary conditions (e.g. periodic) in Poisson equation
pde;boundary conditions;elliptic pde
From a numerical perspective, it's perhaps easiest to discuss the discretizations directly.For the Poisson equation with homogeneous Dirichlet boundary conditions, there is a unique solution for any right-hand side. Once discretized, the equation can be written in the form $Ax = b$, where $A$ is the standard discretization of the 3D Laplacian operator with Dirichlet boundary and $b$ is a standard discretization of $f$. Since $A$ is positive definitive, it is invertible, and the system will have a unique solution for any $b$, and thus any $f$. There are, of course, the usual issues with undersampling; if two different values of $f$ give rise to the same discretization due to use of a coarse grid or due to discontinuities in $f$, there may be some ambiguity about what system is actually being solved. But provided the discretization of $f$ is well-behaved, a meaningful unique solution will exist.The situation is slightly more complicated in the case of periodic boundary conditions because the standard discretization of the 3D Laplacian operator with periodic boundary is positive semidefinite and has a one-dimensional kernel $K$ comprising solutions of the form $x \equiv C$ with $C$ constant. Because $A$ is still symmetric in the periodic case, we have that $\operatorname{Range} A = K^\perp$, and so $Ax = b$ will not have a solution unless $\mathbf{1} \cdot b = 0$, where $\mathbf{1}$ is the vector consisting of all 1s. This provides the consistency condition for the right-hand side in discretized form.Note that, analytically, there is a somewhat simpler way to look at it. Recall that, for $\phi \in C^2(\Omega)$, where $\Omega$ is our domain, we have$$\int_\Omega \Delta \phi \, dx = \int_{\partial \Omega} \frac{\partial \phi}{\partial \mathbf{n}}\, dS.$$If we stipulate a periodic boundary condition on $\phi$, then the boundary term in the right-hand side disappears, and we're left with$$\int_\Omega \Delta\phi\, dx = 0.$$So if $\phi$ satisfies $\Delta \phi = f$, it immediately follows that we must have$$\int_\Omega f\, dx = 0.$$This is the analytical analog to $\mathbf{1} \cdot b = 0$, as both are expressing the fact that the average value of $f$, and thus $b$, over the domain must be zero.