Skip to content

Commit 95f1176

Browse files
committed
Fixed bug where Boundary(with_ghost, model) would also return the faces on the interface between processors
1 parent d04d19a commit 95f1176

1 file changed

Lines changed: 126 additions & 33 deletions

File tree

src/Geometry.jl

Lines changed: 126 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,27 @@ Geometry.num_point_dims(::Type{<:DistributedGrid{Dc,Dp}}) where {Dc,Dp} = Dp
3838
# This object cannot implement the GridTopology interface in a strict sense
3939
"""
4040
"""
41-
struct DistributedGridTopology{Dc,Dp,A} <: GridapType
41+
struct DistributedGridTopology{Dc,Dp,A,B} <: GridapType
4242
topos::A
43-
function DistributedGridTopology(topos::AbstractArray{<:GridTopology{Dc,Dp}}) where {Dc,Dp}
43+
face_gids::B
44+
function DistributedGridTopology(
45+
topos::AbstractArray{<:GridTopology{Dc,Dp}},
46+
face_gids::AbstractArray{<:PRange}
47+
) where {Dc,Dp}
4448
A = typeof(topos)
45-
new{Dc,Dp,A}(topos)
49+
B = typeof(face_gids)
50+
new{Dc,Dp,A,B}(topos,face_gids)
4651
end
4752
end
4853

54+
function DistributedGridTopology(
55+
topos::AbstractArray{<:GridTopology{Dc,Dp}}, cell_gids::PRange
56+
) where {Dc,Dp}
57+
face_gids = Vector{PRange}(undef,Dc+1)
58+
face_gids[Dc+1] = cell_gids
59+
return DistributedGridTopology(topos,face_gids)
60+
end
61+
4962
local_views(a::DistributedGridTopology) = a.topos
5063

5164
function Geometry.OrientationStyle(
@@ -63,6 +76,39 @@ Geometry.num_cell_dims(::Type{<:DistributedGridTopology{Dc,Dp}}) where {Dc,Dp} =
6376
Geometry.num_point_dims(::DistributedGridTopology{Dc,Dp}) where {Dc,Dp} = Dp
6477
Geometry.num_point_dims(::Type{<:DistributedGridTopology{Dc,Dp}}) where {Dc,Dp} = Dp
6578

79+
function get_cell_gids(topo::DistributedGridTopology{Dc}) where Dc
80+
topo.face_gids[Dc+1]
81+
end
82+
83+
function get_face_gids(topo::DistributedGridTopology,dim::Integer)
84+
_setup_face_gids!(topo,dim)
85+
return topo.face_gids[dim+1]
86+
end
87+
88+
function _setup_face_gids!(topo::DistributedGridTopology{Dc},dim) where {Dc}
89+
Gridap.Helpers.@check 0 <= dim <= Dc
90+
if !isassigned(topo.face_gids,dim+1)
91+
cell_gids = topo.face_gids[Dc+1]
92+
nlfaces = map(local_views(topo)) do topo
93+
num_faces(topo,dim)
94+
end
95+
cell_lfaces = map(local_views(topo)) do topo
96+
get_faces(topo, Dc, dim)
97+
end
98+
topo.face_gids[dim+1] = generate_gids(cell_gids,cell_lfaces,nlfaces)
99+
end
100+
end
101+
102+
function Geometry.get_isboundary_face(topo::DistributedGridTopology, d::Integer)
103+
face_gids = get_face_gids(topo, d)
104+
is_local_boundary = map(local_views(topo)) do topo
105+
get_isboundary_face(topo,d)
106+
end
107+
t = assemble!(&,PVector(is_local_boundary, partition(face_gids)))
108+
is_global_boundary = partition(fetch(consistent!(fetch(t))))
109+
return is_global_boundary
110+
end
111+
66112
"""
67113
"""
68114
struct DistributedFaceLabeling{A<:AbstractArray{<:FaceLabeling}}
@@ -72,12 +118,40 @@ end
72118
local_views(a::DistributedFaceLabeling) = a.labels
73119

74120
function Geometry.add_tag_from_tags!(labels::DistributedFaceLabeling, name, tags)
75-
map(labels.labels) do labels
121+
map(local_views(labels)) do labels
76122
add_tag_from_tags!(labels, name, tags)
77123
end
78124
end
79125

80-
# Dsitributed Discrete models
126+
function Geometry.get_face_mask(labels::DistributedFaceLabeling, tags, d::Integer)
127+
map(local_views(labels)) do labels
128+
get_face_mask(labels, tags, d)
129+
end
130+
end
131+
132+
function Geometry.FaceLabeling(topo::DistributedGridTopology)
133+
D = num_cell_dims(topo)
134+
labels = map(local_views(topo)) do topo
135+
d_to_ndfaces = [ num_faces(topo,d) for d in 0:D ]
136+
labels = FaceLabeling(d_to_ndfaces)
137+
for d in 0:D
138+
get_face_entity(labels,d) .= 1 # Interior as default
139+
end
140+
add_tag!(labels,"interior",[1])
141+
add_tag!(labels,"boundary",[2])
142+
return labels
143+
end
144+
for d in 0:D-1
145+
dface_to_is_boundary = get_isboundary_face(topo,d) # Global boundary
146+
map(labels,dface_to_is_boundary) do labels, dface_to_is_boundary
147+
dface_to_entity = get_face_entity(labels,d)
148+
dface_to_entity .+= dface_to_is_boundary
149+
end
150+
end
151+
return labels
152+
end
153+
154+
# Distributed Discrete models
81155
# We do not inherit from DiscreteModel on purpose.
82156
# This object cannot implement the DiscreteModel interface in a strict sense
83157

@@ -131,7 +205,7 @@ function Geometry.get_grid(model::DistributedDiscreteModel)
131205
end
132206

133207
function Geometry.get_grid_topology(model::DistributedDiscreteModel)
134-
DistributedGridTopology(map(get_grid_topology,local_views(model)))
208+
DistributedGridTopology(map(get_grid_topology,local_views(model)),model.face_gids)
135209
end
136210

137211
function Geometry.get_face_labeling(model::DistributedDiscreteModel)
@@ -503,55 +577,74 @@ function Geometry.Triangulation(model::DistributedDiscreteModel;kwargs...)
503577
Triangulation(no_ghost,ReferenceFE{D},model;kwargs...)
504578
end
505579

506-
function Geometry.Triangulation(::Type{ReferenceFE{D}}, model::DistributedDiscreteModel;kwargs...) where D
580+
function Geometry.Triangulation(::Type{ReferenceFE{D}},model::DistributedDiscreteModel;kwargs...) where D
507581
Triangulation(no_ghost, ReferenceFE{D}, model; kwargs...)
508582
end
509583

510-
function Geometry.BoundaryTriangulation(model::DistributedDiscreteModel;kwargs...)
511-
BoundaryTriangulation(no_ghost,model;kwargs...)
584+
function Geometry.Triangulation(portion, model::DistributedDiscreteModel;kwargs...)
585+
D = num_cell_dims(model)
586+
Triangulation(portion,ReferenceFE{D},model;kwargs...)
512587
end
513588

514-
function Geometry.BoundaryTriangulation(trian::DistributedTriangulation;kwargs...)
515-
BoundaryTriangulation(no_ghost,trian;kwargs...)
589+
function Geometry.Triangulation(
590+
portion,::Type{ReferenceFE{D}},model::DistributedDiscreteModel;kwargs...) where D
591+
gids = get_face_gids(model,D)
592+
trians = map(local_views(model)) do model
593+
Triangulation(ReferenceFE{D},model;kwargs...)
594+
end
595+
parent = DistributedTriangulation(trians,model)
596+
return filter_cells_when_needed(portion,gids,parent)
516597
end
517598

518-
function Geometry.SkeletonTriangulation(model::DistributedDiscreteModel;kwargs...)
519-
SkeletonTriangulation(no_ghost,model;kwargs...)
599+
function Geometry.BoundaryTriangulation(model::DistributedDiscreteModel,args...;kwargs...)
600+
BoundaryTriangulation(no_ghost,model,args...;kwargs...)
520601
end
521602

522-
function Geometry.SkeletonTriangulation(trian::DistributedTriangulation;kwargs...)
523-
SkeletonTriangulation(no_ghost,trian;kwargs...)
603+
function Geometry.BoundaryTriangulation(trian::DistributedTriangulation;kwargs...)
604+
BoundaryTriangulation(no_ghost,trian;kwargs...)
524605
end
525606

526-
function Geometry.Triangulation(portion, model::DistributedDiscreteModel;kwargs...)
527-
D = num_cell_dims(model)
528-
Triangulation(portion,ReferenceFE{D},model;kwargs...)
607+
function Geometry.BoundaryTriangulation(
608+
portion,model::DistributedDiscreteModel;kwargs...)
609+
labels = get_face_labeling(model)
610+
Geometry.BoundaryTriangulation(portion,model,labels;kwargs...)
529611
end
530612

531-
function Geometry.Triangulation(
532-
portion,::Type{ReferenceFE{Dt}},model::DistributedDiscreteModel{Dm};kwargs...) where {Dt,Dm}
533-
# Generate global ordering for the faces of dimension Dt (if needed)
534-
gids = get_face_gids(model,Dt)
535-
trians = map(local_views(model)) do model
536-
Triangulation(ReferenceFE{Dt},model;kwargs...)
613+
function Geometry.BoundaryTriangulation(
614+
portion,model::DistributedDiscreteModel,labels::DistributedFaceLabeling;tags=nothing)
615+
Dc = num_cell_dims(model)
616+
if isnothing(tags)
617+
topo = get_grid_topology(model)
618+
face_to_mask = get_isboundary_face(topo,Dc-1) # This is globally consistent
619+
else
620+
face_to_mask = get_face_mask(labels,tags,Dc-1)
537621
end
538-
parent = DistributedTriangulation(trians,model)
539-
return filter_cells_when_needed(portion,gids,parent)
622+
Geometry.BoundaryTriangulation(portion,model,face_to_mask)
540623
end
541624

542625
function Geometry.BoundaryTriangulation(
543-
portion,model::DistributedDiscreteModel{Dc};kwargs...) where Dc
544-
gids = get_face_gids(model,Dc)
545-
trians = map(local_views(model)) do model
546-
BoundaryTriangulation(model;kwargs...)
626+
portion,model::DistributedDiscreteModel,face_to_mask::AbstractArray)
627+
Dc = num_cell_dims(model)
628+
gids = get_face_gids(model,Dc)
629+
trians = map(local_views(model),face_to_mask) do model, face_to_mask
630+
BoundaryTriangulation(model,face_to_mask)
547631
end
548632
parent = DistributedTriangulation(trians,model)
549633
return filter_cells_when_needed(portion,gids,parent)
550634
end
551635

636+
function Geometry.SkeletonTriangulation(model::DistributedDiscreteModel;kwargs...)
637+
SkeletonTriangulation(no_ghost,model;kwargs...)
638+
end
639+
640+
function Geometry.SkeletonTriangulation(trian::DistributedTriangulation;kwargs...)
641+
SkeletonTriangulation(no_ghost,trian;kwargs...)
642+
end
643+
552644
function Geometry.SkeletonTriangulation(
553-
portion,model::DistributedDiscreteModel{Dc};kwargs...) where Dc
554-
gids = get_face_gids(model,Dc)
645+
portion,model::DistributedDiscreteModel;kwargs...)
646+
Dc = num_cell_dims(model)
647+
gids = get_face_gids(model,Dc)
555648
trians = map(local_views(model)) do model
556649
SkeletonTriangulation(model;kwargs...)
557650
end
@@ -614,7 +707,7 @@ function Geometry.InterfaceTriangulation(a::DistributedTriangulation,b::Distribu
614707
DistributedTriangulation(trians,a.model)
615708
end
616709

617-
# Filtering cells dispatch
710+
# Filtering cells
618711

619712
@inline function filter_cells_when_needed(
620713
portion::Union{WithGhost,FullyAssembledRows},cell_gids,trian)

0 commit comments

Comments
 (0)