Skip to content

Commit

Permalink
pep8 fixes, update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
abachma2 committed May 6, 2024
1 parent 4cffc67 commit de80f4b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 38 deletions.
27 changes: 13 additions & 14 deletions openmcyclus/depletion.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,8 @@ def update_materials(self, comp_list, materials):
--------
material_ids: list of strs
material id numbers for the OpenMC model
Outputs:
--------
materials.xml: file
updated XML for OpenMC with new compositions
mats: openmc.Materials()
updated material object
'''

material_ids = []
Expand All @@ -94,12 +90,12 @@ def update_materials(self, comp_list, materials):
def run_depletion(self, flux, materials, microxs):
'''
Run the IndependentOperator class in OpenMC to perform
transport-independent depletion. This method is only
used in the test suite, and not in the OpenMCyclus
transport-independent depletion. This method is only
used in the test suite, and not in the OpenMCyclus
archetype
Parameters:
-----------
-----------
flux: float
flux through nuclear fuel
materials: openmc.Materials()
Expand All @@ -113,13 +109,13 @@ def run_depletion(self, flux, materials, microxs):
HDF5 data base with the results of the depletion simulation
'''
ind_op = od.IndependentOperator(materials,
[np.array([flux])]*len(materials),
[microxs]*len(materials),
[np.array([flux])] * len(materials),
[microxs] * len(materials),
str(self.path + self.chain_file))
ind_op.output_dir = self.path
integrator = od.PredictorIntegrator(
ind_op,
np.ones(self.timesteps)*30,
np.ones(self.timesteps) * 30,
power=self.power *
1e6,
timestep_units='d')
Expand All @@ -129,13 +125,16 @@ def run_depletion(self, flux, materials, microxs):

def get_spent_comps(self, material_ids, microxs):
'''
Creates a list of each of the spent fuel compositions from the
Creates a list of each of the spent fuel compositions from the
OpenMC depletion
Parameters:
-----------
material_id: list of strs
material ids for the assembly materials in the OpenMC model
microxs: openmc.deplete.MicroXS
microscopic cross section data, used to loop over nuclides
of interest.
Returns:
--------
Expand All @@ -152,6 +151,6 @@ def get_spent_comps(self, material_ids, microxs):
mass = results.get_mass(str(material_id), nuclide)[-1][-1]
if mass <= 1e-10:
continue
comp.update({Z*int(1e7)+A*int(1e4) + m :mass})
comp.update({Z * int(1e7) + A * int(1e4) + m: mass})
spent_comps.append(comp)
return spent_comps
53 changes: 29 additions & 24 deletions tests/unit_tests/test_depletion.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,37 @@ def setUp(self):
Set up the instantiation of the Deplete class
'''
self.deplete = Depletion(
"chain_endfb71_pwr.xml",
10,
100e-6,
"chain_endfb71_pwr.xml",
10,
100e-6,
"./examples/")
self.materials = openmc.Materials().from_xml("./examples/materials.xml")
self.micro_xs = od.MicroXS.from_csv("./examples/micro_xs.csv")
self.micro_xs = od.MicroXS.from_csv("./examples/micro_xs.csv")

def test_update_materials(self):
'''
Test that the provided compositions get written to the
materials.xml file correctly.
Test that the provided compositions get written to the
materials.xml file correctly.
'''
comps = [{922350000:0.05, 922380000:0.95},
{551370000:0.1, 360850000:0.8, 541350000:0.1},
{942390000:0.10, 942410000:0.9}]
material_ids, materials = self.deplete.update_materials(comps, self.materials)
assert materials[0].nuclides == [openmc.material.NuclideTuple('U235',0.05, 'wo'),
openmc.material.NuclideTuple('U238',0.95, 'wo')]
assert materials[1].nuclides == [openmc.material.NuclideTuple('Cs137',0.1, 'wo'),
openmc.material.NuclideTuple('Kr85',0.80, 'wo'),
openmc.material.NuclideTuple('Xe135',0.10, 'wo')]
assert materials[2].nuclides == [openmc.material.NuclideTuple('Pu239',0.10, 'wo'),
openmc.material.NuclideTuple('Pu241',0.90, 'wo')]
assert material_ids == [5,6,7]
comps = [{922350000: 0.05, 922380000: 0.95},
{551370000: 0.1, 360850000: 0.8, 541350000: 0.1},
{942390000: 0.10, 942410000: 0.9}]
material_ids, materials = self.deplete.update_materials(
comps, self.materials)
assert materials[0].nuclides == [
openmc.material.NuclideTuple(
'U235', 0.05, 'wo'), openmc.material.NuclideTuple(
'U238', 0.95, 'wo')]
assert materials[1].nuclides == [
openmc.material.NuclideTuple(
'Cs137', 0.1, 'wo'), openmc.material.NuclideTuple(
'Kr85', 0.80, 'wo'), openmc.material.NuclideTuple(
'Xe135', 0.10, 'wo')]
assert materials[2].nuclides == [
openmc.material.NuclideTuple(
'Pu239', 0.10, 'wo'), openmc.material.NuclideTuple(
'Pu241', 0.90, 'wo')]
assert material_ids == [5, 6, 7]

def test_run_depletion(self):
'''
Expand All @@ -50,19 +57,17 @@ def test_run_depletion(self):
assert os.path.isfile('examples/depletion_results.h5')
os.system('rm examples/depletion_results.h5')



def test_get_spent_comps(self):
'''
Test the compositions that are returned from running depletion.
First, the materials are defined and then depletion is run to prevent
Test the compositions that are returned from running depletion.
First, the materials are defined and then depletion is run to prevent
having to store an HDF5 database in the repo
'''
self.deplete.run_depletion(10.3, self.materials, self.micro_xs)
spent_comps = self.deplete.get_spent_comps(['5','6','7'], self.micro_xs)
spent_comps = self.deplete.get_spent_comps(
['5', '6', '7'], self.micro_xs)
assert 551370000 in spent_comps[0].keys()
assert 922350000 in spent_comps[0].keys()
assert 932410000 not in spent_comps[0].keys()
assert spent_comps[0][922350000] == 10.650004036820036
assert spent_comps[0][942390000] == 0.22663550016678385

0 comments on commit de80f4b

Please sign in to comment.