## Background

I've met this problem when I was trying to convert a elliptic PDE problem into the corresponding variational problem in order to apply finite element method.

The PDE is an elliptic PDE with non-zero Dirichlet boundary condition:

Denote
$$
Lu=-\nabla\cdot(a\nabla u)+bu
$$
Then the equation is
$$
\left\{\!\!
\begin{aligned}
&Lu=f,x\in\Omega\\
&u|_{\partial \Omega}=g
\end{aligned}
\right.
$$

**When $g\equiv0$**, I know the corresponding variational problem is

find $u\in H_0^1(\Omega)$, such that
$$
a(u,v)=(f,v), \forall v\in H_0^1(\Omega)
$$
where
$$
\begin{aligned}
a(u,v)&:=\int_\Omega a\nabla u\cdot\nabla v\,dx+\int_\Omega buv\,dx\qquad \\
(f,v)&:=\int_\Omega fv\,dx,\qquad \forall u,v\in H_0^1(\Omega)
\end{aligned}
$$
(This is actually the weak form of the original PDE.)

Here comes my problem:

**For general g**,
if I can find a function $w\in H^1$ such that $w|_{\partial\Omega}=g$, by letting $\tilde u=u-w$,
we have
$$
\left\{\!\!
\begin{aligned}
&L\tilde u=\tilde f,x\in\Omega\\
&\tilde u|_{\partial \Omega}=0
\end{aligned}
\right.
$$
whose solution is already known.

So how to find such a $w$?

divergenceof some $L^2$ function, so the weak formulation (taking the $L^2$ product against $v$) still makes sense. So it suffices to actually consider arbitrary $w$, provided you have good understanding of same problem with vanishing Dirichlet data, and with the RHS being a sum of $L^2$ plus divergence of something in $L^2$. – Willie Wong Jul 19 '11 at 15:58