Skip to content

Commit e2c6947

Browse files
committed
Added a way to restrict gids
1 parent 3c6269e commit e2c6947

File tree

1 file changed

+52
-45
lines changed

1 file changed

+52
-45
lines changed

src/Geometry.jl

Lines changed: 52 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,14 @@ function Geometry.simplexify(model::DistributedDiscreteModel;kwargs...)
596596
return UnstructuredDiscreteModel(Adaptivity.get_model(ref_model))
597597
end
598598

599+
# Restrict
600+
601+
function Geometry.restrict(model::DistributedDiscreteModel, cell_to_parent_cell::AbstractArray)
602+
models = map(Geometry.restrict, local_views(model), cell_to_parent_cell)
603+
gids = restrict_gids(get_cell_gids(model), cell_to_parent_cell)
604+
return GenericDistributedDiscreteModel(models, gids)
605+
end
606+
599607
# Triangulation
600608

601609
# We do not inherit from Triangulation on purpose.
@@ -957,54 +965,53 @@ function generate_cell_gids(dmodel::DistributedDiscreteModel{Dm},
957965
if (covers_all_faces)
958966
tgids = mgids
959967
else
960-
# count number owned cells
961-
notcells, tcell_to_mcell = map(
962-
local_views(dmodel),local_views(dtrian),PArrays.partition(mgids)) do model,trian,partition
963-
lid_to_owner = local_to_owner(partition)
964-
part = part_id(partition)
968+
tcell_to_mcell = map(local_views(dtrian)) do trian
965969
glue = get_glue(trian,Val(Dt))
966970
@assert isa(glue,FaceToFaceGlue)
967-
tcell_to_mcell = glue.tface_to_mface
968-
notcells = count(tcell_to_mcell) do mcell
969-
lid_to_owner[mcell] == part
970-
end
971-
notcells, tcell_to_mcell
972-
end |> tuple_of_arrays
973-
974-
# Find the global range of owned dofs
975-
first_gtcell = scan(+,notcells,type=:exclusive,init=one(eltype(notcells)))
976-
977-
# Assign global cell ids to owned cells
978-
mcell_to_gtcell = map(
979-
first_gtcell,tcell_to_mcell,partition(mgids)) do first_gtcell,tcell_to_mcell,partition
980-
mcell_to_gtcell = zeros(Int,local_length(partition))
981-
loc_to_owner = local_to_owner(partition)
982-
part = part_id(partition)
983-
gtcell = first_gtcell
984-
for mcell in tcell_to_mcell
985-
if loc_to_owner[mcell] == part
986-
mcell_to_gtcell[mcell] = gtcell
987-
gtcell += 1
988-
end
989-
end
990-
mcell_to_gtcell
971+
return glue.tface_to_mface
991972
end
973+
tgids = restrict_gids(mgids,tcell_to_mcell)
974+
end
975+
return tgids
976+
end
977+
978+
function restrict_gids(gids::PRange, new_to_old_lid::AbstractArray)
992979

993-
cache = fetch_vector_ghost_values_cache(mcell_to_gtcell,partition(mgids))
994-
fetch_vector_ghost_values!(mcell_to_gtcell,cache) |> wait
995-
996-
# Prepare new partition
997-
ngtcells = reduction(+,notcells,destination=:all,init=zero(eltype(notcells)))
998-
indices = map(
999-
ngtcells,mcell_to_gtcell,tcell_to_mcell,partition(mgids)
1000-
) do ngtcells,mcell_to_gtcell,tcell_to_mcell,partition
1001-
tcell_to_gtcell = mcell_to_gtcell[tcell_to_mcell]
1002-
lid_to_owner = local_to_owner(partition)
1003-
tcell_to_part = lid_to_owner[tcell_to_mcell]
1004-
LocalIndices(ngtcells,part_id(partition),tcell_to_gtcell,tcell_to_part)
980+
n_own = map(partition(gids), new_to_old_lid) do ids, n2o_lid
981+
rank = part_id(ids)
982+
return count(isequal(rank), view(local_to_owner(ids), n2o_lid))
983+
end
984+
985+
# Assign global ids to owned lids
986+
first_gid = scan(+,n_own,type=:exclusive,init=one(eltype(n_own)))
987+
988+
old_lid_to_new_gid = map(first_gid,new_to_old_lid,partition(gids)) do first_gid, n2o_lid, ids
989+
old_lid_to_new_gid = zeros(Int,local_length(ids))
990+
old_lid_to_owner = local_to_owner(ids)
991+
rank = part_id(ids)
992+
gid = first_gid
993+
for old in n2o_lid
994+
if old_lid_to_owner[old] == rank
995+
old_lid_to_new_gid[old] = gid
996+
gid += 1
997+
end
1005998
end
1006-
_find_neighbours!(indices, partition(mgids))
1007-
tgids = PRange(indices)
999+
return old_lid_to_new_gid
10081000
end
1009-
return tgids
1010-
end
1001+
1002+
consistent!(PVector(old_lid_to_new_gid,partition(gids))) |> wait
1003+
1004+
# Prepare new partition
1005+
n_gids = reduction(+,n_own,destination=:all,init=zero(eltype(n_own)))
1006+
1007+
new_indices = map(
1008+
n_gids, old_lid_to_new_gid, new_to_old_lid, partition(gids)
1009+
) do n_gids, old_lid_to_new_gid, new_to_old_lid, ids
1010+
lid_to_gid = old_lid_to_new_gid[new_to_old_lid]
1011+
lid_to_owner = local_to_owner(ids)[new_to_old_lid]
1012+
return LocalIndices(n_gids,part_id(ids),lid_to_gid,lid_to_owner)
1013+
end
1014+
_find_neighbours!(new_indices, partition(gids))
1015+
1016+
return PRange(new_indices)
1017+
end

0 commit comments

Comments
 (0)