From de80f4ba80e171dde370124fe23ed789403136b7 Mon Sep 17 00:00:00 2001 From: abachmann Date: Mon, 6 May 2024 15:54:16 -0500 Subject: [PATCH] pep8 fixes, update documentation --- openmcyclus/depletion.py | 27 ++++++++------- tests/unit_tests/test_depletion.py | 53 ++++++++++++++++-------------- 2 files changed, 42 insertions(+), 38 deletions(-) diff --git a/openmcyclus/depletion.py b/openmcyclus/depletion.py index 6bcd78d..f1c2afa 100644 --- a/openmcyclus/depletion.py +++ b/openmcyclus/depletion.py @@ -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 = [] @@ -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() @@ -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') @@ -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: -------- @@ -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 diff --git a/tests/unit_tests/test_depletion.py b/tests/unit_tests/test_depletion.py index db792fa..5eb6b4d 100644 --- a/tests/unit_tests/test_depletion.py +++ b/tests/unit_tests/test_depletion.py @@ -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): ''' @@ -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 -