This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Discrete Gradient

+4 votes

I am trying to use Hiptmair's multigrid for Maxwell's equations. Within this I need to be able to produce a matrix C that is in the kernel of the curl operator. This means that I need to be able to produce a discrete gradient matrix.

The matrix takes the following form

$$\nabla \phi_i = \sum_{i = 1}^n C_{i,j}\psi_i, \ \ \ \ j = 1,\ldots,m$$

where
$\psi$ and $\phi$ belongs to the finite element spaces associated with Nedelec elements and nodal elements respectively

asked Mar 10, 2014 by mwathen FEniCS Novice (710 points)
retagged Mar 11, 2014 by mwathen

1 Answer

+4 votes

There are no questions here, so I'll just give some comments.

A matrix corresponding to the gradient can be computed as

u = TrialFunction(...)
v = TestFunction(...)
A = assemble(inner(grad(u), v)*dx

Here v is a field of Nedelec type and u needs to be in
a compatible space.

Notice that the matrix (as always in the FEM method) will be
a mapping between the nodal (left hand side) representation
and the dual (right hand side) representation. If you want
the gradient in the nodal representation you should invert
the (lumped) mass matrix or something similar.

answered Mar 14, 2014 by Kent-Andre Mardal FEniCS Expert (14,380 points)

This is probably not exactly what I meant. If you are given a scalar function $u$ in a standard nodal space its gradient $\nabla u$ belongs to the Nedelec space. Hence, if $\psi_j$ are basis function of the Nedelec space we can write

$$\nabla u = \sum_{j=1}^{n} c_{j}\psi_j$$

So the coefficients $c_j$ are determined by interpolation of the grad of $\nabla u$ over the Nedelec DOFs. Is there a way implement this interpolation procedure without solving a linear system using the existing FEniCS commands?

You would need to loop through the elements and calculate the local info.
In this sense it is similar to what Mikael has done here:
https://github.com/mikaem/fenicstools/blob/master/demo/WeightedGradient.py
(but you would need to look at the underlying C++ code)
https://github.com/mikaem/fenicstools/blob/master/fenicstools/fem/gradient_weight.cpp

...