DOF ordering identical for sub-spaces of vector function space?

Hi all,

in dolfinx, will all collapsed subspaces of a VectorFunctionSpace have the same DOF ordering in parallel?

Context: I have a vectorial PDE where, if written component-wise, all vector components have the same LHS matrix. For efficiency, I want to solve for the components separately, i.e., solve d small N\times N problems with the same linear operator (edited for clarity) instead of one expensive Nd\times Nd solve

A simple example seems to assert that this is the case, but am I safe to assume generality here?

from dolfinx import mesh, fem
from mpi4py import MPI
import numpy as np

N = 16
mesh = mesh.create_unit_cube(MPI.COMM_WORLD, N, N, N)
V = fem.VectorFunctionSpace(mesh, ("CG", 1))
spaces = []
for i in range(V.num_sub_spaces):
    space_i, _ = V.sub(i).collapse()
    spaces.append(space_i)

# "scalar" function space
Vc = fem.FunctionSpace(mesh, ("CG", 1))

# check if DOF ordering looks the same...
assert np.allclose(
    spaces[0].tabulate_dof_coordinates(), spaces[1].tabulate_dof_coordinates()
)
assert np.allclose(
    spaces[0].tabulate_dof_coordinates(), spaces[2].tabulate_dof_coordinates()
)
assert np.allclose(spaces[0].tabulate_dof_coordinates(), Vc.tabulate_dof_coordinates())

assert spaces[0].dofmap.list == spaces[1].dofmap.list == spaces[2].dofmap.list
assert spaces[0].dofmap.list == Vc.dofmap.list

A similar question was asked here but for legacy fenics: Dof ordering: VectorFunctionSpace sub(0) vs. FunctionSpace

Thanks!

Why do you need to know if the ordering is the same?

The second return argument in

is the map from the dof in the collapsed space to the dof in the parent space. Using this map, you will be able to map a solution from a sub space to the parent (vector) space.

Sorry, I hardly explained what’s most important:
If the ordering is the same, the assembled system matrices would be identical and could be used for all components, reducing assembly and ksp/pc setup time.

If the function space is just a VectorFunctionSpace, the ordering should be identical for each component, as the dofmap and index map has corresponding block sizes.
Thus you can use the same matrix for each sub component.
You could verify this by looking at the maps coming out of collapse (you would need those maps to map the data into a vector function space at the end anyhow).

1 Like

Great, thanks! I omitted the maps in the example because I didn’t use them there, but they indeed show consistent ordering