montepy.numbered_object_collection module#
- class montepy.numbered_object_collection.NumberedDataObjectCollection(obj_class, objects=None, problem=None)#
Bases:
NumberedObjectCollection
- append(obj, insert_in_data=True)#
Appends the given object to the end of this collection.
- Parameters:
obj (Numbered_MCNP_Object) – the object to add.
insert_in_data (bool) – Whether to add the object to the linked problem’s data_inputs.
- Raises:
NumberConflictError – if this object has a number that is already in use.
- append_renumber(obj, step=1)#
Appends the object, but will renumber the object if collision occurs.
This behaves like append, except if there is a number collision the object will be renumbered to an available number. The number will be incremented by step until an available number is found.
- Parameters:
obj (Numbered_MCNP_Object) – The MCNP object being added to the collection.
step (int) – the incrementing step to use to find a new number.
- Returns:
the number for the object.
- Return type:
int
- check_number(number)#
Checks if the number is already in use, and if so raises an error.
- Parameters:
number (int) – The number to check.
- Raises:
NumberConflictError – if this number is in use.
- clear()#
Removes all objects from this collection.
- clone(starting_number=None, step=None)#
Create a new instance of this collection, with all new independent objects with new numbers.
This relies mostly on
copy.deepcopy
.Note
If starting_number, or step are not specified
starting_number()
, andstep()
are used as default values.Added in version 0.5.0.
- Parameters:
starting_number (int) – The starting number to request for a new object numbers.
step (int) – the step size to use to find a new valid number.
- Returns:
a cloned copy of this object.
- Return type:
type(self)
- extend(other_list)#
Extends this collection with another list.
- Parameters:
other_list (list) – the list of objects to add.
- Raises:
NumberConflictError – if these items conflict with existing elements.
- get(i: int, default=None) -> (<class 'montepy.numbered_mcnp_object.Numbered_MCNP_Object'>, None)#
Get
i
if possible, or else returndefault
.- Parameters:
i (int) – number of the object to get, not it’s location in the internal list
default (object) – value to return if not found
- Return type:
- items() Generator[Tuple[int, Numbered_MCNP_Object], None, None] #
Get iterator of the collections (number, object) pairs.
- Return type:
tuple(int, MCNP_Object)
- keys() Generator[int, None, None] #
Get iterator of the collection’s numbers.
- Return type:
int
- link_to_problem(problem)#
Links the card to the parent problem for this card.
This is done so that cards can find links to other objects.
- Parameters:
problem (MCNP_Problem) – The problem to link this card to.
- next_number(step=1)#
Get the next available number, based on the maximum number.
This works by finding the current maximum number, and then adding the stepsize to it.
- Parameters:
step (int) – how much to increase the last number by
- property numbers#
A generator of the numbers being used.
- Return type:
generator
- property objects#
Returns a shallow copy of the internal objects list.
The list object is a new instance, but the underlying objects are the same.
- Return type:
list
- pop(pos=-1)#
Pop the final items off of the collection
- Parameters:
pos (int) – The index of the element to pop from the internal list.
- Returns:
the final elements
- Return type:
- remove(delete)#
Removes the given object from the collection.
- Parameters:
delete (Numbered_MCNP_Object) – the object to delete
- request_number(start_num=None, step=None)#
Requests a new available number.
This method does not “reserve” this number. Objects should be immediately added to avoid possible collisions caused by shifting numbers of other objects in the collection.
Note
If starting_number, or step are not specified
starting_number()
, andstep()
are used as default values.Changed in version 0.5.0: In 0.5.0 the default values were changed to reference
starting_number()
andstep()
.- Parameters:
start_num (int) – the starting number to check.
step (int) – the increment to jump by to find new numbers.
- Returns:
an available number
- Return type:
int
- property starting_number#
The starting number to use when an object is cloned.
- Returns:
the starting number
- Return type:
int
- property step#
The step size to use to find a valid number during cloning.
- Returns:
the step size
- Return type:
int
- values() Generator[Numbered_MCNP_Object, None, None] #
Get iterator of the collection’s objects.
- Return type:
- class montepy.numbered_object_collection.NumberedObjectCollection(obj_class, objects=None, problem=None)#
Bases:
ABC
A collections of MCNP objects.
It quacks like a dict, it acts like a dict, but it’s a list.
The items in the collection are accessible by their number. For instance to get the Cell with a number of 2 you can just say:
problem.cells[2]
You can also add delete items like you would in a dictionary normally.
Unlike dictionaries this collection also supports slices e.g.,
[1:3]
. This will return a newNumberedObjectCollection
with objects that have cell numbers that fit that slice. If a number is in a slice that is not an actual object it will just be skipped.Because MCNP numbered objects start at 1, so do the indices. The slices are effectively 1-based and endpoint-inclusive. This means rather than the normal behavior of [0:5] excluding the index 5, 5 would be included.
- Parameters:
obj_class (type) – the class of numbered objects being collected
objects (list) – the list of cells to start with if needed
problem (MCNP_Problem) – the problem to link this collection to.
- append(obj)#
Appends the given object to the end of this collection.
- Parameters:
obj (Numbered_MCNP_Object) – the object to add.
- Raises:
NumberConflictError – if this object has a number that is already in use.
- append_renumber(obj, step=1)#
Appends the object, but will renumber the object if collision occurs.
This behaves like append, except if there is a number collision the object will be renumbered to an available number. The number will be incremented by step until an available number is found.
- Parameters:
obj (Numbered_MCNP_Object) – The MCNP object being added to the collection.
step (int) – the incrementing step to use to find a new number.
- Returns:
the number for the object.
- Return type:
int
- check_number(number)#
Checks if the number is already in use, and if so raises an error.
- Parameters:
number (int) – The number to check.
- Raises:
NumberConflictError – if this number is in use.
- clear()#
Removes all objects from this collection.
- clone(starting_number=None, step=None)#
Create a new instance of this collection, with all new independent objects with new numbers.
This relies mostly on
copy.deepcopy
.Note
If starting_number, or step are not specified
starting_number()
, andstep()
are used as default values.Added in version 0.5.0.
- Parameters:
starting_number (int) – The starting number to request for a new object numbers.
step (int) – the step size to use to find a new valid number.
- Returns:
a cloned copy of this object.
- Return type:
type(self)
- extend(other_list)#
Extends this collection with another list.
- Parameters:
other_list (list) – the list of objects to add.
- Raises:
NumberConflictError – if these items conflict with existing elements.
- get(i: int, default=None) -> (<class 'montepy.numbered_mcnp_object.Numbered_MCNP_Object'>, None)#
Get
i
if possible, or else returndefault
.- Parameters:
i (int) – number of the object to get, not it’s location in the internal list
default (object) – value to return if not found
- Return type:
- items() Generator[Tuple[int, Numbered_MCNP_Object], None, None] #
Get iterator of the collections (number, object) pairs.
- Return type:
tuple(int, MCNP_Object)
- keys() Generator[int, None, None] #
Get iterator of the collection’s numbers.
- Return type:
int
- link_to_problem(problem)#
Links the card to the parent problem for this card.
This is done so that cards can find links to other objects.
- Parameters:
problem (MCNP_Problem) – The problem to link this card to.
- next_number(step=1)#
Get the next available number, based on the maximum number.
This works by finding the current maximum number, and then adding the stepsize to it.
- Parameters:
step (int) – how much to increase the last number by
- property numbers#
A generator of the numbers being used.
- Return type:
generator
- property objects#
Returns a shallow copy of the internal objects list.
The list object is a new instance, but the underlying objects are the same.
- Return type:
list
- pop(pos=-1)#
Pop the final items off of the collection
- Parameters:
pos (int) – The index of the element to pop from the internal list.
- Returns:
the final elements
- Return type:
- remove(delete)#
Removes the given object from the collection.
- Parameters:
delete (Numbered_MCNP_Object) – the object to delete
- request_number(start_num=None, step=None)#
Requests a new available number.
This method does not “reserve” this number. Objects should be immediately added to avoid possible collisions caused by shifting numbers of other objects in the collection.
Note
If starting_number, or step are not specified
starting_number()
, andstep()
are used as default values.Changed in version 0.5.0: In 0.5.0 the default values were changed to reference
starting_number()
andstep()
.- Parameters:
start_num (int) – the starting number to check.
step (int) – the increment to jump by to find new numbers.
- Returns:
an available number
- Return type:
int
- property starting_number#
The starting number to use when an object is cloned.
- Returns:
the starting number
- Return type:
int
- property step#
The step size to use to find a valid number during cloning.
- Returns:
the step size
- Return type:
int
- values() Generator[Numbered_MCNP_Object, None, None] #
Get iterator of the collection’s objects.
- Return type: