From a38ed022dbc7914b344920698ddab7debf7f1e57 Mon Sep 17 00:00:00 2001 From: Abdulaziz Date: Wed, 13 Nov 2024 18:39:15 +0100 Subject: [PATCH] Fix bug where boundary sets are broken for mixed grids --- src/Grid/utils.jl | 1 + test/test_grid_addboundaryset.jl | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/Grid/utils.jl b/src/Grid/utils.jl index ce5937010e..04400ae765 100644 --- a/src/Grid/utils.jl +++ b/src/Grid/utils.jl @@ -165,6 +165,7 @@ function _create_boundaryset(f::Function, grid::AbstractGrid, top::ExclusiveTopo cell_idx = ff_nh_idx[1] facet_nr = ff_nh_idx[2] cell = getcells(grid, cell_idx) + length(facets(cell)) < facet_nr && continue facet_nodes = facets(cell)[facet_nr] for (subentity_idx, subentity_nodes) in pairs(boundaryfunction(BI)(cell)) if Base.all(n -> n in facet_nodes, subentity_nodes) diff --git a/test/test_grid_addboundaryset.jl b/test/test_grid_addboundaryset.jl index ed3ca549ad..ed85602f50 100644 --- a/test/test_grid_addboundaryset.jl +++ b/test/test_grid_addboundaryset.jl @@ -200,4 +200,21 @@ addboundaryfacetset!(grid, topology, "test_boundary_facetset", filter_function) @test getfacetset(grid, "test_boundary_facetset") == Ferrite.create_boundaryfacetset(grid, topology, filter_function) end + + @testset "addboundaryset Mixed grid" begin + nodes = [Node((-1.0, 0.0)), Node((0.0, 0.0)), Node((1.0, 0.0)), Node((-1.0, 1.0)), Node((0.0, 1.0))] + cells = [ + Quadrilateral((1, 2, 5, 4)), + Triangle((3, 5, 2)), + ] + grid = Grid(cells, nodes) + topology = ExclusiveTopology(grid) + @test extractboundary(grid, topology) == extractboundarycheck(grid) + + filter_function(x) = x[1] > 0 + addboundaryvertexset!(grid, topology, "test_boundary_vertexset", filter_function) + @test getvertexset(grid, "test_boundary_vertexset") == Ferrite.create_boundaryvertexset(grid, topology, filter_function) + addboundaryfacetset!(grid, topology, "test_boundary_facetset", filter_function) + @test getfacetset(grid, "test_boundary_facetset") == Ferrite.create_boundaryfacetset(grid, topology, filter_function) + end end