In the weak formulation of the Poisson equation, why is the boundary condition included in the integration of the weighted residual? In the weak formulation of the Poisson equation $\nabla^2u = g$ with boundary conditions $u = \bar{u}$ on $\Gamma_e$ and $\frac{\partial{u}}{\partial{n}} = \bar{q}$ on $\Gamma_n$, why is the integration of the weighted residual expressed as 
$$I = \int_\Omega w(\nabla^2u-g) d\Omega - \int_{\Gamma_e} w\frac{\partial{u}}{\partial{n}}d\Gamma$$ and not just
$$I = \int_\Omega w(\nabla^2u-g) d\Omega$$
 A: Ignoring weights, multiply both sides of the original DE by a test function and "formally" integrate by parts. You get 
$$\int_\Omega -\nabla u \cdot \nabla v dx + \int_{\Gamma_e} v \nabla u \cdot n d \Gamma + \int_{\Gamma_n} v \nabla u \cdot n d \Gamma = \int_\Omega g v dx.$$
Now we apply the boundary conditions in the weak form. On the Neumann part of the boundary $\Gamma_n$, we just replace $\nabla u \cdot n$ by what it should be. It turns out that you're stuck with this seemingly weird approach. That's because in the appropriate space of candidate solutions, restricting solution functions to the boundary makes sense but restricting their derivatives to the boundary does not. 
By contrast, the approach on the Dirichlet part of the boundary is what you would expect. We restrict our solution space to functions which satisfy our Dirichlet condition. To do this without making the problem inconsistent, we must also restrict our test functions to those which vanish on $\Gamma_e$. A nice way of thinking about this is that in the associated variational problem, test functions are the directions in which we can move in the space of possible solutions. If we go in a direction which doesn't vanish on $\Gamma_e$, then our new function doesn't vanish on $\Gamma_e$, so it should not be a candidate for the minimizer in the variational problem.
Thus the weak formulation of the problem says: $u$ is a solution if $u \in H^1$, $u=\overline{u}$ on $\Gamma_e$, and
$$\int_\Omega -\nabla u \cdot \nabla v dx + \int_{\Gamma_n} v \overline{q} d \Gamma = \int_\Omega g v dx$$
for all $v \in H^1$ which vanish on $\Gamma_e$. The manipulations we did in the first place imply that a strong solution is a weak solution. Undoing the manipulations that we did shows that a smooth weak solution is a strong solution. Thus the weak formulation correctly corresponds to the strong formulation.
If you need weights, you can do it again analogously (provided the integration by parts still makes sense with the weights).
