Solution (source code)

= Solution

Assume sufficient smoothness and a regular <boundary> for the <integrations> below, with $n$ outward. Put $\delta=w-\phi$, so $\delta=0$ on $S$. Expanding the <Dirichlet energy> gives
$$
\int_V|\nabla w|^2
=\int_V|\nabla\phi|^2
+2\int_V\nabla\phi\cdot\nabla\delta+\int_V|\nabla\delta|^2.
$$
By <Green's first identity>, the middle <integral> is
$$
\int_V\nabla\phi\cdot\nabla\delta
=\int_S\delta\,\partial_n\phi-\int_V\delta\,\Delta\phi=0.
$$
Thus the <Dirichlet principle> follows with an explicit remainder:
$$
\boxed{\int_V|\nabla w|^2-\int_V|\nabla\phi|^2
=\int_V|\nabla(w-\phi)|^2\geq0.}
$$
Equality means $w-\phi$ is constant on each <connected component>; its zero <boundary> value forces that constant to be zero.

Now let $w$ solve the <heat equation> and set $E(t)=\int_V|\nabla w|^2\,dV$. <Differentiation> followed by <Green's first identity> gives
$$
E'(t)=2\int_V\nabla w\cdot\nabla w_t
=2\int_Sw_t\,\partial_nw-2\int_Vw_t\Delta w.
$$
Under time-independent <Dirichlet boundary conditions>, $w_t=0$ on $S$, while $w_t=\Delta w$ in $V$. Therefore
$$
\boxed{E'(t)=-2\int_V(\Delta w)^2\,dV\leq0.}
$$
If equality holds at a particular time, <continuity> makes $\Delta w=0$ throughout $V$ at that time. Its <boundary> values are still $f$, so uniqueness of the <Dirichlet problem> implies $w=\phi$. Conversely $w=\phi$ has $\Delta w=0$ and gives equality. This proves the full equality criterion for <Dirichlet energy dissipation for the heat equation>.

For the <dynamic boundary condition for the heat equation>, substitute $w_t=-\alpha\partial_nw$ directly into the <boundary term>. The interior equation is unchanged, so
$$
\boxed{E'(t)=-2\int_Vw_t^2\,dV
-2\int_S\alpha(\partial_nw)^2\,dS\leq0.}
$$
This is <Dirichlet energy dissipation with a dynamic heat boundary condition>. It remains valid when $\alpha$ vanishes, because no division by $\alpha$ is used. The last part preserves energy monotonicity; its stationary states need not have the earlier prescribed <Dirichlet data>. For example, with strictly positive $\alpha$ on a connected <boundary>, a stationary harmonic state has zero outward <normal derivative> and is constant, as follows by applying <Green's first identity> to that state itself.