# Find the direction of the gradient on a finite element mesh

Suppose we have a triangular mesh of a two dimensional shape $\Omega$, and on this mesh we define a P1 finite element structure. I know that given $u,v$ by their values at the vertices of the triangles, we can compute $\int_\Omega \nabla u \cdot \nabla v$ using the stiffness matrix $A = (\int_\Omega \nabla \varphi_i\cdot \nabla\varphi_j)$ (where $\varphi_i$ is the P1 basis). This makes it possible to find expressions of the form $\int_\Omega |\nabla u|^2$ if $u$ is known at the triangle vertices.

How can we compute the approximation of the gradient $\nabla u$, given the values of $u$ on the points?

I know that the gradient of $\varphi_i$ is constant on each triangle, but how do we need to combine these gradients for heighboring triangles, such that the value we obtain in the end is relevant.

The purpose of doing this: I would like to integrate a quantity of the form $\int_\Omega \varphi(\nabla u)^2$, where $\varphi$ is a norm, different from the euclidean one. Now that I think about it, I guess it is necessary to compute the matrix $A = \int_\Omega b(\nabla \varphi_i,\nabla \varphi_j)$, where $b$ is the scalar product associated to $\varphi$.

• I think the best answer for this depends on your need for the gradient. If you intend to use it to compute an integrated quantity, then you are best served by just computing the integrated quantity just like you would the bilinear form. I.e., just introduce the basis, do the arithmetic to simplify , and integrate using quadrature. The fact that a direct computation of the gradient is multivalued won't matter. If you need to plot a single-valued vector function of the gradient or use it elsewhere at the points of the mesh, then you need some sort of recovery technique. – Bill Barth Apr 19 '15 at 17:37

• Your solution is defined as $u_h(x) = \sum_j U_j \phi_j(x)$.
• If you want to compute $\int_\Omega \varphi(\nabla u_h(x)) dx$ (i.e., a number), then you need to replace the integral with a quadrature formula. If you use piecewise linear elements, then the one-point midpoint formula is sufficient, i.e., $$\int_\Omega \varphi(\nabla u_h(x)) dx = \sum_K |K| \; \varphi(\nabla u_h(x_K))$$ where $x_K$ is the midpoint (or, in fact, any point in the interior) of cell $K$.
• So you only need to evaluate $\nabla u_h(x_K)$. Using the definition of $u_h$, you get that this equals $$\nabla u_h(x_K) = \sum_j U_j \nabla \phi_j(x_K).$$ On the other hand, because all shape functions are zero on cell $K$ except the ones defined at the three vertices of $K$, you have that in fact $$\nabla u_h(x_K) = \sum_{j_K=1}^3 U_{j(j_K)} \nabla \phi_{j(j_K)}(x_K) = \sum_{j_K=1}^3 U_{j(j_K)} \nabla \phi^K_{j_K}(x_K).$$ Here, $j(j_K)$ is the global index of the $j_K$-th shape function on cell $K$ where $j_K=1..3$, and $\phi^K_{j_K}$ are the three shape functions defined on cell $K$.
So, if you can evaluate the gradients of the three shape functions on cell $K$, then you can compute $\nabla u_h(x_K)$ and then $\varphi(\nabla u_h(x_K)$ and from there the whole integral.