Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 2 additions & 3 deletions cpp/dolfinx/fem/DirichletBC.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,8 @@ class DirichletBC
std::size_t num_owned(const DofMap& dofmap,
std::span<const std::int32_t> dofs)
{
int bs = dofmap.index_map_bs();
std::int32_t map_size = dofmap.index_map->size_local();
std::int32_t owned_size = bs * map_size;
std::int32_t owned_size = map_size;
auto it = std::ranges::lower_bound(dofs, owned_size);
return std::distance(dofs.begin(), it);
}
Expand Down Expand Up @@ -383,8 +382,8 @@ class DirichletBC
// Unroll _dofs0 if dofmap block size > 1
if (const int bs = _function_space->dofmap()->bs(); bs > 1)
{
_owned_indices0 *= bs;
_dofs0 = unroll_dofs(_dofs0, bs);
_owned_indices0 *= bs;
}
}

Expand Down
25 changes: 24 additions & 1 deletion python/test/unit/fem/test_bcs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2020-2021 Joseph P. Dean, Massimiliano Leoni and Jørgen S. Dokken
# Copyright (C) 2020-2025 Joseph P. Dean, Massimiliano Leoni and Jørgen S. Dokken
#
# This file is part of DOLFINx (https://www.fenicsproject.org)
#
Expand Down Expand Up @@ -362,3 +362,26 @@ def test_mixed_blocked_constant():
with pytest.raises(RuntimeError):
dofs1 = locate_dofs_topological(W.sub(1), tdim - 1, boundary_facets)
dirichletbc(c1, dofs1, W.sub(1))


@pytest.mark.parametrize("shape", [(), (2,), (3, 2)])
def test_blocked_dof_ownership(shape):
mesh = create_unit_square(MPI.COMM_WORLD, 4, 4)
V = functionspace(mesh, ("Lagrange", 1, shape))

u_bc = Function(V)
mesh.topology.create_connectivity(mesh.topology.dim - 1, mesh.topology.dim)
bc_facets = exterior_facet_indices(mesh.topology)
# Blocked spaces are not unrolled here
bc_dofs_u = locate_dofs_topological(V, mesh.topology.dim - 1, bc_facets)

# Num owned dofs
num_owned_blocked = V.dofmap.index_map.size_local

input_dofs_owned = bc_dofs_u[bc_dofs_u < num_owned_blocked]

bc = dirichletbc(u_bc, bc_dofs_u)
unrolled_bc_dofs, num_owned = bc.dof_indices()

assert len(input_dofs_owned) * V.dofmap.index_map_bs == num_owned
assert len(unrolled_bc_dofs) == len(bc_dofs_u) * V.dofmap.index_map_bs
Loading