Skip to content

Commit

Permalink
Slight refactor and allowing application through Model.run
Browse files Browse the repository at this point in the history
  • Loading branch information
pshriwise committed Aug 28, 2023
1 parent df7c2c9 commit dce99d9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
10 changes: 9 additions & 1 deletion openmc/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ def import_properties(self, filename):
def run(self, particles=None, threads=None, geometry_debug=False,
restart_file=None, tracks=False, output=True, cwd='.',
openmc_exec='openmc', mpi_args=None, event_based=None,
export_model_xml=True, **export_kwargs):
export_model_xml=True, apply_tally_results=False, **export_kwargs):
"""Run OpenMC
If the C API has been initialized, then the C API is used, otherwise,
Expand Down Expand Up @@ -653,6 +653,11 @@ def run(self, particles=None, threads=None, geometry_debug=False,
to True.
.. versionadded:: 0.13.3
apply_tally_results : bool
Whether or not to apply results of the final statepoint file to the
model's tally objects.
.. versionadded:: 0.13.4
**export_kwargs
Keyword arguments passed to either :meth:`Model.export_to_model_xml`
or :meth:`Model.export_to_xml`.
Expand Down Expand Up @@ -723,6 +728,9 @@ def run(self, particles=None, threads=None, geometry_debug=False,
if mtime >= tstart: # >= allows for poor clock resolution
tstart = mtime
last_statepoint = sp

if apply_tally_results:
self.tallies.add_results(last_statepoint)
return last_statepoint

def calculate_volumes(self, threads=None, output=True, cwd='.',
Expand Down
36 changes: 33 additions & 3 deletions openmc/statepoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,18 @@ def add_volume_information(self, volume_calc):

def match_tally(self, tally):
"""
Find a tally with an exact specification match
Find a tally with an exact specification match.
.. versionadded 0.13.4
Parameters
----------
tally : openmc.Tally instance
The Tally object to match.
Returns
-------
None or openmc.Tally
"""
try:
sp_tally = self.get_tally(tally.scores,
Expand All @@ -553,8 +564,27 @@ def match_tally(self, tally):
if tally.multiply_density != sp_tally.multiply_density:
sp_tally = None

if sp_tally is None:
raise LookupError(f'Could not find matching tally in {self._f.filename}')
return sp_tally

def contains_tally(self, tally):
"""
Determine whether or not the statepoint contains an exact match for this tally.
.. versionadded 0.13.4
Parameters
----------
tally : openmc.Tally instance
The Tally object to check for.
Returns
-------
True if the tally was matched. False if not.
"""
sp_tally = self.match_tally(tally)
return sp_tally is not None



def get_tally(self, scores=[], filters=[], nuclides=[],
name=None, id=None, estimator=None, exact_filters=False,
Expand Down
4 changes: 4 additions & 0 deletions openmc/tallies.py
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,8 @@ def to_xml_element(self):
def add_results(self, statepoint):
"""Add results from the provided statepoint file to this tally instance
.. versionadded: 0.13.4
Parameters
----------
statepoint : openmc.PathLike or openmc.StatePoint instance
Expand Down Expand Up @@ -3183,6 +3185,8 @@ def merge_tallies(self):
def add_results(self, statepoint):
"""Add results from the provided statepoint file the tally objects in this collection
.. versionadded: 0.13.4
Parameters
----------
statepoint : openmc.PathLike or openmc.StatePoint instance
Expand Down

0 comments on commit dce99d9

Please sign in to comment.