montepy.cell module#

class montepy.cell.Cell(input: Input | str = None, number: int = None)#

Bases: Numbered_MCNP_Object

Object to represent a single MCNP cell defined in CSG.

Examples

First the cell needs to be initialized.

import montepy
cell = montepy.Cell()

Then a number can be set. By default the cell is voided:

>>> cell.number = 5
>>> print(cell.material)
None
>>> mat = montepy.Material()
>>> mat.number = 20
>>> mat.add_nuclide("1001.80c", 1.0)
>>> cell.material = mat
>>> # mass and atom density are different
>>> cell.mass_density = 0.1

Cells can be inverted with ~ to make a geometry definition that is a compliment of that cell.

complement = ~cell

Changed in version 1.0.0: Added number parameter

Parameters:
  • input (Union[Input, str]) – The Input syntax object this will wrap and parse.

  • number (int) – The number to set for this object.

Methods:

clone([clone_material, clone_region, ...])

Create a new almost independent instance of this cell with a new number.

format_for_mcnp_input(mcnp_version)

Creates a string representation of this MCNP_Object that can be written to file.

link_to_problem(problem)

Links the input to the parent problem for this input.

mcnp_str([mcnp_version])

Returns a string of this input as it would appear in an MCNP input file.

remove_duplicate_surfaces(deleting_dict)

Updates old surface numbers to prepare for deleting surfaces.

update_pointers(cells, materials, surfaces)

Attaches this object to the appropriate objects for surfaces and materials.

validate()

Validates that the cell is in a usable state.

wrap_string_for_mcnp(string, mcnp_version, ...)

Wraps the list of the words to be a well formed MCNP input.

Attributes:

atom_density

The atom density of the material in the cell, in a/b-cm.

cells_complementing_this

The cells which are a complement of this cell.

comments

The comments associated with this input if any.

complements

The Cell objects that this cell is a complement of

fill

the Fill object representing how this cell is filled.

geometry

The Geometry for this problem.

importance

The importances for this cell for various particle types.

is_atom_dens

Whether or not the density is in atom density [a/b-cm].

lattice

lattice_type

The type of lattice being used by the cell.

leading_comments

Any comments that come before the beginning of the input proper.

mass_density

The mass density of the material in the cell, in g/cc.

material

The Material object for the cell.

not_truncated

Indicates if this cell has been marked as not being truncated for optimization.

number

The current number of the object that will be written out to a new input.

old_mat_number

The material number provided in the original input file

old_number

The original cell number provided in the input file

old_universe_number

The original universe number read in from the input file.

parameters

A dictionary of the additional parameters for the object.

surfaces

List of the Surface objects associated with this cell.

trailing_comment

The trailing comments and padding of an input.

universe

The Universe that this cell is in.

volume

The volume for the cell.

volume_is_set

Whether or not the volume for this cell has been set.

volume_mcnp_calc

Indicates whether or not MCNP will attempt to calculate the cell volume.

static wrap_string_for_mcnp(string, mcnp_version, is_first_line, suppress_blank_end=True) list[str]#

Wraps the list of the words to be a well formed MCNP input.

multi-line inputs will be handled by using the indentation format, and not the “&” method.

Parameters:
  • string (str) – A long string with new lines in it, that needs to be chunked appropriately for MCNP inputs

  • mcnp_version (tuple) – the tuple for the MCNP that must be formatted for.

  • is_first_line (bool) – If true this will be the beginning of an MCNP input. The first line will not be indented.

  • suppress_blank_end (bool) – Whether or not to suppress any blank lines that would be added to the end. Good for anywhere but cell modifiers in the cell block.

Returns:

A list of strings that can be written to an input file, one item to a line.

Return type:

list

clone(clone_material=False, clone_region=False, starting_number=None, step=None, add_collect=True)#

Create a new almost independent instance of this cell with a new number.

This relies mostly on copy.deepcopy. All properties and attributes will be a deep copy unless otherwise requested. The one exception is this will still be internally linked to the original problem. Even if clone_region is True the actual region object will be a copy. This means that changes to the new cell’s geometry will be independent, but may or may not refer to the original surfaces.

Added in version 0.5.0.

Parameters:
  • clone_material (bool) – Whether to create a new clone of the material.

  • clone_region (bool) – Whether to clone the underlying objects (Surfaces, Cells) of this cell’s region.

  • starting_number (int) – The starting number to request for a new cell number.

  • step (int) – the step size to use to find a new valid number.

Returns:

a cloned copy of this cell.

Return type:

Cell

format_for_mcnp_input(mcnp_version)#

Creates a string representation of this MCNP_Object that can be written to file.

Parameters:

mcnp_version (tuple) – The tuple for the MCNP version that must be exported to.

Returns:

a list of strings for the lines that this input will occupy.

Return type:

list

Links the input to the parent problem for this input.

This is done so that inputs can find links to other objects.

Parameters:

problem (MCNP_Problem) – The problem to link this input to.

mcnp_str(mcnp_version: tuple[int] = None)#

Returns a string of this input as it would appear in an MCNP input file.

..versionadded:: 1.0.0

Parameters:

mcnp_version (tuple[int]) – The tuple for the MCNP version that must be exported to.

Returns:

The string that would have been printed in a file

Return type:

str

remove_duplicate_surfaces(deleting_dict)#

Updates old surface numbers to prepare for deleting surfaces.

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, materials, surfaces)#

Attaches this object to the appropriate objects for surfaces and materials.

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

  • materials (Materials) – a materials collection of the materials in the problem

  • surfaces (Surfaces) – a surfaces collection of the surfaces in the problem

validate()#

Validates that the cell is in a usable state.

property atom_density: float#

The atom density of the material in the cell, in a/b-cm.

Returns:

the atom density. If no density is set or it is in mass density will return None.

Return type:

float, None

property cells_complementing_this#

The cells which are a complement of this cell.

This returns a generator.

Return type:

generator

property comments: list[PaddingNode]#

The comments associated with this input if any.

This includes all C comments before this card that aren’t part of another card, and any comments that are inside this card.

Returns:

a list of the comments associated with this comment.

Return type:

list

property complements#

The Cell objects that this cell is a complement of

Rytpe:

montepy.cells.Cells

property fill#

the Fill object representing how this cell is filled.

This not only describes the universe that is filling this, but more complex things like transformations, and matrix fills.

Returns:

The Fill object of how this cell is to be filled.

Return type:

Fill

property geometry#

The Geometry for this problem.

The HalfSpace tree that is able to represent this cell’s geometry. MontePy’s geometry is based upon dividers, which includes both Surfaces, and cells. A half-space is created by choosing one side of the divider. A divider will always create two half-spaces; only one of which can be finite.

For instance a plane creates two infinite half-spaces, one above and one below. A finite cell also creates two half-spaces; inside, and outside.

These halfspaces can then be combined with set-logic to make a new half-space.

To generate a halfspace from a surface you must specify the positive or negative side:

half_space = +plane

To complement a cell you must invert it:

half_space = ~cell

To create more complex geometry you can use binary and & as an intersection, and binary or | as a union:

half_space = -cylinder & + bottom & - top

For better documentation please refer to OpenMC.

Returns:

this cell’s geometry

Return type:

HalfSpace

property importance#

The importances for this cell for various particle types.

Each particle’s importance is a property of Importance. e.g., cell.importance.photon = 1.0.

Returns:

the importance for the Cell.

Return type:

Importance

property is_atom_dens#

Whether or not the density is in atom density [a/b-cm].

True means it is in atom density, False means mass density [g/cc].

Return type:

bool

property lattice#
property lattice_type#

The type of lattice being used by the cell.

Returns:

the type of lattice being used

Return type:

Lattice

property leading_comments: list[PaddingNode]#

Any comments that come before the beginning of the input proper.

Returns:

the leading comments.

Return type:

list

property mass_density: float#

The mass density of the material in the cell, in g/cc.

Returns:

the mass density. If no density is set or it is in atom density will return None.

Return type:

float, None

property material#

The Material object for the cell.

If the material is None this is considered to be voided.

Return type:

Material

property not_truncated#

Indicates if this cell has been marked as not being truncated for optimization.

See Note 1 from section 3.3.1.5.1 of the user manual (LA-UR-17-29981).

Note this can be set to True iff that this cell is not in Universe 0.

Note 1. A problem will run faster by preceding the U card entry with a minus sign for any cell that is not truncated by the boundary of any higher-level cell. (The minus sign indicates that calculating distances to boundary in higher-level cells can be omitted.) Use this capability with EXTREME CAUTION; MCNP6 cannot detect errors in this feature because the logic that enables detection is omitted by the presence of the negative universe. Extremely wrong answers can be quietly calculated. Plot several views of the geometry or run with the VOID card to check for errors.

—LA-UR-17-29981.

Returns:

True if this cell has been marked as not being truncated by the parent filled cell.

Return type:

bool

property number#

The current number of the object that will be written out to a new input.

Return type:

int

property old_mat_number#

The material number provided in the original input file

Return type:

int

property old_number#

The original cell number provided in the input file

Return type:

int

property old_universe_number#

The original universe number read in from the input file.

Returns:

the number of the Universe for the cell in the input file.

Return type:

int

property parameters#

A dictionary of the additional parameters for the object.

e.g.: 1 0 -1 u=1 imp:n=0.5 has the parameters {"U": "1", "IMP:N": "0.5"}

Returns:

a dictionary of the key-value pairs of the parameters.

Return type:

unknown

Rytpe:

dict

property surfaces#

List of the Surface objects associated with this cell.

This list does not convey any of the CGS Boolean logic

Return type:

Surfaces

property trailing_comment: list[PaddingNode]#

The trailing comments and padding of an input.

Generally this will be blank as these will be moved to be a leading comment for the next input.

Returns:

the trailing c style comments and intermixed padding (e.g., new lines)

Return type:

list

property universe#

The Universe that this cell is in.

Returns:

the Universe the cell is in.

Return type:

Universe

property volume#

The volume for the cell.

Will only return a number if the volume has been manually set.

Returns:

the volume that has been manually set or None.

Return type:

float, None

property volume_is_set#

Whether or not the volume for this cell has been set.

Returns:

true if the volume is manually set.

Return type:

bool

property volume_mcnp_calc#

Indicates whether or not MCNP will attempt to calculate the cell volume.

This can be disabled by either manually setting the volume or disabling this calculation globally. This does not guarantee that MCNP will able to calculate the volume. Complex geometries may make this impossible.

See allow_mcnp_volume_calc()

Returns:

True iff MCNP will try to calculate the volume for this cell.

Return type:

bool