Proving that a non-homogeneous wave equation preserves energy $E(t)\equiv\int_{B}(u_t^2+c^2|\nabla u|^2)dx$ The following problem is an old qual. prep problem and I am not sure whether the problem contains all necessary information. The problem is verbatim the following:

Let $B$ be an open and bounded subset of $\mathbb{R}^n$, $c > 0$ and $r$ a smooth enough function. Let $u$ be a solution to equation $(\frac{\partial^2}{\partial t^2} - c^2\Delta)u = r$ in $S\times (0, T)$. Show that the energy $E(t)\equiv \frac{1}{2}\int_B\left(\left(\frac{\partial u}{\partial t}\right)^2 + c^2\left|\nabla u\right|^2\right)dx$ is preserved by $u$. You may assume $u$ to be smooth enough.

The equation in question is a homogeneous/non-homogeneous wave equation. Since no other information is provided about $r$ it is best to assume that $r\not\equiv 0$. Below I am denoting an $n-1$ dimensional surface measure by $dS(x)$.
By Lebesgue's dominated convergence theorem we can differentiate $E$ w.r.t. $t$ to obtain that
$$E'(t) = \frac{1}{2}\int_B 2 \frac{\partial^2u}{\partial t}\cdot \frac{\partial u}{\partial t} + 2c^2\nabla u\cdot \nabla \frac{\partial}{\partial t}udx$$
and then apply Green's first identity to simplify $E'(t)$ to
$$E'(t) = \int_B \frac{\partial^2u}{\partial t}\cdot \frac{\partial u}{\partial t}dx + c^2\left(-\int_B\frac{\partial u}{\partial t}\cdot \Delta udx + \int_{\partial B}\frac{\partial u}{\partial n}\cdot \frac{\partial u}{\partial t}dS(x)\right)\Longleftrightarrow$$
$$E'(t) = \int_B \frac{\partial^2u}{\partial t}\cdot \frac{\partial u}{\partial t} - c^2\frac{\partial }{\partial t}\cdot \Delta udx + c^2\int_{\partial B}\frac{\partial u}{\partial n}\cdot \frac{\partial u}{\partial t}dS(x)\Longleftrightarrow$$
$$E'(t) = \int_B \frac{\partial u}{\partial t}\left(\frac{\partial^2 u}{\partial t} - c^2\Delta u\right)dx + c^2\int_{\partial B}\frac{\partial u}{\partial n}\cdot \frac{\partial u}{\partial t}dS(x)\Longleftrightarrow$$
$$E'(t) = \int_B \frac{\partial u}{\partial t}\cdot rdx + c^2\int_{\partial B}\frac{\partial u}{\partial n}\cdot \frac{\partial u}{\partial t}dS(x)$$
I am not sure how to move beyond this point. We want $\int_B \frac{\partial u}{\partial t}\cdot rdx = -c^2\int_{\partial B}\frac{\partial u}{\partial n}\cdot \frac{\partial u}{\partial t}dS(x)$ but I can't recall any useful identity/lemma to verify this. If we assume that $u$ vanishes on the boundary of $S$ then we would also need to have $r \equiv 0$. I suppose that the integral $ I \equiv \int_B \frac{\partial u}{\partial t}rdx$ can vanish w/o $r\equiv 0$, but considering that this problem is supposedly on the easier side of things, I suspect that there is no need to divide $B$ in any way in order to analyze how $I = 0$, but rather that either there is some information missing or that I am missing some important tool(s).
 A: The usual way of stating the problem is as follows:

Suppose $u$ satisfies $\left(\frac{\partial^2}{\partial t^2}-\Delta\right)u=0$ on $\Bbb{R}^n\times(0,\infty)$. (Assume that $u$ is a smooth enough solution, with sufficient decay properties to justify Leibniz’s integral rule and the divergence theorem.) Then, prove that the energy $E(t):=\frac{1}{2}\int_{\Bbb{R}^n}\left((\partial_tu)^2+ |\nabla u|^2\right)\,dx$ is conserved.

If you want a term on the right, the usual thing I’ve seen is:

Suppose $u$ satisfies the “non-linear wave equation”  $\left(\frac{\partial^2}{\partial t^2}-\Delta\right)u=f(u)$ on $\Bbb{R}^n\times(0,\infty)$. (Assume that $f:\Bbb{R}\to\Bbb{R}$ is smooth enough $u$ is a smooth enough solution, with sufficient decay properties to justify Leibniz’s integral rule and the divergence theorem. Also, $f(u)$ of course really means $f\circ u$) Then, prove that the “modified energy” $E(t):=\int_{\Bbb{R}^n}\left[\frac{1}{2}\left(\partial_tu)^2+ |\nabla u|^2\right)-F\circ u\right]\,dx$ is conserved, where $F$ is an antiderivative of $f$ (and assume it is nice enough so that everything is nice and integrable).

Note that this particular “energy” would only be non-negative if $F\leq 0$. This second form is sometimes useful when dealing with non-linear equations.
Also, the above conservation laws require decay assumptions to apply the divergence theorem, so the usual things people do with energy is to prove “energy-inequalities” of the type $E(t)\leq E(0)$ (this is all that really matters usually anyway when dealing with waves, because you’re bounding Sobolev norms of your function in time by an initial Sobolev norm… and if you can do this for a sufficiently high Sobolev norm, you can prove uniform boundedness and also decay properties of waves). This is done by assuming smoothness, but you don’t assume decay properties. Instead, you carry out the divergence theorem on an “inverted truncated light cone” (see for example Evans’ discussion of waves).
These arguments show that it is the energy over all of space which is conserved. This makes sense: if you’re only looking at a bounded region $B$, then the energy can certainly escape that region, because waves carry that energy as they propagate in space. This is something you expect regardless of whether or not there is a non-zero term on the right side of the equation. But if you really want to work on a bounded domain, you will pick up boundary terms from the divergence theorem (as you have seen), and also a term from the right hand side (again, as you’ve seen). This is not a mistake.
