I want to use the conjugate gradient method to solve poisson's equation in an electrostatic setup: \begin{align} \rho=-\nabla^2\phi \end{align} I am however a little confused when it comes to the boundary conditions. For the dirichlet boundaries $\phi(0)=D$ it is pretty easy because i can implement the condition in the initial guess of the solution. However, when using either neumann $\frac{\partial \phi}{\partial x}=C$ or periodic $\phi(0)=\phi(L)$, no values are known which can be implemented in the initial guess. And so i'm not sure where the b.c should be imposed during the iterative process..?
Thanks in advance.