openmc icon indicating copy to clipboard operation
openmc copied to clipboard

Short circuit for CSG

Open myerspat opened this issue 3 years ago • 1 comments

Changed the way contains_complex works in src/cell.cpp to follow this algorithm:

  1. Work through the reverse polish notation (RPN) vector in reverse order
  2. If the token is a primitive then evaluate the sense of the primitive and update the in_cell boolean and enter a while loop as long as the operator stack is greater than zero
  3. 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
  4. 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
  5. If the operation taken from the stack is a complement then the boolean is flipped
  6. If 3 and 5 are both false then break the outside while loop
  7. If the operator stack is zero then return the boolean
  8. If the original token from 2 was not a primitive then push the token to the operator stack
  9. Finally, return the boolean

This change is made in an effort to speed up the runtime of the CSG particle tracing.

myerspat avatar Jun 27 '22 20:06 myerspat

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.

paulromano avatar Jul 26 '22 14:07 paulromano