Bug fix in Region.from_expression during tokenization (#2733)

This commit is contained in:
Paul Romano 2023-10-20 09:04:05 -05:00 committed by GitHub
parent 55a682d44d
commit f82bdaa718
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 6 deletions

View file

@ -105,17 +105,17 @@ 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)])
else:
tokens.append(+surfaces[abs(j)])
# When an opening parenthesis appears after a non-operator,
# there's an implicit intersection operator between them
if expression[i] == '(':
tokens.append(' ')
if expression[i] in '()|~':
# For everything other than intersection, add the operator
# to the list of tokens

View file

@ -208,7 +208,8 @@ def test_from_expression(reset):
# Opening parenthesis immediately after halfspace
r = openmc.Region.from_expression('1(2|-3)', surfs)
assert str(r) == '(1 (2 | -3))'
r = openmc.Region.from_expression('-1|(1 2(-3))', surfs)
assert str(r) == '(-1 | (1 2 -3))'
def test_translate_inplace():
sph = openmc.Sphere()