I want to check whether my numerical FEM solver is correct or not. So I seek a solution of \begin{equation} -\Delta u(x,y)=f(x,y) \text{ on } [-1,1]\times[-1,1]\\ u(-1,y)=1\\ u(x,y)=0\text{ on other boundary} \end{equation} In other words, the boundary value is 1 when $x=-1$ and zero otherwise.
Is there any $f$ so that a closed form of $u$ exists for such equations? Or is there another way to check my FEM solver is correct? Thanks for any helps!
Usually the easiest way how to check if your solver is correct is to pick a solution $u$ and then compute the boundary conditions and the right hand side $f$. I. e. pick your favourite $u$, find the values on boundaries and set $f = -\Delta u$. Constant or linear $u$ might be a good first choice.
Your boundary conditions are a bit problematic because of the corners in which is the jump between $u=0$ and $u=1$. This means that $u \notin H^{\frac 1 2}(\partial \Omega)$ and the standard variational formulation will fail to apply. Intuitively, your boundary conditions force the solution to have infinite gradient in the two corners.