Solution (source code)

= Solution

For the <uniform space charge in a grounded spherical cavity>, <grounding> sets the metal's <electric potential> to zero. With no external sources and zero <electric potential> at infinity, the exterior <electric potential> is also zero by the <uniqueness theorem for the electrostatic potential>. The original shell <electric charge> is no longer fixed: <electric charge> can flow to or from earth.

Inside the cavity, <Gauss's law> gives $\mathbf E=\rho r\hat{\mathbf r}/(3\epsilon_0)$. Integrating the <electric field> inward from the zero boundary <electric potential> gives
$$
V(r)=\int_r^{r_1}\frac{\rho s}{3\epsilon_0}\,ds
=\frac{\rho(r_1^2-r^2)}{6\epsilon_0},\qquad
\boxed{V(0)=\frac{\rho r_1^2}{6\epsilon_0}.}
$$
The inner surface carries $-Q_\rho$, where $Q_\rho=4\pi\rho r_1^3/3$, and the outer surface carries zero net <electric charge>. Only the cavity contributes to the final <electrostatic energy>:
$$
U=\frac{\epsilon_0}{2}\int |\mathbf E|^2\,d^3r
=\frac{\epsilon_0}{2}4\pi\int_0^{r_1}\left(\frac{\rho r}{3\epsilon_0}\right)^2r^2\,dr,
\qquad
\boxed{U=\frac{2\pi\rho^2r_1^5}{45\epsilon_0}
=\frac{Q_\rho^2}{40\pi\epsilon_0r_1}.}
$$
The same result follows from $U=\tfrac12\int\rho V\,d^3r$; the conductor's <surface charge> contributes zero because its <electric potential> is zero. This is the final stored <electrostatic energy>, not the change from the earlier central-charge configuration, whose ideal <point charge> has divergent self-energy.