Region expression: ensure halfspace followed by ( results in implicit & operator

This commit is contained in:
Paul Romano 2022-06-09 08:51:29 -05:00
parent 50cafaf61c
commit 0e38755a0e
2 changed files with 9 additions and 0 deletions

View file

@ -106,6 +106,11 @@ class Region(ABC):
# If special character appears immediately after a non-operator,
# create a token with the appropriate half-space
if i_start >= 0:
# When an opening parenthesis appears after a non-operator,
# there's an implicit intersection operator between them
if expression[i] == '(':
tokens.append(' ')
j = int(expression[i_start:i])
if j < 0:
tokens.append(-surfaces[abs(j)])

View file

@ -204,3 +204,7 @@ def test_from_expression(reset):
# Make sure ")(" is handled correctly
r = openmc.Region.from_expression('(-1|2)(2|-3)', surfs)
assert str(r) == '((-1 | 2) (2 | -3))'
# Opening parenthesis immediately after halfspace
r = openmc.Region.from_expression('1(2|-3)', surfs)
assert str(r) == '(1 (2 | -3))'