mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 22:26:08 -04:00
PEP8 compliance changes to the new test, testing_harness and input_set
This commit is contained in:
parent
117ca2e1b2
commit
e201b898ed
3 changed files with 49 additions and 33 deletions
|
|
@ -15,8 +15,10 @@ class InputSet(object):
|
|||
self.settings.export_to_xml()
|
||||
self.materials.export_to_xml()
|
||||
self.geometry.export_to_xml()
|
||||
if self.tallies is not None: self.tallies.export_to_xml()
|
||||
if self.plots is not None: self.plots.export_to_xml()
|
||||
if self.tallies is not None:
|
||||
self.tallies.export_to_xml()
|
||||
if self.plots is not None:
|
||||
self.plots.export_to_xml()
|
||||
|
||||
def build_default_materials_and_geometry(self):
|
||||
# Define materials.
|
||||
|
|
@ -82,7 +84,7 @@ class InputSet(object):
|
|||
hot_water.add_s_alpha_beta('HH2O', '71t')
|
||||
|
||||
rpv_steel = openmc.Material(name='Reactor pressure vessel steel',
|
||||
material_id=5)
|
||||
material_id=5)
|
||||
rpv_steel.set_density('g/cm3', 7.9)
|
||||
rpv_steel.add_nuclide("Fe-54", 0.05437098, 'wo')
|
||||
rpv_steel.add_nuclide("Fe-56", 0.88500663, 'wo')
|
||||
|
|
@ -113,7 +115,7 @@ class InputSet(object):
|
|||
rpv_steel.add_nuclide("Cu-65", 0.0006304, 'wo')
|
||||
|
||||
lower_rad_ref = openmc.Material(name='Lower radial reflector',
|
||||
material_id=6)
|
||||
material_id=6)
|
||||
lower_rad_ref.set_density('g/cm3', 4.32)
|
||||
lower_rad_ref.add_nuclide("H-1", 0.0095661, 'wo')
|
||||
lower_rad_ref.add_nuclide("O-16", 0.0759107, 'wo')
|
||||
|
|
@ -189,7 +191,8 @@ class InputSet(object):
|
|||
bot_plate.add_nuclide("Cr-54", 0.004612692337, 'wo')
|
||||
bot_plate.add_s_alpha_beta('HH2O', '71t')
|
||||
|
||||
bot_nozzle = openmc.Material(name='Bottom nozzle region', material_id=9)
|
||||
bot_nozzle = openmc.Material(name='Bottom nozzle region',
|
||||
material_id=9)
|
||||
bot_nozzle.set_density('g/cm3', 2.53)
|
||||
bot_nozzle.add_nuclide("H-1", 0.0245014, 'wo')
|
||||
bot_nozzle.add_nuclide("O-16", 0.1944274, 'wo')
|
||||
|
|
@ -252,7 +255,8 @@ class InputSet(object):
|
|||
top_fa.add_nuclide("Zr-96", 0.02511169542, 'wo')
|
||||
top_fa.add_s_alpha_beta('HH2O', '71t')
|
||||
|
||||
bot_fa = openmc.Material(name='Bottom of fuel assemblies', material_id=12)
|
||||
bot_fa = openmc.Material(name='Bottom of fuel assemblies',
|
||||
material_id=12)
|
||||
bot_fa.set_density('g/cm3', 1.762)
|
||||
bot_fa.add_nuclide("H-1", 0.0292856, 'wo')
|
||||
bot_fa.add_nuclide("O-16", 0.2323919, 'wo')
|
||||
|
|
@ -570,6 +574,7 @@ class InputSet(object):
|
|||
|
||||
self.plots.add_plot(plot)
|
||||
|
||||
|
||||
class PinCellInputSet(object):
|
||||
def __init__(self):
|
||||
self.settings = openmc.Settings()
|
||||
|
|
@ -582,8 +587,10 @@ class PinCellInputSet(object):
|
|||
self.settings.export_to_xml()
|
||||
self.materials.export_to_xml()
|
||||
self.geometry.export_to_xml()
|
||||
if self.tallies is not None: self.tallies.export_to_xml()
|
||||
if self.plots is not None: self.plots.export_to_xml()
|
||||
if self.tallies is not None:
|
||||
self.tallies.export_to_xml()
|
||||
if self.plots is not None:
|
||||
self.plots.export_to_xml()
|
||||
|
||||
def build_default_materials_and_geometry(self):
|
||||
# Define materials.
|
||||
|
|
@ -669,6 +676,7 @@ class PinCellInputSet(object):
|
|||
|
||||
self.plots.add_plot(plot)
|
||||
|
||||
|
||||
class MGInputSet(InputSet):
|
||||
def build_default_materials_and_geometry(self):
|
||||
# Define materials needed for 1D/1G slab problem
|
||||
|
|
@ -694,21 +702,21 @@ class MGInputSet(InputSet):
|
|||
# Define surfaces.
|
||||
|
||||
# Assembly/Problem Boundary
|
||||
left = openmc.XPlane(x0=0.0, surface_id=200,
|
||||
boundary_type='reflective')
|
||||
right = openmc.XPlane(x0=10.0, surface_id=201,
|
||||
boundary_type='reflective')
|
||||
left = openmc.XPlane(x0=0.0, surface_id=200,
|
||||
boundary_type='reflective')
|
||||
right = openmc.XPlane(x0=10.0, surface_id=201,
|
||||
boundary_type='reflective')
|
||||
bottom = openmc.YPlane(y0=0.0, surface_id=300,
|
||||
boundary_type='reflective')
|
||||
top = openmc.YPlane(y0=10.0, surface_id=301,
|
||||
boundary_type='reflective')
|
||||
top = openmc.YPlane(y0=10.0, surface_id=301,
|
||||
boundary_type='reflective')
|
||||
|
||||
down = openmc.ZPlane(z0=0.0, surface_id=0,
|
||||
boundary_type='reflective')
|
||||
down = openmc.ZPlane(z0=0.0, surface_id=0,
|
||||
boundary_type='reflective')
|
||||
fuel_clad_intfc = openmc.ZPlane(z0=2.0, surface_id=1)
|
||||
clad_lwtr_intfc = openmc.ZPlane(z0=2.4, surface_id=2)
|
||||
up = openmc.ZPlane(z0=5.0, surface_id=3,
|
||||
boundary_type='reflective')
|
||||
up = openmc.ZPlane(z0=5.0, surface_id=3,
|
||||
boundary_type='reflective')
|
||||
|
||||
# Define cells
|
||||
c1 = openmc.Cell(cell_id=1)
|
||||
|
|
@ -724,7 +732,7 @@ class MGInputSet(InputSet):
|
|||
# Define root universe.
|
||||
root = openmc.Universe(universe_id=0, name='root universe')
|
||||
|
||||
root.add_cells((c1,c2,c3))
|
||||
root.add_cells((c1, c2, c3))
|
||||
|
||||
# Assign root universe to geometry
|
||||
self.geometry.root_universe = root
|
||||
|
|
|
|||
|
|
@ -26,7 +26,8 @@ class MGXSTestHarness(PyAPITestHarness):
|
|||
# self._input_set.settings.export_to_xml()
|
||||
|
||||
# Initialize a two-group structure
|
||||
energy_groups = openmc.mgxs.EnergyGroups(group_edges=[0, 0.625e-6, 20.])
|
||||
energy_groups = openmc.mgxs.EnergyGroups(group_edges=[0, 0.625e-6,
|
||||
20.])
|
||||
|
||||
# Initialize MGXS Library for a few cross section types
|
||||
self.mgxs_lib = openmc.mgxs.Library(self._input_set.geometry)
|
||||
|
|
@ -90,7 +91,8 @@ class MGXSTestHarness(PyAPITestHarness):
|
|||
def _cleanup(self):
|
||||
super(MGXSTestHarness, self)._cleanup()
|
||||
f = os.path.join(os.getcwd(), 'mgxs.xml')
|
||||
if os.path.exists(f): os.remove(f)
|
||||
if os.path.exists(f):
|
||||
os.remove(f)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import hashlib
|
|||
from optparse import OptionParser
|
||||
import os
|
||||
import shutil
|
||||
from subprocess import Popen, STDOUT, PIPE, call
|
||||
import sys
|
||||
|
||||
import numpy as np
|
||||
|
|
@ -18,6 +17,7 @@ import openmc
|
|||
|
||||
class TestHarness(object):
|
||||
"""General class for running OpenMC regression tests."""
|
||||
|
||||
def __init__(self, statepoint_name, tallies_present=False):
|
||||
self._sp_name = statepoint_name
|
||||
self._tallies = tallies_present
|
||||
|
|
@ -74,13 +74,13 @@ class TestHarness(object):
|
|||
def _test_output_created(self):
|
||||
"""Make sure statepoint.* and tallies.out 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.'
|
||||
assert len(statepoint) == 1, 'Either multiple or no statepoint files' \
|
||||
' exist.'
|
||||
assert statepoint[0].endswith('h5'), \
|
||||
'Statepoint file is not a HDF5 file.'
|
||||
'Statepoint file is not a HDF5 file.'
|
||||
if self._tallies:
|
||||
assert os.path.exists(os.path.join(os.getcwd(), 'tallies.out')), \
|
||||
'Tally output file does not exist.'
|
||||
'Tally output file does not exist.'
|
||||
|
||||
def _get_results(self, hash_output=False):
|
||||
"""Digest info in the statepoint and return as a string."""
|
||||
|
|
@ -98,7 +98,7 @@ class TestHarness(object):
|
|||
tally_num = 1
|
||||
for tally_ind in sp.tallies:
|
||||
tally = sp.tallies[tally_ind]
|
||||
results = np.zeros((tally.sum.size*2, ))
|
||||
results = np.zeros((tally.sum.size * 2, ))
|
||||
results[0::2] = tally.sum.ravel()
|
||||
results[1::2] = tally.sum_sq.ravel()
|
||||
results = ['{0:12.6E}'.format(x) for x in results]
|
||||
|
|
@ -144,6 +144,7 @@ class TestHarness(object):
|
|||
|
||||
class HashedTestHarness(TestHarness):
|
||||
"""Specialized TestHarness that hashes the results."""
|
||||
|
||||
def _get_results(self):
|
||||
"""Digest info in the statepoint and return as a string."""
|
||||
return super(HashedTestHarness, self)._get_results(True)
|
||||
|
|
@ -151,6 +152,7 @@ class HashedTestHarness(TestHarness):
|
|||
|
||||
class CMFDTestHarness(TestHarness):
|
||||
"""Specialized TestHarness for running OpenMC CMFD tests."""
|
||||
|
||||
def _get_results(self):
|
||||
"""Digest info in the statepoint and return as a string."""
|
||||
# Read the statepoint file.
|
||||
|
|
@ -184,6 +186,7 @@ class CMFDTestHarness(TestHarness):
|
|||
|
||||
class ParticleRestartTestHarness(TestHarness):
|
||||
"""Specialized TestHarness for running OpenMC particle restart tests."""
|
||||
|
||||
def _run_openmc(self):
|
||||
# Set arguments
|
||||
args = {'openmc_exec': self._opts.exe}
|
||||
|
|
@ -204,9 +207,9 @@ class ParticleRestartTestHarness(TestHarness):
|
|||
"""Make sure the restart file has been created."""
|
||||
particle = glob.glob(os.path.join(os.getcwd(), self._sp_name))
|
||||
assert len(particle) == 1, 'Either multiple or no particle restart ' \
|
||||
'files exist.'
|
||||
'files exist.'
|
||||
assert particle[0].endswith('h5'), \
|
||||
'Particle restart file is not a HDF5 file.'
|
||||
'Particle restart file is not a HDF5 file.'
|
||||
|
||||
def _get_results(self):
|
||||
"""Digest info in the statepoint and return as a string."""
|
||||
|
|
@ -229,10 +232,10 @@ class ParticleRestartTestHarness(TestHarness):
|
|||
outstr += 'particle energy:\n'
|
||||
outstr += "{0:12.6E}\n".format(p.energy)
|
||||
outstr += 'particle xyz:\n'
|
||||
outstr += "{0:12.6E} {1:12.6E} {2:12.6E}\n".format(p.xyz[0],p.xyz[1],
|
||||
outstr += "{0:12.6E} {1:12.6E} {2:12.6E}\n".format(p.xyz[0], p.xyz[1],
|
||||
p.xyz[2])
|
||||
outstr += 'particle uvw:\n'
|
||||
outstr += "{0:12.6E} {1:12.6E} {2:12.6E}\n".format(p.uvw[0],p.uvw[1],
|
||||
outstr += "{0:12.6E} {1:12.6E} {2:12.6E}\n".format(p.uvw[0], p.uvw[1],
|
||||
p.uvw[2])
|
||||
|
||||
return outstr
|
||||
|
|
@ -240,13 +243,15 @@ class ParticleRestartTestHarness(TestHarness):
|
|||
|
||||
class PyAPITestHarness(TestHarness):
|
||||
def __init__(self, statepoint_name, tallies_present=False, mg=False):
|
||||
super(PyAPITestHarness, self).__init__(statepoint_name, tallies_present)
|
||||
super(PyAPITestHarness, self).__init__(statepoint_name,
|
||||
tallies_present)
|
||||
self.parser.add_option('--build-inputs', dest='build_only',
|
||||
action='store_true', default=False)
|
||||
if mg:
|
||||
self._input_set = MGInputSet()
|
||||
else:
|
||||
self._input_set = InputSet()
|
||||
|
||||
def main(self):
|
||||
"""Accept commandline arguments and either run or update tests."""
|
||||
(self._opts, self._args) = self.parser.parse_args()
|
||||
|
|
@ -321,7 +326,8 @@ class PyAPITestHarness(TestHarness):
|
|||
compare = filecmp.cmp('inputs_test.dat', 'inputs_true.dat')
|
||||
if not compare:
|
||||
f = open('inputs_test.dat')
|
||||
for line in f.readlines(): print(line)
|
||||
for line in f.readlines():
|
||||
print(line)
|
||||
f.close()
|
||||
os.rename('inputs_test.dat', 'inputs_error.dat')
|
||||
assert compare, 'Input files are broken.'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue