montepy.mcnp_problem module#
- class montepy.mcnp_problem.MCNP_Problem(destination)#
Bases:
object
A class to represent an entire MCNP problem in a semantic way.
Note
If a stream is provided. It will not be closed by this function.
- Parameters:
destination (io.TextIOBase, str, os.PathLike) – the path to the input file to read, or a readable stream.
- add_cell_children_to_problem()#
Adds the surfaces, materials, and transforms of all cells in this problem to this problem to the internal lists to allow them to be written to file.
Warning
this does not move complement cells, and probably other objects.
- property cells#
A collection of the Cell objects in this problem.
- Returns:
a collection of the Cell objects, ordered by the order they were in the input file.
- Return type:
- clone()#
Creates a complete independent copy of this problem.
Added in version 0.5.0.
- Return type:
- property data_inputs#
A list of the DataInput objects in this problem.
- Returns:
a list of the
DataCardAbstract
objects, ordered by the order they were in the input file.- Return type:
list
- property input_file#
The file name of the original file name this problem was read from.
- Return type:
- property materials#
A collection of the Material objects in this problem.
- Returns:
a colection of the Material objects, ordered by the order they were in the input file.
- Return type:
- property mcnp_version#
The version of MCNP that this is intended for.
Note
MCNP versions prior to 6.2 aren’t fully supported to avoid Export Control Restrictions. Documentation for MCNP 6.2 is public in report: LA-UR-17-29981. All features are based on MCNP 6.2, and may cause other versions of MCNP to break.
The version is a tuple of major, minor, revision. 6.2.0 would be represented as (6, 2, 0)
- Return type:
tuple
- property original_inputs#
A list of the MCNP_Inputs read from the original file.
This should not be mutated, and should be used as a reference to maintain the structure
Deprecated since version 0.2.0: This will likely be removed soon, and it’s functionality will not be necessary to reproduce.
- Returns:
A list of the MCNP_Object objects representing the file as it was read
- Return type:
list
- parse_input(check_input=False, replace=True)#
Semantically parses the MCNP file provided to the constructor.
- Parameters:
check_input (bool) – If true, will try to find all errors with input and collect them as warnings to log.
replace (bool) – replace all non-ASCII characters with a space (0x20)
- property print_in_data_block#
Controls whether or not the specific input gets printed in the cell block or the data block.
This acts like a dictionary. The key is the case insensitive name of the card. For example to enable printing importance data in the data block run:
problem.print_in_data_block["Imp"] = True
- Return type:
bool
- remove_duplicate_surfaces(tolerance)#
Finds duplicate surfaces in the problem, and remove them.
- Parameters:
tolerance (float) – The amount of relative error to consider two surfaces identical
- set_mode(particles)#
Sets the mode of problem to the given particles.
For details see:
montepy.data_cards.mode.Mode.set()
.- Parameters:
particles (list, str) – the particles that the mode will be switched to.
- Raises:
ValueError – if string is not a valid particle shorthand.
- property surfaces#
A collection of the Surface objects in this problem.
- Returns:
a collection of the Surface objects, ordered by the order they were in the input file.
- Return type:
- property transforms#
The collection of transform objects in this problem.
- Returns:
a collection of transforms in the problem.
- Return type:
- property universes#
The Universes object holding all problem universes.
- Returns:
a collection of universes in the problem.
- Return type:
- write_problem(destination, overwrite=False)#
Write the problem to a file or writeable object.
- Parameters:
destination (io.TextIOBase, str, os.PathLike) – File path or writable object
overwrite (bool) – Whether to overwrite ‘destination’ if it is an existing file
- write_to_file(file_path, overwrite=False)#
Writes the problem to a file.
Changed in version 0.3.0: The overwrite parameter was added.
- Parameters:
file_path (str, os.PathLike) – the file path to write this problem to
overwrite (bool) – Whether to overwrite the file at ‘new_problem’ if it exists
- Raises:
IllegalState – if an object in the problem has not been fully initialized.
FileExistsError – if a file already exists with the same path.
IsADirectoryError – if the path given is actually a directory.