@@ -54,19 +54,24 @@ def domain_border_ghost_boxes(domain_box, patches):
5454 elif domain_box .ndim == 2 :
5555 upper_x , upper_y = domain_box .upper
5656 return {
57- "bottom" : Box (
58- (
59- 0 ,
60- 0 ,
61- ),
62- (upper_x , ghost_box_width ),
63- ),
64- "top" : Box ((0 , upper_y - ghost_box_width ), (upper_x , upper_y )),
6557 "left" : Box ((0 , 0 ), (ghost_box_width , upper_y )),
6658 "right" : Box ((upper_x - ghost_box_width , 0 ), (upper_x , upper_y )),
59+ "bottom" : Box ((0 , 0 ), (upper_x , ghost_box_width )),
60+ "top" : Box ((0 , upper_y - ghost_box_width ), (upper_x , upper_y )),
6761 }
6862
69- raise ValueError ("Unhandeled dimension" )
63+ else :
64+ upper_x , upper_y , upper_z = domain_box .upper
65+ return {
66+ "left" : Box ((0 , 0 , 0 ), (ghost_box_width , upper_y , upper_z )),
67+ "right" : Box (
68+ (upper_x - ghost_box_width , 0 , 0 ), (upper_x , upper_y , upper_z )
69+ ),
70+ "bottom" : Box ((0 , 0 , 0 ), (upper_x , ghost_box_width , upper_z )),
71+ "top" : Box ((0 , upper_y - ghost_box_width , 0 ), (upper_x , upper_y , upper_z )),
72+ "front" : Box ((0 , 0 , 0 ), (upper_x , upper_y , ghost_box_width )),
73+ "back" : Box ((0 , 0 , upper_z - ghost_box_width ), (upper_x , upper_y , upper_z )),
74+ }
7075
7176
7277def touch_domain_border (box , domain_box , border ):
@@ -79,21 +84,29 @@ def touch_domain_border(box, domain_box, border):
7984
8085
8186def periodicity_shifts (domain_box ):
87+ shifts = {}
88+
8289 if domain_box .ndim == 1 :
8390 shape_x = domain_box .shape
84- return {
91+ shifts = {
8592 "left" : shape_x ,
8693 "right" : - shape_x ,
8794 }
95+ shifts .update ({"leftright" : [shifts ["left" ], shifts ["right" ]]})
8896
8997 if domain_box .ndim == 2 :
9098 shape_x , shape_y = domain_box .shape
99+ if domain_box .ndim == 3 :
100+ shape_x , shape_y , shape_z = domain_box .shape
101+
102+ if domain_box .ndim > 1 :
91103 shifts = {
92104 "left" : [(shape_x , 0 )],
93105 "right" : [(- shape_x , 0 )],
94106 "bottom" : [(0 , shape_y )],
95107 "top" : [(0 , - shape_y )],
96108 }
109+
97110 shifts .update (
98111 {
99112 "bottomleft" : [* shifts ["left" ], * shifts ["bottom" ], (shape_x , shape_y )],
@@ -134,7 +147,7 @@ def periodicity_shifts(domain_box):
134147 shifts ["topleft" ][- 1 ],
135148 shifts ["topright" ][- 1 ],
136149 ],
137- "bottomtopleftright " : [ # one patch covers domain
150+ "leftrightbottomtop " : [ # one patch covers domain
138151 * shifts ["bottomleft" ],
139152 * shifts ["topright" ],
140153 shifts ["bottomright" ][- 1 ],
@@ -144,7 +157,35 @@ def periodicity_shifts(domain_box):
144157 )
145158
146159 if domain_box .ndim == 3 :
147- raise ValueError ("Unhandeled dimension" )
160+ front = {
161+ f"{ k } front" : [(v [0 ], v [1 ], shape_z ) for v in l ] for k , l in shifts .items ()
162+ }
163+ back = {
164+ f"{ k } back" : [([v [0 ], v [1 ], - shape_z ]) for v in l ] for k , l in shifts .items ()
165+ }
166+
167+ shifts = {k : [([v [0 ], v [1 ], 0 ]) for v in l ] for k , l in shifts .items ()}
168+
169+ shifts .update (front )
170+ shifts .update (back )
171+ shifts .update (
172+ {
173+ "back" : [(0 , 0 , - shape_z )],
174+ "front" : [(0 , 0 , shape_z )],
175+ "leftrightbottomtopfrontback" : [
176+ * shifts ["bottomleftfront" ],
177+ * shifts ["bottomrightback" ],
178+ * shifts ["topleftfront" ],
179+ * shifts ["toprightback" ],
180+ ],
181+ }
182+ )
183+
184+ assert len (list (shifts .keys ())) == len (
185+ set (["" .join (sorted (k )) for k in list (shifts .keys ())])
186+ )
187+
188+ shifts = {"" .join (sorted (k )): l for k , l in shifts .items ()}
148189
149190 return shifts
150191
@@ -246,7 +287,7 @@ def borders_per(patch):
246287 ]
247288
248289 for patch_i , ref_patch in enumerate (border_patches ):
249- in_sides = borders_per_patch [ref_patch ]
290+ in_sides = "" . join ( sorted ( borders_per_patch [ref_patch ]))
250291 assert in_sides in shifts
251292
252293 for ref_pdname , ref_pd in ref_patch .patch_datas .items ():
@@ -336,36 +377,41 @@ def get_periodic_list(patches, domain_box, n_ghosts):
336377 shift_patch (first_patch , domain_box .shape )
337378 sorted_patches .append (first_patch )
338379
380+ return sorted_patches
381+
382+ dbu = domain_box .upper
383+
339384 if dim == 2 :
340385 sides = {
341- "bottom" : Box ([0 , 0 ], [domain_box .upper [0 ], 0 ]),
342- "top" : Box (
343- [0 , domain_box .upper [1 ]], [domain_box .upper [0 ], domain_box .upper [1 ]]
344- ),
345- "left" : Box ([0 , 0 ], [0 , domain_box .upper [1 ]]),
346- "right" : Box (
347- [domain_box .upper [0 ], 0 ], [domain_box .upper [0 ], domain_box .upper [1 ]]
348- ),
386+ "left" : Box ([0 , 0 ], [0 , dbu [1 ]]),
387+ "right" : Box ([dbu [0 ], 0 ], [dbu [0 ], dbu [1 ]]),
388+ "bottom" : Box ([0 , 0 ], [dbu [0 ], 0 ]),
389+ "top" : Box ([0 , dbu [1 ]], [dbu [0 ], dbu [1 ]]),
349390 }
350391
351- shifts = periodicity_shifts (domain_box )
392+ else :
393+ sides = {
394+ "left" : Box ([0 , 0 , 0 ], [0 , dbu [1 ], dbu [2 ]]),
395+ "right" : Box ([dbu [0 ], 0 , 0 ], [dbu [0 ], dbu [1 ], dbu [2 ]]),
396+ "bottom" : Box ([0 , 0 , 0 ], [dbu [0 ], 0 , dbu [2 ]]),
397+ "top" : Box ([0 , dbu [1 ], 0 ], [dbu [0 ], dbu [1 ], dbu [2 ]]),
398+ "front" : Box ([0 , 0 , 0 ], [dbu [0 ], dbu [1 ], 0 ]),
399+ "back" : Box ([0 , 0 , dbu [2 ]], [dbu [0 ], dbu [1 ], dbu [2 ]]),
400+ }
352401
353- def borders_per (box ):
354- return "" .join (
355- [key for key , side in sides .items () if box * side is not None ]
356- )
402+ shifts = periodicity_shifts (domain_box )
357403
358- for patch in patches :
359- in_sides = borders_per ( boxm . grow ( patch . box , n_ghosts ) )
404+ def borders_per ( box ) :
405+ return "" . join ([ key for key , side in sides . items () if box * side is not None ] )
360406
361- if in_sides in shifts : # in_sides might be empty, so no borders
362- for shift in shifts [in_sides ]:
363- patch_copy = copy (patch )
364- shift_patch (patch_copy , shift )
365- sorted_patches .append (patch_copy )
407+ for patch in patches :
408+ in_sides = "" .join (sorted (borders_per (boxm .grow (patch .box , n_ghosts ))))
366409
367- if dim == 3 :
368- raise ValueError ("not yet implemented" )
410+ if in_sides in shifts : # in_sides might be empty, so no borders
411+ for shift in shifts [in_sides ]:
412+ patch_copy = copy (patch )
413+ shift_patch (patch_copy , shift )
414+ sorted_patches .append (patch_copy )
369415
370416 return sorted_patches
371417
@@ -470,18 +516,7 @@ def level_ghost_boxes(hierarchy, quantities, levelNbrs=[], time=None):
470516 check_patches = patches
471517
472518 for gabox in ghostAreaBoxes :
473- remaining = gabox - check_patches [0 ].box
474-
475- for patch in check_patches [1 :]:
476- tmp = []
477- remove = []
478- for i , rem in enumerate (remaining ):
479- if rem * patch .box is not None :
480- remove .append (i )
481- tmp += rem - patch .box
482- for rm in reversed (remove ):
483- del remaining [rm ]
484- remaining += tmp
519+ remaining = gabox - [p .box for p in check_patches ]
485520
486521 if ilvl not in lvl_gaboxes :
487522 lvl_gaboxes [ilvl ] = {}
0 commit comments