montepy.cell module

class montepy.cell.Cell(input=None)

Bases: Numbered_MCNP_Object

Object to represent a single MCNP cell defined in CSG.

Changed in version 0.2.0: Removed the comments argument due to overall simplification of init process.

Parameters:

input (Input) – the input for the cell definition

property allowed_keywords

The allowed keywords for this class of MCNP_Card.

The allowed keywords that would appear in the parameters block. For instance for cells the keywords IMP and VOL are allowed. The allowed keywords need to be in upper case.

Deprecated since version 0.2.0: This is no longer needed. Instead this is specified in montepy.input_parser.tokens.MCNP_Lexer._KEYWORDS().

Returns:

A set of the allowed keywords. If there are none this should return the empty set.

Return type:

set

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

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

static compress_jump_values(values)

Takes a list of strings and jump values and combines repeated jump values.

e.g., 1 1 J J 3 J becomes 1 1 2J 3 J

Deprecated since version 0.2.0: This should be automatically handled by the syntax tree instead.

Parameters:

values (list) – a list of string and Jump values to try to compress

Returns:

a list of MCNP word strings that have jump compression

Return type:

list

Raises:

DeprecationWarning – raised always.

static compress_repeat_values(values, threshold=1e-06)

Takes a list of floats, and tries to compress it using repeats.

E.g., 1 1 1 1 would compress to 1 3R

Deprecated since version 0.2.0: This should be automatically handled by the syntax tree instead.

Parameters:
  • values (list) – a list of float values to try to compress

  • threshold (float) – the minimum threshold to consider two values different

Returns:

a list of MCNP word strings that have repeat compression

Return type:

list

Raises:

DeprecationWarning – always raised.

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

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

property geometry

The Geometry for this problem.

Added in version 0.2.0: Added with the new ability to represent true CSG geometry logic.

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 geometry_logic_string

The original geoemtry input string for the cell.

Warning

Deprecated since version 0.2.0: This was removed to allow for geometry() to truly implement CSG geometry.

Raises:

DeprecationWarning – Will always be raised as an error (which will cause program to halt).

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

The type of lattice being used by the cell.

Returns:

the type of lattice being used

Return type:

Lattice

property leading_comments

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

Added in version 0.2.0.

Returns:

the leading comments.

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.

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.

Return type:

bool

Returns:

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

property number

The current cell number 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.

Rytpe:

dict

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

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

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.

Raises:

IllegalState if any condition exists that make the object incomplete.

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

property words

The words from the input file for this card.

Warning

Deprecated since version 0.2.0: This has been replaced by the syntax tree data structure.

Raises:

DeprecationWarning – Access the syntax tree instead.

static wrap_string_for_mcnp(string, mcnp_version, is_first_line)

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.

Returns:

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

Return type:

list

static wrap_words_for_mcnp(words, mcnp_version, is_first_line)

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

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

Deprecated since version 0.2.0: The concept of words is deprecated, and should be handled by syntax trees now.

Parameters:
  • words (list) – A list of the “words” or data-grams that needed to added to this card. Each word will be separated by at least one space.

  • 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 card. The first line will not be indented.

Returns:

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

Return type:

list

Raises:

DeprecationWarning – raised always.