Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test for collapsing function spaces #2919

Merged
merged 7 commits into from
Dec 5, 2023
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions python/test/unit/fem/test_function_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,30 @@ def test_clone(W):


def test_collapse(W, V):
Vs = W.sub(2)
with pytest.raises(RuntimeError):
Function(Vs)
assert Vs.dofmap.cell_dofs(0)[0] != V.dofmap.cell_dofs(0)[0]

# Collapse the space it should now be the same as V
Vc = Vs.collapse()[0]
assert Vc.dofmap.cell_dofs(0)[0] == V.dofmap.cell_dofs(0)[0]
f0 = Function(V)
f1 = Function(Vc)
assert f0.vector.getSize() == f1.vector.getSize()
Function(W.sub(1))

Ws = [W.sub(i).collapse() for i in range(W.num_sub_spaces)]

msh = W.mesh
cell_imap = msh.topology.index_map(msh.topology.dim)
num_cells = cell_imap.size_local + cell_imap.num_ghosts
bs = W.dofmap.index_map_bs
for c in range(num_cells):
cell_dofs = W.dofmap.cell_dofs(c)
for (i, dof) in enumerate(cell_dofs):
for k in range(bs):
new_dof = Ws[k][0].dofmap.cell_dofs(c)[i]
new_to_old = Ws[k][1]
assert dof * bs + k == new_to_old[new_dof]

f_0 = Function(Ws[0][0])
f_1 = Function(V)
assert f_0.vector.getSize() == f_1.vector.getSize()

# FIXME Should this work?
# for Ws_i in Ws:
# assert np.array_equal(Ws_i[0].dofmap.list, V.dofmap.list)


def test_argument_equality(mesh, V, V2, W, W2):
Expand Down
Loading