@@ -366,22 +366,36 @@ def test_mixed_blocked_constant():
366366
367367@pytest .mark .parametrize ("shape" , [(), (2 ,), (3 , 2 )])
368368def test_blocked_dof_ownership (shape ):
369+ """Test that dof ownership is correctly handled for blocked function spaces."""
369370 mesh = create_unit_square (MPI .COMM_WORLD , 4 , 4 )
370371 V = functionspace (mesh , ("Lagrange" , 1 , shape ))
371-
372372 u_bc = Function (V )
373- mesh .topology .create_connectivity (mesh .topology .dim - 1 , mesh .topology .dim )
374- bc_facets = exterior_facet_indices (mesh .topology )
375- # Blocked spaces are not unrolled here
376- bc_dofs_u = locate_dofs_topological (V , mesh .topology .dim - 1 , bc_facets )
377-
378- # Num owned dofs
379- num_owned_blocked = V .dofmap .index_map .size_local
380373
381- input_dofs_owned = bc_dofs_u [bc_dofs_u < num_owned_blocked ]
374+ tdim = mesh .topology .dim
375+ mesh .topology .create_connectivity (tdim - 1 , tdim )
376+ boundary_facets = exterior_facet_indices (mesh .topology )
377+ boundary_dofs = locate_dofs_topological (V , tdim - 1 , boundary_facets )
382378
383- bc = dirichletbc (u_bc , bc_dofs_u )
384- unrolled_bc_dofs , num_owned = bc .dof_indices ()
379+ # Test full space BC
380+ bc = dirichletbc (u_bc , boundary_dofs )
381+ unrolled_dofs , num_owned = bc .dof_indices ()
385382
386- assert len (input_dofs_owned ) * V .dofmap .index_map_bs == num_owned
387- assert len (unrolled_bc_dofs ) == len (bc_dofs_u ) * V .dofmap .index_map_bs
383+ num_owned_blocked = V .dofmap .index_map .size_local
384+ bs = V .dofmap .index_map_bs
385+ owned_input_dofs = boundary_dofs [boundary_dofs < num_owned_blocked ]
386+
387+ assert len (owned_input_dofs ) * bs == num_owned
388+ assert len (unrolled_dofs ) == len (boundary_dofs ) * bs
389+
390+ # Test subspace BC for tensor spaces
391+ if len (shape ) > 1 :
392+ V0 , _ = V .sub (0 ).collapse ()
393+ boundary_dofs = locate_dofs_topological ((V .sub (0 ), V0 ), tdim - 1 , boundary_facets )
394+ bc_sub = dirichletbc (u_bc , boundary_dofs , V )
395+ unrolled_dofs_sub , num_owned_sub = bc_sub .dof_indices ()
396+
397+ # Check number of unrolled owned dofs in the full non-collapsed space
398+ boundary_dofs_V = boundary_dofs [0 ]
399+ owned_sub_dofs = boundary_dofs_V [boundary_dofs_V < num_owned_blocked * bs ]
400+ assert len (owned_sub_dofs ) == num_owned_sub
401+ assert len (unrolled_dofs_sub ) == len (boundary_dofs_V )
0 commit comments