Skip to content

Commit eb63cb9

Browse files
committed
Added documentation
1 parent ef98aec commit eb63cb9

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

src/FESpaces.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,15 @@ function fetch_vector_ghost_values!(vector_partition,cache)
161161
assemble!((a,b)->b, vector_partition, cache)
162162
end
163163

164+
"""
165+
generate_gids(cell_gids::PRange, cell_to_lids, nlids) -> PRange
166+
167+
Given a set of cell global ids, a distributed array of local tables mapping cells to local dof ids,
168+
and a distributed array with the number of local dofs in each partition, this function
169+
generates the global dof ids and returns them as a `PRange` of `LocalIndices`.
170+
171+
Ignores negative local dof ids (usually used for Dirichlet dofs).
172+
"""
164173
function generate_gids(
165174
cell_range::PRange,
166175
cell_to_ldofs::AbstractArray{<:AbstractArray},
@@ -248,6 +257,13 @@ function generate_gids(
248257
return PRange(local_indices)
249258
end
250259

260+
"""
261+
generate_posneg_gids(cell_gids::PRange, cell_to_lposneg, nlpos, nlneg) -> (PRange,PRange)
262+
263+
Similar to `generate_gids`, but also handles negative local dof ids. Returns two sets of
264+
global ids: one for positive local ids and another for negative local ids.
265+
This can be used to generate simultaneously free and dirichlet dof global ids.
266+
"""
251267
function generate_posneg_gids(
252268
cell_range::PRange,
253269
cell_to_lposneg::AbstractArray{<:AbstractArray},
@@ -360,6 +376,16 @@ function generate_posneg_gids(
360376
return PRange(local_indices_pos), PRange(local_indices_neg)
361377
end
362378

379+
"""
380+
generate_gids_by_color(cell_gids::PRange, cell_to_lids, lid_to_color, ncolors)
381+
382+
Similar to `generate_gids`, but uses a global partition given by `lid_to_color` to generate
383+
a different set of global ids per color. Returns:
384+
385+
- a tuple with a `PRange` of `LocalIndices` per color.
386+
- a mapping `lid_to_clid` that maps local ids to local color ids
387+
- a mapping `color_to_clid_to_lid` that maps, for each color, local color ids to local ids.
388+
"""
363389
function generate_gids_by_color(
364390
cell_range::PRange,
365391
cell_to_lids::AbstractArray{<:AbstractArray},
@@ -490,6 +516,13 @@ function generate_gids_by_color(
490516
return map(PRange,color_to_indices), lid_to_clid, color_to_clid_to_lid
491517
end
492518

519+
"""
520+
split_gids_by_color(gids::PRange, lid_to_color::AbstractArray, ncolors) -> NTuple{ncolors,PRange}
521+
522+
Given a set of global ids and a mapping from local ids to colors, this function splits
523+
the global ids into different sets of global ids per color. Returns a tuple with a `PRange`
524+
of `LocalIndices` per color.
525+
"""
493526
function split_gids_by_color(
494527
gids::PRange, lid_to_color::AbstractArray,
495528
ncolors = getany(reduction(max,map(maximum,lid_to_color);destination=:all))

test/FESpacesTests.jl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,44 @@ using Test
99

1010
u((x,y)) = x+y
1111

12+
function gid_generation_tests(distribute,parts)
13+
ranks = distribute(LinearIndices((prod(parts),)))
14+
15+
model = CartesianDiscreteModel(ranks,parts,(0,1,0,1),(8,4))
16+
reffe = ReferenceFE(lagrangian,Float64,1)
17+
cgids = GridapDistributed.get_cell_gids(model)
18+
19+
V0 = FESpace(model,reffe)
20+
I0 = partition(get_free_dof_ids(V0))
21+
22+
V1 = FESpace(model,reffe;dirichlet_tags=["tag_1","tag_2","tag_3","tag_4","tag_5","tag_6"])
23+
I1 = partition(get_free_dof_ids(V1))
24+
25+
fgids_1, dgids_1 = GridapDistributed.generate_posneg_gids(
26+
cgids,get_cell_dof_ids(V1),map(num_free_dofs,local_views(V1)),map(num_dirichlet_dofs,local_views(V1))
27+
)
28+
29+
# 1 -> free, 2 -> dirichlet
30+
lid_to_color = map(local_views(V0),local_views(V1)) do V0, V1
31+
lid_to_color = zeros(Int16,num_free_dofs(V0))
32+
for (I,J) in zip(get_cell_dof_ids(V0),get_cell_dof_ids(V1))
33+
lid_to_color[I] .= map(j -> ifelse(j > 0, 1, 2), J)
34+
end
35+
return lid_to_color
36+
end
37+
38+
fgids_2, dgids_2 = GridapDistributed.split_gids_by_color(
39+
get_free_dof_ids(V0), lid_to_color
40+
)
41+
42+
(fgids_3, dgids_3), _, _ = GridapDistributed.generate_gids_by_color(
43+
cgids, get_cell_dof_ids(V0), lid_to_color
44+
)
45+
46+
@test fgids_1 == fgids_2 == fgids_3
47+
@test dgids_1 == dgids_2 == dgids_3
48+
end
49+
1250
function assemble_tests(das,dΩ,dΩass,U,V)
1351
# Assembly
1452
dv = get_fe_basis(V)

0 commit comments

Comments
 (0)