@@ -6,8 +6,75 @@ using PartitionedArrays
66using LinearAlgebra
77using Test
88
9- function main (distribute,parts)
9+ using Gridap. Geometry
10+
11+ function test_local_part_face_labelings_consistency (lmodel:: CartesianDiscreteModel{D} ,gids,gmodel) where {D}
12+ local_topology = lmodel. grid_topology
13+ global_topology = gmodel. grid_topology
14+ local_labelings = lmodel. face_labeling
15+ global_labelings = gmodel. face_labeling
16+ l_d_to_dface_to_entity = local_labelings. d_to_dface_to_entity
17+ g_d_to_dface_to_entity = global_labelings. d_to_dface_to_entity
18+ loc_to_glo = local_to_global (gids)
19+ # traverse local cells
20+ for cell_lid= 1 : num_cells (lmodel)
21+ cell_gid= loc_to_glo[cell_lid]
22+ for d = 0 : D- 1
23+ local_cell_to_faces = local_topology. n_m_to_nface_to_mfaces[D+ 1 ,d+ 1 ]
24+ global_cell_to_faces = global_topology. n_m_to_nface_to_mfaces[D+ 1 ,d+ 1 ]
25+ la = local_cell_to_faces. ptrs[cell_lid]
26+ lb = local_cell_to_faces. ptrs[cell_lid+ 1 ]
27+ ga = global_cell_to_faces. ptrs[cell_gid]
28+ gb = global_cell_to_faces. ptrs[cell_gid+ 1 ]
29+ @assert (lb- la)== (gb- ga)
30+ for i = 0 : lb- la- 1
31+ face_lid = local_cell_to_faces. data[la+ i]
32+ face_gid = global_cell_to_faces. data[ga+ i]
33+ local_entity = l_d_to_dface_to_entity[d+ 1 ][face_lid]
34+ global_entity = g_d_to_dface_to_entity[d+ 1 ][face_gid]
35+ if (local_entity != global_entity)
36+ return false
37+ end
38+ end
39+ end
40+ end
41+ return true
42+ end
43+
44+ function test_model (model)
45+ D = num_cell_dims (model)
46+
47+ grid = get_grid (model)
48+ labels = get_grid (model)
49+
50+ topo = get_grid_topology (model)
51+ GridapDistributed. isconsistent_faces (topo)
52+
53+ for d in 0 : D
54+ fgids = get_face_gids (model,d)
55+ trian = Triangulation (no_ghost,ReferenceFE{d},model)
56+ @test num_cells (trian) == length (fgids)
57+ trian = Triangulation (with_ghost,ReferenceFE{d},model)
58+ @test num_cells (trian) == length (fgids)
59+ end
60+
61+ Ω = Triangulation (with_ghost,model)
62+ @test num_cells (Ω) == num_cells (model)
1063
64+ Ω = Triangulation (no_ghost,model)
65+ @test num_cells (Ω) == num_cells (model)
66+
67+ Γ = Boundary (with_ghost,model,tags= " boundary" )
68+ nbfacets = num_cells (Γ)
69+
70+ Γ = Boundary (no_ghost,model,tags= " boundary" )
71+ @test num_cells (Γ) == nbfacets
72+
73+ return true
74+ end
75+
76+ function main_cartesian (distribute,parts)
77+ ranks = distribute (LinearIndices ((prod (parts),)))
1178 output = mkpath (joinpath (@__DIR__ ," output" ))
1279
1380 if length (parts) == 2
@@ -18,14 +85,12 @@ function main(distribute,parts)
1885 cells = (4 ,4 ,4 )
1986 end
2087
21- ranks = distribute (LinearIndices ((prod (parts),)))
22-
23-
2488 model = CartesianDiscreteModel (ranks,parts,domain,cells)
2589 writevtk (model,joinpath (output," model" ))
2690
27- @test num_cells (model)== prod (cells)
28- @test num_vertices (model)== prod (cells .+ 1 )
91+ @test test_model (model)
92+ @test num_cells (model) == prod (cells)
93+ @test num_vertices (model) == prod (cells .+ 1 )
2994 @test num_cell_dims (model) == length (cells)
3095 @test num_point_dims (model) == length (cells)
3196
@@ -54,25 +119,6 @@ function main(distribute,parts)
54119 @test test_local_part_face_labelings_consistency (lmodel,gids,gmodel)
55120 end
56121
57- grid = get_grid (model)
58- labels = get_grid (model)
59-
60- Ω = Triangulation (with_ghost,model)
61- writevtk (Ω,joinpath (output," Ω" ))
62- @test num_cells (Ω) == num_cells (model)
63-
64- Ω = Triangulation (no_ghost,model)
65- writevtk (Ω,joinpath (output," Ω" ))
66- @test num_cells (Ω) == num_cells (model)
67-
68- Γ = Boundary (with_ghost,model,tags= " boundary" )
69- writevtk (Γ,joinpath (output," Γ" ))
70- nbfacets = num_cells (Γ)
71-
72- Γ = Boundary (no_ghost,model,tags= " boundary" )
73- writevtk (Γ,joinpath (output," Γ" ))
74- @test num_cells (Γ) == nbfacets
75-
76122 function is_in (coords)
77123 R = 1.6
78124 n = length (coords)
@@ -111,40 +157,48 @@ function main(distribute,parts)
111157
112158 # Multiple ghost layers
113159 model = CartesianDiscreteModel (ranks,parts,domain,cells;ghost= map (i-> 2 ,parts))
160+ @test test_model (model)
161+
162+ # Unstructured conversion
163+ model = Geometry. UnstructuredDiscreteModel (
164+ CartesianDiscreteModel (ranks,parts,domain,cells)
165+ )
166+ @test test_model (model)
167+
168+ # Simplexify
169+ model = simplexify (
170+ CartesianDiscreteModel (ranks,parts,domain,cells)
171+ )
172+ @test test_model (model)
114173
115174end
116175
117- function test_local_part_face_labelings_consistency (lmodel:: CartesianDiscreteModel{D} ,gids,gmodel) where {D}
118- local_topology = lmodel. grid_topology
119- global_topology = gmodel. grid_topology
120- local_labelings = lmodel. face_labeling
121- global_labelings = gmodel. face_labeling
122- l_d_to_dface_to_entity = local_labelings. d_to_dface_to_entity
123- g_d_to_dface_to_entity = global_labelings. d_to_dface_to_entity
124- loc_to_glo = local_to_global (gids)
125- # traverse local cells
126- for cell_lid= 1 : num_cells (lmodel)
127- cell_gid= loc_to_glo[cell_lid]
128- for d= 0 : D- 1
129- local_cell_to_faces = local_topology. n_m_to_nface_to_mfaces[D+ 1 ,d+ 1 ]
130- global_cell_to_faces = global_topology. n_m_to_nface_to_mfaces[D+ 1 ,d+ 1 ]
131- la = local_cell_to_faces. ptrs[cell_lid]
132- lb = local_cell_to_faces. ptrs[cell_lid+ 1 ]
133- ga = global_cell_to_faces. ptrs[cell_gid]
134- gb = global_cell_to_faces. ptrs[cell_gid+ 1 ]
135- @assert (lb- la)== (gb- ga)
136- for i= 0 : lb- la- 1
137- face_lid = local_cell_to_faces. data[la+ i]
138- face_gid = global_cell_to_faces. data[ga+ i]
139- local_entity = l_d_to_dface_to_entity[d+ 1 ][face_lid]
140- global_entity = g_d_to_dface_to_entity[d+ 1 ][face_gid]
141- if (local_entity != global_entity)
142- return false
143- end
144- end
145- end
146- end
147- return true
176+ function main_polytopal (distribute,parts)
177+ ranks = distribute (LinearIndices ((prod (parts),)))
178+
179+ if length (parts) == 2
180+ domain = (0 ,4 ,0 ,4 )
181+ cells = (4 ,4 )
182+ elseif length (parts) == 3
183+ domain = (0 ,4 ,0 ,4 ,0 ,4 )
184+ cells = (4 ,4 ,4 )
185+ end
186+
187+ model = Geometry. PolytopalDiscreteModel (
188+ CartesianDiscreteModel (ranks,parts,domain,cells)
189+ )
190+ @test test_model (model)
191+
192+ model = Geometry. PolytopalDiscreteModel (
193+ simplexify (CartesianDiscreteModel (ranks,parts,domain,cells))
194+ )
195+ @test test_model (model)
196+
197+ end
198+
199+ function main (distribute,parts)
200+ main_cartesian (distribute,parts)
201+ main_polytopal (distribute,parts)
148202end
149203
150204end # module
0 commit comments