mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 14:15:42 -04:00
Obtain last statepoint from a glob of output dir. Reverted regex filter in executor as this is no longer needed
This commit is contained in:
parent
4c96fc11d0
commit
1312a1cc63
4 changed files with 28 additions and 20 deletions
|
|
@ -11,10 +11,6 @@ def _run(args, output, cwd):
|
|||
p = subprocess.Popen(args, cwd=cwd, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT, universal_newlines=True)
|
||||
|
||||
# Compile a regex object to identify statepoint writes
|
||||
sp_rxprog = re.compile(r'Creating state point (.+)\.\.\.')
|
||||
last_statepoint = None
|
||||
|
||||
# Capture and re-print OpenMC output in real-time
|
||||
lines = []
|
||||
while True:
|
||||
|
|
@ -23,11 +19,6 @@ def _run(args, output, cwd):
|
|||
if not line and p.poll() is not None:
|
||||
break
|
||||
|
||||
# If a statepoint was written, capture its filename
|
||||
sp_match = sp_rxprog.search(line)
|
||||
if sp_match:
|
||||
last_statepoint = sp_match.group(1)
|
||||
|
||||
lines.append(line)
|
||||
if output:
|
||||
# If user requested output, print to screen
|
||||
|
|
@ -37,7 +28,6 @@ def _run(args, output, cwd):
|
|||
if p.returncode != 0:
|
||||
raise subprocess.CalledProcessError(p.returncode, ' '.join(args),
|
||||
''.join(lines))
|
||||
return last_statepoint
|
||||
|
||||
|
||||
def plot_geometry(output=True, openmc_exec='openmc', cwd='.'):
|
||||
|
|
@ -195,11 +185,6 @@ def run(particles=None, threads=None, geometry_debug=False,
|
|||
event_based : bool, optional
|
||||
Turns on event-based parallelism, instead of default history-based
|
||||
|
||||
Returns
|
||||
-------
|
||||
str
|
||||
Name of the last written statepoint file, or None
|
||||
|
||||
Raises
|
||||
------
|
||||
subprocess.CalledProcessError
|
||||
|
|
@ -229,4 +214,4 @@ def run(particles=None, threads=None, geometry_debug=False,
|
|||
if mpi_args is not None:
|
||||
args = mpi_args + args
|
||||
|
||||
return _run(args, output, cwd)
|
||||
_run(args, output, cwd)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
from collections.abc import Iterable
|
||||
from pathlib import Path
|
||||
import time
|
||||
|
||||
import openmc
|
||||
from openmc.checkvalue import check_type, check_value
|
||||
|
|
@ -175,7 +176,7 @@ class Model:
|
|||
will be created.
|
||||
|
||||
"""
|
||||
# Create directory if
|
||||
# Create directory if required
|
||||
d = Path(directory)
|
||||
if not d.is_dir():
|
||||
d.mkdir(parents=True)
|
||||
|
|
@ -201,7 +202,7 @@ class Model:
|
|||
|
||||
def run(self, **kwargs):
|
||||
"""Creates the XML files, runs OpenMC, and returns k-effective.
|
||||
The last statepoint filename is available in model.statepoint
|
||||
The last statepoint Path is available in model.statepoint
|
||||
|
||||
Parameters
|
||||
----------
|
||||
|
|
@ -211,14 +212,32 @@ class Model:
|
|||
Returns
|
||||
-------
|
||||
uncertainties.UFloat
|
||||
Combined estimator of k-effective from the statepoint
|
||||
Combined estimator of k-effective from the last statepoint
|
||||
(None if no statepoint was written)
|
||||
|
||||
"""
|
||||
|
||||
self.export_to_xml()
|
||||
|
||||
self.statepoint = openmc.run(**kwargs)
|
||||
# Setting tstart here ensures we don't pick up any old statepoint
|
||||
# files that might preexist in the output directory
|
||||
tstart = time.time()
|
||||
self.statepoint = None
|
||||
|
||||
openmc.run(**kwargs)
|
||||
|
||||
# Get output directory and last statepoint written by this run
|
||||
if self.settings.output and 'path' in self.settings.output:
|
||||
output_dir = Path(self.settings.output['path'])
|
||||
else:
|
||||
output_dir = Path.cwd()
|
||||
for sp in output_dir.glob('statepoint.*.h5'):
|
||||
mtime = sp.stat().st_mtime
|
||||
if mtime >= tstart: # >= allows for poor clock resolution
|
||||
tstart = mtime
|
||||
self.statepoint = sp
|
||||
|
||||
# Open the last statepoint to get the final k-effective
|
||||
keff = None
|
||||
if self.statepoint:
|
||||
with openmc.StatePoint(self.statepoint) as sp:
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
<max_batches>1000</max_batches>
|
||||
<batch_interval>1</batch_interval>
|
||||
</trigger>
|
||||
<verbosity>1</verbosity>
|
||||
</settings>
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<tallies>
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ def model():
|
|||
settings.trigger_max_batches = 1000
|
||||
settings.trigger_batch_interval = 1
|
||||
settings.trigger_active = True
|
||||
settings.verbosity = 1 # to test that this works even with no output
|
||||
|
||||
# Tallies
|
||||
tallies = openmc.Tallies()
|
||||
|
|
@ -88,6 +89,7 @@ class TriggerStatepointRestartTestHarness(PyAPITestHarness):
|
|||
# First non-restart run
|
||||
k_combined_1 = self._model.run(**args)
|
||||
sp_batchno_1 = 0
|
||||
assert self._model.statepoint
|
||||
with openmc.StatePoint(self._model.statepoint) as sp:
|
||||
sp_batchno_1 = sp.current_batch
|
||||
assert sp_batchno_1 > 10
|
||||
|
|
@ -102,6 +104,7 @@ class TriggerStatepointRestartTestHarness(PyAPITestHarness):
|
|||
args['restart_file'] = restart_spfile[0]
|
||||
k_combined_2 = self._model.run(**args)
|
||||
sp_batchno_2 = 0
|
||||
assert self._model.statepoint
|
||||
with openmc.StatePoint(self._model.statepoint) as sp:
|
||||
sp_batchno_2 = sp.current_batch
|
||||
assert sp_batchno_2 > 10
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue