openmc
openmc copied to clipboard
Short circuit for CSG
Changed the way contains_complex works in src/cell.cpp to follow this algorithm:
- Work through the reverse polish notation (RPN) vector in reverse order
- If the token is a primitive then evaluate the sense of the primitive and update the
in_cellboolean and enter a while loop as long as the operator stack is greater than zero - Remove an operation from the top of the stack and check if the particle is in the cell and is operated on by a union or if the particle is not in the cell and is operated on by an intersection
- If 3 is true then the next token is checked to see if it is a surface or an operation, if it is a surface then it is skipped, if it is an operation and is the same as the one removed from the stack then the code enters a while loop to skip any other operations or primitives apart of the original operation
- If the operation taken from the stack is a complement then the boolean is flipped
- If 3 and 5 are both false then break the outside while loop
- If the operator stack is zero then return the boolean
- If the original token from 2 was not a primitive then push the token to the operator stack
- Finally, return the boolean
This change is made in an effort to speed up the runtime of the CSG particle tracing.
Thanks for taking a look @pshriwise! We're still investigating other methods for doing logical evaluation (namely, using the original infix expression, which also enables short-circuiting) so I'm going to put this on hold until we've gone down all paths and agree on what the best method is.