2014-02-22 17:26:31 -05:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
2015-09-14 21:42:25 -04:00
|
|
|
import glob
|
|
|
|
|
import os
|
2018-01-29 10:53:46 -06:00
|
|
|
|
|
|
|
|
from tests.testing_harness import *
|
2015-06-25 00:10:07 -06:00
|
|
|
|
2014-02-22 17:26:31 -05:00
|
|
|
|
|
|
|
|
settings1="""<?xml version="1.0"?>
|
|
|
|
|
<settings>
|
|
|
|
|
<state_point batches="10" />
|
2014-03-06 17:02:04 -05:00
|
|
|
<source_point separate="true" />
|
2014-02-22 17:26:31 -05:00
|
|
|
<eigenvalue>
|
|
|
|
|
<batches>10</batches>
|
|
|
|
|
<inactive>5</inactive>
|
|
|
|
|
<particles>1000</particles>
|
|
|
|
|
</eigenvalue>
|
|
|
|
|
<source>
|
|
|
|
|
<space type="box">
|
|
|
|
|
<parameters>-4 -4 -4 4 4 4</parameters>
|
|
|
|
|
</space>
|
|
|
|
|
</source>
|
|
|
|
|
</settings>
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
settings2 = """<?xml version="1.0"?>
|
|
|
|
|
<settings>
|
|
|
|
|
<eigenvalue>
|
|
|
|
|
<batches>10</batches>
|
|
|
|
|
<inactive>5</inactive>
|
|
|
|
|
<particles>1000</particles>
|
|
|
|
|
</eigenvalue>
|
|
|
|
|
<source>
|
|
|
|
|
<file> source.10.{0} </file>
|
|
|
|
|
</source>
|
|
|
|
|
</settings>
|
|
|
|
|
"""
|
|
|
|
|
|
2014-03-11 18:59:37 -04:00
|
|
|
|
2015-06-25 00:10:07 -06:00
|
|
|
class SourceFileTestHarness(TestHarness):
|
|
|
|
|
def execute_test(self):
|
2015-06-29 18:50:53 -06:00
|
|
|
"""Run OpenMC with the appropriate arguments and check the outputs."""
|
2015-06-25 00:10:07 -06:00
|
|
|
try:
|
|
|
|
|
self._run_openmc()
|
|
|
|
|
self._test_output_created()
|
|
|
|
|
self._run_openmc_restart()
|
2015-06-28 00:06:33 -06:00
|
|
|
results = self._get_results()
|
|
|
|
|
self._write_results(results)
|
2015-06-25 00:10:07 -06:00
|
|
|
self._compare_results()
|
|
|
|
|
finally:
|
|
|
|
|
self._cleanup()
|
|
|
|
|
|
2015-06-29 18:50:53 -06:00
|
|
|
def update_results(self):
|
|
|
|
|
"""Update the results_true using the current version of OpenMC."""
|
|
|
|
|
try:
|
|
|
|
|
self._run_openmc()
|
|
|
|
|
self._test_output_created()
|
|
|
|
|
self._run_openmc_restart()
|
|
|
|
|
results = self._get_results()
|
|
|
|
|
self._write_results(results)
|
|
|
|
|
self._overwrite_results()
|
|
|
|
|
finally:
|
|
|
|
|
self._cleanup()
|
|
|
|
|
|
2015-06-25 00:10:07 -06:00
|
|
|
def _test_output_created(self):
|
|
|
|
|
"""Make sure statepoint and source files have been created."""
|
|
|
|
|
statepoint = glob.glob(os.path.join(os.getcwd(), self._sp_name))
|
|
|
|
|
assert len(statepoint) == 1, 'Either multiple or no statepoint files ' \
|
|
|
|
|
'exist.'
|
2015-09-04 12:50:19 +07:00
|
|
|
assert statepoint[0].endswith('h5'), \
|
|
|
|
|
'Statepoint file is not a HDF5 file.'
|
2015-06-25 00:10:07 -06:00
|
|
|
|
|
|
|
|
source = glob.glob(os.path.join(os.getcwd(), 'source.10.*'))
|
|
|
|
|
assert len(source) == 1, 'Either multiple or no source files exist.'
|
2015-09-04 12:50:19 +07:00
|
|
|
assert source[0].endswith('h5'), \
|
|
|
|
|
'Source file is not a HDF5 file.'
|
2015-06-25 00:10:07 -06:00
|
|
|
|
|
|
|
|
def _run_openmc_restart(self):
|
2015-06-28 13:23:24 -06:00
|
|
|
# Get the name of the source file.
|
2015-06-25 00:10:07 -06:00
|
|
|
source = glob.glob(os.path.join(os.getcwd(), 'source.10.*'))
|
2015-06-28 13:23:24 -06:00
|
|
|
|
|
|
|
|
# Write the new settings.xml file.
|
2015-06-25 00:10:07 -06:00
|
|
|
with open('settings.xml','w') as fh:
|
|
|
|
|
fh.write(settings2.format(source[0].split('.')[-1]))
|
|
|
|
|
|
2015-06-28 13:23:24 -06:00
|
|
|
# Run OpenMC.
|
2015-06-30 23:20:54 -06:00
|
|
|
self._run_openmc()
|
2015-06-25 00:10:07 -06:00
|
|
|
|
|
|
|
|
def _cleanup(self):
|
|
|
|
|
TestHarness._cleanup(self)
|
|
|
|
|
output = glob.glob(os.path.join(os.getcwd(), 'source.*'))
|
|
|
|
|
for f in output:
|
|
|
|
|
if os.path.exists(f):
|
|
|
|
|
os.remove(f)
|
|
|
|
|
with open('settings.xml','w') as fh:
|
|
|
|
|
fh.write(settings1)
|
2014-03-11 18:59:37 -04:00
|
|
|
|
2015-06-25 00:10:07 -06:00
|
|
|
|
2018-01-29 12:10:24 -06:00
|
|
|
def test_source_file():
|
2017-04-07 10:25:24 -05:00
|
|
|
harness = SourceFileTestHarness('statepoint.10.h5')
|
2015-06-29 18:50:53 -06:00
|
|
|
harness.main()
|