From ed7b8fb8f39715f03f51d633307a4991a137ca09 Mon Sep 17 00:00:00 2001 From: yardasol Date: Mon, 7 Nov 2022 15:12:20 -0600 Subject: [PATCH] write_mat_file() -> update_depleted_materials() - docstring changes - associated testfile changes --- doc/releasenotes/v0.5.0.rst | 2 +- saltproc/abc.py | 2 +- saltproc/app.py | 4 +- saltproc/openmc_depcode.py | 2 +- saltproc/serpent_depcode.py | 46 +++++++++---------- .../file_interface_serpent/test.py | 4 +- .../run_no_reprocessing/test.py | 2 +- 7 files changed, 29 insertions(+), 33 deletions(-) diff --git a/doc/releasenotes/v0.5.0.rst b/doc/releasenotes/v0.5.0.rst index a07fc578f..d5164198e 100644 --- a/doc/releasenotes/v0.5.0.rst +++ b/doc/releasenotes/v0.5.0.rst @@ -134,7 +134,7 @@ Python API Changes - ``run_depcode()`` → ``run_depletion_step()`` - ``OpenMCDepcode`` is a ``Depcode`` subclass that interfaces with ``openmc``. This class implements the following functions - - ``run_depcode()`` + - ``run_depletion_step()`` - ``switch_to_next_geometry()`` - ``write_depcode_input()`` - ``write_depletion_settings()`` diff --git a/saltproc/abc.py b/saltproc/abc.py index 39a5ba87e..b39bd7b7f 100644 --- a/saltproc/abc.py +++ b/saltproc/abc.py @@ -139,7 +139,7 @@ def write_depcode_input(self, reactor, dep_step, restart): """ @abstractmethod - def write_mat_file(self, dep_dict, dep_end_time): + def update_depleted_materials(self, dep_dict, dep_end_time): """Writes the iteration input file containing the burnable materials composition used in depletion runs and updated after each depletion step. diff --git a/saltproc/app.py b/saltproc/app.py index 9444c16c4..ef770743d 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -84,7 +84,7 @@ def run(): print("Removed mass [g]:", extracted_mass) # Store in DB after reprocessing and refill (right before next depl) simulation.store_after_repr(mats, waste_and_feed_streams, dep_step) - depcode.write_mat_file(mats, simulation.burn_time) + depcode.update_depleted_materials(mats, simulation.burn_time) del mats, waste_streams, waste_and_feed_streams, extracted_mass gc.collect() # Switch to another geometry? @@ -520,7 +520,7 @@ def refill_materials(mats, extracted_mass, waste_streams, process_file): process_file : str Path to the `.json` file describing the fuel reprocessing components. - Returns + Returns ------- waste_streams : dict of str to dict Superset of the input parameter `waste_streams`. Dictionary has diff --git a/saltproc/openmc_depcode.py b/saltproc/openmc_depcode.py index 6187a468a..361b82291 100644 --- a/saltproc/openmc_depcode.py +++ b/saltproc/openmc_depcode.py @@ -255,7 +255,7 @@ def write_depletion_settings(self, reactor, current_depstep_idx): with open(self.iter_inputfile['depletion_settings'], 'w') as f: f.writelines(json_dep_settings) - def write_mat_file(self, dep_dict, dep_end_time): + def update_depleted_materials(self, dep_dict, dep_end_time): """Writes the iteration input file containing the burnable materials composition used in OpenMC depletion runs and updated after each depletion step. diff --git a/saltproc/serpent_depcode.py b/saltproc/serpent_depcode.py index 4003b9c14..227d6f960 100644 --- a/saltproc/serpent_depcode.py +++ b/saltproc/serpent_depcode.py @@ -518,40 +518,36 @@ def write_depcode_input(self, reactor, dep_step, restart): out_file.writelines(data) out_file.close() - def write_mat_file(self, dep_dict, dep_end_time): - """Writes the iteration input file containing the burnable materials - composition used in Serpent2 runs and updated after each depletion - step. + def update_depleted_materials(self, mats, dep_end_time): + """Update material file with reprocessed material compositions. Parameters ---------- - dep_dict : dict of str to Materialflow - Dictionary that contains `Materialflow` objects. + mats : dict of str to Materialflow + Dictionary containing reprocessed material compositions ``key`` Name of burnable material. ``value`` - `Materialflow` object holding composition and properties. + :class:`Materialflow` object holding composition and properties. dep_end_time : float Current time at the end of the depletion step (d). """ - matf = open(self.iter_matfile, 'w') - matf.write('%% Material compositions (after %f days)\n\n' - % dep_end_time) - nuc_code_map = self.map_nuclide_code_zam_to_serpent() - for key, value in dep_dict.items(): - matf.write('mat %s %5.9E burn 1 fix %3s %4i vol %7.5E\n' % - (key, - -dep_dict[key].density, - '09c', - dep_dict[key].temp, - dep_dict[key].vol)) - for nuc_code, wt_frac in dep_dict[key].comp.items(): - # Transforms iso name from zas to zzaaam and then to SERPENT - iso_name_serpent = pyname.zzaaam(nuc_code) - matf.write(' %9s %7.14E\n' % - (nuc_code_map[iso_name_serpent], - -wt_frac)) - matf.close() + with open(self.iter_matfile, 'w') as f: + f.write('%% Material compositions (after %f days)\n\n' + % dep_end_time) + nuc_code_map = self.map_nuclide_code_zam_to_serpent() + for name, mat in mats.items(): + f.write('mat %s %5.9E burn 1 fix %3s %4i vol %7.5E\n' % + (name, + -mat.density, + '09c', + mat.temp, + mat.vol)) + for nuc_code, mass_fraction in mat.comp.items(): + zam_code = pyname.zzaaam(nuc_code) + f.write(' %9s %7.14E\n' % + (nuc_code_map[zam_code], + -mass_fraction)) diff --git a/tests/integration_tests/file_interface_serpent/test.py b/tests/integration_tests/file_interface_serpent/test.py index 00f9e276b..a9f92df0d 100644 --- a/tests/integration_tests/file_interface_serpent/test.py +++ b/tests/integration_tests/file_interface_serpent/test.py @@ -60,8 +60,8 @@ def test_iter_input_from_template(serpent_depcode, msr): def test_write_iter_files(serpent_depcode, msr): mats = serpent_depcode.read_depleted_materials(True) - # write_mat_file - serpent_depcode.write_mat_file(mats, 12.0) + # update_depleted_materials + serpent_depcode.update_depleted_materials(mats, 12.0) file = serpent_depcode.iter_matfile file_data = serpent_depcode.read_plaintext_file(file) assert file_data[0] == '% Material compositions (after 12.000000 days)\n' diff --git a/tests/integration_tests/run_no_reprocessing/test.py b/tests/integration_tests/run_no_reprocessing/test.py index 78978424a..b33ac3d18 100644 --- a/tests/integration_tests/run_no_reprocessing/test.py +++ b/tests/integration_tests/run_no_reprocessing/test.py @@ -101,6 +101,6 @@ def runsim_no_reproc(simulation, reactor, nsteps): True) simulation.store_mat_data(mats, dep_step, False) simulation.store_run_step_info() - simulation.sim_depcode.write_mat_file( + simulation.sim_depcode.update_depleted_materials( mats, simulation.burn_time)