It's a sphere with radius a. I need to calculate the flux through $x^2+y^2+z^2=a^2$ when $z \ge 0$. Using Gauss Law:
$$\iint \vec fd\vec S=\int(\nabla f)d^3r$$
I've calculated that the divergence is $\nabla f=4z$.
Solving using spherical coordinates I get:
$$\iint \vec fd\vec S=\pi a^4$$
This doesn't seem to be correct solution, since I seem to be missing a step. Apparently I need to integrate another section, and subtract it from $\pi a^4$ but I'm not sure which. I'd appreciate an explanation
I get the same result for the volume integral over the divergence: \begin{align} \int\limits_{V} 4z \, dV &= \int\limits_0^a \pi \rho(z)^2 \, 4z \, dz \\ &= \int\limits_0^a \pi (a^2 - z^2) \, 4z \, dz \\ &= 4 \pi \int\limits_0^a (a^2 z - z^3) \, dz \\ &= 4 \pi \left[\frac{a^2}{2}z^2 - \frac{1}{4} z^4 \right]_{z=0}^{z=a} \\ &= 4 \pi \left( \frac{a^4}{2} - \frac{a^4}{4} \right) \\ &= \pi a^4 \end{align} This corresponds to the flux through $\partial V$, which is the top half sphere ($x^2 + y^2 + z^2 = a^2, z \ge 0$) and the disk of radius $a$ in the $x$-$y$-plane at $z=0$.
So you have to subtract the flow through the disk, for which one needs to know your $f$, or $f \cdot e_z$.