Skip to content

Commit 450bf5b

Browse files
committed
Merge pull request #466 from OP2/multiple_top_bottom_masks
Multiple top bottom masks
2 parents 081c312 + 36b3e76 commit 450bf5b

File tree

4 files changed

+54
-29
lines changed

4 files changed

+54
-29
lines changed

pyop2/base.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2890,11 +2890,15 @@ def __init__(self, iterset, toset, arity, values=None, name=None, offset=None, p
28902890
self._cache = {}
28912891
# Which indices in the extruded map should be masked out for
28922892
# the application of strong boundary conditions
2893-
self._bottom_mask = np.zeros(len(offset)) if offset is not None else []
2894-
self._top_mask = np.zeros(len(offset)) if offset is not None else []
2893+
self._bottom_mask = {}
2894+
self._top_mask = {}
2895+
28952896
if offset is not None and bt_masks is not None:
2896-
self._bottom_mask[bt_masks[0]] = -1
2897-
self._top_mask[bt_masks[1]] = -1
2897+
for name, mask in bt_masks.iteritems():
2898+
self._bottom_mask[name] = np.zeros(len(offset))
2899+
self._bottom_mask[name][mask[0]] = -1
2900+
self._top_mask[name] = np.zeros(len(offset))
2901+
self._top_mask[name][mask[1]] = -1
28982902
Map._globalcount += 1
28992903

29002904
@validate_type(('index', (int, IterationIndex), IndexTypeError))

pyop2/host.py

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ def c_map_init(self, is_top=False, layers=1, is_facet=False):
520520
'off': ' + ' + str(m.offset[idx])})
521521
return '\n'.join(val)+'\n'
522522

523-
def c_map_bcs(self, sign):
523+
def c_map_bcs(self, sign, is_facet):
524524
maps = as_tuple(self.map, Map)
525525
val = []
526526
# To throw away boundary condition values, we subtract a large
@@ -534,16 +534,22 @@ def c_map_bcs(self, sign):
534534
if not map.iterset._extruded:
535535
continue
536536
for j, m in enumerate(map):
537-
if 'bottom' not in m.implicit_bcs:
538-
continue
539-
need_bottom = True
540-
for idx in range(m.arity):
541-
if m.bottom_mask[idx] < 0:
542-
val.append("xtr_%(name)s[%(ind)s] %(sign)s= %(val)s;" %
543-
{'name': self.c_map_name(i, j),
544-
'val': max_int,
545-
'ind': idx,
546-
'sign': sign})
537+
bottom_masks = None
538+
for location, name in m.implicit_bcs:
539+
if location == "bottom":
540+
if bottom_masks is None:
541+
bottom_masks = m.bottom_mask[name].copy()
542+
else:
543+
bottom_masks += m.bottom_mask[name]
544+
need_bottom = True
545+
if bottom_masks is not None:
546+
for idx in range(m.arity):
547+
if bottom_masks[idx] < 0:
548+
val.append("xtr_%(name)s[%(ind)s] %(sign)s= %(val)s;" %
549+
{'name': self.c_map_name(i, j),
550+
'val': max_int,
551+
'ind': idx,
552+
'sign': sign})
547553
if need_bottom:
548554
val.insert(0, "if (j_0 == 0) {")
549555
val.append("}")
@@ -555,18 +561,25 @@ def c_map_bcs(self, sign):
555561
if not map.iterset._extruded:
556562
continue
557563
for j, m in enumerate(map):
558-
if 'top' not in m.implicit_bcs:
559-
continue
560-
need_top = True
561-
for idx in range(m.arity):
562-
if m.top_mask[idx] < 0:
563-
val.append("xtr_%(name)s[%(ind)s] %(sign)s= %(val)s;" %
564-
{'name': self.c_map_name(i, j),
565-
'val': max_int,
566-
'ind': idx,
567-
'sign': sign})
564+
top_masks = None
565+
for location, name in m.implicit_bcs:
566+
if location == "top":
567+
if top_masks is None:
568+
top_masks = m.top_mask[name].copy()
569+
else:
570+
top_masks += m.top_mask[name]
571+
need_top = True
572+
if top_masks is not None:
573+
facet_offset = m.arity if is_facet else 0
574+
for idx in range(m.arity):
575+
if top_masks[idx] < 0:
576+
val.append("xtr_%(name)s[%(ind)s] %(sign)s= %(val)s;" %
577+
{'name': self.c_map_name(i, j),
578+
'val': max_int,
579+
'ind': idx + facet_offset,
580+
'sign': sign})
568581
if need_top:
569-
val.insert(pos, "if (j_0 == end_layer - 1) {")
582+
val.insert(pos, "if (j_0 == top_layer - 1) {")
570583
val.append("}")
571584
return '\n'.join(val)+'\n'
572585

@@ -865,13 +878,13 @@ def extrusion_loop():
865878
_map_bcs_p = ""
866879
_layer_arg = ""
867880
if self._itspace._extruded:
868-
_layer_arg = ", int start_layer, int end_layer"
881+
_layer_arg = ", int start_layer, int end_layer, int top_layer"
869882
_map_decl += ';\n'.join([arg.c_map_decl(is_facet=is_facet)
870883
for arg in self._args if arg._uses_itspace])
871884
_map_init += ';\n'.join([arg.c_map_init(is_top=is_top, layers=self._itspace.layers, is_facet=is_facet)
872885
for arg in self._args if arg._uses_itspace])
873-
_map_bcs_m += ';\n'.join([arg.c_map_bcs("-") for arg in self._args if arg._is_mat])
874-
_map_bcs_p += ';\n'.join([arg.c_map_bcs("+") for arg in self._args if arg._is_mat])
886+
_map_bcs_m += ';\n'.join([arg.c_map_bcs("-", is_facet) for arg in self._args if arg._is_mat])
887+
_map_bcs_p += ';\n'.join([arg.c_map_bcs("+", is_facet) for arg in self._args if arg._is_mat])
875888
_apply_offset += ';\n'.join([arg.c_add_offset_map(is_facet=is_facet)
876889
for arg in self._args if arg._uses_itspace])
877890
_apply_offset += ';\n'.join([arg.c_add_offset(is_facet=is_facet)

pyop2/openmp.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,15 +260,19 @@ def prepare_arglist(self, iterset, *args):
260260
if region is ON_BOTTOM:
261261
arglist.append(0)
262262
arglist.append(1)
263+
arglist.append(iterset.layers - 1)
263264
elif region is ON_TOP:
264265
arglist.append(iterset.layers - 2)
265266
arglist.append(iterset.layers - 1)
267+
arglist.append(iterset.layers - 1)
266268
elif region is ON_INTERIOR_FACETS:
267269
arglist.append(0)
268270
arglist.append(iterset.layers - 2)
271+
arglist.append(iterset.layers - 2)
269272
else:
270273
arglist.append(0)
271274
arglist.append(iterset.layers - 1)
275+
arglist.append(iterset.layers - 1)
272276

273277
return arglist
274278

pyop2/sequential.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,19 @@ def prepare_arglist(self, iterset, *args):
130130
if region is ON_BOTTOM:
131131
arglist.append(0)
132132
arglist.append(1)
133+
arglist.append(iterset.layers - 1)
133134
elif region is ON_TOP:
134135
arglist.append(iterset.layers - 2)
135136
arglist.append(iterset.layers - 1)
137+
arglist.append(iterset.layers - 1)
136138
elif region is ON_INTERIOR_FACETS:
137139
arglist.append(0)
138140
arglist.append(iterset.layers - 2)
141+
arglist.append(iterset.layers - 2)
139142
else:
140143
arglist.append(0)
141144
arglist.append(iterset.layers - 1)
145+
arglist.append(iterset.layers - 1)
142146
return arglist
143147

144148
@cached_property

0 commit comments

Comments
 (0)