From 15a863e6457766ae792ca44e4b706060318e85f4 Mon Sep 17 00:00:00 2001 From: lewisgross1296 Date: Mon, 15 Aug 2022 14:49:36 -0500 Subject: [PATCH] suggestion by Paul Romano. removed need for _get_tally_index_ funciton by using python's fancy self[key] and self[key]._index capabilities --- openmc/lib/tally.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/openmc/lib/tally.py b/openmc/lib/tally.py index 79f1193e60..90983d1719 100644 --- a/openmc/lib/tally.py +++ b/openmc/lib/tally.py @@ -390,7 +390,7 @@ class Tally(_FortranObjectWithID): class _TallyMapping(Mapping): def __getitem__(self, key): - return Tally(index=self._get_tally_index(key)) + return Tally(index=self[key]) def __iter__(self): for i in range(len(self)): @@ -404,16 +404,6 @@ class _TallyMapping(Mapping): def __delitem__(self, key): """Delete a tally from tally vector and remove the ID,index pair from tally""" - _dll.openmc_remove_tally(self._get_tally_index(key)) - - def _get_tally_index(self, key): - """Given the ID, return the index""" - index = c_int32() - try: - _dll.openmc_get_tally_index(key, index) - except (AllocationError, InvalidIDError) as e: - # __contains__ expects a KeyError to work correctly - raise KeyError(str(e)) - return index.value + _dll.openmc_remove_tally(self[key]._index) tallies = _TallyMapping()