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:

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

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

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

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:

HalfSpace

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.

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:
  • 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

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

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

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:

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

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.