Skip to content

Commit

Permalink
Bug fix in Region.from_expression during tokenization (#2733)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulromano committed Oct 20, 2023
1 parent 55a682d commit f82bdaa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 5 additions & 5 deletions openmc/region.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,17 @@ def from_expression(expression, surfaces):
# 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
Expand Down
3 changes: 2 additions & 1 deletion tests/unit_tests/test_region.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit f82bdaa

Please sign in to comment.