pymchelper.flair.common package#
Submodules#
pymchelper.flair.common.bmath module#
- class pymchelper.flair.common.bmath.Matrix(rows=4, cols=-1, type=0)[source]#
Bases:
list
Matrix 4x4 used for vector transformations
- O = [[0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0]]#
- U = [[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]]#
- determinant(eps=1e-15)#
determinant of square matrix using Gauss method
- inverse()#
Inverse matrix in place
- rotate(angle, axis)[source]#
Add rotation elements to the matrix around one axis Axis X=0, Y=1, Z=2, or an arbitrary one given by vector axis
- static translate(x, y=0.0, z=0.0)[source]#
m = Matrix.translate(x,y,z|vector) @return a translation matrix
- transpose()#
@return transpose matrix
- class pymchelper.flair.common.bmath.Quaternion(a, b=None, c=None, d=None)[source]#
Bases:
list
- normalize()#
normalize quaternion
- class pymchelper.flair.common.bmath.Vector(x=3, *args)[source]#
Bases:
list
Vector class
- O = [0.0, 0.0, 0.0]#
- X = [1.0, 0.0, 0.0]#
- Y = [0.0, 1.0, 0.0]#
- Z = [0.0, 0.0, 1.0]#
- normalize()#
Normalize vector and return length
- class pymchelper.flair.common.bmath.ZeroDict[source]#
Bases:
DefaultDict
- class pymchelper.flair.common.bmath.ZeroIntDict[source]#
Bases:
DefaultDict
- pymchelper.flair.common.bmath.eigenvalues(M, eps=1e-15, check=False)[source]#
Return eigen values and eigen vectors of a symmetric matrix
- pymchelper.flair.common.bmath.format_number(number, length=10, useExp=False, useD=False)[source]#
Format a number to fit in the minimum space given by length
- pymchelper.flair.common.bmath.frange(start, stop, step)[source]#
range(start,stop,step) for floating point numbers
- pymchelper.flair.common.bmath.limit(min_, num, max_)[source]#
limit a number within a specific range :param min_: :param num: :param max_: :return:
- pymchelper.flair.common.bmath.linear(X, Y)[source]#
Solve linear regression y = ax + b @return a,b,r
- pymchelper.flair.common.bmath.polar(x, y, deg=False)[source]#
- Convert from rectangular (x,y) to polar (r,w)
r = sqrt(x^2 + y^2) w = arctan(y/x) = [-pi,pi] = [-180,180]
- pymchelper.flair.common.bmath.polyderiv(a)[source]#
- p’(x) = polyderiv(a)
= b[0] + b[1]x + b[2]x^2 +…+ b[n-2]x^{n-2} + b[n-1]x^{n-1}
where b[i] = (i+1)a[i+1]
- pymchelper.flair.common.bmath.polyeval(a, x)[source]#
- p(x) = polyeval(a, x)
= a[0] + a[1]x + a[2]x^2 +…+ a[n-1]x^{n-1} + a[n]x^n = a[0] + x(a[1] + x(a[2] +…+ x(a[n-1] + a[n]x)…)
- pymchelper.flair.common.bmath.polyreduce(a, root)[source]#
Given x = r is a root of n’th degree polynomial p(x) = (x-r)q(x), divide p(x) by linear factor (x-r) using the same algorithm as polynomial evaluation. Then, return the (n-1)’th degree quotient q(x) = polyreduce(a, r)
= c[0] + c[1]x + c[2]x^2 +…+ c[n-2]x^{n-2} + c[n-1]x^{n-1}
- pymchelper.flair.common.bmath.rect(r, w, deg=False)[source]#
- Convert from polar (r,w) to rectangular (x,y)
x = r cos(w) y = r sin(w)
pymchelper.flair.common.csg module#
- 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 2high 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.fortran module#
- pymchelper.flair.common.fortran.read(f)[source]#
Read a fortran structure from a binary file :param f: file to read from :return: data, None for EOF
pymchelper.flair.common.log module#
pymchelper.flair.common.rexx module#
- pymchelper.flair.common.rexx.abbrev(information, info, length=0)[source]#
return true if the info is an abbreviation of information with minimum length l
- pymchelper.flair.common.rexx.insert(new, target, n, pad=' ')[source]#
insert new string to target as position n padded with pad characters
- pymchelper.flair.common.rexx.left(str, length, pad=' ')[source]#
return left of string str of length padded with pad chars
- pymchelper.flair.common.rexx.translate(str, tableo=None, tablei=None, pad=' ')[source]#
translate string