Flux of a vector field over a sphere I have been given $\bar{F}=x\hat{x}+xy\hat{y}+xyz\hat{z}$, and I need to compute the flux over a sphere of radius $2$ which I assume is centered at the origin. I have already computed this using the divergence theorem. I begin with $$\int_S\bar{F}\cdot \bar{da}$$
where $$\bar{F}\cdot\bar{da}=(x\hat{x}+xy\hat{y}+xyz\hat{z})\cdot\frac{x\hat{x}+y\hat{y}+z\hat{z}}{\sqrt{x^2+y^2+z^2}}\vert da\vert$$
where the magnitude is $\vert da \vert=r^2\sin^2\theta d\theta d\phi$. So I'm immediately stuck in this problem, because the dot product term is tricky. I've tried to simplify it via factoring terms etc, but no luck so far. Eventually this will be computed in spherical coordinates with $r=2$. How should I work with this dot product term?
EDIT : I'm trying to compute the flux, and I am not applying the divergence theorem here.
 A: Divergence Theorem gives:-
$$\iint_{S}F\,dS=\iiint_{V}\nabla\cdot F\,dV$$
$$\nabla\cdot F = 1+x+xy$$.
Now you convert into spherical polar coordinates and integrate over the sphere
$$\int_{0}^{2}\int_{0}^{2\pi}\int_{0}^{\pi}\left(1+r\cos(\phi)\sin(\theta)+r^{2}\cos(\phi)\sin(\phi)\sin^{2}(\theta)\right)r^{2}\sin(\theta)\,d\theta\,d\phi\,dr$$.
The integral is actually much simpler as $\int_{0}^{2\pi}\cos(\phi)\,d\phi=0$ and $\int_{0}^{2\pi}\cos(\phi)\sin(\phi)\,d\phi=0$
So only the first term survives and gives you $\frac{4\pi}{3}\cdot 2^{3}$ which is precisely the volume of the sphere.
Else you can also view it logically. both $x$ and $xy$ are symmetric about the sphere. So their volume integral should give you $0$. So only the term for $1$ survives. And integral of $1$ over the volume of the sphere is precisely the volume of the sphere.
Otherwise if you want to go for direct surface integral as you were trying , you need to integrate over the surface of the upper hemisphere with the normal vector oriented towards the positive $z$ axis. And for the lower hemisphere you need the normal oriented towards negative $z$ axis and then integrate using $\iint_{S}F\,dS=\iint \frac{F\cdot \vec{n}}{|\vec{n}\cdot \hat{z}|}\,dxdy$ for both the upper and lower hemisphere.
the normal vector to the surface of the sphere is given by the gradient
So we have for the upper hemisphere where $z=\sqrt{4-x^{2}-y^{2}}$
So the gradient would be $\hat{z}+\frac{x}{\sqrt{4-x^{2}-y^{2}}}\hat{x}+\frac{y}{\sqrt{4-x^{2}-y^{2}}}\hat{y}$
Following the formula I gave above we get:-
The integral is :-
$$\iint_{D}\left(\frac{x^{2}}{\sqrt{4-x^{2}-y^{2}}}+\frac{xy^{2}}{\sqrt{4-x^{2}-y^{2}}}+xyz\right)\,dxdy$$.
Convert to polar coordinates to get
$$\int_{0}^{2}\int_{0}^{2\pi}\frac{\left(r^{2}\left(\cos\left(t\right)\right)^{2}+r^{3}\sin\left(t\right)\cos\left(t\right)+r^{2}\left(4-r^{2}\right)\right)}{\sqrt{4-r^{2}}}rdtdr$$.
Similarly we do it for the lower hemisphere. The only difference is that
for the normal you would need to find the gradient of $z=-\sqrt{4-x^{2}-y^{2}}$ . And as you might have guessed , we need to keep it pointed towards $-\hat{z}$ .
So we actually need to find the gradient of $ -\sqrt{4-x^{2}-y^{2}}-z\equiv 0$
We get the gradient as $$\frac{x}{\sqrt{4-x^{2}-y^{2}}}\hat{x}+\frac{y}{\sqrt{4-x^{2}-y^{2}}}\hat{y}-\hat{z}$$
Now again following the formula and converting to polar we get
$$\int_{0}^{2}\int_{0}^{2\pi}\frac{\left(r^{2}\left(\cos\left(t\right)\right)^{2}+r^{3}\sin\left(t\right)\cos\left(t\right)-r^{2}\left(4-r^{2}\right)\right)}{\sqrt{4-r^{2}}}rdtdr$$
Add them up to get
$$2\int_{0}^{2}\int_{0}^{2\pi}\frac{\left(r^{2}\left(\cos\left(t\right)\right)^{2}+r^{3}\sin\left(t\right)\cos\left(t\right)\right)}{\sqrt{4-r^{2}}}rdtdr$$
Now again $\int_{0}^{2\pi}\sin(t)\cos(t)\,dt=0$
So we have :-
$$2\int_{0}^{2}\int_{0}^{2\pi}\frac{r^{2}\left(\cos\left(t\right)\right)^{2}}{\sqrt{4-r^{2}}}rdtdr$$
$$=2\pi\int_{0}^{2}\frac{r^{3}}{\sqrt{4-r^{2}}}\,dr=\frac{32\pi}{3}$$
Thus both ways give the same answer.
Remember that you cannot integrate over the whole sphere at once. You have to respect the direction of the normal and break it into upper and lower hemisphere.
