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

Vertex submesh support #3455

Merged
merged 8 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion cpp/dolfinx/mesh/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,12 @@ create_subgeometry(const Mesh<T>& mesh, int dim,
// Create sub-geometry coordinate element
CellType sub_coord_cell
= cell_entity_type(geometry.cmap().cell_shape(), dim, 0);
fem::CoordinateElement<T> sub_cmap(sub_coord_cell, geometry.cmap().degree(),
// Special handling if point meshes, as they only support constant basis
// functions
int degree = geometry.cmap().degree();
if (sub_coord_cell == CellType::point)
degree = 0;
fem::CoordinateElement<T> sub_cmap(sub_coord_cell, degree,
geometry.cmap().variant());

// Sub-geometry input_global_indices
Expand Down
3 changes: 1 addition & 2 deletions python/dolfinx/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,11 +675,10 @@ def create_submesh(
submsh, entity_map, vertex_map, geom_map = _cpp.mesh.create_submesh(
msh._cpp_object, dim, entities
)
submsh_ufl_cell = ufl.Cell(to_string(submsh.topology.cell_type))
submsh_domain = ufl.Mesh(
basix.ufl.element(
"Lagrange",
submsh_ufl_cell.cellname(),
to_string(submsh.topology.cell_type),
submsh.geometry.cmap.degree,
basix.LagrangeVariant(submsh.geometry.cmap.variant),
shape=(submsh.geometry.dim,),
Expand Down
16 changes: 9 additions & 7 deletions python/test/unit/mesh/test_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,35 +503,37 @@ def boundary_2(x):


# TODO Test that submesh of full mesh is a copy of the mesh
@pytest.mark.parametrize("d", [2, 3])
@pytest.mark.parametrize("d", [1, 2, 3])
@pytest.mark.parametrize("n", [3, 6])
@pytest.mark.parametrize("codim", [0, 1, 2])
@pytest.mark.parametrize("marker", [lambda x: x[0] >= 0.5, lambda x: x[0] >= -1])
@pytest.mark.parametrize("ghost_mode", [GhostMode.none, GhostMode.shared_facet])
@pytest.mark.parametrize("simplex", [True, False])
def test_submesh_full(d, n, codim, marker, ghost_mode, simplex):
if d == codim:
pytest.xfail("Cannot create vertex submesh")
if d == 2:
if d == 1:
mesh = create_unit_interval(MPI.COMM_WORLD, n, ghost_mode=ghost_mode)
elif d == 2:
ct = CellType.triangle if simplex else CellType.quadrilateral
mesh = create_unit_square(MPI.COMM_WORLD, n, n, ghost_mode=ghost_mode, cell_type=ct)
else:
ct = CellType.tetrahedron if simplex else CellType.hexahedron
mesh = create_unit_cube(MPI.COMM_WORLD, n, n, n, ghost_mode=ghost_mode, cell_type=ct)

edim = mesh.topology.dim - codim
edim = max(mesh.topology.dim - codim, 0)
entities = locate_entities(mesh, edim, marker)
submesh, entity_map, vertex_map, geom_map = create_submesh(mesh, edim, entities)
submesh_topology_test(mesh, submesh, entity_map, vertex_map, edim)
submesh_geometry_test(mesh, submesh, entity_map, geom_map, edim)


@pytest.mark.parametrize("d", [2, 3])
@pytest.mark.parametrize("d", [1, 2, 3])
@pytest.mark.parametrize("n", [3, 6])
@pytest.mark.parametrize("boundary", [boundary_0, boundary_1, boundary_2])
@pytest.mark.parametrize("ghost_mode", [GhostMode.none, GhostMode.shared_facet])
def test_submesh_boundary(d, n, boundary, ghost_mode):
if d == 2:
if d == 1:
mesh = create_unit_interval(MPI.COMM_WORLD, n, ghost_mode=ghost_mode)
elif d == 2:
mesh = create_unit_square(MPI.COMM_WORLD, n, n, ghost_mode=ghost_mode)
else:
mesh = create_unit_cube(MPI.COMM_WORLD, n, n, n, ghost_mode=ghost_mode)
Expand Down
Loading