I've been following this link in order to try to solve Poisson's equation on a rectangle $[L_x, L_y]$: \begin{equation} \left(\frac{\partial^2}{\partial x^2} + \frac{\partial^2}{\partial y^2}\right)\varphi(x, y) = f(x, y) \end{equation} with $\varphi = 0$ on the boundaries. They solve the eigenvalue problem $\Delta \varphi = \lambda \varphi$ to find that $\varphi(x, y) = \sin(k_x x)\sin(k_y y)$ for $k_x = m\pi/L_x$ and $k_y = n\pi/L_y$. Then they claim that $f(x, y)$ may be expanded as \begin{equation} f(x, y) = \sum_{k_x, k_y} B_{k_x, k_y} \sin(k_x x)\sin(k_y y) \end{equation} Then go on to use this to solve Poisson's equation.
I am confused, however, because it seems like we have only pinned $\varphi$ at the boundaries, and said nothing about what values $f(x, y)$ should take. However, based on this series expansion it seems impossible that $f(x, y)$ can be anything other than zero at the boundaries. How would we expand an $f(x, y)$ that is nonzero at the boundaries? Is there even necessarily a solution for such an $f(x, y)$? Does it even matter what values it takes at the boundaries? And what if we had a source term which looked like $\partial_x f(x, y)$? Could we expand it with: \begin{equation} f(x, y) = \sum_{k_x, k_y} B_{k_x, k_y} \cos(k_x x)\sin(k_y y) \end{equation}