Skip to content

Commit 021e992

Browse files
committed
Cell aggregation on p4est meshes
1 parent 52cec03 commit 021e992

File tree

2 files changed

+78
-7
lines changed

2 files changed

+78
-7
lines changed

src/AgFEM/CellAggregation.jl

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,18 @@ function aggregate(
8989
cut::EmbeddedDiscretization,
9090
geo::CSG.Geometry,
9191
lid_to_gid::AbstractVector,
92-
in_or_out)
92+
in_or_out;
93+
grid_topology=nothing)
9394

9495
facet_to_inoutcut = compute_bgfacet_to_inoutcut(cut.bgmodel,geo)
9596
cell_to_lcellin, cell_to_value, _ =
96-
_aggregate_by_threshold(strategy.threshold,cut,geo,in_or_out,facet_to_inoutcut,lid_to_gid)
97+
_aggregate_by_threshold(strategy.threshold,
98+
cut,
99+
geo,
100+
in_or_out,
101+
facet_to_inoutcut,
102+
lid_to_gid,
103+
grid_topology)
97104
cell_to_gcellin = fill(0,length(lid_to_gid))
98105
for i in eachindex(cell_to_gcellin)
99106
if !iszero(cell_to_lcellin[i])
@@ -132,7 +139,13 @@ function aggregate(
132139
cell_to_cellin
133140
end
134141

135-
function _aggregate_by_threshold(threshold,cut,geo,loc,facet_to_inoutcut,lid_to_gid)
142+
function _aggregate_by_threshold(threshold,
143+
cut,
144+
geo,
145+
loc,
146+
facet_to_inoutcut,
147+
lid_to_gid,
148+
topo=nothing)
136149
@assert loc in (IN,OUT)
137150

138151
cutinorout = loc == IN ? (CUT_IN,IN) : (CUT_OUT,OUT)
@@ -146,7 +159,8 @@ function _aggregate_by_threshold(threshold,cut,geo,loc,facet_to_inoutcut,lid_to_
146159
cell_to_inoutcut = compute_bgcell_to_inoutcut(cut,geo)
147160

148161
cell_to_coords = get_cell_coordinates(bgtrian)
149-
topo = get_grid_topology(model)
162+
topo === nothing ? topo = get_grid_topology(model) : topo
163+
150164
D = num_cell_dims(model)
151165
cell_to_faces = get_faces(topo,D,D-1)
152166
face_to_cells = get_faces(topo,D-1,D)

test/dev/eric_dev.jl

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module DistributedAggregationP4estMeshes
22

33
using Gridap
44
using GridapEmbedded
5+
using GridapEmbedded.Interfaces: CUT
56
using GridapDistributed
67
using PartitionedArrays
78
using MPI
@@ -27,16 +28,72 @@ module DistributedAggregationP4estMeshes
2728
num_uniform_refinements;
2829
num_ghost_layers=num_ghost_layers)
2930

31+
geo1 = quadrilateral(;x0=Point(-0.9,-0.9),
32+
d1=VectorValue(1.8,0.0),
33+
d2=VectorValue(0.0,1.8))
34+
geo2 = ! disk(0.4)
35+
geo = intersect(geo1,geo2)
36+
37+
cutgeo = cut(dmodel, geo)
38+
cell_to_inoutcut = compute_bgcell_to_inoutcut(cutgeo,geo)
3039
fmodel_refine_coarsen_flags =
31-
map(ranks,partition(get_cell_gids(dmodel.dmodel))) do rank,indices
40+
map(ranks,
41+
partition(get_cell_gids(dmodel.dmodel)),
42+
cell_to_inoutcut) do rank,indices,cell_to_inoutcut
3243
flags = zeros(Int,length(indices))
33-
flags .= nothing_flag
34-
flags[1] = refine_flag
44+
flags .= nothing_flag
45+
toref = findall(c->c==CUT,cell_to_inoutcut)
46+
flags[toref] .= refine_flag
3547
flags
3648
end
3749
fmodel,_ = Gridap.Adaptivity.adapt(dmodel,fmodel_refine_coarsen_flags);
3850

51+
for i in 1:4
52+
cutgeo = cut(fmodel, geo)
53+
cell_to_inoutcut = compute_bgcell_to_inoutcut(cutgeo,geo)
54+
fmodel_refine_coarsen_flags =
55+
map(ranks,
56+
partition(get_cell_gids(fmodel)),
57+
cell_to_inoutcut) do rank,indices,cell_to_inoutcut
58+
flags = zeros(Int,length(indices))
59+
flags .= nothing_flag
60+
toref = findall(c->c==CUT,cell_to_inoutcut)
61+
flags[toref] .= refine_flag
62+
flags
63+
end
64+
fmodel,_ = Gridap.Adaptivity.adapt(fmodel,fmodel_refine_coarsen_flags);
65+
end
66+
67+
writevtk(EmbeddedBoundary(cutgeo),"data/quad_bnd");
68+
# The next line fails unless I comment out the assertion
69+
# in the constructor of AppendedTriangulations.jl:
70+
# @assert get_background_model(a) === get_background_model(b)
71+
writevtk(Triangulation(cutgeo,PHYSICAL_IN),"data/quad_phys");
72+
73+
cell_gids = get_cell_gids(fmodel)
74+
cell_indices = partition(cell_gids)
75+
76+
cutgeo = cut(fmodel, geo)
3977
ncgt = NonConformingGridTopology(fmodel)
78+
strategy = AggregateCutCellsByThreshold(1.0)
79+
lcell_to_lroot, lcell_to_root, lcell_to_value =
80+
map(local_views(cutgeo),cell_indices,ncgt) do cutgeo,cell_indices,ncgt
81+
lid_to_gid = local_to_global(cell_indices)
82+
aggregate(strategy,cutgeo,geo,lid_to_gid,IN,grid_topology=ncgt)
83+
end |> tuple_of_arrays
84+
85+
# Output for verification of lcell_to_root map
86+
ocell_to_root = map(lcell_to_root,own_to_local(cell_gids)) do agg,o_to_l
87+
map(Reindex(agg),o_to_l)
88+
end
89+
90+
writevtk(EmbeddedBoundary(cutgeo),"data/quad_bnd");
91+
writevtk(Triangulation(cutgeo,PHYSICAL),"data/quad_phys");
92+
writevtk(
93+
Triangulation(fmodel), "data/quad_aggregates",
94+
celldata = ["aggregate" => ocell_to_root],
95+
);
96+
4097
map(ncgt) do ncgt
4198
get_faces(ncgt,D,0)
4299
get_faces(ncgt,0,D)

0 commit comments

Comments
 (0)