pymchelper.flair.common.csg module

exception pymchelper.flair.common.csg.CSGException[source]

Bases: Exception

pymchelper.flair.common.csg.check(expr)[source]

check depth of an rpn expression

pymchelper.flair.common.csg.exp2rpn(expr)[source]

Convert the FLUKA Boolean expression to Reverse Polish Notation (RPN) Since the normalization routine does not accept the +/- as signs to objects, the routine is converting the leading - to @- (Universe minus) where the special symbol @ is treated as the universe. Furthermore the leading + is ignored as well as the leading | which is accepted by fluka.

WARNING: No check is done for the correctness of the expression apart
from the parenthesis nesting
ie.
A+B -> A B +

(A+B)|C -> A B + C | (A|B)|C+D|E -> A B | C D + | E | -A -> @ A - -(-A) -> @ @ A - -

The routine is using the same array for returning the Reverse Polish expression, since the format is more compact. This is generally true apart one case -A -> @ A -

Priorities are treated as:

Operator Priority In Out ——– ——– — —

lower 1 2
  • high 3 4
  • high 3 4

( higher 99 0 ) higher 0 99 object highest 101 100

Algorithm

Consider the expression as a train moving on a railroad with a T-shape, where each token is one wagon

<- (A|B)|C+D

————. .———— RPN-End | / Exp-End


S| t| a| c| k|

Each wagon to move from the Exp-End to the RPN-End it has to make a stop first in the Stack-End. Before entering in the stack, the priority-IN will be checked against the objects in the stack. All top-most objects currently present in the stack with higher priority-OUT will be transfered from the stack to the RPN-End. Apart from the opening parenthesis ( which is discarded.

Example: (1) A+B|C (1) (2) A +B|C (2) (3) A B|C (3) (4) A |C (4) (5) A B + C (5) (6) A B + C (7) A B + C |

————. .———— RPN-End | / Exp-End


S| t| a| c| B C k| A + + | | |

1 2 3 4 5 6 7
Parameters:expr
Returns:
pymchelper.flair.common.csg.optZone(plus, minus)[source]

Optimize a product, by removing the universe @, duplicated terms like A+A, A-A, -A-A, and finally calling the geometrical optimizations and sorting by name the primitives in both the plus and minus terms.

The product is described by 2 arrays the PLUS,NPLUS and MINUS,NMINUS with all the plus and minus terms of the product

WARNING: It doesn’t delete the term from the arrays but changes the name to space. :param plus: :param minus: :return:

pymchelper.flair.common.csg.rmDoubles(zones)[source]

Remove duplicates of products A+B|A+B|C+D -> A+B|C+D :param zones: :return:

pymchelper.flair.common.csg.rpn2exp(rpn)[source]

Convert a NORMALIZED Reverse Polish notation to a standard expression WARNING: The routine expects an expression where for each UNION operator the right-sub-expression is a product while the left can be UNION or a product :param rpn: :return:

pymchelper.flair.common.csg.rpnorm(expr)[source]

Normalize a CG expression given in Reverse Polish Notation. Normalized CG expression is an expression given as sum (Boolean OR) of products (Boolean intersection or subtraction). The normalization (expansion of parenthesis and operator priorities) should be performed by recursively calling the RPNRULE subroutine. Since Fortran-77 doesn’t have recursion, call the RPNRULE for every operator starting from the right-most one, until no rule is found. :param expr: :return:

pymchelper.flair.common.csg.split(expr)[source]

Break products into lists :param expr: :return:

pymchelper.flair.common.csg.splitZones(expr)[source]

split a tokenized expression into zones

pymchelper.flair.common.csg.toString(expr)[source]

return a string version of a tokenize expression

pymchelper.flair.common.csg.tokenize(expr)[source]

return a list of expression tokens