Skip to content

Implement depth-awareness when enforcing precedence between union/intersection operators#3730

Merged
pshriwise merged 3 commits intoopenmc-dev:developfrom
paulromano:depth-aware-precedence
Jan 16, 2026
Merged

Implement depth-awareness when enforcing precedence between union/intersection operators#3730
pshriwise merged 3 commits intoopenmc-dev:developfrom
paulromano:depth-aware-precedence

Conversation

@paulromano
Copy link
Copy Markdown
Contributor

Description

This PR is an alternative to #3698 and is intended to solve the same problem but in a more rigorous way by ensuring that when we add parentheses in region expressions to enforce precedence between intersection and union operators, it is done in a manner that accounts for the depth at which the operators appear. With this fix, it is not necessary to convert to/from postfix as is done in #3698. I've added numerous test cases that demonstrate that it functions correctly.

Fixes #3685

Checklist

  • I have performed a self-review of my own code
  • I have run clang-format (version 15) on any C++ source files (if applicable)
  • I have followed the style guidelines for Python source files (if applicable)
  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works (if applicable)

@paulromano paulromano requested a review from GuySten January 15, 2026 04:37
Copy link
Copy Markdown
Contributor

@GuySten GuySten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me!

Its also nice to have a rich test suite for the region parsing.

Copy link
Copy Markdown
Contributor

@pshriwise pshriwise left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to @GuySten's approval. And ditto on the new C++ tests! 🏆

@pshriwise pshriwise merged commit 51ea89c into openmc-dev:develop Jan 16, 2026
17 checks passed
@paulromano paulromano deleted the depth-aware-precedence branch January 16, 2026 06:04
@MicahGale
Copy link
Copy Markdown
Contributor

Do you have any literature on these algorithms? This sounds like a bug I have been dealing with.

jon-proximafusion pushed a commit to shimwell/openmc that referenced this pull request Apr 13, 2026
…ersection operators (openmc-dev#3730)

Co-authored-by: GuySten <guyste@post.bgu.ac.il>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect logic in Cell definitions leading to incorrect definitions.

4 participants