From 32c02bef365433e938739cd34217dafcf410e420 Mon Sep 17 00:00:00 2001 From: yardasol Date: Mon, 28 Nov 2022 12:27:12 -0600 Subject: [PATCH 01/13] add machinery to use the original material card in the runtime material file --- saltproc/serpent_depcode.py | 47 +++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/saltproc/serpent_depcode.py b/saltproc/serpent_depcode.py index b526f5d9c..a1217a1a0 100644 --- a/saltproc/serpent_depcode.py +++ b/saltproc/serpent_depcode.py @@ -127,10 +127,39 @@ def create_runtime_matfile(self, file_lines): # Create data directory Path.mkdir(Path(self.runtime_matfile).parents[0], exist_ok=True) - # Create file with path for SaltProc rewritable iterative material file + # Get material cards + file_lines = read_plaintext_file(abs_src_matfile) + self.get_material_data(file_lines) + + # Create file with path for SaltProc rewritable iterative material file shutil.copy2(abs_src_matfile, self.runtime_matfile) return [line.replace(src_file, self.runtime_matfile) for line in file_lines] + def get_material_data(self, file_lines): + # Get data for matfile + mat_cards = \ + [line.split() for line in file_lines if line.startswith("mat ")] + mat_idx = [file_lines.index(card) for card in mat_cards] + + # Get library IDs + #mat_extensions = [] + #nuclide_regex = "^\\s*[^%]*\\s*([0-9]{4,}|[A-Z]{1}[a-z]{0,1}-[0-9]{1,3})\\.[0-9]{2}c" + #for i, idx in enumerate(mat_idx): + # j = 0 + # while(not(nuclide_match)): + # j += 1 + # nuclide_match = re.match(nuclide_regex, file_lines[mat_idx+i]) + # if(j == len(file_lines) or j == mat_idx[i+1]): + # ## warning about decay only nucs + # break + # mat_extensions.append(nuclide_match.group(0).split('.')[1]) + + # Get volume indices + card_volume_idx = [card.index('vol') for card in mat_cards] + mat_names = [card.split()[1] for card in mat_cards] + mat_data = (mat_cards, card_volume_idx)#, mat_extensions) + self.material_metadata = dict(zip(mat_names, mat_data)) + def convert_nuclide_code_to_name(self, nuc_code): """Converts Serpent2 nuclide code to symbolic nuclide name. If nuclide is in a metastable state, the nuclide name is concatenated @@ -521,12 +550,16 @@ def update_depletable_materials(self, mats, dep_end_time): % 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)) + mat_card, card_volume_idx = self.material_metadata[name] + mat_card[1] = str(-mat.density) + mat_card[card_volume_idx + 1] = "%7.5E" % mat.vol + f.write(" ".join(mat_card)) + #f.write('mat %s %5.9E burn 1 fix %3s %4i vol %7.5E\n' % + # (name, + # -mat.density, + # self.material_library_id[name], + # 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' % From 0f690a3a638b68a73cab9a63d4d2c816ecdcded4 Mon Sep 17 00:00:00 2001 From: yardasol Date: Mon, 28 Nov 2022 12:56:21 -0600 Subject: [PATCH 02/13] add missing comma --- saltproc/openmc_depcode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saltproc/openmc_depcode.py b/saltproc/openmc_depcode.py index ff8437f52..e3da6cc26 100644 --- a/saltproc/openmc_depcode.py +++ b/saltproc/openmc_depcode.py @@ -129,7 +129,7 @@ def run_depletion_step(self, cores, nodes): '-n', str(nodes), 'python', - self.exec_path + self.exec_path, '--materials', self.runtime_matfile, '--geometry', From 42a1253be1dc1ebcd1aba15972a05aac3c1ba9c5 Mon Sep 17 00:00:00 2001 From: yardasol Date: Mon, 28 Nov 2022 13:22:49 -0600 Subject: [PATCH 03/13] syntax fixes --- saltproc/serpent_depcode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saltproc/serpent_depcode.py b/saltproc/serpent_depcode.py index a1217a1a0..fc42f20a6 100644 --- a/saltproc/serpent_depcode.py +++ b/saltproc/serpent_depcode.py @@ -128,7 +128,7 @@ def create_runtime_matfile(self, file_lines): Path.mkdir(Path(self.runtime_matfile).parents[0], exist_ok=True) # Get material cards - file_lines = read_plaintext_file(abs_src_matfile) + file_lines = self.read_plaintext_file(abs_src_matfile) self.get_material_data(file_lines) # Create file with path for SaltProc rewritable iterative material file From 5586a09793dea378fdc2f75e000f8e480344f16c Mon Sep 17 00:00:00 2001 From: yardasol Date: Tue, 29 Nov 2022 12:20:18 -0600 Subject: [PATCH 04/13] fix nonpassing tests --- saltproc/serpent_depcode.py | 39 ++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/saltproc/serpent_depcode.py b/saltproc/serpent_depcode.py index fc42f20a6..c2ab24210 100644 --- a/saltproc/serpent_depcode.py +++ b/saltproc/serpent_depcode.py @@ -108,6 +108,20 @@ def create_runtime_matfile(self, file_lines): Serpent2 runtime input file with updated material file path. """ + src_file, abs_src_matfile = self.get_burnable_materials_file(file_lines) + + # Create data directory + Path.mkdir(Path(self.runtime_matfile).parents[0], exist_ok=True) + + # Get material cards + flines = self.read_plaintext_file(abs_src_matfile) + self.get_material_data(flines) + + # Create file with path for SaltProc rewritable iterative material file + shutil.copy2(abs_src_matfile, self.runtime_matfile) + return [line.replace(src_file, self.runtime_matfile) for line in file_lines] + + def get_burnable_materials_file(self, file_lines): runtime_dir = Path(self.template_input_file_path).parents[0] include_str = [line for line in file_lines if line.startswith("include ")] if not include_str: @@ -124,22 +138,16 @@ def create_runtime_matfile(self, file_lines): raise IOError('Template file ' f'{self.template_input_file_path} includes ' 'no file with materials description') - # Create data directory - Path.mkdir(Path(self.runtime_matfile).parents[0], exist_ok=True) - - # Get material cards - file_lines = self.read_plaintext_file(abs_src_matfile) - self.get_material_data(file_lines) - - # Create file with path for SaltProc rewritable iterative material file - shutil.copy2(abs_src_matfile, self.runtime_matfile) - return [line.replace(src_file, self.runtime_matfile) for line in file_lines] + return src_file, abs_src_matfile def get_material_data(self, file_lines): # Get data for matfile mat_cards = \ - [line.split() for line in file_lines if line.startswith("mat ")] + [line for line in file_lines if line.startswith("mat ")] mat_idx = [file_lines.index(card) for card in mat_cards] + mat_cards = \ + [line.split() for line in file_lines if line.startswith("mat ")] + # Get library IDs #mat_extensions = [] @@ -156,8 +164,8 @@ def get_material_data(self, file_lines): # Get volume indices card_volume_idx = [card.index('vol') for card in mat_cards] - mat_names = [card.split()[1] for card in mat_cards] - mat_data = (mat_cards, card_volume_idx)#, mat_extensions) + mat_names = [card[1] for card in mat_cards] + mat_data = zip(mat_cards, card_volume_idx)#, mat_extensions) self.material_metadata = dict(zip(mat_names, mat_data)) def convert_nuclide_code_to_name(self, nuc_code): @@ -549,6 +557,11 @@ def update_depletable_materials(self, mats, dep_end_time): f.write('%% Material compositions (after %f days)\n\n' % dep_end_time) nuc_code_map = self.map_nuclide_code_zam_to_serpent() + if not(hasattr(self, 'material_metadata')): + lines = self.read_plaintext_file(self.template_input_file_path) + _, abs_src_matfile = self.get_burnable_materials_file(lines) + file_lines = self.read_plaintext_file(abs_src_matfile) + self.get_material_data(file_lines) for name, mat in mats.items(): mat_card, card_volume_idx = self.material_metadata[name] mat_card[1] = str(-mat.density) From d0c5b5561dc06151528bb5a7aeb19a5c7a8a1fd6 Mon Sep 17 00:00:00 2001 From: yardasol Date: Wed, 7 Dec 2022 10:27:55 -0600 Subject: [PATCH 05/13] update release notes --- doc/releasenotes/v0.5.0.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/releasenotes/v0.5.0.rst b/doc/releasenotes/v0.5.0.rst index b4e995d75..c25a0fb51 100644 --- a/doc/releasenotes/v0.5.0.rst +++ b/doc/releasenotes/v0.5.0.rst @@ -148,13 +148,15 @@ Python API Changes - ``write_mat_file()`` → ``update_depletable_materials()`` - ``get_nuc_name()`` → ``convert_nuclide_code_to_name()`` - ``convert_nuclide_name_serpent_to_zam()`` → ``convert_nuclide_code_to_zam()`` - - ``change_sim_par()`` → (deleted) - - (new function) → ``get_neutron_settings()`` - ``create_iter_matfile()`` → ``create_runtime_matfile()`` - ``replace_burnup_parameters()`` → ``set_power_load()`` - ``write_depcode_input()`` → ``write_runtime_input()`` - ``iter_inputfile`` → ``runtime_inputfile`` - ``iter_matfile`` → ``runtime_matfile`` + - ``change_sim_par()`` → (deleted) + - (new function) → ``get_neutron_settings()`` + - (new function) → ``get_burnable_materials_file()`` + - (new function) → ``get_material_data()`` - ``OpenMCDepcode`` is a ``Depcode`` subclass that interfaces with ``openmc``. This class implements the following functions From df1c026216478aeaff1b46b2d288d9a296f1cb7c Mon Sep 17 00:00:00 2001 From: yardasol Date: Wed, 7 Dec 2022 10:52:35 -0600 Subject: [PATCH 06/13] get_material_data() -> get_burnable_material_card_data() --- doc/releasenotes/v0.5.0.rst | 2 +- saltproc/serpent_depcode.py | 25 ++++++++----------------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/doc/releasenotes/v0.5.0.rst b/doc/releasenotes/v0.5.0.rst index c25a0fb51..f36dd5ec0 100644 --- a/doc/releasenotes/v0.5.0.rst +++ b/doc/releasenotes/v0.5.0.rst @@ -156,7 +156,7 @@ Python API Changes - ``change_sim_par()`` → (deleted) - (new function) → ``get_neutron_settings()`` - (new function) → ``get_burnable_materials_file()`` - - (new function) → ``get_material_data()`` + - (new function) → ``get_burnable_material_card_data()`` - ``OpenMCDepcode`` is a ``Depcode`` subclass that interfaces with ``openmc``. This class implements the following functions diff --git a/saltproc/serpent_depcode.py b/saltproc/serpent_depcode.py index f8268100e..fcae96485 100644 --- a/saltproc/serpent_depcode.py +++ b/saltproc/serpent_depcode.py @@ -115,7 +115,7 @@ def create_runtime_matfile(self, file_lines): # Get material cards flines = self.read_plaintext_file(absolute_path) - self.get_material_data(flines) + self.get_burnable_material_card_data(flines) # Create file with path for SaltProc rewritable iterative material file shutil.copy2(absolute_path, self.runtime_matfile) @@ -140,19 +140,16 @@ def get_burnable_materials_file(self, file_lines): 'no file with materials description') return burnable_materials_path, absolute_path.resolve() - def get_material_data(self, file_lines): + def get_burnable_material_card_data(self, file_lines): # Get data for matfile - mat_cards = \ - [line for line in file_lines if line.startswith("mat ")] - mat_idx = [file_lines.index(card) for card in mat_cards] mat_cards = \ [line.split() for line in file_lines if line.startswith("mat ")] # Get volume indices - card_volume_idx = [card.index('vol') for card in mat_cards] + card_volume_idx = [(card.index('vol') + 1) for card in mat_cards] mat_names = [card[1] for card in mat_cards] mat_data = zip(mat_cards, card_volume_idx)#, mat_extensions) - self.material_metadata = dict(zip(mat_names, mat_data)) + self.burnable_material_card_data = dict(zip(mat_names, mat_data)) def convert_nuclide_code_to_name(self, nuc_code): """Converts Serpent2 nuclide code to symbolic nuclide name. @@ -543,22 +540,16 @@ def update_depletable_materials(self, mats, dep_end_time): f.write('%% Material compositions (after %f days)\n\n' % dep_end_time) nuc_code_map = self.map_nuclide_code_zam_to_serpent() - if not(hasattr(self, 'material_metadata')): + if not(hasattr(self, 'burnable_material_card_data')): lines = self.read_plaintext_file(self.template_input_file_path) _, abs_src_matfile = self.get_burnable_materials_file(lines) file_lines = self.read_plaintext_file(abs_src_matfile) - self.get_material_data(file_lines) + self.get_burnable_material_card_data(file_lines) for name, mat in mats.items(): - mat_card, card_volume_idx = self.material_metadata[name] + mat_card, card_volume_idx = self.burnable_material_card_data[name] mat_card[1] = str(-mat.density) - mat_card[card_volume_idx + 1] = "%7.5E" % mat.vol + mat_card[card_volume_idx] = "%7.5E" % mat.vol f.write(" ".join(mat_card)) - #f.write('mat %s %5.9E burn 1 fix %3s %4i vol %7.5E\n' % - # (name, - # -mat.density, - # self.material_library_id[name], - # 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' % From d51b204647fdfa73d04704ab87759ead8602c755 Mon Sep 17 00:00:00 2001 From: yardasol Date: Wed, 7 Dec 2022 11:18:18 -0600 Subject: [PATCH 07/13] added test for burnable_material_card_data attribute --- .../file_interface_serpent/test.py | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/integration_tests/file_interface_serpent/test.py b/tests/integration_tests/file_interface_serpent/test.py index e1e0bffd0..caec7398f 100644 --- a/tests/integration_tests/file_interface_serpent/test.py +++ b/tests/integration_tests/file_interface_serpent/test.py @@ -36,6 +36,54 @@ def test_runtime_input_from_template(serpent_depcode, msr): file_data = serpent_depcode.create_runtime_matfile(file_data) assert file_data[0].split()[-1] == '\"' + \ serpent_depcode.runtime_matfile + '\"' + + # get_burnable_material_card_data + burnable_material_card_data = {'fuel': + (['mat', + 'fuel', + '-4.960200000E+00', + 'rgb', + '253', + '231', + '37', + 'burn', + '1', + 'fix', + '09c', + '900', + 'vol', + '4.435305E+7', + '%', + 'just', + 'core', + 'volume', + '2.27175E+07'], 13), + 'ctrlPois': + (['mat', + 'ctrlPois', + '-2.52', + 'burn', + '1', + 'fix', + '09c', + '900', + 'rgb', + '255', + '128', + '0', + 'vol', + '1.11635E+04'], 13)} + + + for ref_key, test_key in \ + zip(serpent_depcode.burnable_material_card_data.keys(), + burnable_material_card_data.keys()): + assert ref_key == test_key + ref_data = serpent_depcode.burnable_material_card_data[ref_key] + test_data = burnable_material_card_data[test_key] + np.testing.assert_array_equal(np.array(ref_data, dtype=object), + np.array(test_data, dtype=object)) + remove(serpent_depcode.runtime_matfile) # set_power_load From f0e9b22734cb630e034dca1c566023adda26a5da Mon Sep 17 00:00:00 2001 From: yardasol Date: Wed, 7 Dec 2022 11:35:03 -0600 Subject: [PATCH 08/13] fix writing of runtime material file --- saltproc/serpent_depcode.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/saltproc/serpent_depcode.py b/saltproc/serpent_depcode.py index fcae96485..ccccc80dc 100644 --- a/saltproc/serpent_depcode.py +++ b/saltproc/serpent_depcode.py @@ -34,7 +34,9 @@ class SerpentDepcode(Depcode): Number of active cycles. inactive_cycles : int Number of inactive cycles. - + burnable_material_card_data : dict of str to tuple + Dictionary containing burnable material cards + and the index of the `vol` option. """ @@ -547,9 +549,10 @@ def update_depletable_materials(self, mats, dep_end_time): self.get_burnable_material_card_data(file_lines) for name, mat in mats.items(): mat_card, card_volume_idx = self.burnable_material_card_data[name] - mat_card[1] = str(-mat.density) + mat_card[2] = str(-mat.density) mat_card[card_volume_idx] = "%7.5E" % mat.vol f.write(" ".join(mat_card)) + f.write("\n") for nuc_code, mass_fraction in mat.comp.items(): zam_code = pyname.zzaaam(nuc_code) f.write(' %9s %7.14E\n' % From d206857596d3476601f0a64a7b13b22f511d0e0d Mon Sep 17 00:00:00 2001 From: yardasol Date: Wed, 7 Dec 2022 11:45:48 -0600 Subject: [PATCH 09/13] add check for fix option in mat card --- saltproc/serpent_depcode.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/saltproc/serpent_depcode.py b/saltproc/serpent_depcode.py index ccccc80dc..ba409b21b 100644 --- a/saltproc/serpent_depcode.py +++ b/saltproc/serpent_depcode.py @@ -147,6 +147,13 @@ def get_burnable_material_card_data(self, file_lines): mat_cards = \ [line.split() for line in file_lines if line.startswith("mat ")] + for card in mat_cards: + if 'fix' not in card: + raise IOError(f'"mat" card for burnable material "{card[1]}' + 'does not have a "fix" option. Burnable materials' + 'in SaltProc must include the "fix" option. See' + 'the serpent wiki for more information: ' + 'https://serpent.vtt.fi/mediawiki/index.php/Input_syntax_manual#mat') # Get volume indices card_volume_idx = [(card.index('vol') + 1) for card in mat_cards] mat_names = [card[1] for card in mat_cards] From 08d94a5ac81c8b8c23b8aa01953b7e854a59d813 Mon Sep 17 00:00:00 2001 From: yardasol Date: Wed, 7 Dec 2022 12:31:01 -0600 Subject: [PATCH 10/13] make new functions private --- doc/releasenotes/v0.5.0.rst | 4 ++-- saltproc/serpent_depcode.py | 16 ++++++++-------- .../file_interface_serpent/test.py | 10 +++++----- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/doc/releasenotes/v0.5.0.rst b/doc/releasenotes/v0.5.0.rst index f36dd5ec0..22a8e2a73 100644 --- a/doc/releasenotes/v0.5.0.rst +++ b/doc/releasenotes/v0.5.0.rst @@ -155,8 +155,8 @@ Python API Changes - ``iter_matfile`` → ``runtime_matfile`` - ``change_sim_par()`` → (deleted) - (new function) → ``get_neutron_settings()`` - - (new function) → ``get_burnable_materials_file()`` - - (new function) → ``get_burnable_material_card_data()`` + - (new function) → ``_get_burnable_materials_file()`` + - (new function) → ``_get_burnable_material_card_data()`` - ``OpenMCDepcode`` is a ``Depcode`` subclass that interfaces with ``openmc``. This class implements the following functions diff --git a/saltproc/serpent_depcode.py b/saltproc/serpent_depcode.py index ba409b21b..ae818592e 100644 --- a/saltproc/serpent_depcode.py +++ b/saltproc/serpent_depcode.py @@ -110,20 +110,20 @@ def create_runtime_matfile(self, file_lines): Serpent2 runtime input file with updated material file path. """ - burnable_materials_path, absolute_path = self.get_burnable_materials_file(file_lines) + burnable_materials_path, absolute_path = self._get_burnable_materials_file(file_lines) # Create data directory Path.mkdir(Path(self.runtime_matfile).parents[0], exist_ok=True) # Get material cards flines = self.read_plaintext_file(absolute_path) - self.get_burnable_material_card_data(flines) + self._get_burnable_material_card_data(flines) # Create file with path for SaltProc rewritable iterative material file shutil.copy2(absolute_path, self.runtime_matfile) return [line.replace(burnable_materials_path, self.runtime_matfile) for line in file_lines] - def get_burnable_materials_file(self, file_lines): + def _get_burnable_materials_file(self, file_lines): runtime_dir = Path(self.template_input_file_path).parents[0] include_card = [line for line in file_lines if line.startswith("include ")] if not include_card: @@ -142,7 +142,7 @@ def get_burnable_materials_file(self, file_lines): 'no file with materials description') return burnable_materials_path, absolute_path.resolve() - def get_burnable_material_card_data(self, file_lines): + def _get_burnable_material_card_data(self, file_lines): # Get data for matfile mat_cards = \ [line.split() for line in file_lines if line.startswith("mat ")] @@ -158,7 +158,7 @@ def get_burnable_material_card_data(self, file_lines): card_volume_idx = [(card.index('vol') + 1) for card in mat_cards] mat_names = [card[1] for card in mat_cards] mat_data = zip(mat_cards, card_volume_idx)#, mat_extensions) - self.burnable_material_card_data = dict(zip(mat_names, mat_data)) + self._burnable_material_card_data = dict(zip(mat_names, mat_data)) def convert_nuclide_code_to_name(self, nuc_code): """Converts Serpent2 nuclide code to symbolic nuclide name. @@ -549,13 +549,13 @@ def update_depletable_materials(self, mats, dep_end_time): f.write('%% Material compositions (after %f days)\n\n' % dep_end_time) nuc_code_map = self.map_nuclide_code_zam_to_serpent() - if not(hasattr(self, 'burnable_material_card_data')): + if not(hasattr(self, '_burnable_material_card_data')): lines = self.read_plaintext_file(self.template_input_file_path) _, abs_src_matfile = self.get_burnable_materials_file(lines) file_lines = self.read_plaintext_file(abs_src_matfile) - self.get_burnable_material_card_data(file_lines) + self._get_burnable_material_card_data(file_lines) for name, mat in mats.items(): - mat_card, card_volume_idx = self.burnable_material_card_data[name] + mat_card, card_volume_idx = self._burnable_material_card_data[name] mat_card[2] = str(-mat.density) mat_card[card_volume_idx] = "%7.5E" % mat.vol f.write(" ".join(mat_card)) diff --git a/tests/integration_tests/file_interface_serpent/test.py b/tests/integration_tests/file_interface_serpent/test.py index caec7398f..2f1d79773 100644 --- a/tests/integration_tests/file_interface_serpent/test.py +++ b/tests/integration_tests/file_interface_serpent/test.py @@ -38,7 +38,7 @@ def test_runtime_input_from_template(serpent_depcode, msr): serpent_depcode.runtime_matfile + '\"' # get_burnable_material_card_data - burnable_material_card_data = {'fuel': + _burnable_material_card_data = {'fuel': (['mat', 'fuel', '-4.960200000E+00', @@ -76,11 +76,11 @@ def test_runtime_input_from_template(serpent_depcode, msr): for ref_key, test_key in \ - zip(serpent_depcode.burnable_material_card_data.keys(), - burnable_material_card_data.keys()): + zip(serpent_depcode._burnable_material_card_data.keys(), + _burnable_material_card_data.keys()): assert ref_key == test_key - ref_data = serpent_depcode.burnable_material_card_data[ref_key] - test_data = burnable_material_card_data[test_key] + ref_data = serpent_depcode._burnable_material_card_data[ref_key] + test_data = _burnable_material_card_data[test_key] np.testing.assert_array_equal(np.array(ref_data, dtype=object), np.array(test_data, dtype=object)) From aa4695151a74e50bf97169943c76c0238f1b7e11 Mon Sep 17 00:00:00 2001 From: yardasol Date: Wed, 7 Dec 2022 13:37:17 -0600 Subject: [PATCH 11/13] clean up new functions --- saltproc/serpent_depcode.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/saltproc/serpent_depcode.py b/saltproc/serpent_depcode.py index ae818592e..e5ccdc6c1 100644 --- a/saltproc/serpent_depcode.py +++ b/saltproc/serpent_depcode.py @@ -34,9 +34,6 @@ class SerpentDepcode(Depcode): Number of active cycles. inactive_cycles : int Number of inactive cycles. - burnable_material_card_data : dict of str to tuple - Dictionary containing burnable material cards - and the index of the `vol` option. """ @@ -135,11 +132,11 @@ def _get_burnable_materials_file(self, file_lines): absolute_path = (runtime_dir / burnable_materials_path) else: absolute_path = Path(burnable_materials_path) - with open(absolute_path) as f: - if 'mat ' not in f.read(): - raise IOError('Template file ' - f'{self.template_input_file_path} includes ' - 'no file with materials description') + with open(absolute_path) as f: + if 'mat ' not in f.read(): + raise IOError('Template file ' + f'{self.template_input_file_path} includes ' + 'no file with materials description') return burnable_materials_path, absolute_path.resolve() def _get_burnable_material_card_data(self, file_lines): @@ -149,11 +146,11 @@ def _get_burnable_material_card_data(self, file_lines): for card in mat_cards: if 'fix' not in card: - raise IOError(f'"mat" card for burnable material "{card[1]}' - 'does not have a "fix" option. Burnable materials' - 'in SaltProc must include the "fix" option. See' - 'the serpent wiki for more information: ' - 'https://serpent.vtt.fi/mediawiki/index.php/Input_syntax_manual#mat') + raise IOError(f'"mat" card for burnable material "{card[1]}"' + ' does not have a "fix" option. Burnable materials' + ' in SaltProc must include the "fix" option. See' + ' the serpent wiki for more information:' + ' https://serpent.vtt.fi/mediawiki/index.php/Input_syntax_manual#mat') # Get volume indices card_volume_idx = [(card.index('vol') + 1) for card in mat_cards] mat_names = [card[1] for card in mat_cards] From 0c17f30824407d0055490aadc531b8e0a2eb256f Mon Sep 17 00:00:00 2001 From: yardasol Date: Wed, 7 Dec 2022 13:37:35 -0600 Subject: [PATCH 12/13] add tests for if statements in new functions --- tests/unit_tests/test_serpent_depcode.py | 33 ++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/unit_tests/test_serpent_depcode.py b/tests/unit_tests/test_serpent_depcode.py index 4a5f2d244..691d16f09 100644 --- a/tests/unit_tests/test_serpent_depcode.py +++ b/tests/unit_tests/test_serpent_depcode.py @@ -1,6 +1,8 @@ """Test SerpentDepcode functions""" import pytest import numpy as np +import tempfile +from pathlib import Path from saltproc import SerpentDepcode @@ -35,6 +37,37 @@ def test_get_neutron_settings(serpent_depcode): assert serpent_depcode.active_cycles == 20 assert serpent_depcode.inactive_cycles == 20 +def test_get_burnable_materials_file(serpent_depcode): + err1 = (f'Template file {serpent_depcode.template_input_file_path}' + ' has no statements') + + with pytest.raises(IOError, match=err1): + lines_no_include = ['this line does not start with include'] + serpent_depcode._get_burnable_materials_file(lines_no_include) + + with tempfile.NamedTemporaryFile(mode='w+') as tf: + tf.write('some junk') + old_template = serpent_depcode.template_input_file_path + serpent_depcode.template_input_file_path = tf.name + + err2 = (f'Template file {serpent_depcode.template_input_file_path}' + ' includes no file with materials description') + with pytest.raises(IOError, match=err2): + lines_bad_matfile = [f'include "{tf.name}"'] + serpent_depcode._get_burnable_materials_file(lines_bad_matfile) + serpent_depcode.template_input_file_path = old_template + +def test_get_burnable_material_card_data(serpent_depcode): + bad_mat_cards = ['mat fuel -9.2 burn 1 fix 09c', + 'mat blanket -9.1 burn 1'] + + err = ('"mat" card for burnable material "blanket" does not have a "fix"' + ' option. Burnable materials in SaltProc must include the "fix"' + ' option. See the serpent wiki for more information:' + ' https://serpent.vtt.fi/mediawiki/index.php/Input_syntax_manual#mat') + with pytest.raises(IOError, match=err): + serpent_depcode._get_burnable_material_card_data(bad_mat_cards) + def test_read_plaintext_file(serpent_depcode): template_str = serpent_depcode.read_plaintext_file( From 35cdb8d17f97939967282121c52149b337b77bb0 Mon Sep 17 00:00:00 2001 From: yardasol Date: Thu, 15 Dec 2022 16:48:57 -0600 Subject: [PATCH 13/13] remove '_' prefix in test variable --- .../file_interface_serpent/test.py | 75 +++++++++---------- 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/tests/integration_tests/file_interface_serpent/test.py b/tests/integration_tests/file_interface_serpent/test.py index 2f1d79773..6096d77a4 100644 --- a/tests/integration_tests/file_interface_serpent/test.py +++ b/tests/integration_tests/file_interface_serpent/test.py @@ -38,49 +38,48 @@ def test_runtime_input_from_template(serpent_depcode, msr): serpent_depcode.runtime_matfile + '\"' # get_burnable_material_card_data - _burnable_material_card_data = {'fuel': - (['mat', - 'fuel', - '-4.960200000E+00', - 'rgb', - '253', - '231', - '37', - 'burn', - '1', - 'fix', - '09c', - '900', - 'vol', - '4.435305E+7', - '%', - 'just', - 'core', - 'volume', - '2.27175E+07'], 13), - 'ctrlPois': - (['mat', - 'ctrlPois', - '-2.52', - 'burn', - '1', - 'fix', - '09c', - '900', - 'rgb', - '255', - '128', - '0', - 'vol', - '1.11635E+04'], 13)} - + burnable_material_card_data = {'fuel': + (['mat', + 'fuel', + '-4.960200000E+00', + 'rgb', + '253', + '231', + '37', + 'burn', + '1', + 'fix', + '09c', + '900', + 'vol', + '4.435305E+7', + '%', + 'just', + 'core', + 'volume', + '2.27175E+07'], 13), + 'ctrlPois': + (['mat', + 'ctrlPois', + '-2.52', + 'burn', + '1', + 'fix', + '09c', + '900', + 'rgb', + '255', + '128', + '0', + 'vol', + '1.11635E+04'], 13)} for ref_key, test_key in \ zip(serpent_depcode._burnable_material_card_data.keys(), - _burnable_material_card_data.keys()): + burnable_material_card_data.keys()): assert ref_key == test_key ref_data = serpent_depcode._burnable_material_card_data[ref_key] - test_data = _burnable_material_card_data[test_key] + test_data = burnable_material_card_data[test_key] np.testing.assert_array_equal(np.array(ref_data, dtype=object), np.array(test_data, dtype=object))