Hi all!
I’m trying to determine if a function space is a subspace for a wrapper that I’m writing. My current method is to run a try block searching for a RunTimeError on the the collapse()
function. Is there another attribute available though the python API I could use?
MWE:
import dolfinx
import basix
from mpi4py import MPI
def is_subspace(space):
try:
space.collapse()
return True
except RuntimeError as e:
if "Function space is not a subspace" in str(e):
return False
else:
raise
# Define mesh
mesh = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, 20, 20, dolfinx.mesh.CellType.quadrilateral)
# Define poly, quad, and mixed elements
PE = basix.ufl.element('CG', mesh.basix_cell(), degree=1)
QE = basix.ufl.element('CG', mesh.basix_cell(), degree=1, shape=(mesh.topology.dim,))
ME = basix.ufl.mixed_element([QE, PE])
# Define function spaces
V = dolfinx.fem.functionspace(mesh, ME)
V_subspace = V.sub(0)
W = dolfinx.fem.functionspace(mesh, PE)
# Check if the space is a subspace of a mixed function space
print(is_subspace(V_subspace)) # ---> Returns true
print(is_subspace(W)) # ---> Returns false