Skip to content

Commit 8a90d4f

Browse files
committed
Starting to give shape to NonConformingGridTopologies
1 parent 01b48c5 commit 8a90d4f

File tree

3 files changed

+127
-117
lines changed

3 files changed

+127
-117
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
module NonConformingGridTopologies
2+
3+
using Gridap
4+
using Gridap.Helpers
5+
6+
import Gridap.Geometry: get_faces
7+
using Gridap.Geometry: GridTopology
8+
using Gridap.Geometry: UnstructuredGridTopology
9+
using Gridap.Geometry: get_grid_topology
10+
using Gridap.Arrays: Table, length_to_ptrs!
11+
12+
using GridapDistributed
13+
14+
using GridapP4est: OctreeDistributedDiscreteModel
15+
using GridapP4est: NonConformingGlue
16+
17+
struct NonConformingGridTopology{Dc,Dp,T,O} <: GridTopology{Dc,Dp}
18+
conforming_grid_topology::UnstructuredGridTopology{Dc,Dp,T,O}
19+
coarse_cell_to_hanging_faces::Vector{Table{Int32,Vector{Int32},Vector{Int32}}}
20+
hanging_faces_to_coarse_cell::Vector{Table{Int32,Vector{Int32},Vector{Int32}}}
21+
end
22+
23+
function NonConformingGridTopology(model::OctreeDistributedDiscreteModel)
24+
map(local_views(model),model.non_conforming_glue) do model,ncg
25+
conforming_grid_topology = get_grid_topology(model)
26+
coarse_cell_to_hanging_faces, hanging_faces_to_coarse_cell =
27+
generate_hanging_faces_to_coarse_cell_glue(ncg,
28+
num_cells(model),
29+
num_dims(model))
30+
NonConformingGridTopology(conforming_grid_topology,
31+
coarse_cell_to_hanging_faces,
32+
hanging_faces_to_coarse_cell)
33+
end
34+
end
35+
36+
function generate_hanging_faces_to_coarse_cell_glue(
37+
ncg::NonConformingGlue,num_cells::Int,D::Int)
38+
39+
hanging_faces_to_cell_data =
40+
map(Broadcasting(first),ncg.hanging_faces_glue)
41+
42+
hanging_faces_to_cell_ptrs =
43+
map(Broadcasting(ones),tfill(Int32,Val{D}()),ncg.num_hanging_faces.+1)
44+
map(length_to_ptrs!,hanging_faces_to_cell_ptrs)
45+
46+
cell_to_hanging_faces_data =
47+
map(sortperm,hanging_faces_to_cell_data)
48+
cell_to_hanging_faces_data =
49+
map(Broadcasting(+),cell_to_hanging_faces_data,ncg.num_regular_faces)
50+
51+
cell_to_hanging_faces_ptrs =
52+
map(_count_owned_hanging_faces,
53+
hanging_faces_to_cell_data,
54+
tfill(num_cells,Val{D}()))
55+
map(length_to_ptrs!,cell_to_hanging_faces_ptrs)
56+
57+
# Convert data from Int64 to Int32
58+
cell_to_hanging_faces_data =
59+
map(Broadcasting(Int32),cell_to_hanging_faces_data)
60+
hanging_faces_to_cell_data =
61+
map(Broadcasting(Int32),hanging_faces_to_cell_data)
62+
63+
coarse_cell_to_hanging_faces = map(cell_to_hanging_faces_data,
64+
cell_to_hanging_faces_ptrs) do d,p
65+
Table(d,p)
66+
end
67+
hanging_faces_to_coarse_cell = map(hanging_faces_to_cell_data,
68+
hanging_faces_to_cell_ptrs) do d,p
69+
Table(d,p)
70+
end
71+
72+
hanging_faces_to_coarse_cell, coarse_cell_to_hanging_faces
73+
end
74+
75+
function _count_owned_hanging_faces(x::AbstractArray{<:Integer},num_cells::Int)
76+
r = zeros(Int32,num_cells+1)
77+
for xi in x
78+
r[xi+1] += 1
79+
end
80+
return r
81+
end
82+
83+
export NonConformingGridTopology
84+
85+
# Implementation of abstract API
86+
87+
OrientationStyle(
88+
::Type{<:NonConformingGridTopology{Dc,Dp,T,O}}) where
89+
{Dc,Dp,T,O} = O()
90+
91+
RegularityStyle(
92+
::Type{<:NonConformingGridTopology{Dc,Dp,T,O}}) where
93+
{Dc,Dp,T,O} = Irregular()
94+
95+
get_vertex_coordinates(ncgt::NonConformingGridTopology) =
96+
ncgt.conforming_grid_topology.vertex_coordinates
97+
98+
get_cell_type(ncgt::NonConformingGridTopology) =
99+
ncgt.conforming_grid_topology.cell_type
100+
101+
get_polytopes(ncgt::NonConformingGridTopology) =
102+
collect1d(ncgt.conforming_grid_topology.polytopes)
103+
104+
function get_faces(ncgt::NonConformingGridTopology{Dc,Dp,T,O},
105+
::Val{Dc},dimto::Integer) where {Dc,Dp,T,O}
106+
@show ncgt.coarse_cell_to_hanging_faces[dimto+1]
107+
end
108+
109+
function get_faces(ncgt::NonConformingGridTopology{Dc,Dp,T,O},
110+
dimfrom::Integer,::Val{Dc}) where {Dc,Dp,T,O}
111+
@show ncgt.hanging_faces_to_coarse_cell[dimfrom+1]
112+
end
113+
114+
# What other procs do I need? Review CA (e.g., facet_to_inoutcut)
115+
116+
end # module

test/dev/eric_dev.jl

Lines changed: 11 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,18 @@ module DistributedAggregationP4estMeshes
66
using PartitionedArrays
77
using MPI
88

9+
using Gridap.Geometry: get_faces
10+
911
using P4est_wrapper
1012
using GridapP4est
1113

12-
using Gridap.Arrays: Table
13-
using Gridap.Geometry: get_grid_topology
14-
using Gridap.Geometry: get_faces
15-
16-
using FillArrays
14+
include("NonConformingGridTopologies.jl")
15+
using .NonConformingGridTopologies
1716

1817
function run(distribute)
1918

2019
ranks = distribute(LinearIndices((MPI.Comm_size(MPI.COMM_WORLD),)))
21-
coarse_model = CartesianDiscreteModel((-1,1,-1,1,-1,1),(1,1,1))
20+
coarse_model = CartesianDiscreteModel((-1,1,-1,1),(1,1))
2221
num_uniform_refinements = 1
2322
num_ghost_layers = 2
2423
D = num_dims(coarse_model)
@@ -37,78 +36,14 @@ module DistributedAggregationP4estMeshes
3736
end
3837
fmodel,_ = Gridap.Adaptivity.adapt(dmodel,fmodel_refine_coarsen_flags);
3938

40-
# map(local_views(fmodel)) do m
41-
# gt = get_grid_topology(m)
42-
# @show get_faces(gt,1,2)
43-
# @show get_faces(gt,2,1)
44-
# end
45-
46-
# map(fmodel.non_conforming_glue) do ncg
47-
# @show ncg.num_regular_faces
48-
# @show ncg.num_hanging_faces
49-
# @show ncg.hanging_faces_glue
50-
# @show ncg.hanging_faces_to_cell
51-
# @show ncg.hanging_faces_to_lface
52-
# @show ncg.owner_faces_pindex
53-
# @show ncg.owner_faces_lids
54-
# end
55-
56-
cell_to_hanging_faces =
57-
map(local_views(fmodel),fmodel.non_conforming_glue) do m,ncg
58-
59-
hanging_face_to_owner_cell =
60-
map(Broadcasting(first),ncg.hanging_faces_glue)
61-
cell_to_hanging_faces_data =
62-
map(sortperm,hanging_face_to_owner_cell)
63-
@time hanging_face_to_owner_cell =
64-
map(sort,hanging_face_to_owner_cell)
65-
66-
# # Only for facets
67-
# hanging_face_to_owner_cell = first.(ncg.hanging_faces_glue[D])
68-
# cell_to_hanging_faces_data = sortperm(hanging_face_to_owner_cell)
69-
70-
# cell_to_hanging_faces_ptr = zeros(Int32,num_cells(m)+1)
71-
# owner_cells_ptr = unique(hanging_face_to_owner_cell) .+ 1
72-
# # Alternatively, for owner_cells_ptr evaluate every 2^(D-1) entries
73-
# # But with unique I can do it for every dimension
74-
# cell_to_hanging_faces_ptr[owner_cells_ptr] .= 2^(D-1)
75-
# length_to_ptrs!(cell_to_hanging_faces_ptr)
76-
77-
# cell_to_hanging_faces_ptr = [zeros(Int32,num_cells(m)+1) for i in 1:D]
78-
79-
# # Non-sorted 3D: 0.028385 seconds (65.36 k allocations: 3.451 MiB, 99.81% compilation time)
80-
# # Sorted 3D: 0.027257 seconds (65.36 k allocations: 3.451 MiB, 99.73% compilation time)
81-
# @time map(cell_to_hanging_faces_ptr,hanging_face_to_owner_cell) do cthf_ptr,hftoc
82-
# for oc in hftoc
83-
# cthf_ptr[oc+1] += 1
84-
# end
85-
# end
86-
@time owner_cells = map(unique,hanging_face_to_owner_cell)
87-
# # Sorted 3D: 0.039553 seconds (113.76 k allocations: 6.096 MiB, 99.85% compilation time)
88-
# @time cell_to_hanging_faces_ptr = map(hanging_face_to_owner_cell,owner_cells) do hftoc,oc
89-
# map(x->searchsortedfirst(hftoc,x),oc)
90-
# end
91-
# # Sorted 3D: 0.000010 seconds (22 allocations: 1.766 KiB)
92-
@time owner_cell_to_hanging_faces_ptr =
93-
map(indexin,owner_cells,hanging_face_to_owner_cell)
94-
95-
cell_to_hanging_faces_data =
96-
map(Broadcasting(+),cell_to_hanging_faces_data,ncg.num_regular_faces)
97-
# cell_to_hanging_faces_data =
98-
# cell_to_hanging_faces_data .+ ncg.num_regular_faces[D]
99-
100-
# @show cell_to_hanging_faces_ptr
101-
@show hanging_face_to_owner_cell
102-
@show cell_to_hanging_faces_data
103-
@show owner_cell_to_hanging_faces_ptr
104-
@show owner_cells
105-
106-
# Table(cell_to_hanging_faces_ptr,cell_to_hanging_faces_data)
107-
cell_to_hanging_faces_data
39+
ncgt = NonConformingGridTopology(fmodel)
40+
map(ncgt) do ncgt
41+
get_faces(ncgt,D,0)
42+
get_faces(ncgt,0,D)
43+
get_faces(ncgt,D,1)
44+
get_faces(ncgt,1,D)
10845
end
10946

110-
# @show typeof(cell_to_hanging_faces)
111-
11247
end
11348

11449
end

test/dev/non_conforming_grid_topology.jl

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)