Energy density in electrostatics - definition
Background:
It can be shown that the potential energy of charge distribution can be calculated by
$U = \frac{1}{2}\int_V \rho(r')\Phi(r') d^3r' $
by means of integration by parts and the poisson equation $\Delta\Phi(r) = 4\pi \rho(r)$ the integral can be rewritten
$U = \frac{1}{2}\int_V \rho(r')\Phi(r') d^3r' = \frac{1}{8\pi}\int_V (\nabla \Phi(r')) (\nabla \Phi(r') )d^3r' = \int_V \frac{|E(r')|^2}{8\pi}d^3r'$
The integrand of the integral can be interpreted as the energy density $u$:
$u(r) = \frac{|E(r)|}{8\pi}$
Considering an example of a homogeneously charged solid sphere with radius $R$:
$\rho(r) = \rho_0 \Theta(r-R)$
where $\Theta(r)$ is the heavyside-function.
With $Q=\frac{4}{3}\pi \rho_0 R^3$, this results in the following potential:
$\Phi(r) = \frac{Q}{R} \left(\frac{3}{2}-\frac{r^2}{2R^2} \right)$ for $r<R$
$\Phi(r) = \frac{Q}{r}$ for $r>R$
The radial electric field is:
$E(r) = \frac{Qr}{R^3}$ for $r<R$
$E(r) = \frac{Q}{r^2}$ for $r>R$
With this in mind we can calculate the energy density:
$u(r) = \frac{Q^2r^2}{8\pi R^6}$ for $r<R$
$u(r) = \frac{Q^2}{8 \pi r^4}$ for $r>R$
Integrating this will result in the total potential energy:
$U = \int_0^{\infty} 4\pi r^2 u(r) dr = \frac{3Q^2}{5R}$
Now to my question:
Starting from the first integral, why can't the energy density be defined as followed:
$u(r) = \frac{1}{2} \rho(r')\Phi(r')$
When considering the example above this would equate to:
$u(r) = \rho_0 \frac{Q}{R} \left(\frac{3}{2}-\frac{r^2}{2R^2} \right) = \frac{3Q^2}{4\pi R^4} \left(\frac{3}{2}-\frac{r^2}{2R^2} \right)$ for $r<R$
$u(r) = 0$ for $r>R$
Integrating over this we get the same energy (as expected)!
$U = \int_0^{\infty} 4\pi r^2 u(r) dr = \frac{3Q^2}{5R}$
How can there be two different ways of defining a energy density $u(r)$. Where have I made a mistake?
Help will be apprechiated! 649