mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-26 13:15:39 -04:00
Move reset_auto_ids to mixin module and add set_auto_id and reserve_ids functions
This commit is contained in:
parent
c3c9df6a85
commit
3aa456fd4b
2 changed files with 36 additions and 8 deletions
|
|
@ -7,14 +7,6 @@ from six import string_types
|
|||
import openmc
|
||||
from openmc.clean_xml import sort_xml_elements, clean_xml_indentation
|
||||
from openmc.checkvalue import check_type
|
||||
from openmc.mixin import IDManagerMixin
|
||||
|
||||
|
||||
def reset_auto_ids():
|
||||
"""Reset counters for all auto-generated IDs"""
|
||||
for cls in IDManagerMixin.__subclasses__():
|
||||
cls.used_ids.clear()
|
||||
cls.next_id = 1
|
||||
|
||||
|
||||
class Geometry(object):
|
||||
|
|
|
|||
|
|
@ -57,3 +57,39 @@ class IDManagerMixin(object):
|
|||
else:
|
||||
cls.used_ids.add(uid)
|
||||
self._id = uid
|
||||
|
||||
|
||||
def reset_auto_ids():
|
||||
"""Reset counters for all auto-generated IDs"""
|
||||
for cls in IDManagerMixin.__subclasses__():
|
||||
cls.used_ids.clear()
|
||||
cls.next_id = 1
|
||||
|
||||
|
||||
def reserve_ids(ids, cls=None):
|
||||
"""Reserve a set of IDs that won't be used for auto-generated IDs.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
ids : iterable of int
|
||||
IDs to reserve
|
||||
|
||||
"""
|
||||
if cls is None:
|
||||
for cls in IDManagerMixin.__subclasses__():
|
||||
cls.used_ids |= set(ids)
|
||||
else:
|
||||
cls.used_ids |= set(ids)
|
||||
|
||||
|
||||
def set_auto_id(next_id):
|
||||
"""Set the next ID for auto-generated IDs.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
next_id : int
|
||||
The next ID to assign to objects with auto-generated IDs.
|
||||
|
||||
"""
|
||||
for cls in IDManagerMixin.__subclasses__():
|
||||
cls.next_id = next_id
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue