Ways to define vector elements

This is a short question regarding defining a vector valued trial/testfunction in fenicsx, more on syntax.

I am going throught mixed_poisson, Navier_Stokes, multiphenicsx_Navier since they both contain unknown functions as vectors. I collected ways to general vector element:

  1. Q_el = element("BDMCF", domain_cell(), k)
  2. P2 = element("Lagrange", msh.basix_cell(), 2, shape=(msh.geometry.dim,))
  3. Q_el = VectorElement("Lagrange", domain.ufl_cell(), k)

The second and the third entry determine the domain where the basis functions are generated and the order of these functions. The first entry specify the type of finite elements. “BDMCF” is a type of vector elements. The third entry in function element() specify the dimension of the element, say, shape=2 implies the element is a two dimensional vector. The defaut implies a scalar, i.e., shape=1. 1. Is this understanding correct? 2. I want to ask what’s the default dimension for vector element "BDMCF" and in VectorElement(). Is it equal to the dimension of the mesh, say, we have a three component vector in a box? 3. Is the vector element considered somewhat a form of mixed element so that to get the component we can simply use a line like u1, u2 = u.sub(0).collapse(), u.sub(1).collapse()?

Thank you very much!

The default shape is (), Which means a scalar value, (N,) would be a N-dimensional vector, (N,M) an NxM matrix etc

When it comes to BDMCF, see:

an element in this space has a vector basis, as seen in: DefElement
i.e. the degree of freedom is a scalar value, that is then multiplied by the vector basis to get a vector valued function.

As such an element has a scalar DOF and a vector valued basis, you cannot decompose it into sub spaces for coordinate components, as you can do with a VectorElement with a Lagrange basis.

It can even represent a matrix or a higher order tensor, so powerful!

Can you say more specific what does it mean by “degree of freedom”? Is it just the undetermined coefficients in the basis function of finite element?

The degrees of freedom is the coefficients in the linear combination of basis functions.

Thank you very much!

Hi dokken,

Is there any function space to store a third order tensor function? I’m now dealing third order tensors by storing them with 3 tensor function spaces, but it’s a bit messy.

Yes, legacy FEniCS has TensorElement, and DOLFINx uses basix, where you can supply the shape of your tensor as input, see for instance:
https://fenics.readthedocs.io/projects/ufl/en/latest/manual/form_language.html#tensor-elements
or

The tensor can be of

If I get this right then if I am using a DG0 element for a 3rd order tensor in 3D, it should be something:

Se = basix.element("DG", msh.basix_cell(), 0, shape=(3, 3, 3), dtype=PETSc.RealType)

Yes, that is correct.

However, you should use basix.ufl.element, as you want to have an element compatible with usage with UFL.