Skip to content

Commit e0a1dc4

Browse files
committed
Merge branch 'master' of github.com:gridap/GridapDistributed.jl into bugfix-vtk
2 parents ebbc2d0 + d8e5289 commit e0a1dc4

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

NEWS.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Fixed
1111

12+
- 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).
1213
- Fixed bug in writevtk when dealing with empty processors. Since PR[#158](https://github.com/gridap/GridapDistributed.jl/pull/158).
1314

1415
## [0.4.4] 2024-08-14

src/Geometry.jl

+26-9
Original file line numberDiff line numberDiff line change
@@ -474,8 +474,21 @@ function Geometry.get_background_model(a::DistributedTriangulation)
474474
a.model
475475
end
476476

477-
function Geometry.num_cells(a::DistributedTriangulation)
478-
sum(map(trian->num_cells(trian),local_views(a)))
477+
function Geometry.num_cells(a::DistributedTriangulation{Df}) where Df
478+
gids = get_face_gids(a.model,Df)
479+
n_loc_ocells = map(local_views(a),partition(gids)) do a, gids
480+
glue = get_glue(a,Val(Df))
481+
@assert isa(glue,FaceToFaceGlue)
482+
tcell_to_mcell = glue.tface_to_mface
483+
if isa(tcell_to_mcell,IdentityVector)
484+
own_length(gids)
485+
else
486+
mcell_to_owned = local_to_own(gids)
487+
is_owned(mcell) = !iszero(mcell_to_owned[mcell])
488+
sum(is_owned,tcell_to_mcell)
489+
end
490+
end
491+
return sum(n_loc_ocells)
479492
end
480493

481494
# Triangulation constructors
@@ -670,19 +683,23 @@ function add_ghost_cells(dtrian::DistributedTriangulation)
670683
add_ghost_cells(dmodel,dtrian)
671684
end
672685

673-
function _covers_all_faces(dmodel::DistributedDiscreteModel{Dm},
674-
dtrian::DistributedTriangulation{Dt}) where {Dm,Dt}
675-
covers_all_faces=map(local_views(dmodel),local_views(dtrian)) do model, trian
686+
function _covers_all_faces(
687+
dmodel::DistributedDiscreteModel{Dm},
688+
dtrian::DistributedTriangulation{Dt}
689+
) where {Dm,Dt}
690+
covers_all_faces = map(local_views(dmodel),local_views(dtrian)) do model, trian
676691
glue = get_glue(trian,Val(Dt))
677692
@assert isa(glue,FaceToFaceGlue)
678693
isa(glue.tface_to_mface,IdentityVector)
679694
end
680695
reduce(&,covers_all_faces,init=true)
681696
end
682697

683-
function add_ghost_cells(dmodel::DistributedDiscreteModel{Dm},
684-
dtrian::DistributedTriangulation{Dt}) where {Dm,Dt}
685-
covers_all_faces=_covers_all_faces(dmodel,dtrian)
698+
function add_ghost_cells(
699+
dmodel::DistributedDiscreteModel{Dm},
700+
dtrian::DistributedTriangulation{Dt}
701+
) where {Dm,Dt}
702+
covers_all_faces = _covers_all_faces(dmodel,dtrian)
686703
if (covers_all_faces)
687704
trians = map(local_views(dmodel)) do model
688705
Triangulation(ReferenceFE{Dt},model)
@@ -703,7 +720,7 @@ function add_ghost_cells(dmodel::DistributedDiscreteModel{Dm},
703720
cache=fetch_vector_ghost_values_cache(mcell_intrian,partition(gids))
704721
fetch_vector_ghost_values!(mcell_intrian,cache) |> wait
705722

706-
dreffes=map(local_views(dmodel)) do model
723+
dreffes = map(local_views(dmodel)) do model
707724
ReferenceFE{Dt}
708725
end
709726
trians = map(Triangulation,dreffes,local_views(dmodel),mcell_intrian)

test/GeometryTests.jl

+4
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,19 @@ function main(distribute,parts)
5959

6060
Ω = Triangulation(with_ghost,model)
6161
writevtk(Ω,joinpath(output,"Ω"))
62+
@test num_cells(Ω) == num_cells(model)
6263

6364
Ω = Triangulation(no_ghost,model)
6465
writevtk(Ω,joinpath(output,"Ω"))
66+
@test num_cells(Ω) == num_cells(model)
6567

6668
Γ = Boundary(with_ghost,model,tags="boundary")
6769
writevtk(Γ,joinpath(output,"Γ"))
70+
nbfacets = num_cells(Γ)
6871

6972
Γ = Boundary(no_ghost,model,tags="boundary")
7073
writevtk(Γ,joinpath(output,"Γ"))
74+
@test num_cells(Γ) == nbfacets
7175

7276
function is_in(coords)
7377
R = 1.6

0 commit comments

Comments
 (0)