montepy.surfaces.half_space module#
- class montepy.surfaces.half_space.HalfSpace(left, operator, right=None, node=None)#
Bases:
object
Class representing a geometry half_space.
Added in version 0.2.0: This was added as the core of the rework to how MCNP geometries are implemented.
The term half-spaces in MontePy is used very loosely, and is not mathematically rigorous. In MontePy a divider is a something that splits a space (R3 ) into two half-spaces. At the simplest this would be a plane or other quadratic surface. There will always be two half-spaces, a negative, or inside (False) or positive, outside (True). This class proper is for binary trees implementing constructive solid geometry (CSG) set logic. The same logic with half-spaces still apply as the intersection will always create two half-spaces (though one may be the empty set). In this case thinking of “inside” and “outside” may be more useful.
HalfSpaces use binary operators to implement set logic.
For Intersection:
half_space = left & right half_space &= other_side
For Union:
half_space = left | right half_space |= other_side
And you can also complement a HalfSpace:
half_space = ~ other_half_space
Parantheses are allowed, and handled properly
half_space = +bottom & (-left | +right)
- Parameters:
left (HalfSpace) – The left side of the binary tree.
operator (Operator) – the operator to apply between the two branches.
right (HalfSpace) – the right side of the binary tree.
node (GeometryTree) – the node this was parsed from.
- property left#
The left side of the binary tree of this half_space.
- Returns:
the left side of the tree.
- Return type:
- property node#
The syntax node for this HalfSpace if any.
If this was generated by
parse_input_node()
, that initial node will be given. If this was created from scratch, a new node will be generated prior as this is being written to file.- Returns:
the node for this tree.
- Return type:
- property operator#
The operator for applying to this binary tree.
- Returns:
the operator for the tree.
- Return type:
- static parse_input_node(node)#
Parses the given syntax node as a half_space.
- Parameters:
node (GeometryTree) – the Input syntax node to parse.
- Returns:
the HalfSpace properly representing the input geometry.
- Return type:
- remove_duplicate_surfaces(deleting_dict)#
Updates old surface numbers to prepare for deleting surfaces.
This will ensure any new surfaces or complements properly get added to the parent cell’s
surfaces()
andcomplements()
.- Parameters:
deleting_dict (dict) – a dict of the surfaces to delete, mapping the old surface to the new surface to replace it.
- property right#
The right side of the binary tree of this half_space if any.
- Returns:
the right side of the tree.
- Return type:
- update_pointers(cells, surfaces, cell)#
Update pointers, and link this object to other objects in the problem.
This will:
Link this HalfSpace (and its children) to the parent cell.
Update the divider parameter to point to the relevant surface or cell.
Update the parent’s
surfaces()
, andcomplements()
.
- class montepy.surfaces.half_space.UnitHalfSpace(divider, side, is_cell, node=None)#
Bases:
HalfSpace
The leaf node for the HalfSpace tree.
Added in version 0.2.0: This was added as the core of the rework to how MCNP geometries are implemented.
This can only be used as leaves and represents one half_space of a a divider. The easiest way to generate one is with the divider with unary operators. For surfaces you can choose the positive (True) or negative (False) side quickly:
bottom_half = -surf top_half = +surf
For a cell you can only take the complement:
comp = ~cell
Note
When you complement a cell you don’t actually get a UnitHalfSpace directly. You get a UnitHalfSpace wrapped with a complementing HalfSpace Tree
HalfSpace / # \ UnitHalfSpace None | Cell
- Parameters:
- property divider#
The divider this UnitHalfSpace is based on.
- property is_cell#
Whether or not the divider this uses is a cell.
- Returns:
True if this is a cell based HalfSpace
- Return type:
bool
- property left#
The left side of the binary tree of this half_space.
- Returns:
the left side of the tree.
- Return type:
- property node#
The node that this UnitHalfSpace is based on if any.
- Returns:
The ValueNode that this UnitHalfSpace is tied to.
- Return type:
- property operator#
The operator for applying to this binary tree.
- Returns:
the operator for the tree.
- Return type:
- static parse_input_node(node, is_cell=False)#
Parses the given syntax node as a UnitHalfSpace.
- Parameters:
node (ValueNode) – the Input syntax node to parse.
is_cell (bool) – Whether or not this UnitHalfSpace represents a cell.
- Returns:
the HalfSpace properly representing the input geometry.
- Return type:
- remove_duplicate_surfaces(deleting_dict)#
Updates old surface numbers to prepare for deleting surfaces.
- Parameters:
deleting_dict (dict) – a dict of the surfaces to delete.
- property right#
The right side of the binary tree of this half_space if any.
- Returns:
the right side of the tree.
- Return type:
- property side#
Which side of the divider this HalfSpace is on.
This maps the conventional positive/negative half_spaces of MCNP to boolean values. True is the positive side, and False is the negative one. For cells this is always True as the Complementing logic is handled by the parent binary tree.
- Returns:
the side of the divider for the HalfSpace
- Return type:
bool
- update_pointers(cells, surfaces, cell)#
Update pointers, and link this object to other objects in the problem.
This will:
Link this HalfSpace (and its children) to the parent cell.
Update the divider parameter to point to the relevant surface or cell.
Update the parent’s
surfaces()
, andcomplements()
.