From 995627881e426eaa70e0e0beb48341f32d3256ac Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Mon, 28 Oct 2024 11:38:44 +1100 Subject: [PATCH 1/4] Bugfix: Wrong num_cells for triangulations containing ghosts --- src/Geometry.jl | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/src/Geometry.jl b/src/Geometry.jl index 4c78824..9e2d00c 100644 --- a/src/Geometry.jl +++ b/src/Geometry.jl @@ -474,8 +474,21 @@ function Geometry.get_background_model(a::DistributedTriangulation) a.model end -function Geometry.num_cells(a::DistributedTriangulation) - sum(map(trian->num_cells(trian),local_views(a))) +function Geometry.num_cells(a::DistributedTriangulation{Df}) where Df + gids = get_face_gids(a.model,Df) + n_loc_ocells = map(local_views(a),partition(gids)) do a, gids + glue = get_glue(a,Val(Df)) + @assert isa(glue,FaceToFaceGlue) + tcell_to_mcell = glue.tface_to_mface + if isa(tcell_to_mcell,IdentityVector) + own_length(gids) + else + mcell_to_owned = local_to_own(gids) + is_owned(mcell) = !iszero(mcell_to_owned[mcell]) + sum(is_owned,tcell_to_mcell) + end + end + return sum(n_loc_ocells) end # Triangulation constructors @@ -670,9 +683,11 @@ function add_ghost_cells(dtrian::DistributedTriangulation) add_ghost_cells(dmodel,dtrian) end -function _covers_all_faces(dmodel::DistributedDiscreteModel{Dm}, - dtrian::DistributedTriangulation{Dt}) where {Dm,Dt} - covers_all_faces=map(local_views(dmodel),local_views(dtrian)) do model, trian +function _covers_all_faces( + dmodel::DistributedDiscreteModel{Dm}, + dtrian::DistributedTriangulation{Dt} +) where {Dm,Dt} + covers_all_faces = map(local_views(dmodel),local_views(dtrian)) do model, trian glue = get_glue(trian,Val(Dt)) @assert isa(glue,FaceToFaceGlue) isa(glue.tface_to_mface,IdentityVector) @@ -680,9 +695,11 @@ function _covers_all_faces(dmodel::DistributedDiscreteModel{Dm}, reduce(&,covers_all_faces,init=true) end -function add_ghost_cells(dmodel::DistributedDiscreteModel{Dm}, - dtrian::DistributedTriangulation{Dt}) where {Dm,Dt} - covers_all_faces=_covers_all_faces(dmodel,dtrian) +function add_ghost_cells( + dmodel::DistributedDiscreteModel{Dm}, + dtrian::DistributedTriangulation{Dt} +) where {Dm,Dt} + covers_all_faces = _covers_all_faces(dmodel,dtrian) if (covers_all_faces) trians = map(local_views(dmodel)) do model Triangulation(ReferenceFE{Dt},model) @@ -703,7 +720,7 @@ function add_ghost_cells(dmodel::DistributedDiscreteModel{Dm}, cache=fetch_vector_ghost_values_cache(mcell_intrian,partition(gids)) fetch_vector_ghost_values!(mcell_intrian,cache) |> wait - dreffes=map(local_views(dmodel)) do model + dreffes = map(local_views(dmodel)) do model ReferenceFE{Dt} end trians = map(Triangulation,dreffes,local_views(dmodel),mcell_intrian) From 1add052a3a69989b5fa2e0ff57fbf3b7ed8bf321 Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Mon, 28 Oct 2024 11:43:16 +1100 Subject: [PATCH 2/4] Updated NEWS --- NEWS.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/NEWS.md b/NEWS.md index c69eb42..17541d5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Fixed + +- Fixed bug in `num_cells` in the case where a `DistributedTriangulation` contained ghost cells. Since PR[#160](https://github.com/gridap/GridapDistributed.jl/pull/160). + ## [0.4.4] 2024-08-14 ### Added From 8b43ee48b8839900da1510ce5bfacbf3337f241e Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Mon, 28 Oct 2024 13:02:58 +1100 Subject: [PATCH 3/4] Added tests --- test/GeometryTests.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/GeometryTests.jl b/test/GeometryTests.jl index beeae4d..2b65d3e 100644 --- a/test/GeometryTests.jl +++ b/test/GeometryTests.jl @@ -59,9 +59,11 @@ function main(distribute,parts) Ω = Triangulation(with_ghost,model) writevtk(Ω,joinpath(output,"Ω")) + @test num_cells(Ω) == num_cells(model) Ω = Triangulation(no_ghost,model) writevtk(Ω,joinpath(output,"Ω")) + @test num_cells(Ω) == num_cells(model) Γ = Boundary(with_ghost,model,tags="boundary") writevtk(Γ,joinpath(output,"Γ")) From 977c878046a4aef7bbf4f3129ea2f5d47b0fb905 Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Mon, 28 Oct 2024 13:04:18 +1100 Subject: [PATCH 4/4] More tests --- test/GeometryTests.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/GeometryTests.jl b/test/GeometryTests.jl index 2b65d3e..f46264a 100644 --- a/test/GeometryTests.jl +++ b/test/GeometryTests.jl @@ -67,9 +67,11 @@ function main(distribute,parts) Γ = Boundary(with_ghost,model,tags="boundary") writevtk(Γ,joinpath(output,"Γ")) + nbfacets = num_cells(Γ) Γ = Boundary(no_ghost,model,tags="boundary") writevtk(Γ,joinpath(output,"Γ")) + @test num_cells(Γ) == nbfacets function is_in(coords) R = 1.6