Block_size of a mixed element in DOLFINx

I am a little confused with the meaning of the block_size property of a mixed element in FEniCSx. Consider the following FEniCS code:

from dolfin import *
mesh = UnitSquareMesh(1, 1)
FE   = FiniteElement("Lagrange", mesh.ufl_cell(), 1)
ME   = MixedElement([FE, FE])
V_ME = FunctionSpace(mesh, ME)
V    = VectorFunctionSpace(mesh, "CG", 1)

print(V_ME.dofmap().block_size())         # 2
print(V.dofmap().block_size())            # 2

I think the result 2 of block_size() means the number of components in a mixed element function space as that in a vector function space. However, the equivalent FEniCSx code (version 0.6.0) in my mind returns 1 for a mixed element function space as follows

from mpi4py import MPI
from dolfinx import mesh, fem
from ufl import FiniteElement, MixedElement
msh  = mesh.create_unit_square(MPI.COMM_WORLD, 2, 2)
FE   = FiniteElement("Lagrange", msh.ufl_cell(), 1)
ME   = MixedElement([FE, FE])
V_ME = fem.FunctionSpace(msh, ME)
V    = fem.VectorFunctionSpace(msh, ("CG", 1))

print(V_ME.dofmap.index_map_bs)           # 1
print(V.dofmap.index_map_bs)              # 2

Consider Getting cell dofs for vector valued function space in dolfinx.

Please note that you are comparing two different block sizes.
Note that DOLFINx also has a DofMap block size, which tells you if dofs are blocked in the cell_dofs, i.e.

print(V_ME.dofmap.bs)
 1
print(V_ME.dofmap.cell_dofs(0))
array([0, 1, 2, 3, 4, 5], dtype=int32)

Note that for V, you get:

print(V.dofmap.bs)
2
print(V.dofmap.cell_dofs(0))
print(array([0, 1, 2], dtype=int32))

You would need to unroll the latter to get all of the degrees of freedom.

In general I would advice you to use vector-elements (also known as blocked elements) whenever you know that you have copies of the same finite element basis functions in an N-dimensional tensor.

There are no optimizations to the dofmap of the mixed elements to convert them to vector/block spaces if you supply them as a mixed element in dolfinx.

2 Likes