@@ -6,7 +6,29 @@ using PartitionedArrays
66
77using GridapEmbedded: aggregate
88
9- function generate_dumbell (ranks, np, nc, ng)
9+ function generate_asymmetric_kettlebell (ranks, np, nc, ng)
10+ L = 1
11+ p0 = Point (0.0 ,0.0 )
12+ pmin = Point (- L/ 4 ,- L/ 8 )
13+ pmax = Point (L/ 4 ,3 * L/ 8 )
14+
15+ R = 0.2
16+ x = VectorValue (1.0 ,0.0 )
17+ h = L/ (2 * nc)
18+
19+ geo1 = disk (R,x0= p0)
20+ geo2 = quadrilateral (;x0= Point (- L/ 4 + h/ 4 ,5 * h/ 4 ),
21+ d1= VectorValue (6 * h+ h/ 2 ,0.0 ),
22+ d2= VectorValue (0.0 ,4 * h+ h/ 2 ))
23+ geo3 = quadrilateral (;x0= Point (- L/ 4 + 3 * h/ 4 ,7 * h/ 4 ),
24+ d1= VectorValue (6 * h- h/ 2 ,0.0 ),
25+ d2= VectorValue (0.0 ,4 * h- h/ 2 ))
26+ geo = union (geo1,intersect (geo2,! geo3))
27+ bgmodel = CartesianDiscreteModel (ranks,np,pmin,pmax,(nc,nc);ghost= (ng,ng))
28+ return bgmodel, geo
29+ end
30+
31+ function generate_symmetric_kettlebell (ranks, np, nc, ng)
1032 L = 1
1133 p0 = Point (0.0 ,0.0 )
1234 pmin = Point (- L/ 4 ,- L/ 8 )
@@ -43,59 +65,42 @@ function exchange_impl!(vector_partition,cache)
4365 return t
4466end
4567
46- function find_optimal_roots! (lcell_to_root,lcell_to_path_length,lcell_to_bbox_diam ,cell_indices)
68+ function find_optimal_roots! (lcell_to_root,lcell_to_value ,cell_indices)
4769 # Bring all root candidates to the owner of the cut cell
4870 roots_cache = PartitionedArrays. p_vector_cache (lcell_to_root,cell_indices)
4971 t1 = exchange_impl! (lcell_to_root,roots_cache)
50- lengths_cache = PartitionedArrays. p_vector_cache (lcell_to_path_length,cell_indices)
51- t2 = exchange_impl! (lcell_to_path_length,lengths_cache)
52- bb_diams_cache = PartitionedArrays. p_vector_cache (lcell_to_bbox_diam,cell_indices)
53- t3 = exchange_impl! (lcell_to_bbox_diam,bb_diams_cache)
72+ values_cache = PartitionedArrays. p_vector_cache (lcell_to_value,cell_indices)
73+ t2 = exchange_impl! (lcell_to_value,values_cache)
5474 lcell_to_owner = map (copy∘ local_to_owner,cell_indices)
5575 owners_cache = PartitionedArrays. p_vector_cache (lcell_to_owner,cell_indices)
5676 wait (t1)
5777 wait (t2)
58- wait (t3)
5978
6079 # Select the optimal root for each local cut cell
6180 map (
62- lcell_to_root,lcell_to_path_length,lcell_to_bbox_diam,
63- lcell_to_owner,roots_cache,lengths_cache,bb_diams_cache
64- ) do lcell_to_root,lcell_to_path_length,lcell_to_bbox_diam,
65- lcell_to_owner,roots_cache,lengths_cache,bb_diams_cache
66-
81+ lcell_to_root,lcell_to_value,lcell_to_owner,roots_cache,values_cache
82+ ) do lcell_to_root, lcell_to_value, lcell_to_owner, roots_cache, values_cache
6783 lids_rcv = roots_cache. local_indices_rcv
68- lengths_rcv = lengths_cache. buffer_rcv
69- bb_diams_rcv = bb_diams_cache. buffer_rcv
84+ values_rcv = values_cache. buffer_rcv
7085 roots_rcv = roots_cache. buffer_rcv
71-
72- for (k,nbor) in enumerate (roots_cache. neighbors_rcv)
73- for (lcell,root,len,bb_diam) in zip (lids_rcv[k],roots_rcv[k],lengths_rcv[k],bb_diams_rcv[k])
86+ for (k, nbor) in enumerate (roots_cache. neighbors_rcv)
87+ for (lcell,root,value) in zip (lids_rcv[k], roots_rcv[k], values_rcv[k])
7488 root == 0 && continue
75- if lcell_to_path_length [lcell] > len
89+ if lcell_to_value [lcell] > value # Take the minimum
7690 lcell_to_root[lcell] = root
91+ lcell_to_value[lcell] = value
7792 lcell_to_owner[lcell] = nbor
78- elseif lcell_to_path_length[lcell] == len
79- if ( lcell_to_bbox_diam[lcell] > bb_diam ) &
80- ! isapprox (lcell_to_bbox_diam[lcell],bb_diam,atol= 1.0e-9 )
81- lcell_to_root[lcell] = root
82- lcell_to_owner[lcell] = nbor
83- elseif isapprox (lcell_to_bbox_diam[lcell],bb_diam,atol= 1.0e-9 ) &
84- ( lcell_to_root[lcell] > root )
85- lcell_to_root[lcell] = root
86- lcell_to_owner[lcell] = nbor
87- end
8893 end
8994 end
9095 end
91-
9296 end
9397
9498 # Scatter the optimal roots and values
9599 # Technically, we do not need to scatter the values, it can be removed after
96100 # we are done debugging
97101 t1 = consistent! (PVector (lcell_to_owner,cell_indices,owners_cache))
98102 t2 = consistent! (PVector (lcell_to_root,cell_indices,roots_cache))
103+ t3 = consistent! (PVector (lcell_to_value,cell_indices,values_cache))
99104
100105 wait (t1)
101106
@@ -104,29 +109,30 @@ function find_optimal_roots!(lcell_to_root,lcell_to_path_length,lcell_to_bbox_di
104109 end
105110
106111 wait (t2)
112+ wait (t3)
107113
108- return lcell_to_root, lcell_to_owner, agg_cell_indices
114+ return lcell_to_root, lcell_to_owner, lcell_to_value, agg_cell_indices
109115end
110116
111117distribute = PartitionedArrays. DebugArray
112118np = (3 ,1 )
113119ranks = distribute (LinearIndices ((prod (np),)))
114- bgmodel, geo = generate_dumbell (ranks, np, 9 , 2 )
120+ bgmodel, geo = generate_symmetric_kettlebell (ranks, np, 9 , 2 )
115121cutgeo = cut (bgmodel, geo)
116122
117123cell_indices = partition (get_cell_gids (bgmodel))
118124
119125strategy = AggregateCutCellsByThreshold (1.0 )
120- lcell_to_root, lcell_to_path_length, lcell_to_bbox_diam =
126+ lcell_to_root, lcell_to_value =
121127 map (local_views (cutgeo),cell_indices) do cutgeo,cell_indices
122128 lid_to_gid = local_to_global (cell_indices)
123129 aggregate (strategy,cutgeo,geo,lid_to_gid,IN)
124130 end |> tuple_of_arrays
125131
126132lcell_to_inconsistent_root = map (copy,lcell_to_root)
127133
128- lcell_to_root, lcell_to_owner, agg_cell_indices =
129- find_optimal_roots! (lcell_to_root,lcell_to_path_length,lcell_to_bbox_diam ,cell_indices);
134+ lcell_to_root, lcell_to_owner, lcell_to_value, agg_cell_indices =
135+ find_optimal_roots! (lcell_to_root,lcell_to_value ,cell_indices);
130136
131137# Creating aggregate-conforming cell partition
132138
@@ -137,28 +143,22 @@ end
137143
138144writevtk (EmbeddedBoundary (cutgeo)," data/bnd" );
139145writevtk (
140- Triangulation (bgmodel), " data/dumbell_aggregates " ,
146+ Triangulation (bgmodel), " data/kettlebell_aggregates " ,
141147 celldata = [" aggregate" => ocell_to_root],
142148);
143149
144150map (ranks,
145151 local_views (bgmodel),
146152 lcell_to_root,
147153 lcell_to_inconsistent_root,
148- lcell_to_owner,
149- lcell_to_path_length,
150- lcell_to_bbox_diam) do r,bgmodel,
151- lcell_to_root,
152- lcell_to_iroot,
153- lcell_to_owner,
154- lcell_to_path_length,
155- lcell_to_bbox_diam
154+ lcell_to_owner) do r,bgmodel,
155+ lcell_to_root,
156+ lcell_to_iroot,
157+ lcell_to_owner
156158 writevtk (
157- Triangulation (bgmodel), " data/dumbell_aggregates_ $(r) " ,
159+ Triangulation (bgmodel), " data/kettlebell_aggregates_ $(r) " ,
158160 celldata = [ " roots" => lcell_to_root,
159161 " inconsistent roots" => lcell_to_iroot,
160- " owners" => lcell_to_owner,
161- " length" => lcell_to_path_length,
162- " diameter" => lcell_to_bbox_diam ],
162+ " owners" => lcell_to_owner ],
163163 );
164164end
0 commit comments