How to set up a function space consisting of multiple domains from an imported gmsh mesh for an elasticity analysis

You are assuming a 1 to 1 relationship between the dofs of a DG-1 space and the cell indices. This is not correct, as there is only a 1-1 relationship between a DG-0 space and the cell indices. So i would suggest using a DG-0 space.

See also part two of the tutorial: Defining subdomains for different materials — FEniCSx tutorial
which creates materials based on cell data from the mesh markers.

1 Like