Skip to content

Commit

Permalink
Faster indexing in MicroXS object (openmc-dev#2702)
Browse files Browse the repository at this point in the history
Co-authored-by: Paul Romano <[email protected]>
  • Loading branch information
eepeterson and paulromano authored Sep 26, 2023
1 parent 9cf2f22 commit 11a4638
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions openmc/deplete/microxs.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ def __init__(self, data: np.ndarray, nuclides: List[str], reactions: List[str]):
self.data = data
self.nuclides = nuclides
self.reactions = reactions
self._index_nuc = {nuc: i for i, nuc in enumerate(nuclides)}
self._index_rx = {rx: i for i, rx in enumerate(reactions)}

# TODO: Add a classmethod for generating MicroXS directly from cross section
# data using a known flux spectrum
Expand Down Expand Up @@ -224,8 +226,8 @@ def from_csv(cls, csv_file, **kwargs):

def __getitem__(self, index):
nuc, rx = index
i_nuc = self.nuclides.index(nuc)
i_rx = self.reactions.index(rx)
i_nuc = self._index_nuc[nuc]
i_rx = self._index_rx[rx]
return self.data[i_nuc, i_rx]

def to_csv(self, *args, **kwargs):
Expand Down

0 comments on commit 11a4638

Please sign in to comment.