montepy.UnitHalfSpace#

class montepy.UnitHalfSpace(divider, side, is_cell, node=None)#

Bases: HalfSpace

The leaf node for the HalfSpace tree.

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:
  • divider (int, Cell, Surface) – the divider object

  • side (bool) – which side the divider is on. For Cells this will be True.

  • is_cell (bool) – Whether or not this is a cell or not for the divider.

  • node (ValueNode) – the node if any this UnitHalfSpace was built from

Methods:

_update_values()

parse_input_node(node[, is_cell])

Parses the given syntax node as a UnitHalfSpace.

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:

divider

The divider this UnitHalfSpace is based on.

is_cell

Whether or not the divider this uses is a cell.

left

The left side of the binary tree of this half_space.

node

The node that this UnitHalfSpace is based on 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.

side

Which side of the divider this HalfSpace is on.

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:

UnitHalfSpace

_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 divider#

The divider this UnitHalfSpace is based on.

Returns:

the divider defining this HalfSpace

Return type:

int, Cell, Surface

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:

HalfSpace

property node#

The node that this UnitHalfSpace is based on if any.

Returns:

The ValueNode that this UnitHalfSpace is tied to.

Return type:

ValueNode

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

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