montepy.HalfSpace#

class montepy.HalfSpace(left, operator, right=None, node=None)#

Bases: object

Class representing a geometry half_space.

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.

Methods:

_update_values()

parse_input_node(node)

Parses the given syntax node as a half_space.

remove_duplicate_surfaces(deleting_dict)

Updates old surface numbers to prepare for deleting surfaces.

update_pointers(cells, surfaces, cell)

Update pointers, and link this object to other objects in the problem.

Attributes:

left

The left side of the binary tree of this half_space.

node

The syntax node for this HalfSpace if any.

operator

The operator for applying to this binary tree.

right

The right side of the binary tree of this half_space if any.

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:

HalfSpace

_update_values()#
remove_duplicate_surfaces(deleting_dict: dict[int, tuple[Surface, Surface]])#

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() and complements().

Changed in version 1.0.0: The form of the deleting_dict was changed as Surface is no longer hashable.

Parameters:

deleting_dict (dict[int, tuple[Surface, Surface]]) – a dict of the surfaces to delete, mapping the old surface to the new surface to replace it. The keys are the number of the old surface. The values are a tuple of the old surface, and then the new surface.

update_pointers(cells, surfaces, cell)#

Update pointers, and link this object to other objects in the problem.

This will:

  1. Link this HalfSpace (and its children) to the parent cell.

  2. Update the divider parameter to point to the relevant surface or cell.

  3. Update the parent’s surfaces(), and complements().

Parameters:
  • cells (Cells) – the cells in the problem.

  • surfaces (Surfaces) – The surfaces in the problem.

  • cell (Cell) – the cell this HalfSpace is tied to.

property left#

The left side of the binary tree of this half_space.

Returns:

the left side of the tree.

Return type:

HalfSpace

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:

GeometryTree

property operator#

The operator for applying to this binary tree.

Returns:

the operator for the tree.

Return type:

Operator

property right#

The right side of the binary tree of this half_space if any.

Returns:

the right side of the tree.

Return type:

HalfSpace