How to define weak solution for an elliptic PDE with non-zero Dirichlet boundary condition? For homogeneous Dirichlet boundary condition, for example
$$
\left\{\!\!
\begin{aligned}
&-\Delta u+c(x)u=f(x),x\in\Omega\\
&u|_{\partial\Omega}=0
\end{aligned}
\right.
$$
The weak solution is defined as a function $u\in H_0^1(\Omega)$ satisfying
$$
\int_\Omega\left(\sum_{i=1}^n\frac{\partial u}{\partial x_i}
\frac{\partial v}{\partial x_i}+c(x)uv\right)\,dx=\int_\Omega fv\,dx
$$
for every $v\in H_0^1(\Omega)$.
I wonder how to define weak solution for an elliptic PDE with non-zero Dirichlet boundary condition.
For example,
 $$
\left\{\!\!
\begin{aligned}
&-\Delta u+c(x)u=f(x),x\in\Omega\\
&u|_{\partial\Omega}=g
\end{aligned}
\right.
$$
Evans's Partial Differential Equations (1st edition, Section 6.1.2) says:

... is is necessary for $g$ to be the trace of some $H^1$ function, 
  say $w$. But then $\tilde u:=u-w$ belongs to $H_0^1(\Omega)$, and is a
  weak solution of the boundary-value problem
  $$
\left\{\!\!
\begin{aligned}
&-\Delta \tilde u+c(x)\tilde u=\tilde f(x),x\in\Omega\\
&\tilde u|_{\partial\Omega}=0
\end{aligned}
\right.
$$
  where $\tilde f:=f-(-\Delta w+c(x)w)$

The problem is: how to find the function $w$, in a constructive way?
Can you please help? Thank you.
 A: You don't find $w$. $w$ is a "given", in the following sense. For the weak formulation of the problem to make sense, the statement 
$$ u|_{\partial\Omega} = g $$
is in fact the following statement: $\exists$ a fixed $w \in H^1(\Omega)$ such that the trace of $w$ to $\partial \Omega$ is equal to the trace of $u$. 
The relevant section in Evans is trying to explain this. Basically what he is trying to say is that the intuition for the Dirichlet problem with "strong" solutions, where you prescribe boundary value as some continuous function $g$ on the boundary, must be replaced by an appropriate weak version defined relative to the trace operator to hypersurfaces, when you consider the weak formulation of the problem. This is because a solution $u$, as an object in the space $W^{1,2} = H^1$, is only an equivalent class of functions defined up to sets of measure zero. If $\Omega$ is a sufficiently regular open set, $\partial\Omega$ has measure zero, so it is meaningless to state that $u$ coincides with $g$ on $\partial\Omega$, since $u$ can always be modified on just $\partial\Omega$ to give any value you want there. 
You should compare this to, for example, Theorem 8.3 in Gilbarg and Trudinger, Elliptical partial differential equations of second order, which states

Let [$L$ be an elliptic operator]. Then for $\psi \in W^{1,2}(\Omega)$ and $g,f^i\in L^2(\Omega)$, $i = 1 , \ldots, n$, the generalized Dirichlet problem, $Lu = g + D_i f^i$ in $\Omega$, $u = \psi$ on $\partial\Omega$ is uniquely solvable. 

A: I ran across this old question and I would like to say something about it. While the point of view provided by Willie Wong is satisfactory, there is a theory of "inverse traces" which answers OP's question in bold more or less directly. For an example, have a look at the following theorem taken from Kufner, John, Kufcik, "Function Spaces".

6.9.2 Theorem Let $p>1$ and $\Omega\in C^{0, 1}$ [meaning that its boundary is Lipschitz and bounded]. Then there exists a continuous linear mapping $T$ from $W^{1-1/p, 1}(\partial \Omega)$ into $W^{1,p}(\Omega)$ such that for $v=Tu$ we have $v=u$ on $\Omega$ [in trace sense]. 

The idea of the proof is simpler than one might expect (at least, it is simpler than I expect). Suppose that $$\Omega=\mathbb{R}^{n+1}_+=\{(x, t)\in \mathbb{R}^n\times \mathbb{R}\ :\ t>0\}.$$
If you have a function $u\in C^{\infty}_0(\mathbb{R}^n)$ you can construct a function $v\in C^\infty(\mathbb{R}^{n+1}_+)$ by convolution against the heat kernel:
$$v(x,t)=\frac{1}{(4\pi t)^{n/2}}\int_{\mathbb{R}^n} e^{-\frac{\lvert x-y\rvert^2}{4t}}u(y)\, dy.$$
Then the trace of $v$ on the boundary $\{t=0\}$ is $u$, as we already know. 
If $\Omega$ is a domain with a nice enough boundary, we can use charts to perform this construction locally and then patch everything up with a partition of unity. This is the idea. Unfortunately, there are some technical difficulties which require the introduction of the cumbersome fractionary order Sobolev spaces $W^{1-1/p, p}$.
