I am in the process of writing a finite element solver for the Navier-Stokes equations and am having trouble computing things like the divergence and vorticity correctly. Currently to compute the vorticity,
$\omega = \frac{\partial{v}}{\partial{x}} - \frac{\partial{u}}{\partial{y}}$,
I would multiply the r.h.s by a test function and integrate over the element. This gives element matrices of the form:
$\Sigma_{i}\int\int_{\Omega}v_{i}\frac{d\phi_{i}}{dx}\phi_{j}dA \hspace{5mm}\text{and}\hspace{5mm} \Sigma_{i}\int\int_{\Omega}u_{i}\frac{d\phi_{i}}{dy}\phi_{j}dA$,
after plugging in our expansions for u and v. This however appears to be the wrong way to do this since my results do not look right. For example after computing the u and v velocity fields:
my vorticity looks like:
In particular the vorticity appears very non-smooth. Here is another example showing the u-velocity and vorticity (zoomed in for clarity):
I have a similar problem with calculating the divergence. It seems that my computed velocity field is not smooth enough and thus when computing the vorticity and divergence I get many positive and negative gradients resulting in choppy fields. So my question is, how do you calculate the vorticity (or divergence) of a computed velocity field using finite elements?