From 9da4e00af39324cb43f69a8aa89e669f3a42e774 Mon Sep 17 00:00:00 2001 From: yardasol Date: Mon, 10 Jan 2022 13:52:51 -0600 Subject: [PATCH 001/118] add codename parameter to App.py --- saltproc/app.py | 55 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/saltproc/app.py b/saltproc/app.py index 852365664..67e55f182 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -87,8 +87,9 @@ def read_main_input(main_inp_file): """ with open(main_inp_file) as f: j = json.load(f) - global exec_path, spc_inp_file, dot_inp_file, template_file, db_file - exec_path = j["Path to Serpent executable"] + global depcode_name, exec_path, spc_inp_file, dot_inp_file, template_file, db_file + codename = j["Depletion code name"].lower() + exec_path = j["Path to depletion code executable"] spc_inp_file = os.path.join( os.path.dirname(f.name), j["File containing processing system objects"]) @@ -97,7 +98,7 @@ def read_main_input(main_inp_file): j["Graph file containing processing system structure"]) template_file = os.path.join( os.path.dirname(f.name), - j["User's Serpent input file with reactor model"]) + j["User's depletion code input file with reactor model"]) db_path = j["Path output data storing folder"] db_file = os.path.join( os.path.dirname(f.name), @@ -115,10 +116,10 @@ def read_main_input(main_inp_file): # Read paths to geometry files global geo_file if adjust_geo: - geo_list = j["Geometry file/files to use in Serpent runs"] + geo_list = j["Geometry file/files to use in depletion code runs"] geo_file = [g for g in geo_list] elif not adjust_geo: - geo_file = [j["Geometry file/files to use in Serpent runs"]] + geo_file = [j["Geometry file/files to use in depletion code runs"]] core_massflow_rate = \ j["Salt mass flow rate throughout reactor core (g/s)"] global depl_hist, power_hist @@ -388,18 +389,34 @@ def run(): '\tOutput HDF5 DB Path = ' + os.path.abspath(db_file) + '\n' ) # Intializing objects - serpent = DepcodeSerpent( - exec_path=exec_path, - template_path=template_file, - input_path=input_file, - iter_matfile=iter_matfile, - geo_file=geo_file, - npop=neutron_pop, - active_cycles=active_cycles, - inactive_cycles=inactive_cycles) + if codename == 'serpent': + depcode = DepcodeSerpent( + codename=codename, + exec_path=exec_path, + template_path=template_file, + input_path=input_file, + iter_matfile=iter_matfile, + geo_file=geo_file, + npop=neutron_pop, + active_cycles=active_cycles, + inactive_cycles=inactive_cycles) + elif codename == 'openmc': + depcode = DepcodeOpenMC( + codename=codename, + exec_path=exec_path, + template_path=template_file, + input_path=input_file, + iter_matfile=iter_matfile, + geo_file=geo_file, + npop=neutron_pop, + active_cycles=active_cycles, + inactive_cycles=inactive_cycles) + else: + throw ValueError(f'{codename} is not a supported depletion code') + simulation = Simulation( sim_name='Super test', - sim_depcode=serpent, + sim_depcode=depcode, core_number=cores, node_number=nodes, h5_file=db_file, @@ -415,21 +432,21 @@ def run(): # Start sequence for dts in range(len(depl_hist)): print("\n\n\nStep #%i has been started" % (dts + 1)) - serpent.write_depcode_input(template_file, + depcode.write_depcode_input(template_file, input_file, msr, dts, restart_flag) - serpent.run_depcode(cores, nodes) + depcode.run_depcode(cores, nodes) if dts == 0 and restart_flag is False: # First step # Read general simulation data which never changes simulation.store_run_init_info() # Parse and store data for initial state (beginning of dts) - mats = serpent.read_dep_comp(input_file, False) + mats = depcode.read_dep_comp(input_file, False) simulation.store_mat_data(mats, dts - 1, 'before_reproc') # Finish of First step # Main sequence - mats = serpent.read_dep_comp(input_file, True) + mats = depcode.read_dep_comp(input_file, True) simulation.store_mat_data(mats, dts, 'before_reproc') simulation.store_run_step_info() # Reprocessing here From 4c493f217cfe8146e7f289c2c737bafb406cb8a9 Mon Sep 17 00:00:00 2001 From: yardasol Date: Mon, 10 Jan 2022 13:59:21 -0600 Subject: [PATCH 002/118] typo fixes --- saltproc/app.py | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/saltproc/app.py b/saltproc/app.py index 67e55f182..5068d0917 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -87,8 +87,8 @@ def read_main_input(main_inp_file): """ with open(main_inp_file) as f: j = json.load(f) - global depcode_name, exec_path, spc_inp_file, dot_inp_file, template_file, db_file - codename = j["Depletion code name"].lower() + global codename, exec_path, spc_inp_file, dot_inp_file, template_file, db_file + codename = j["Name of depletion code"].lower() exec_path = j["Path to depletion code executable"] spc_inp_file = os.path.join( os.path.dirname(f.name), @@ -400,17 +400,6 @@ def run(): npop=neutron_pop, active_cycles=active_cycles, inactive_cycles=inactive_cycles) - elif codename == 'openmc': - depcode = DepcodeOpenMC( - codename=codename, - exec_path=exec_path, - template_path=template_file, - input_path=input_file, - iter_matfile=iter_matfile, - geo_file=geo_file, - npop=neutron_pop, - active_cycles=active_cycles, - inactive_cycles=inactive_cycles) else: throw ValueError(f'{codename} is not a supported depletion code') From 3cfd4b01b338415c67a65f2efecf76ea274e04c5 Mon Sep 17 00:00:00 2001 From: yardasol Date: Mon, 10 Jan 2022 14:04:12 -0600 Subject: [PATCH 003/118] update test and example input files --- examples/msbr/msbr_main.json | 7 ++++--- examples/tap/tap_main.json | 7 ++++--- .../tests/integration_tests/const_repr/tap_main_test.json | 7 ++++--- saltproc/tests/test.json | 7 ++++--- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/examples/msbr/msbr_main.json b/examples/msbr/msbr_main.json index 202c1ea19..843a55a6a 100644 --- a/examples/msbr/msbr_main.json +++ b/examples/msbr/msbr_main.json @@ -1,15 +1,16 @@ { - "Path to Serpent executable": "sss2", + "Name of depletion code": "serpent", + "Path to depletion code executable": "sss2", "File containing processing system objects": "msbr_objects.json", "Graph file containing processing system structure": "msbr.dot", - "User's Serpent input file with reactor model": "msbr.serpent", + "User's depletion code input file with reactor model": "msbr.serpent", "Path output data storing folder": "../../saltproc/data/", "Output HDF5 database file name": "msbr_kl_100_saltproc.h5", "Number of neutrons per generation": 50, "Number of active generations": 20, "Number of inactive generations": 20, "Restart simulation from the step when it stopped?": false, - "Geometry file/files to use in Serpent runs": "geometry/msbr_full.ini", + "Geometry file/files to use in depletion code runs": "geometry/msbr_full.ini", "Switch to another geometry when keff drops below 1?": false, "Salt mass flow rate throughout reactor core (g/s)": 9920000, "Number of steps for constant power and depletion interval case": 12, diff --git a/examples/tap/tap_main.json b/examples/tap/tap_main.json index 83f521bef..f6f5c9b62 100644 --- a/examples/tap/tap_main.json +++ b/examples/tap/tap_main.json @@ -1,15 +1,16 @@ { - "Path to Serpent executable": "sss2", + "Name of depletion code": "serpent", + "Path to depletion code executable": "sss2", "File containing processing system objects": "tap_objects.json", "Graph file containing processing system structure": "tap.dot", - "User's Serpent input file with reactor model": "tap.serpent", + "User's depletion code input file with reactor model": "tap.serpent", "Path output data storing folder": "../../saltproc/data/", "Output HDF5 database file name": "db_saltproc.h5", "Number of neutrons per generation": 50, "Number of active generations": 20, "Number of inactive generations": 20, "Restart simulation from the step when it stopped?": false, - "Geometry file/files to use in Serpent runs": [ + "Geometry file/files to use in depletion code runs": [ "geometry/347_base.ini", "geometry/406.ini", "geometry/427.ini", diff --git a/saltproc/tests/integration_tests/const_repr/tap_main_test.json b/saltproc/tests/integration_tests/const_repr/tap_main_test.json index 62cdf5b63..9c17c912d 100644 --- a/saltproc/tests/integration_tests/const_repr/tap_main_test.json +++ b/saltproc/tests/integration_tests/const_repr/tap_main_test.json @@ -1,15 +1,16 @@ { - "Path to Serpent executable": "sss2", + "Name of depletion code" : "serpent", + "Path to depletion code executable": "sss2", "File containing processing system objects": "input_5leu.json", "Graph file containing processing system structure": "tap.dot", - "User's Serpent input file with reactor model": "tap_test.serpent", + "User's depletion code input file with reactor model": "tap_test.serpent", "Path output data storing folder": "./", "Output HDF5 database file name": "db_saltproc.h5", "Number of neutrons per generation": 50, "Number of active generations": 20, "Number of inactive generations": 20, "Restart simulation from the step when it stopped?": false, - "Geometry file/files to use in Serpent runs": "347_base.ini", + "Geometry file/files to use in depletion code runs": "347_base.ini", "Switch to another geometry when keff drops below 1?": false, "Salt mass flow rate throughout reactor core (g/s)": 9.92E+6, "Number of steps for constant power and depletion interval case": 2, diff --git a/saltproc/tests/test.json b/saltproc/tests/test.json index 2360a8d97..97eb7ca4f 100644 --- a/saltproc/tests/test.json +++ b/saltproc/tests/test.json @@ -1,15 +1,16 @@ { - "Path to Serpent executable": "/home/andrei2/serpent/serpent2/src_2131/sss2", + "Name of depletion code" : "serpent" , + "Path to depletion code executable": "/home/andrei2/serpent/serpent2/src_2131/sss2", "File containing processing system objects": "processes.json", "Graph file containing processing system structure": "test.dot", - "User's Serpent input file with reactor model": "tap_test1.serpent", + "User's depletion code input file with reactor model": "tap_test1.serpent", "Path output data storing folder": "./", "Output HDF5 database file name": "db_saltproc.h5", "Number of neutrons per generation": 50, "Number of active generations": 20, "Number of inactive generations": 20, "Restart simulation from the step when it stopped?": false, - "Geometry file/files to use in Serpent runs": "347_base.ini", + "Geometry file/files to use in depletion code runs": "347_base.ini", "Switch to another geometry when keff drops below 1?": false, "Salt mass flow rate throughout reactor core (g/s)": 9.92E+6, "Number of steps for constant power and depletion interval case": 2, From 4168ce489c81457ec0d291d01c03ace6ceb3964a Mon Sep 17 00:00:00 2001 From: yardasol Date: Mon, 10 Jan 2022 14:05:02 -0600 Subject: [PATCH 004/118] remove un needed codename parameter --- saltproc/app.py | 1 - 1 file changed, 1 deletion(-) diff --git a/saltproc/app.py b/saltproc/app.py index 5068d0917..0a602f81d 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -391,7 +391,6 @@ def run(): # Intializing objects if codename == 'serpent': depcode = DepcodeSerpent( - codename=codename, exec_path=exec_path, template_path=template_file, input_path=input_file, From 833969f1185daf3d312bddfb5234544a264850d0 Mon Sep 17 00:00:00 2001 From: yardasol Date: Mon, 10 Jan 2022 14:14:23 -0600 Subject: [PATCH 005/118] fix throw to raise --- saltproc/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saltproc/app.py b/saltproc/app.py index 0a602f81d..b3d5a0396 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -400,7 +400,7 @@ def run(): active_cycles=active_cycles, inactive_cycles=inactive_cycles) else: - throw ValueError(f'{codename} is not a supported depletion code') + raise ValueError(f'{codename} is not a supported depletion code') simulation = Simulation( sim_name='Super test', From 95a613182725e941f6ce5adf9486e694ac23349f Mon Sep 17 00:00:00 2001 From: yardasol Date: Mon, 10 Jan 2022 14:17:13 -0600 Subject: [PATCH 006/118] fix typos in test input file --- saltproc/tests/test.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saltproc/tests/test.json b/saltproc/tests/test.json index 97eb7ca4f..f5603ea24 100644 --- a/saltproc/tests/test.json +++ b/saltproc/tests/test.json @@ -1,5 +1,5 @@ { - "Name of depletion code" : "serpent" , + "Name of depletion code": "serpent", "Path to depletion code executable": "/home/andrei2/serpent/serpent2/src_2131/sss2", "File containing processing system objects": "processes.json", "Graph file containing processing system structure": "test.dot", From c7a2ac1b43e93dfc935e0df47c77d27f76460ec1 Mon Sep 17 00:00:00 2001 From: yardasol Date: Mon, 10 Jan 2022 14:17:25 -0600 Subject: [PATCH 007/118] add test for codename --- saltproc/tests/test_app.py | 1 + 1 file changed, 1 insertion(+) diff --git a/saltproc/tests/test_app.py b/saltproc/tests/test_app.py index b73aacb1f..c243ebe28 100644 --- a/saltproc/tests/test_app.py +++ b/saltproc/tests/test_app.py @@ -21,6 +21,7 @@ def test_read_main_input(): app.read_main_input(main_input) + assert app.codename == "serpent" assert app.neutron_pop == 50 assert app.active_cycles == 20 assert app.active_cycles == 20 From 25e0b6041a444331ea3b9e494e21cadace316dd6 Mon Sep 17 00:00:00 2001 From: yardasol Date: Mon, 10 Jan 2022 15:01:29 -0600 Subject: [PATCH 008/118] fix overlength line --- saltproc/app.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/saltproc/app.py b/saltproc/app.py index b3d5a0396..bb2100651 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -87,7 +87,8 @@ def read_main_input(main_inp_file): """ with open(main_inp_file) as f: j = json.load(f) - global codename, exec_path, spc_inp_file, dot_inp_file, template_file, db_file + global codename, exec_path, spc_inp_file, dot_inp_file, template_file, \ + db_file codename = j["Name of depletion code"].lower() exec_path = j["Path to depletion code executable"] spc_inp_file = os.path.join( From 0a0bb5f63ed69442a79fd44138355b848d7b5913 Mon Sep 17 00:00:00 2001 From: yardasol Date: Wed, 12 Jan 2022 13:15:49 -0600 Subject: [PATCH 009/118] pep8 fixes --- saltproc/app.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/saltproc/app.py b/saltproc/app.py index bb2100651..b3d5a0396 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -87,8 +87,7 @@ def read_main_input(main_inp_file): """ with open(main_inp_file) as f: j = json.load(f) - global codename, exec_path, spc_inp_file, dot_inp_file, template_file, \ - db_file + global codename, exec_path, spc_inp_file, dot_inp_file, template_file, db_file codename = j["Name of depletion code"].lower() exec_path = j["Path to depletion code executable"] spc_inp_file = os.path.join( From 538bbfcb4859d00424ceabfca9b2887230b3c2fd Mon Sep 17 00:00:00 2001 From: yardasol Date: Wed, 12 Jan 2022 13:18:12 -0600 Subject: [PATCH 010/118] more pep8 fixes --- saltproc/app.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/saltproc/app.py b/saltproc/app.py index b3d5a0396..9cfd47167 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -87,7 +87,8 @@ def read_main_input(main_inp_file): """ with open(main_inp_file) as f: j = json.load(f) - global codename, exec_path, spc_inp_file, dot_inp_file, template_file, db_file + global codename, exec_path, spc_inp_file, dot_inp_file, \ + template_file, db_file codename = j["Name of depletion code"].lower() exec_path = j["Path to depletion code executable"] spc_inp_file = os.path.join( From d7531a9591f0cc54f2d5d6fa1f9895af82a8c438 Mon Sep 17 00:00:00 2001 From: yardasol Date: Thu, 13 Jan 2022 12:57:10 -0600 Subject: [PATCH 011/118] update Simulation docstring --- saltproc/simulation.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/saltproc/simulation.py b/saltproc/simulation.py index 95693fac6..fe87c088c 100644 --- a/saltproc/simulation.py +++ b/saltproc/simulation.py @@ -5,8 +5,13 @@ class Simulation(): - """Class sets up parameters for simulation, runs Serpent, parses output, - creates input. + """Class for handling simulation information. Contains information + for running simulation wiht parallelism. Also contains the simulation + name, a `Depcode` object, and the filename for the simulation database. + Contains methods to store simulation metadata and depletion results in + a database, predict reactor criticality at next depletion step, and + switch simulation geometry. + """ def __init__( From b2af45c428a01d7f7a18a0c39a1007b7a40e9ecd Mon Sep 17 00:00:00 2001 From: yardasol Date: Thu, 13 Jan 2022 13:15:15 -0600 Subject: [PATCH 012/118] update __init__ docstring --- saltproc/simulation.py | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/saltproc/simulation.py b/saltproc/simulation.py index fe87c088c..4f774b160 100644 --- a/saltproc/simulation.py +++ b/saltproc/simulation.py @@ -29,22 +29,27 @@ def __init__( Parameters ---------- - sim_name: str - Name of simulation may contain number of reference case, paper name - or other specific information to identify simulation. - sim_depcode: obj - Depcode object initiated using Depcode class. - cores: int - Number of cores to use for Serpent run (`-omp` flag in Serpent). - nodes: int - Number of nodes to use for Serpent run (`-mpi` flag in Serpent). - h5_file: str - Name of HDF5 database. - compression: Pytables filter object - HDF5 database compression parameters. - iter_matfile: str - Name of file containing burnable materials composition used in - Serpent runs and update after each depletion step. + sim_name : str + Name to identify the simulation. May contain information such as + the number of a reference case, a paper name, or some other + specific information identify the simulation. + sim_depcode : Depcode object + An instance of one of the `Depcode` child classes + cores : int + Number of cores to use for depletion code run (`-omp` flag in + Serpent). + nodes : int + Number of nodes to use for depletion code run (`-mpi` flag in + Serpent). + db_path : str + Path of HDF5 database that stores simulation information and + data. + compression_params : Pytables filter object + Compression parameters for HDF5 database. + iter_matfile : str + Name of iterative, rewritable material file for depletion code + rerunning. This file is modified during the simulation. + """ # initialize all object attributes self.sim_name = sim_name From 21b1fa31355723d71923aa4f0b004068eeb4aa05 Mon Sep 17 00:00:00 2001 From: yardasol Date: Thu, 13 Jan 2022 13:23:14 -0600 Subject: [PATCH 013/118] h5_file -> db_path --- saltproc/app.py | 2 +- saltproc/simulation.py | 16 ++++++++-------- .../no_repro/test_no_reproc_run.py | 2 +- saltproc/tests/test_simulation.py | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/saltproc/app.py b/saltproc/app.py index 9cfd47167..5b9f7b02e 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -408,7 +408,7 @@ def run(): sim_depcode=depcode, core_number=cores, node_number=nodes, - h5_file=db_file, + db_path=db_file, iter_matfile=iter_matfile) msr = Reactor( volume=1.0, diff --git a/saltproc/simulation.py b/saltproc/simulation.py index 4f774b160..5c7734d48 100644 --- a/saltproc/simulation.py +++ b/saltproc/simulation.py @@ -20,7 +20,7 @@ def __init__( sim_depcode="SERPENT", core_number=1, node_number=1, - h5_file="db_saltproc.h5", + db_path="db_saltproc.h5", compression=tb.Filters(complevel=9, complib='blosc', fletcher32=True), @@ -56,7 +56,7 @@ def __init__( self.sim_depcode = sim_depcode self.core_number = core_number self.node_number = node_number - self.h5_file = h5_file + self.db_path = db_path self.compression = compression self.iter_matfile = iter_matfile @@ -132,7 +132,7 @@ def store_after_repr(self, after_mats, waste_dict, step): """ streams_gr = 'in_out_streams' - db = tb.open_file(self.h5_file, mode='a', filters=self.compression) + db = tb.open_file(self.db_path, mode='a', filters=self.compression) for mn in waste_dict.keys(): # iterate over materials mat_node = getattr(db.root.materials, mn) if not hasattr(mat_node, streams_gr): @@ -210,7 +210,7 @@ def store_mat_data(self, mats, d_step, moment): ]) print('\nStoring material data for depletion step #%i.' % (d_step + 1)) - db = tb.open_file(self.h5_file, mode='a', filters=self.compression) + db = tb.open_file(self.db_path, mode='a', filters=self.compression) if not hasattr(db.root, 'materials'): comp_group = db.create_group('/', 'materials', @@ -276,7 +276,7 @@ def store_mat_data(self, mats, d_step, moment): np.empty(0, dtype=mpar_dtype), "Material parameters data") print('Dumping Material %s data %s to %s.' % - (key, moment, os.path.abspath(self.h5_file))) + (key, moment, os.path.abspath(self.db_path))) # Add row for the timestep to EArray and Material Parameters table earr.append(np.array([iso_wt_frac], dtype=np.float64)) mpar_table.append(mpar_array) @@ -311,7 +311,7 @@ class Step_info(tb.IsDescription): fission_mass_bds = tb.Float32Col() fission_mass_eds = tb.Float32Col() # Open or restore db and append data to it - db = tb.open_file(self.h5_file, mode='a', filters=self.compression) + db = tb.open_file(self.db_path, mode='a', filters=self.compression) try: step_info_table = db.get_node( db.root, @@ -391,7 +391,7 @@ def store_run_init_info(self): ) sim_info_array = np.array([sim_info_row], dtype=sim_info_dtype) # Open or restore db and append datat to it - db = tb.open_file(self.h5_file, mode='a', filters=self.compression) + db = tb.open_file(self.db_path, mode='a', filters=self.compression) try: sim_info_table = db.get_node(db.root, 'initial_depcode_siminfo') except Exception: @@ -449,7 +449,7 @@ def read_k_eds_delta(self, current_timestep, restart): if current_timestep > 3 or restart: # Open or restore db and read data - db = tb.open_file(self.h5_file, mode='r') + db = tb.open_file(self.db_path, mode='r') sim_param = db.root.simulation_parameters k_eds = np.array([x['keff_eds'][0] for x in sim_param.iterrows()]) db.close() diff --git a/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py b/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py index c316ff849..23921c6c0 100644 --- a/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py +++ b/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py @@ -36,7 +36,7 @@ sim_depcode=depcode, core_number=1, node_number=1, - h5_file=db_file, + db_path=db_file, iter_matfile=iter_matfile) tap = Reactor(volume=1.0, diff --git a/saltproc/tests/test_simulation.py b/saltproc/tests/test_simulation.py index 8c3c2bc7b..a32778c61 100644 --- a/saltproc/tests/test_simulation.py +++ b/saltproc/tests/test_simulation.py @@ -24,7 +24,7 @@ sim_depcode=serpent, core_number=1, node_number=1, - h5_file=directory + '/test_db.h5', + db_path=directory + '/test_db.h5', iter_matfile=serpent.iter_matfile) From c27c82bb486726b50b64499988a537df8cb6fd7d Mon Sep 17 00:00:00 2001 From: yardasol Date: Thu, 13 Jan 2022 13:24:58 -0600 Subject: [PATCH 014/118] compression -> compression_params --- saltproc/simulation.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/saltproc/simulation.py b/saltproc/simulation.py index 5c7734d48..52481b25b 100644 --- a/saltproc/simulation.py +++ b/saltproc/simulation.py @@ -21,7 +21,7 @@ def __init__( core_number=1, node_number=1, db_path="db_saltproc.h5", - compression=tb.Filters(complevel=9, + compression_params=tb.Filters(complevel=9, complib='blosc', fletcher32=True), iter_matfile="./saltproc_mat"): @@ -57,7 +57,7 @@ def __init__( self.core_number = core_number self.node_number = node_number self.db_path = db_path - self.compression = compression + self.compression_params = compression_params self.iter_matfile = iter_matfile def runsim_no_reproc(self, reactor, nsteps): @@ -132,7 +132,7 @@ def store_after_repr(self, after_mats, waste_dict, step): """ streams_gr = 'in_out_streams' - db = tb.open_file(self.db_path, mode='a', filters=self.compression) + db = tb.open_file(self.db_path, mode='a', filters=self.compression_params) for mn in waste_dict.keys(): # iterate over materials mat_node = getattr(db.root.materials, mn) if not hasattr(mat_node, streams_gr): @@ -210,7 +210,7 @@ def store_mat_data(self, mats, d_step, moment): ]) print('\nStoring material data for depletion step #%i.' % (d_step + 1)) - db = tb.open_file(self.db_path, mode='a', filters=self.compression) + db = tb.open_file(self.db_path, mode='a', filters=self.compression_params) if not hasattr(db.root, 'materials'): comp_group = db.create_group('/', 'materials', @@ -311,7 +311,7 @@ class Step_info(tb.IsDescription): fission_mass_bds = tb.Float32Col() fission_mass_eds = tb.Float32Col() # Open or restore db and append data to it - db = tb.open_file(self.db_path, mode='a', filters=self.compression) + db = tb.open_file(self.db_path, mode='a', filters=self.compression_params) try: step_info_table = db.get_node( db.root, @@ -391,7 +391,7 @@ def store_run_init_info(self): ) sim_info_array = np.array([sim_info_row], dtype=sim_info_dtype) # Open or restore db and append datat to it - db = tb.open_file(self.db_path, mode='a', filters=self.compression) + db = tb.open_file(self.db_path, mode='a', filters=self.compression_params) try: sim_info_table = db.get_node(db.root, 'initial_depcode_siminfo') except Exception: From 826e11929ae71e284f404d6098452f761a11e1d2 Mon Sep 17 00:00:00 2001 From: yardasol Date: Thu, 13 Jan 2022 13:28:37 -0600 Subject: [PATCH 015/118] update run_sim_no_reproc docstring --- saltproc/simulation.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/saltproc/simulation.py b/saltproc/simulation.py index 52481b25b..992d4a128 100644 --- a/saltproc/simulation.py +++ b/saltproc/simulation.py @@ -17,7 +17,7 @@ class Simulation(): def __init__( self, sim_name="default", - sim_depcode="SERPENT", + sim_depcode="depcode", core_number=1, node_number=1, db_path="db_saltproc.h5", @@ -61,12 +61,13 @@ def __init__( self.iter_matfile = iter_matfile def runsim_no_reproc(self, reactor, nsteps): - """Run simulation sequence for integral test. No reprocessing involved, - just re-running Serpent for comparision with model output. + """Run simulation sequence for integration test. No reprocessing + involved, just re-running depletion code for comparision with model + output. Parameters ---------- - reactor : Reactor + reactor : Reactor object Contains information about power load curve and cumulative depletion time for the integration test. nsteps : int From 5bedb329f75dffaacdfc91a7ad17cee89f3649b8 Mon Sep 17 00:00:00 2001 From: yardasol Date: Thu, 13 Jan 2022 13:40:48 -0600 Subject: [PATCH 016/118] update store_after_reproc docstring --- saltproc/simulation.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/saltproc/simulation.py b/saltproc/simulation.py index 992d4a128..c0c85a3db 100644 --- a/saltproc/simulation.py +++ b/saltproc/simulation.py @@ -33,7 +33,7 @@ def __init__( Name to identify the simulation. May contain information such as the number of a reference case, a paper name, or some other specific information identify the simulation. - sim_depcode : Depcode object + sim_depcode : `Depcode` object An instance of one of the `Depcode` child classes cores : int Number of cores to use for depletion code run (`-omp` flag in @@ -67,7 +67,7 @@ def runsim_no_reproc(self, reactor, nsteps): Parameters ---------- - reactor : Reactor object + reactor : `Reactor` Contains information about power load curve and cumulative depletion time for the integration test. nsteps : int @@ -113,13 +113,14 @@ def runsim_no_reproc(self, reactor, nsteps): self.burn_time) def store_after_repr(self, after_mats, waste_dict, step): - """Adds to HDF5 database waste streams data for each process after - reprocessing was performed (grams per depletion step). + """Add data for waste streams [grams per depletion step] of each + process to the HDF5 database after reprocessing. Parameters ---------- after_mats : `Materialflow` - Burnable material stream object after performing reprocessing. + `Materialflow` object representing a material stream after + performing reprocessing. waste_dict : dict of str to Materialflow Dictionary that maps `Process` objects to waste `Materialflow` objects. @@ -128,8 +129,9 @@ def store_after_repr(self, after_mats, waste_dict, step): `Process` name (`str`) ``value`` `Materialflow` object containing waste streams data. - step : int - Current depletion step. + dep_step : int + Current depletion time step. + """ streams_gr = 'in_out_streams' From b321e2c6344a1806e72733041e08953a1897615d Mon Sep 17 00:00:00 2001 From: yardasol Date: Thu, 13 Jan 2022 13:46:17 -0600 Subject: [PATCH 017/118] dts -> dep_step in app.py --- saltproc/app.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/saltproc/app.py b/saltproc/app.py index 5b9f7b02e..a83881d46 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -419,24 +419,24 @@ def run(): check_restart(restart_flag) # Run sequence # Start sequence - for dts in range(len(depl_hist)): - print("\n\n\nStep #%i has been started" % (dts + 1)) + for dep_step in range(len(depl_hist)): + print("\n\n\nStep #%i has been started" % (dep_step + 1)) depcode.write_depcode_input(template_file, input_file, msr, - dts, + dep_step, restart_flag) depcode.run_depcode(cores, nodes) - if dts == 0 and restart_flag is False: # First step + if dep_step == 0 and restart_flag is False: # First step # Read general simulation data which never changes simulation.store_run_init_info() - # Parse and store data for initial state (beginning of dts) + # Parse and store data for initial state (beginning of dep_step) mats = depcode.read_dep_comp(input_file, False) - simulation.store_mat_data(mats, dts - 1, 'before_reproc') + simulation.store_mat_data(mats, dep_step - 1, 'before_reproc') # Finish of First step # Main sequence mats = depcode.read_dep_comp(input_file, True) - simulation.store_mat_data(mats, dts, 'before_reproc') + simulation.store_mat_data(mats, dep_step, 'before_reproc') simulation.store_run_step_info() # Reprocessing here print("\nMass and volume of fuel before reproc %f g; %f cm3" % @@ -461,12 +461,12 @@ def run(): # mats['ctrlPois'].vol)) print("Removed mass [g]:", rem_mass) # Store in DB after reprocessing and refill (right before next depl) - simulation.store_after_repr(mats, waste_feed_st, dts) + simulation.store_after_repr(mats, waste_feed_st, dep_step) serpent.write_mat_file(mats, iter_matfile, simulation.burn_time) del mats, waste_st, waste_feed_st, rem_mass gc.collect() # Switch to another geometry? - if adjust_geo and simulation.read_k_eds_delta(dts, restart_flag): + if adjust_geo and simulation.read_k_eds_delta(dep_step, restart_flag): simulation.switch_to_next_geometry() print("\nTime at the end of current depletion step %fd" % simulation.burn_time) From 6399e597b92078a22a0e5af443419679b9b55a0a Mon Sep 17 00:00:00 2001 From: yardasol Date: Thu, 13 Jan 2022 13:51:22 -0600 Subject: [PATCH 018/118] update store_mat_data docstring --- saltproc/simulation.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/saltproc/simulation.py b/saltproc/simulation.py index c0c85a3db..7096f4fa5 100644 --- a/saltproc/simulation.py +++ b/saltproc/simulation.py @@ -175,13 +175,14 @@ def store_after_repr(self, after_mats, waste_dict, step): del iso_wt_frac del iso_idx # Also save materials AFTER reprocessing and refill here - self.store_mat_data(after_mats, step, 'after_reproc') + self.store_mat_data(after_mats, dep_step, 'after_reproc') db.close() def store_mat_data(self, mats, d_step, moment): - """Initializes HDF5/Pytables database (if not exist) or append burnable - material composition, mass, density, volume, temperature, burnup, - mass_flowrate, void_fraction, at the current depletion step to it. + """Initialize the HDF5/Pytables database (if it doesn't exist) or + append the following data at the current depletion step to the + database: burnable material composition, mass, density, volume, + temperature, burnup, mass_flowrate, void_fraction. Parameters ---------- @@ -192,11 +193,15 @@ def store_mat_data(self, mats, d_step, moment): Name of burnable material. ``value`` `Materialflow` object holding composition and properties. - d_step : int + dep_step : int Current depletion step. + read_at_end : bool, optional + Controls at which moment in the depletion step to read the data. + If `True`, the function reads data at the end of the + depletion step. Otherwise, the function reads data at the + beginning of the depletion step. + moment : int - Indicates at which moment in the depletion step store the data. `0` - refers the beginning, `1` refers the end of depletion step. """ # Moment when store compositions From 18c359922587b7193a1a3b0f34d5e12fc0e15856 Mon Sep 17 00:00:00 2001 From: yardasol Date: Thu, 13 Jan 2022 13:57:04 -0600 Subject: [PATCH 019/118] dts, d_step -> dep_step in simulation.py --- saltproc/simulation.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/saltproc/simulation.py b/saltproc/simulation.py index 7096f4fa5..87e4075bb 100644 --- a/saltproc/simulation.py +++ b/saltproc/simulation.py @@ -77,25 +77,25 @@ def runsim_no_reproc(self, reactor, nsteps): ###################################################################### # Start sequence - for dts in range(nsteps): - print("\nStep #%i has been started" % (dts + 1)) - if dts == 0: # First step + for dep_step in range(nsteps): + print("\nStep #%i has been started" % (dep_step + 1)) + if dep_step == 0: # First step self.sim_depcode.write_depcode_input( self.sim_depcode.template_path, self.sim_depcode.input_path, reactor, - dts, + dep_step, False) self.sim_depcode.run_depcode( self.core_number, self.node_number) # Read general simulation data which never changes self.store_run_init_info() - # Parse and store data for initial state (beginning of dts) + # Parse and store data for initial state (beginning of dep_step) mats = self.sim_depcode.read_dep_comp( self.sim_depcode.input_path, False) - self.store_mat_data(mats, dts, 'before_reproc') + self.store_mat_data(mats, dep_step, 'before_reproc') # Finish of First step # Main sequence else: @@ -105,7 +105,7 @@ def runsim_no_reproc(self, reactor, nsteps): mats = self.sim_depcode.read_dep_comp( self.sim_depcode.input_path, True) - self.store_mat_data(mats, dts, 'before_reproc') + self.store_mat_data(mats, dep_step, 'before_reproc') self.store_run_step_info() self.sim_depcode.write_mat_file( mats, @@ -178,7 +178,7 @@ def store_after_repr(self, after_mats, waste_dict, step): self.store_mat_data(after_mats, dep_step, 'after_reproc') db.close() - def store_mat_data(self, mats, d_step, moment): + def store_mat_data(self, mats, dep_step, moment): """Initialize the HDF5/Pytables database (if it doesn't exist) or append the following data at the current depletion step to the database: burnable material composition, mass, density, volume, @@ -217,7 +217,7 @@ def store_mat_data(self, mats, d_step, moment): ('burnup', float) ]) - print('\nStoring material data for depletion step #%i.' % (d_step + 1)) + print('\nStoring material data for depletion step #%i.' % (dep_step + 1)) db = tb.open_file(self.db_path, mode='a', filters=self.compression_params) if not hasattr(db.root, 'materials'): comp_group = db.create_group('/', From ac606b73cc80318981b73053e9e84fe9a31aca7c Mon Sep 17 00:00:00 2001 From: yardasol Date: Thu, 13 Jan 2022 14:30:38 -0600 Subject: [PATCH 020/118] moment -> store_at_end (int -> bool); make necesary changes in other files --- saltproc/app.py | 4 ++-- saltproc/depcode.py | 4 +++- saltproc/simulation.py | 34 +++++++++++++++++++--------------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/saltproc/app.py b/saltproc/app.py index a83881d46..03ef81063 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -432,11 +432,11 @@ def run(): simulation.store_run_init_info() # Parse and store data for initial state (beginning of dep_step) mats = depcode.read_dep_comp(input_file, False) - simulation.store_mat_data(mats, dep_step - 1, 'before_reproc') + simulation.store_mat_data(mats, dep_step - 1, False) # Finish of First step # Main sequence mats = depcode.read_dep_comp(input_file, True) - simulation.store_mat_data(mats, dep_step, 'before_reproc') + simulation.store_mat_data(mats, dep_step, True) simulation.store_run_step_info() # Reprocessing here print("\nMass and volume of fuel before reproc %f g; %f cm3" % diff --git a/saltproc/depcode.py b/saltproc/depcode.py index 3e5702abc..b5bfb92eb 100644 --- a/saltproc/depcode.py +++ b/saltproc/depcode.py @@ -409,9 +409,11 @@ def read_dep_comp(self, input_file, read_at_end=False): `Materialflow` object holding composition and properties. """ - moment = 0 + # Determine moment in depletion step to read data from if read_at_end: moment = 1 + else: + moment = 0 dep_file = os.path.join('%s_dep.m' % input_file) dep = serpent.parse_dep(dep_file, make_mats=False) diff --git a/saltproc/simulation.py b/saltproc/simulation.py index 87e4075bb..7f70356db 100644 --- a/saltproc/simulation.py +++ b/saltproc/simulation.py @@ -95,7 +95,7 @@ def runsim_no_reproc(self, reactor, nsteps): mats = self.sim_depcode.read_dep_comp( self.sim_depcode.input_path, False) - self.store_mat_data(mats, dep_step, 'before_reproc') + self.store_mat_data(mats, dep_step, False) # Finish of First step # Main sequence else: @@ -105,14 +105,14 @@ def runsim_no_reproc(self, reactor, nsteps): mats = self.sim_depcode.read_dep_comp( self.sim_depcode.input_path, True) - self.store_mat_data(mats, dep_step, 'before_reproc') + self.store_mat_data(mats, dep_step, False) self.store_run_step_info() self.sim_depcode.write_mat_file( mats, self.iter_matfile, self.burn_time) - def store_after_repr(self, after_mats, waste_dict, step): + def store_after_repr(self, after_mats, waste_dict, dep_step): """Add data for waste streams [grams per depletion step] of each process to the HDF5 database after reprocessing. @@ -175,10 +175,10 @@ def store_after_repr(self, after_mats, waste_dict, step): del iso_wt_frac del iso_idx # Also save materials AFTER reprocessing and refill here - self.store_mat_data(after_mats, dep_step, 'after_reproc') + self.store_mat_data(after_mats, dep_step, True) db.close() - def store_mat_data(self, mats, dep_step, moment): + def store_mat_data(self, mats, dep_step, store_at_end = False): """Initialize the HDF5/Pytables database (if it doesn't exist) or append the following data at the current depletion step to the database: burnable material composition, mass, density, volume, @@ -195,15 +195,19 @@ def store_mat_data(self, mats, dep_step, moment): `Materialflow` object holding composition and properties. dep_step : int Current depletion step. - read_at_end : bool, optional - Controls at which moment in the depletion step to read the data. - If `True`, the function reads data at the end of the - depletion step. Otherwise, the function reads data at the + store_at_end : bool, optional + Controls at which moment in the depletion step to store data from. + If `True`, the function stores data from the end of the + depletion step. Otherwise, the function stores data from the beginning of the depletion step. - moment : int - """ + # Determine moment in depletion step from which to store data + if store_at_end: + dep_step_str = "after_reproc" + else: + dep_step_str = "before_reproc" + # Moment when store compositions iso_idx = OrderedDict() # numpy array row storage data for material physical properties @@ -234,11 +238,11 @@ def store_mat_data(self, mats, dep_step, moment): key) # Create group for composition and parameters before reprocessing mat_node = getattr(db.root.materials, key) - if not hasattr(mat_node, moment): + if not hasattr(mat_node, dep_step_str): db.create_group(mat_node, - moment, + dep_step_str, 'Material data before reprocessing') - comp_pfx = '/materials/' + str(key) + '/' + str(moment) + comp_pfx = '/materials/' + str(key) + '/' + dep_step_str # Read isotopes from Materialflow for material for nuc_code, wt_frac in mats[key].comp.items(): # Dictonary in format {isotope_name : index(int)} @@ -284,7 +288,7 @@ def store_mat_data(self, mats, dep_step, moment): np.empty(0, dtype=mpar_dtype), "Material parameters data") print('Dumping Material %s data %s to %s.' % - (key, moment, os.path.abspath(self.db_path))) + (key, dep_step_str, os.path.abspath(self.db_path))) # Add row for the timestep to EArray and Material Parameters table earr.append(np.array([iso_wt_frac], dtype=np.float64)) mpar_table.append(mpar_array) From e2f1b6c44ecbcf1a55728e6d2f3c2acf07c65094 Mon Sep 17 00:00:00 2001 From: yardasol Date: Thu, 13 Jan 2022 17:05:15 -0600 Subject: [PATCH 021/118] started writing tests for remaining simulation.py functions --- saltproc/tests/test_simulation.py | 46 +++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/saltproc/tests/test_simulation.py b/saltproc/tests/test_simulation.py index a32778c61..bc38bf84a 100644 --- a/saltproc/tests/test_simulation.py +++ b/saltproc/tests/test_simulation.py @@ -4,6 +4,8 @@ import os import sys import shutil +import numpy as np +import tables as tb path = os.path.realpath(__file__) sys.path.append(os.path.dirname(os.path.dirname(path))) # global class object @@ -27,6 +29,50 @@ db_path=directory + '/test_db.h5', iter_matfile=serpent.iter_matfile) +def test_check_switch_geo_trigger() + +def test_store_after_repr() + +def test_store_mat_data(): + # read data + mats_before = simulation.sim_depcode.read_dep_comp( + simulation.sim_depcode.input_path+, + False) + mats_after = simulation.sim_depcode.read_dep_comp( + simulation.sim_depcode.input_path+, + True) + + # store data at end + simulation.store_mat_data(mats_before, -1, False) + simulation.store_mat_data(mats_after, -1, True) + + # read stored data + db = tb.open_file(simulation.db_path, mode='r', + filters=simulation.compression_params) + tmats = db.root.materials + tmats_before = tmats.before_reproc.comp[-1,:] + tmats_after = tmats.after_reproc.comp[-1,:] + + # check that they match + assert mats_before['fuel']['U235'] == tmats_before[1566] + assert mats_before['fuel']['U238'] == tmats_before[1570] + assert mats_before['fuel']['F19'] == tmats_before[37] + assert mats_before['fuel']['Li7'] == tmats_before[8] + assert mats_before['fuel']['Cm240'] == tmats_before[1610] + assert mats_before['fuel']['Pu239'] == tmats_before[1589] + # still need to do these ones!! + assert mats_before['ctrlPois']['Gd155'] == + assert mats_before['ctrlPois']['O16'] == + + + # then tdo one for mats_after + + # then remove the entries you added to the file + +def test_store_run_init_info() + +def test_store_run_step_info() + def test_read_k_eds_delta(): assert simulation.read_k_eds_delta(7, False) is False From e360c6c4b942d07a24e1ec9df89caf900c28c889 Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 14 Jan 2022 14:50:03 -0600 Subject: [PATCH 022/118] rework + finish test_store_mat_data --- saltproc/tests/test_simulation.py | 115 +++++++++++++++++++++++------- 1 file changed, 88 insertions(+), 27 deletions(-) diff --git a/saltproc/tests/test_simulation.py b/saltproc/tests/test_simulation.py index bc38bf84a..625c765cc 100644 --- a/saltproc/tests/test_simulation.py +++ b/saltproc/tests/test_simulation.py @@ -29,49 +29,110 @@ db_path=directory + '/test_db.h5', iter_matfile=serpent.iter_matfile) -def test_check_switch_geo_trigger() +#def test_check_switch_geo_trigger() -def test_store_after_repr() +#def test_store_after_repr() def test_store_mat_data(): # read data mats_before = simulation.sim_depcode.read_dep_comp( - simulation.sim_depcode.input_path+, + simulation.sim_depcode.input_path, False) mats_after = simulation.sim_depcode.read_dep_comp( - simulation.sim_depcode.input_path+, + simulation.sim_depcode.input_path, True) + # we want to keep the old path for other sims, but for this + # test we'll want a fresh db + db_path_old = simulation.db_path + db_file = serpent.input_path + '.h5' + simulation.db_path = db_file + # store data at end - simulation.store_mat_data(mats_before, -1, False) - simulation.store_mat_data(mats_after, -1, True) + simulation.store_mat_data(mats_before, 0, False) + simulation.store_mat_data(mats_after, 0, True) # read stored data db = tb.open_file(simulation.db_path, mode='r', filters=simulation.compression_params) tmats = db.root.materials - tmats_before = tmats.before_reproc.comp[-1,:] - tmats_after = tmats.after_reproc.comp[-1,:] - - # check that they match - assert mats_before['fuel']['U235'] == tmats_before[1566] - assert mats_before['fuel']['U238'] == tmats_before[1570] - assert mats_before['fuel']['F19'] == tmats_before[37] - assert mats_before['fuel']['Li7'] == tmats_before[8] - assert mats_before['fuel']['Cm240'] == tmats_before[1610] - assert mats_before['fuel']['Pu239'] == tmats_before[1589] - # still need to do these ones!! - assert mats_before['ctrlPois']['Gd155'] == - assert mats_before['ctrlPois']['O16'] == - - - # then tdo one for mats_after - - # then remove the entries you added to the file - -def test_store_run_init_info() -def test_store_run_step_info() + tfuel_before = tmats.fuel.before_reproc.comp[0] + tfuel_before_params = tmats.fuel.before_reproc.parameters[0] + + tfuel_after = tmats.fuel.after_reproc.comp[0] + tfuel_after_params = tmats.fuel.after_reproc.parameters[0] + + tpois_before = tmats.ctrlPois.before_reproc.comp[0] + tpois_before_params = tmats.ctrlPois.before_reproc.parameters[0] + + tpois_after = tmats.ctrlPois.after_reproc.comp[0] + tpois_after_params = tmats.ctrlPois.after_reproc.parameters[0] + + # Check the mass fractions + assert mats_before['fuel']['U235'] == tfuel_before[1566] + assert mats_before['fuel']['U238'] == tfuel_before[1570] + assert mats_before['fuel']['F19'] == tfuel_before[37] + assert mats_before['fuel']['Li7'] == tfuel_before[8] + assert mats_before['fuel']['Cm240'] == tfuel_before[1610] + assert mats_before['fuel']['Pu239'] == tfuel_before[1589] + assert mats_before['ctrlPois']['Gd155'] == tpois_before[1213] + assert mats_before['ctrlPois']['O16'] == tpois_before[32] + + assert mats_after['fuel']['U235'] == tfuel_after[1566] + assert mats_after['fuel']['U238'] == tfuel_after[1570] + assert mats_after['fuel']['F19'] == tfuel_after[37] + assert mats_after['fuel']['Li7'] == tfuel_after[8] + assert mats_after['fuel']['Cm240'] == tfuel_after[1610] + assert mats_after['fuel']['Pu239'] == tfuel_after[1589] + assert mats_after['ctrlPois']['Gd155'] == tpois_after[1213] + assert mats_after['ctrlPois']['O16'] == tpois_after[32] + + # Check the parameters + assert mats_before['fuel'].mass == tfuel_before_params[0] + assert mats_before['fuel'].density == tfuel_before_params[1] + assert mats_before['fuel'].vol == tfuel_before_params[2] + assert mats_before['fuel'].temp == tfuel_before_params[3] + assert mats_before['fuel'].mass_flowrate == tfuel_before_params[4] + assert mats_before['fuel'].void_frac == tfuel_before_params[5] + assert mats_before['fuel'].burnup == tfuel_before_params[6] + + assert mats_before['ctrlPois'].mass == tpois_before_params[0] + assert mats_before['ctrlPois'].density == tpois_before_params[1] + assert mats_before['ctrlPois'].vol == tpois_before_params[2] + assert mats_before['ctrlPois'].temp == tpois_before_params[3] + assert mats_before['ctrlPois'].mass_flowrate == tpois_before_params[4] + assert mats_before['ctrlPois'].void_frac == tpois_before_params[5] + assert mats_before['ctrlPois'].burnup == tpois_before_params[6] + + assert mats_after['fuel'].mass == tfuel_after_params[0] + assert mats_after['fuel'].density == tfuel_after_params[1] + assert mats_after['fuel'].vol == tfuel_after_params[2] + assert mats_after['fuel'].temp == tfuel_after_params[3] + assert mats_after['fuel'].mass_flowrate == tfuel_after_params[4] + assert mats_after['fuel'].void_frac == tfuel_after_params[5] + assert mats_after['fuel'].burnup == tfuel_after_params[6] + + assert mats_after['ctrlPois'].mass == tpois_after_params[0] + assert mats_after['ctrlPois'].density == tpois_after_params[1] + assert mats_after['ctrlPois'].vol == tpois_after_params[2] + assert mats_after['ctrlPois'].temp == tpois_after_params[3] + assert mats_after['ctrlPois'].mass_flowrate == tpois_after_params[4] + assert mats_after['ctrlPois'].void_frac == tpois_after_params[5] + assert mats_after['ctrlPois'].burnup == tpois_after_params[6] + + # close the file + db.close() + + # delete test file + os.remove(db_file) + + #use original db path + simulation.db_path = db_path_old + +#def test_store_run_init_info() + +#def test_store_run_step_info() def test_read_k_eds_delta(): From 2554e6367194050de615e79de869eb7e7db87cab Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 14 Jan 2022 15:16:19 -0600 Subject: [PATCH 023/118] add test_store_run_init_info; restructure test_store_mat_data --- saltproc/tests/test_simulation.py | 129 ++++++++++++++++++------------ 1 file changed, 80 insertions(+), 49 deletions(-) diff --git a/saltproc/tests/test_simulation.py b/saltproc/tests/test_simulation.py index 625c765cc..5bca0a8ba 100644 --- a/saltproc/tests/test_simulation.py +++ b/saltproc/tests/test_simulation.py @@ -70,56 +70,56 @@ def test_store_mat_data(): tpois_after_params = tmats.ctrlPois.after_reproc.parameters[0] # Check the mass fractions - assert mats_before['fuel']['U235'] == tfuel_before[1566] - assert mats_before['fuel']['U238'] == tfuel_before[1570] - assert mats_before['fuel']['F19'] == tfuel_before[37] - assert mats_before['fuel']['Li7'] == tfuel_before[8] - assert mats_before['fuel']['Cm240'] == tfuel_before[1610] - assert mats_before['fuel']['Pu239'] == tfuel_before[1589] - assert mats_before['ctrlPois']['Gd155'] == tpois_before[1213] - assert mats_before['ctrlPois']['O16'] == tpois_before[32] - - assert mats_after['fuel']['U235'] == tfuel_after[1566] - assert mats_after['fuel']['U238'] == tfuel_after[1570] - assert mats_after['fuel']['F19'] == tfuel_after[37] - assert mats_after['fuel']['Li7'] == tfuel_after[8] - assert mats_after['fuel']['Cm240'] == tfuel_after[1610] - assert mats_after['fuel']['Pu239'] == tfuel_after[1589] - assert mats_after['ctrlPois']['Gd155'] == tpois_after[1213] - assert mats_after['ctrlPois']['O16'] == tpois_after[32] + assert tfuel_before[1566] == mats_before['fuel']['U235'] + assert tfuel_before[1570] == mats_before['fuel']['U238'] + assert tfuel_before[37] == mats_before['fuel']['F19'] + assert tfuel_before[8] == mats_before['fuel']['Li7'] + assert tfuel_before[1610] == mats_before['fuel']['Cm240'] + assert tfuel_before[1589] == mats_before['fuel']['Pu239'] + assert tpois_before[1213] == mats_before['ctrlPois']['Gd155'] + assert tpois_before[32] == mats_before['ctrlPois']['O16'] + + assert tfuel_after[1566] == mats_after['fuel']['U235'] + assert tfuel_after[1570] == mats_after['fuel']['U238'] + assert tfuel_after[37] == mats_after['fuel']['F19'] + assert tfuel_after[8] == mats_after['fuel']['Li7'] + assert tfuel_after[1610] == mats_after['fuel']['Cm240'] + assert tfuel_after[1589] == mats_after['fuel']['Pu239'] + assert tpois_after[1213] == mats_after['ctrlPois']['Gd155'] + assert tpois_after[32] == mats_after['ctrlPois']['O16'] # Check the parameters - assert mats_before['fuel'].mass == tfuel_before_params[0] - assert mats_before['fuel'].density == tfuel_before_params[1] - assert mats_before['fuel'].vol == tfuel_before_params[2] - assert mats_before['fuel'].temp == tfuel_before_params[3] - assert mats_before['fuel'].mass_flowrate == tfuel_before_params[4] - assert mats_before['fuel'].void_frac == tfuel_before_params[5] - assert mats_before['fuel'].burnup == tfuel_before_params[6] - - assert mats_before['ctrlPois'].mass == tpois_before_params[0] - assert mats_before['ctrlPois'].density == tpois_before_params[1] - assert mats_before['ctrlPois'].vol == tpois_before_params[2] - assert mats_before['ctrlPois'].temp == tpois_before_params[3] - assert mats_before['ctrlPois'].mass_flowrate == tpois_before_params[4] - assert mats_before['ctrlPois'].void_frac == tpois_before_params[5] - assert mats_before['ctrlPois'].burnup == tpois_before_params[6] - - assert mats_after['fuel'].mass == tfuel_after_params[0] - assert mats_after['fuel'].density == tfuel_after_params[1] - assert mats_after['fuel'].vol == tfuel_after_params[2] - assert mats_after['fuel'].temp == tfuel_after_params[3] - assert mats_after['fuel'].mass_flowrate == tfuel_after_params[4] - assert mats_after['fuel'].void_frac == tfuel_after_params[5] - assert mats_after['fuel'].burnup == tfuel_after_params[6] - - assert mats_after['ctrlPois'].mass == tpois_after_params[0] - assert mats_after['ctrlPois'].density == tpois_after_params[1] - assert mats_after['ctrlPois'].vol == tpois_after_params[2] - assert mats_after['ctrlPois'].temp == tpois_after_params[3] - assert mats_after['ctrlPois'].mass_flowrate == tpois_after_params[4] - assert mats_after['ctrlPois'].void_frac == tpois_after_params[5] - assert mats_after['ctrlPois'].burnup == tpois_after_params[6] + assert tfuel_before_params[0] == mats_before['fuel'].mass + assert tfuel_before_params[1] == mats_before['fuel'].density + assert tfuel_before_params[2] == mats_before['fuel'].vol + assert tfuel_before_params[3] == mats_before['fuel'].temp + assert tfuel_before_params[4] == mats_before['fuel'].mass_flowrate + assert tfuel_before_params[5] == mats_before['fuel'].void_frac + assert tfuel_before_params[6] == mats_before['fuel'].burnup + + assert tpois_before_params[0] == mats_before['ctrlPois'].mass + assert tpois_before_params[1] == mats_before['ctrlPois'].density + assert tpois_before_params[2] == mats_before['ctrlPois'].vol + assert tpois_before_params[3] == mats_before['ctrlPois'].temp + assert tpois_before_params[4] == mats_before['ctrlPois'].mass_flowrate + assert tpois_before_params[5] == mats_before['ctrlPois'].void_frac + assert tpois_before_params[6] == mats_before['ctrlPois'].burnup + + assert tfuel_after_params[0] == mats_after['fuel'].mass + assert tfuel_after_params[1] == mats_after['fuel'].density + assert tfuel_after_params[2] == mats_after['fuel'].vol + assert tfuel_after_params[3] == mats_after['fuel'].temp + assert tfuel_after_params[4] == mats_after['fuel'].mass_flowrate + assert tfuel_after_params[5] == mats_after['fuel'].void_frac + assert tfuel_after_params[6] == mats_after['fuel'].burnup + + assert tpois_after_params[0] == mats_after['ctrlPois'].mass + assert tpois_after_params[1] == mats_after['ctrlPois'].density + assert tpois_after_params[2] == mats_after['ctrlPois'].vol + assert tpois_after_params[3] == mats_after['ctrlPois'].temp + assert tpois_after_params[4] == mats_after['ctrlPois'].mass_flowrate + assert tpois_after_params[5] == mats_after['ctrlPois'].void_frac + assert tpois_after_params[6] == mats_after['ctrlPois'].burnup # close the file db.close() @@ -130,7 +130,38 @@ def test_store_mat_data(): #use original db path simulation.db_path = db_path_old -#def test_store_run_init_info() +def test_store_run_init_info() + # read data + init_info = simulation.sim_depcode.read_depcode_info() + + # we want to keep the old path for other sims, but for this + # test we'll want a fresh db + db_path_old = simulation.db_path + db_file = serpent.input_path + '.h5' + simulation.db_path = db_file + + # store data at + simulation.store_run_init_info() + + # read stored data + db = tb.open_file(simulation.db_path, mode='r', + filters=simulation.compression_params) + + tinit_info = tb.root.initial_depcode_siminfo[0] + + assert tinit_info[0] == simulation.sim_depcode.npop + assert tinit_info[1] == simulation.sim_depcode.active_cycles + assert tinit_info[2] == simulation.sim_depcode.inactive_cycles + assert tinit_info[3] == init_info['serpent_version'] + assert tinit_info[4] == init_info['title'] + assert tinit_info[5] == init_info['serpent_input_filename'] + assert tinit_info[6] == init_info['serpent_working_dir'] + assert tinit_info[7] == init_info['xs_data_path'] + assert tinit_info[8] == init_info['OMP_threads'] + assert tinit_info[9] == init_info['MPI_tasks'] + assert tinit_info[10] == init_info['memory_optimization_mode'] + assert tinit_info[11] == init_info['depletion_timestep'] + #def test_store_run_step_info() From aac559edb5769b8e4e27362052b70b7d7dd92892 Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 14 Jan 2022 15:33:33 -0600 Subject: [PATCH 024/118] fix up test_write_store_run_init_info --- saltproc/tests/test_simulation.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/saltproc/tests/test_simulation.py b/saltproc/tests/test_simulation.py index 5bca0a8ba..6527eb7e4 100644 --- a/saltproc/tests/test_simulation.py +++ b/saltproc/tests/test_simulation.py @@ -130,9 +130,10 @@ def test_store_mat_data(): #use original db path simulation.db_path = db_path_old -def test_store_run_init_info() +def test_store_run_init_info(): # read data - init_info = simulation.sim_depcode.read_depcode_info() + simulation.sim_depcode.read_depcode_info() + init_info = simulation.sim_depcode.sim_info # we want to keep the old path for other sims, but for this # test we'll want a fresh db @@ -147,21 +148,29 @@ def test_store_run_init_info() db = tb.open_file(simulation.db_path, mode='r', filters=simulation.compression_params) - tinit_info = tb.root.initial_depcode_siminfo[0] + tinit_info = db.root.initial_depcode_siminfo[0] assert tinit_info[0] == simulation.sim_depcode.npop assert tinit_info[1] == simulation.sim_depcode.active_cycles assert tinit_info[2] == simulation.sim_depcode.inactive_cycles - assert tinit_info[3] == init_info['serpent_version'] - assert tinit_info[4] == init_info['title'] - assert tinit_info[5] == init_info['serpent_input_filename'] - assert tinit_info[6] == init_info['serpent_working_dir'] - assert tinit_info[7] == init_info['xs_data_path'] + assert str(tinit_info[3])[2:-1] == init_info['serpent_version'] + assert str(tinit_info[4])[2:-1] == init_info['title'] + assert str(tinit_info[5])[2:-1] == init_info['serpent_input_filename'] + assert str(tinit_info[6])[2:-1] == init_info['serpent_working_dir'] + assert str(tinit_info[7])[2:-1] == init_info['xs_data_path'] assert tinit_info[8] == init_info['OMP_threads'] assert tinit_info[9] == init_info['MPI_tasks'] assert tinit_info[10] == init_info['memory_optimization_mode'] assert tinit_info[11] == init_info['depletion_timestep'] + # close the file + db.close() + + # delete test file + os.remove(db_file) + + #use original db path + simulation.db_path = db_path_old #def test_store_run_step_info() From d51cd781dd62972c7fed2202cc24ed564d3d4a94 Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 14 Jan 2022 16:12:17 -0600 Subject: [PATCH 025/118] Added test_store_run_step_info --- saltproc/tests/test_simulation.py | 52 +++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/saltproc/tests/test_simulation.py b/saltproc/tests/test_simulation.py index 6527eb7e4..c7aa3515d 100644 --- a/saltproc/tests/test_simulation.py +++ b/saltproc/tests/test_simulation.py @@ -29,9 +29,9 @@ db_path=directory + '/test_db.h5', iter_matfile=serpent.iter_matfile) -#def test_check_switch_geo_trigger() +#def test_check_switch_geo_trigger(): -#def test_store_after_repr() +#def test_store_after_repr(): def test_store_mat_data(): # read data @@ -172,7 +172,53 @@ def test_store_run_init_info(): #use original db path simulation.db_path = db_path_old -#def test_store_run_step_info() +def test_store_run_step_info(): + # read data + simulation.sim_depcode.read_depcode_step_param() + step_info = simulation.sim_depcode.param + + # we want to keep the old path for other sims, but for this + # test we'll want a fresh db + db_path_old = simulation.db_path + db_file = serpent.input_path + '.h5' + simulation.db_path = db_file + + # store data at + simulation.store_run_step_info() + + # read stored data + db = tb.open_file(simulation.db_path, mode='r', + filters=simulation.compression_params) + + tstep_info = db.root.simulation_parameters[0] + + assert np.array_equal(tstep_info[0], + step_info['beta_eff'].astype('float32')) + assert np.array_equal(tstep_info[1], + step_info['breeding_ratio'].astype('float32')) + assert tstep_info[2] == simulation.burn_time + assert np.array_equal(tstep_info[3], + step_info['delayed_neutrons_lambda'].\ + astype('float32')) + assert tstep_info[4] == step_info['fission_mass_bds'].astype('float32') + assert tstep_info[5] == step_info['fission_mass_eds'].astype('float32') + assert np.array_equal(tstep_info[6], + step_info['keff_bds'].astype('float32')) + assert np.array_equal(tstep_info[7], + step_info['keff_eds'].astype('float32')) + assert tstep_info[8] == step_info['memory_usage'].astype('float32') + assert tstep_info[9] == step_info['power_level'].astype('float32') + assert tstep_info[10] == step_info['execution_time'].astype('float32') + + # close the file + db.close() + + # delete test file + os.remove(db_file) + + #use original db path + simulation.db_path = db_path_old + def test_read_k_eds_delta(): From 4035363bda0f34d05e44bb6a3dc5de06558dbc29 Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 14 Jan 2022 16:36:30 -0600 Subject: [PATCH 026/118] added test_check_switch_geo_trigger --- saltproc/tests/test_simulation.py | 32 ++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/saltproc/tests/test_simulation.py b/saltproc/tests/test_simulation.py index c7aa3515d..a51e102d1 100644 --- a/saltproc/tests/test_simulation.py +++ b/saltproc/tests/test_simulation.py @@ -29,11 +29,30 @@ db_path=directory + '/test_db.h5', iter_matfile=serpent.iter_matfile) -#def test_check_switch_geo_trigger(): +def test_check_switch_geo_trigger(): + """ + This unit test checks that ``check_switch_geo_trigger`` functions + consistent with its docstring. + """ + + switch_times = [1.0, 3, -31, 86.23333, 1e-16, 2e-18, "two o clock"] + assert simulation.check_switch_geo_trigger(1.0, switch_times) is True + assert simulation.check_switch_geo_trigger(3, switch_times) is True + assert simulation.check_switch_geo_trigger(-32, switch_times) is False + assert simulation.check_switch_geo_trigger(86.233, switch_times) is False + assert simulation.check_switch_geo_trigger(1e-16, switch_times) is True + assert simulation.check_switch_geo_trigger(5e-18, switch_times) is False + assert simulation.check_switch_geo_trigger("three o clock") is False + assert simulation.check_switch_geo_trigger("two o clock") is True #def test_store_after_repr(): def test_store_mat_data(): + """ + This unit test checks that select entries that ``store_mat_data_()` + stores in the database match the corresponding entries from the input + explicity in value and implicitly in type. + """ # read data mats_before = simulation.sim_depcode.read_dep_comp( simulation.sim_depcode.input_path, @@ -131,6 +150,12 @@ def test_store_mat_data(): simulation.db_path = db_path_old def test_store_run_init_info(): + """ + This unit test checks that the entries ``store_run_init_info()` + stores in the database match the corresponding entries from the input + explicity in value and implicitly in type. + """ + # read data simulation.sim_depcode.read_depcode_info() init_info = simulation.sim_depcode.sim_info @@ -173,6 +198,11 @@ def test_store_run_init_info(): simulation.db_path = db_path_old def test_store_run_step_info(): + """ + This unit test checks that the entries ``store_run_step_info()` + stores in the database match the corresponding entries from the input + explicity in value and implicitly in type. + """ # read data simulation.sim_depcode.read_depcode_step_param() step_info = simulation.sim_depcode.param From 639cf2298ca40b6236bf077995d9eef8ec6d1c08 Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 14 Jan 2022 16:38:45 -0600 Subject: [PATCH 027/118] typo fixes --- saltproc/tests/test_simulation.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/saltproc/tests/test_simulation.py b/saltproc/tests/test_simulation.py index a51e102d1..027195077 100644 --- a/saltproc/tests/test_simulation.py +++ b/saltproc/tests/test_simulation.py @@ -35,15 +35,17 @@ def test_check_switch_geo_trigger(): consistent with its docstring. """ - switch_times = [1.0, 3, -31, 86.23333, 1e-16, 2e-18, "two o clock"] - assert simulation.check_switch_geo_trigger(1.0, switch_times) is True - assert simulation.check_switch_geo_trigger(3, switch_times) is True - assert simulation.check_switch_geo_trigger(-32, switch_times) is False - assert simulation.check_switch_geo_trigger(86.233, switch_times) is False - assert simulation.check_switch_geo_trigger(1e-16, switch_times) is True - assert simulation.check_switch_geo_trigger(5e-18, switch_times) is False - assert simulation.check_switch_geo_trigger("three o clock") is False - assert simulation.check_switch_geo_trigger("two o clock") is True + switch_times = [1.0, 3, -31, 86.23333, 1e-16, 2e-18, "two o clock"] + assert simulation.check_switch_geo_trigger(1.0, switch_times) is True + assert simulation.check_switch_geo_trigger(3, switch_times) is True + assert simulation.check_switch_geo_trigger(-32, switch_times) is False + assert simulation.check_switch_geo_trigger(86.233, switch_times) is False + assert simulation.check_switch_geo_trigger(1e-16, switch_times) is True + assert simulation.check_switch_geo_trigger(5e-18, switch_times) is False + assert simulation.check_switch_geo_trigger("three o clock", + switch_times) is False + assert simulation.check_switch_geo_trigger("two o clock", + switch_times) is True #def test_store_after_repr(): From 47a8af675ab8f12828132c5b9b5bc3cbbdff9da5 Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 14 Jan 2022 17:03:00 -0600 Subject: [PATCH 028/118] make code consistnet w/ docstrings --- saltproc/app.py | 60 ++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/saltproc/app.py b/saltproc/app.py index 03ef81063..3e994c977 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -242,7 +242,7 @@ def read_dot(dot_file): return mat_name, paths_list -def reprocessing(mat): +def reprocessing(mats): """Applies reprocessing scheme to burnable materials. Parameters @@ -276,40 +276,40 @@ def reprocessing(mat): inmass = {} extracted_mass = {} waste = OrderedDict() - forked_mat = OrderedDict() + forked_mats = OrderedDict() prcs = read_processes_from_input() - mat_name_dot, paths = read_dot(dot_inp_file) + mats_name_dot, paths = read_dot(dot_inp_file) for mname in prcs.keys(): # iterate over materials waste[mname] = {} - forked_mat[mname] = [] - inmass[mname] = float(mat[mname].mass) + forked_mats[mname] = [] + inmass[mname] = float(mats[mname].mass) print("Material mass before reprocessing %f g" % inmass[mname]) - if mname == 'fuel' and mat_name_dot == 'fuel': + if mname == 'fuel' and mats_name_dot == 'fuel': w = 'waste_' ctr = 0 for path in paths: - forked_mat[mname].append(copy.deepcopy(mat[mname])) - print("Material mass %f" % mat[mname].mass) + forked_mats[mname].append(copy.deepcopy(mats[mname])) + print("Material mass %f" % mats[mname].mass) for p in path: # Calculate fraction of the flow going to the process p divisor = float(prcs[mname][p].mass_flowrate / prcs[mname]['core_outlet'].mass_flowrate) print('Process %s, divisor=%f' % (p, divisor)) # Update materialflow byt multiplying it by flow fraction - forked_mat[mname][ctr] = \ - divisor * copy.deepcopy(forked_mat[mname][ctr]) + forked_mats[mname][ctr] = \ + divisor * copy.deepcopy(forked_mats[mname][ctr]) waste[mname][w + p] = \ - prcs[mname][p].rem_elements(forked_mat[mname][ctr]) + prcs[mname][p].rem_elements(forked_mats[mname][ctr]) ctr += 1 # Sum all forked material objects together - mat[mname] = forked_mat[mname][0] # initilize correct obj instance - for idx in range(1, len(forked_mat[mname])): - mat[mname] += forked_mat[mname][idx] - print('1 Forked material mass %f' % (forked_mat[mname][0].mass)) - print('2 Forked material mass %f' % (forked_mat[mname][1].mass)) + mats[mname] = forked_mats[mname][0] # initilize correct obj instance + for idx in range(1, len(forked_mats[mname])): + mats[mname] += forked_mats[mname][idx] + print('1 Forked material mass %f' % (forked_mats[mname][0].mass)) + print('2 Forked material mass %f' % (forked_mats[mname][1].mass)) print('\nMass balance %f g = %f + %f + %f + %f + %f + %f' % (inmass[mname], - mat[mname].mass, + mats[mname].mass, waste[mname]['waste_sparger'].mass, waste[mname]['waste_entrainment_separator'].mass, waste[mname]['waste_nickel_filter'].mass, @@ -318,9 +318,9 @@ def reprocessing(mat): # Bootstrap for many materials if mname == 'ctrlPois': waste[mname]['removal_tb_dy'] = \ - prcs[mname]['removal_tb_dy'].rem_elements(mat[mname]) - extracted_mass[mname] = inmass[mname] - float(mat[mname].mass) - del prcs, inmass, mname, forked_mat, mat_name_dot, paths, divisor + prcs[mname]['removal_tb_dy'].rem_elements(mats[mname]) + extracted_mass[mname] = inmass[mname] - float(mats[mname].mass) + del prcs, inmass, mname, forked_mats, mats_name_dot, paths, divisor return waste, extracted_mass @@ -329,7 +329,7 @@ def refill(mat, extracted_mass, waste_dict): Parameters ----------- - mat : dict of str to Materialflow + mats : dict of str to Materialflow ``key`` Name of burnable material. @@ -341,7 +341,7 @@ def refill(mat, extracted_mass, waste_dict): Name of burnable material. ``value`` Mass removed as waste in reprocessing function for each material. - waste : dict of str to Materialflow + waste_dict : dict of str to Materialflow ``key`` Process name. @@ -358,19 +358,19 @@ def refill(mat, extracted_mass, waste_dict): ``value`` `Materialflow` object after adding fresh fuel. """ - print('Fuel before refill ^^^', mat['fuel'].print_attr()) + print('Fuel before refill ^^^', mats['fuel'].print_attr()) feeds = read_feeds_from_input() refill_mat = OrderedDict() for mn, v in feeds.items(): # iterate over materials - refill_mat[mn] = {} + refill_mats[mn] = {} for feed_n, fval in feeds[mn].items(): # works with one feed only scale = extracted_mass[mn] / feeds[mn][feed_n].mass - refill_mat[mn] = scale * feeds[mn][feed_n] - waste_dict[mn]['feed_' + str(feed_n)] = refill_mat[mn] - mat[mn] += refill_mat[mn] - print('Refilled fresh material %s %f g' % (mn, refill_mat[mn].mass)) - print('Refill Material ^^^', refill_mat[mn].print_attr()) - print('Fuel after refill ^^^', mat[mn].print_attr()) + refill_mats[mn] = scale * feeds[mn][feed_n] + waste_dict[mn]['feed_' + str(feed_n)] = refill_mats[mn] + mats[mn] += refill_mats[mn] + print('Refilled fresh material %s %f g' % (mn, refill_mats[mn].mass)) + print('Refill Material ^^^', refill_mats[mn].print_attr()) + print('Fuel after refill ^^^', mats[mn].print_attr()) return waste_dict From ee689ea28e2be472736149c7560890cd38cd5e2e Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 14 Jan 2022 20:24:11 -0600 Subject: [PATCH 029/118] Added test_store_after_reproc --- saltproc/tests/test_simulation.py | 307 ++++++++++++++++++++++-------- 1 file changed, 223 insertions(+), 84 deletions(-) diff --git a/saltproc/tests/test_simulation.py b/saltproc/tests/test_simulation.py index 027195077..4b62ea67a 100644 --- a/saltproc/tests/test_simulation.py +++ b/saltproc/tests/test_simulation.py @@ -1,6 +1,7 @@ from __future__ import absolute_import, division, print_function from saltproc import DepcodeSerpent from saltproc import Simulation +import saltproc.app import os import sys import shutil @@ -11,6 +12,9 @@ # global class object directory = os.path.dirname(path) input_file = directory + '/test' +main_input = directory + '/test.json' +dot_input = directory + '/test.dot' + geo_test_input = directory + '/test_geometry_switch.inp' serpent = DepcodeSerpent( @@ -47,7 +51,108 @@ def test_check_switch_geo_trigger(): assert simulation.check_switch_geo_trigger("two o clock", switch_times) is True -#def test_store_after_repr(): +def test_store_after_repr(): + """ + This unit test checks that select entries that ``store_after_repr_()` + stores in the database match the corresponding entries from the input + explicity in value and implicitly in type. + + unchecked processes: waste_bypass + waste_core_inlet + waste_core_outlet + waste_heat_exchanger + removal_tb_dy + feed_pure_gd + + """ + saltproc.app.read_main_input(main_input) + + # read data + mats = simulation.sim_depcode.read_dep_comp( + simulation.sim_depcode.input_path, + True) + waste_st, rem_mass = saltproc.app.reprocessing(mats) + m_after_refill = saltproc.app.refill(mats, rem_mass, waste_st) + + fuel_st = m_after_refill['fuel'] + + f_feed_leu = fuel_st['feed_leu'] + f_entrain_sep = fuel_st['waste_entrainment_separator'] + f_liq_met = fuel_st['waste_liquid_metal'] + f_nickel_filt = fuel_st['waste_nickel_filter'] + f_sparger = fuel_st['waste_sparger'] + + # we want to keep the old path for other sims, but for this + # test we'll want a fresh db + db_path_old = simulation.db_path + db_file = serpent.input_path + '.h5' + simulation.db_path = db_file + + # store data + simulation.store_mat_data(mats,0,False) + simulation.store_after_repr(mats, m_after_refill, 0) + + # read stored data + try: + db = tb.open_file(simulation.db_path, mode='r', + filters=simulation.compression_params) + except Exception: + print('Unable to assign correct value to db. See error stack for more info.') + + tmats = db.root.materials + tfuel_st = tmats.fuel.in_out_streams + + tf_feed_leu = tfuel_st.feed_leu[0] + tf_entrain_sep = tfuel_st.waste_entrainment_separator[0] + tf_liq_met = tfuel_st.waste_liquid_metal[0] + tf_nickel_filt = tfuel_st.waste_nickel_filter[0] + tf_sparger = tfuel_st.waste_sparger[0] + try: + assert tf_feed_leu[0] == f_feed_leu['Li6'] + assert tf_feed_leu[1] == f_feed_leu['Li7'] + assert tf_feed_leu[2] == f_feed_leu['F19'] + assert tf_feed_leu[3] == f_feed_leu['U235'] + assert tf_feed_leu[4] == f_feed_leu['U238'] + + assert tf_entrain_sep[0] == f_entrain_sep['H1'] + assert tf_entrain_sep[1] == f_entrain_sep['H2'] + assert tf_entrain_sep[459] == f_entrain_sep['Kr91'] + assert tf_entrain_sep[461] == f_entrain_sep['Kr93'] + assert tf_entrain_sep[991] == f_entrain_sep['Xe135'] + assert tf_entrain_sep[993] == f_entrain_sep['Xe136'] + + assert tf_liq_met[117] == f_liq_met['Ca49'] + assert tf_liq_met[288] == f_liq_met['Cu69'] + assert tf_liq_met[513] == f_liq_met['Sr102'] + assert tf_liq_met[518] == f_liq_met['Y89'] + assert tf_liq_met[1123] == f_liq_met['Pr159'] + assert tf_liq_met[1124] == f_liq_met['Nd142'] + + assert tf_nickel_filt[309] == f_nickel_filt['Zn70'] + assert tf_nickel_filt[437] == f_nickel_filt['Br90'] + assert tf_nickel_filt[964] == f_nickel_filt['I134'] + assert tf_nickel_filt[630] == f_nickel_filt['Tc99'] + + assert tf_sparger[0] == f_sparger['H1'] + assert tf_sparger[1] == f_sparger['H2'] + assert tf_sparger[459] == f_sparger['Kr91'] + assert tf_sparger[461] == f_sparger['Kr93'] + assert tf_sparger[991] == f_sparger['Xe135'] + assert tf_sparger[993] == f_sparger['Xe136'] + except AssertionError: + db.close() + os.remove(db_file) + simulation.db_path = db_path_old + raise AssertionError("incorrect Value") + + # close the file + db.close() + + # delete test file + os.remove(db_file) + + #use original db path + simulation.db_path = db_path_old def test_store_mat_data(): """ @@ -63,6 +168,12 @@ def test_store_mat_data(): simulation.sim_depcode.input_path, True) + fuel_before = mats_before['fuel'] + pois_before = mats_before['ctrlPois'] + + fuel_after = mats_after['fuel'] + pois_after = mats_after['ctrlPois'] + # we want to keep the old path for other sims, but for this # test we'll want a fresh db db_path_old = simulation.db_path @@ -74,8 +185,12 @@ def test_store_mat_data(): simulation.store_mat_data(mats_after, 0, True) # read stored data - db = tb.open_file(simulation.db_path, mode='r', + try: + db = tb.open_file(simulation.db_path, mode='r', filters=simulation.compression_params) + except Exception: + print('Unable to assign correct value to db. See error stack for more info.') + tmats = db.root.materials tfuel_before = tmats.fuel.before_reproc.comp[0] @@ -91,56 +206,62 @@ def test_store_mat_data(): tpois_after_params = tmats.ctrlPois.after_reproc.parameters[0] # Check the mass fractions - assert tfuel_before[1566] == mats_before['fuel']['U235'] - assert tfuel_before[1570] == mats_before['fuel']['U238'] - assert tfuel_before[37] == mats_before['fuel']['F19'] - assert tfuel_before[8] == mats_before['fuel']['Li7'] - assert tfuel_before[1610] == mats_before['fuel']['Cm240'] - assert tfuel_before[1589] == mats_before['fuel']['Pu239'] - assert tpois_before[1213] == mats_before['ctrlPois']['Gd155'] - assert tpois_before[32] == mats_before['ctrlPois']['O16'] - - assert tfuel_after[1566] == mats_after['fuel']['U235'] - assert tfuel_after[1570] == mats_after['fuel']['U238'] - assert tfuel_after[37] == mats_after['fuel']['F19'] - assert tfuel_after[8] == mats_after['fuel']['Li7'] - assert tfuel_after[1610] == mats_after['fuel']['Cm240'] - assert tfuel_after[1589] == mats_after['fuel']['Pu239'] - assert tpois_after[1213] == mats_after['ctrlPois']['Gd155'] - assert tpois_after[32] == mats_after['ctrlPois']['O16'] - - # Check the parameters - assert tfuel_before_params[0] == mats_before['fuel'].mass - assert tfuel_before_params[1] == mats_before['fuel'].density - assert tfuel_before_params[2] == mats_before['fuel'].vol - assert tfuel_before_params[3] == mats_before['fuel'].temp - assert tfuel_before_params[4] == mats_before['fuel'].mass_flowrate - assert tfuel_before_params[5] == mats_before['fuel'].void_frac - assert tfuel_before_params[6] == mats_before['fuel'].burnup - - assert tpois_before_params[0] == mats_before['ctrlPois'].mass - assert tpois_before_params[1] == mats_before['ctrlPois'].density - assert tpois_before_params[2] == mats_before['ctrlPois'].vol - assert tpois_before_params[3] == mats_before['ctrlPois'].temp - assert tpois_before_params[4] == mats_before['ctrlPois'].mass_flowrate - assert tpois_before_params[5] == mats_before['ctrlPois'].void_frac - assert tpois_before_params[6] == mats_before['ctrlPois'].burnup - - assert tfuel_after_params[0] == mats_after['fuel'].mass - assert tfuel_after_params[1] == mats_after['fuel'].density - assert tfuel_after_params[2] == mats_after['fuel'].vol - assert tfuel_after_params[3] == mats_after['fuel'].temp - assert tfuel_after_params[4] == mats_after['fuel'].mass_flowrate - assert tfuel_after_params[5] == mats_after['fuel'].void_frac - assert tfuel_after_params[6] == mats_after['fuel'].burnup - - assert tpois_after_params[0] == mats_after['ctrlPois'].mass - assert tpois_after_params[1] == mats_after['ctrlPois'].density - assert tpois_after_params[2] == mats_after['ctrlPois'].vol - assert tpois_after_params[3] == mats_after['ctrlPois'].temp - assert tpois_after_params[4] == mats_after['ctrlPois'].mass_flowrate - assert tpois_after_params[5] == mats_after['ctrlPois'].void_frac - assert tpois_after_params[6] == mats_after['ctrlPois'].burnup + try: + assert tfuel_before[1566] == fuel_before['U235'] + assert tfuel_before[1570] == fuel_before['U238'] + assert tfuel_before[37] == fuel_before['F19'] + assert tfuel_before[8] == fuel_before['Li7'] + assert tfuel_before[1610] == fuel_before['Cm240'] + assert tfuel_before[1589] == fuel_before['Pu239'] + assert tpois_before[1213] == pois_before['Gd155'] + assert tpois_before[32] == pois_before['O16'] + + assert tfuel_after[1566] == fuel_after['U235'] + assert tfuel_after[1570] == fuel_after['U238'] + assert tfuel_after[37] == fuel_after['F19'] + assert tfuel_after[8] == fuel_after['Li7'] + assert tfuel_after[1610] == fuel_after['Cm240'] + assert tfuel_after[1589] == fuel_after['Pu239'] + assert tpois_after[1213] == pois_after['Gd155'] + assert tpois_after[32] == pois_after['O16'] + + # Check the parameters + assert tfuel_before_params[0] == fuel_before.mass + assert tfuel_before_params[1] == fuel_before.density + assert tfuel_before_params[2] == fuel_before.vol + assert tfuel_before_params[3] == fuel_before.temp + assert tfuel_before_params[4] == fuel_before.mass_flowrate + assert tfuel_before_params[5] == fuel_before.void_frac + assert tfuel_before_params[6] == fuel_before.burnup + + assert tpois_before_params[0] == pois_before.mass + assert tpois_before_params[1] == pois_before.density + assert tpois_before_params[2] == pois_before.vol + assert tpois_before_params[3] == pois_before.temp + assert tpois_before_params[4] == pois_before.mass_flowrate + assert tpois_before_params[5] == pois_before.void_frac + assert tpois_before_params[6] == pois_before.burnup + + assert tfuel_after_params[0] == fuel_after.mass + assert tfuel_after_params[1] == fuel_after.density + assert tfuel_after_params[2] == fuel_after.vol + assert tfuel_after_params[3] == fuel_after.temp + assert tfuel_after_params[4] == fuel_after.mass_flowrate + assert tfuel_after_params[5] == fuel_after.void_frac + assert tfuel_after_params[6] == fuel_after.burnup + + assert tpois_after_params[0] == pois_after.mass + assert tpois_after_params[1] == pois_after.density + assert tpois_after_params[2] == pois_after.vol + assert tpois_after_params[3] == pois_after.temp + assert tpois_after_params[4] == pois_after.mass_flowrate + assert tpois_after_params[5] == pois_after.void_frac + assert tpois_after_params[6] == pois_after.burnup + except AssertionError: + db.close() + os.remove(db_file) + simulation.db_path = db_path_old + raise AssertionError("incorrect Value") # close the file db.close() @@ -172,23 +293,33 @@ def test_store_run_init_info(): simulation.store_run_init_info() # read stored data - db = tb.open_file(simulation.db_path, mode='r', + try: + db = tb.open_file(simulation.db_path, mode='r', filters=simulation.compression_params) + except Exception: + print('Unable to assign correct value to db. See error stack for more info.') + tinit_info = db.root.initial_depcode_siminfo[0] - assert tinit_info[0] == simulation.sim_depcode.npop - assert tinit_info[1] == simulation.sim_depcode.active_cycles - assert tinit_info[2] == simulation.sim_depcode.inactive_cycles - assert str(tinit_info[3])[2:-1] == init_info['serpent_version'] - assert str(tinit_info[4])[2:-1] == init_info['title'] - assert str(tinit_info[5])[2:-1] == init_info['serpent_input_filename'] - assert str(tinit_info[6])[2:-1] == init_info['serpent_working_dir'] - assert str(tinit_info[7])[2:-1] == init_info['xs_data_path'] - assert tinit_info[8] == init_info['OMP_threads'] - assert tinit_info[9] == init_info['MPI_tasks'] - assert tinit_info[10] == init_info['memory_optimization_mode'] - assert tinit_info[11] == init_info['depletion_timestep'] + try: + assert tinit_info[0] == simulation.sim_depcode.npop + assert tinit_info[1] == simulation.sim_depcode.active_cycles + assert tinit_info[2] == simulation.sim_depcode.inactive_cycles + assert str(tinit_info[3])[2:-1] == init_info['serpent_version'] + assert str(tinit_info[4])[2:-1] == init_info['title'] + assert str(tinit_info[5])[2:-1] == init_info['serpent_input_filename'] + assert str(tinit_info[6])[2:-1] == init_info['serpent_working_dir'] + assert str(tinit_info[7])[2:-1] == init_info['xs_data_path'] + assert tinit_info[8] == init_info['OMP_threads'] + assert tinit_info[9] == init_info['MPI_tasks'] + assert tinit_info[10] == init_info['memory_optimization_mode'] + assert tinit_info[11] == init_info['depletion_timestep'] + except AssertionError: + db.close() + os.remove(db_file) + simulation.db_path = db_path_old + raise AssertionError("incorrect Value") # close the file db.close() @@ -219,28 +350,36 @@ def test_store_run_step_info(): simulation.store_run_step_info() # read stored data - db = tb.open_file(simulation.db_path, mode='r', + try: + db = tb.open_file(simulation.db_path, mode='r', filters=simulation.compression_params) + except Exception: + print('Unable to assign correct value to db. See error stack for more info.') tstep_info = db.root.simulation_parameters[0] - - assert np.array_equal(tstep_info[0], - step_info['beta_eff'].astype('float32')) - assert np.array_equal(tstep_info[1], - step_info['breeding_ratio'].astype('float32')) - assert tstep_info[2] == simulation.burn_time - assert np.array_equal(tstep_info[3], - step_info['delayed_neutrons_lambda'].\ - astype('float32')) - assert tstep_info[4] == step_info['fission_mass_bds'].astype('float32') - assert tstep_info[5] == step_info['fission_mass_eds'].astype('float32') - assert np.array_equal(tstep_info[6], - step_info['keff_bds'].astype('float32')) - assert np.array_equal(tstep_info[7], - step_info['keff_eds'].astype('float32')) - assert tstep_info[8] == step_info['memory_usage'].astype('float32') - assert tstep_info[9] == step_info['power_level'].astype('float32') - assert tstep_info[10] == step_info['execution_time'].astype('float32') + try: + assert np.array_equal(tstep_info[0], + step_info['beta_eff'].astype('float32')) + assert np.array_equal(tstep_info[1], + step_info['breeding_ratio'].astype('float32')) + assert tstep_info[2] == simulation.burn_time + assert np.array_equal(tstep_info[3], + step_info['delayed_neutrons_lambda'].\ + astype('float32')) + assert tstep_info[4] == step_info['fission_mass_bds'].astype('float32') + assert tstep_info[5] == step_info['fission_mass_eds'].astype('float32') + assert np.array_equal(tstep_info[6], + step_info['keff_bds'].astype('float32')) + assert np.array_equal(tstep_info[7], + step_info['keff_eds'].astype('float32')) + assert tstep_info[8] == step_info['memory_usage'].astype('float32') + assert tstep_info[9] == step_info['power_level'].astype('float32') + assert tstep_info[10] == step_info['execution_time'].astype('float32') + except AssertionError: + db.close() + os.remove(db_file) + simulation.db_path = db_path_old + raise AssertionError("incorrect Value") # close the file db.close() From 56473bc4d8ebd488ab0212792abf996b2388ec37 Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 14 Jan 2022 20:24:56 -0600 Subject: [PATCH 030/118] consistency fixes --- saltproc/app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/saltproc/app.py b/saltproc/app.py index 3e994c977..6bd2e8bd5 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -324,7 +324,7 @@ def reprocessing(mats): return waste, extracted_mass -def refill(mat, extracted_mass, waste_dict): +def refill(mats, extracted_mass, waste_dict): """Makes up material loss in removal processes by adding fresh fuel. Parameters @@ -360,7 +360,7 @@ def refill(mat, extracted_mass, waste_dict): """ print('Fuel before refill ^^^', mats['fuel'].print_attr()) feeds = read_feeds_from_input() - refill_mat = OrderedDict() + refill_mats = OrderedDict() for mn, v in feeds.items(): # iterate over materials refill_mats[mn] = {} for feed_n, fval in feeds[mn].items(): # works with one feed only From 4fd2c744eedbc0e08588f79d766a34c716ea4f85 Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 14 Jan 2022 21:07:22 -0600 Subject: [PATCH 031/118] docstring edits --- saltproc/simulation.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/saltproc/simulation.py b/saltproc/simulation.py index 7f70356db..c50db5cef 100644 --- a/saltproc/simulation.py +++ b/saltproc/simulation.py @@ -298,10 +298,11 @@ def store_mat_data(self, mats, dep_step, store_at_end = False): db.close() def store_run_step_info(self): - """Adds to database Serpent and Saltproc simulation parameters - (execution time, memory usage), multiplication factor, breeding ratio, + """Adds the following depletion code and SaltProc simulation + data at the current depletion step to the database: + execution time, memory usage, multiplication factor, breeding ratio, delayed neutron precursor data, fission mass, cumulative depletion - time, power level for the current time step. + time, power level. """ # Read info from depcode _res.m File @@ -366,8 +367,13 @@ class Step_info(tb.IsDescription): db.close() def store_run_init_info(self): - """Adds to database Serpent and Saltproc simulation parameters before - starting depletion sequence. + """Adds the following depletion code and SaltProc simulation parameters + to the database: + neutron population, active cycles, inactive cycles, depletion code version + simulation title, depetion code input file path, depletion code working + directory, cross section data path, # of OMP threads, # of MPI tasks, + memory optimization mode (Serpent), depletion timestep size. + """ # numpy arraw row storage for run info sim_info_dtype = np.dtype([ @@ -475,8 +481,9 @@ def read_k_eds_delta(self, current_timestep, restart): return False def check_switch_geo_trigger(self, current_time, switch_time): - """Compares current timestep with user defined time to switch geometry. - Returns `True` if its time. + """Compares the current timestep with the user defined times + at which to switch reactor geometry, and returns `True` if there + is a match. Parameters ---------- From 0ca64c6494291110e4d2c75ad7e245da6c35767f Mon Sep 17 00:00:00 2001 From: yardasol Date: Mon, 17 Jan 2022 09:38:59 -0600 Subject: [PATCH 032/118] (serpent->depcode in app.py (loose end)) --- saltproc/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saltproc/app.py b/saltproc/app.py index 9cfd47167..d47e31f9c 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -462,7 +462,7 @@ def run(): print("Removed mass [g]:", rem_mass) # Store in DB after reprocessing and refill (right before next depl) simulation.store_after_repr(mats, waste_feed_st, dts) - serpent.write_mat_file(mats, iter_matfile, simulation.burn_time) + depcode.write_mat_file(mats, iter_matfile, simulation.burn_time) del mats, waste_st, waste_feed_st, rem_mass gc.collect() # Switch to another geometry? From 88fea3d8bdbcfafbab1d438b2c916dd7f4a94342 Mon Sep 17 00:00:00 2001 From: yardasol Date: Tue, 25 Jan 2022 13:16:51 -0600 Subject: [PATCH 033/118] start making input file a json input schema --- saltproc/tests/test.json | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/saltproc/tests/test.json b/saltproc/tests/test.json index f5603ea24..7b22f1858 100644 --- a/saltproc/tests/test.json +++ b/saltproc/tests/test.json @@ -1,14 +1,26 @@ { - "Name of depletion code": "serpent", - "Path to depletion code executable": "/home/andrei2/serpent/serpent2/src_2131/sss2", + "depcode": { + "codename": "serpent", + "exec_path": "sss2", + "template_path": "tap_test1.serpent", + "npop": "50", + "active_cycles": "20", + "inactive_cycles": "20", + "geo_file": ["347_base.ini"], + + "": "", + "": "", + "": "", + "": "", + "": "", + "": "", + "": "", + "": "", + } "File containing processing system objects": "processes.json", "Graph file containing processing system structure": "test.dot", - "User's depletion code input file with reactor model": "tap_test1.serpent", "Path output data storing folder": "./", "Output HDF5 database file name": "db_saltproc.h5", - "Number of neutrons per generation": 50, - "Number of active generations": 20, - "Number of inactive generations": 20, "Restart simulation from the step when it stopped?": false, "Geometry file/files to use in depletion code runs": "347_base.ini", "Switch to another geometry when keff drops below 1?": false, From c5d16e4b6fd8d5b80db78e3c1a160168e1db27b0 Mon Sep 17 00:00:00 2001 From: yardasol Date: Tue, 25 Jan 2022 13:53:34 -0600 Subject: [PATCH 034/118] adjust docstrings of app.py --- saltproc/reactor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saltproc/reactor.py b/saltproc/reactor.py index 690b22889..80404ad88 100644 --- a/saltproc/reactor.py +++ b/saltproc/reactor.py @@ -15,7 +15,7 @@ def __init__(self, volume : float Total volume of the reactor core (:math:`cm^3`). mass_flowrate : float - Total mass flowrate through reactor (g/s). + Total mass flowrate through reactor core (g/s). power_levels : array [:math:`N_{steps}` x1] Normalized power level for each depletion step (W). depl_hist : array [:math:`N_{steps}` x1] From e7cdc1a4977d0b8a38a0ee2da99b910e8a9f0826 Mon Sep 17 00:00:00 2001 From: yardasol Date: Tue, 25 Jan 2022 14:12:20 -0600 Subject: [PATCH 035/118] make test input file use JSON schema --- saltproc/tests/test.json | 50 ++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/saltproc/tests/test.json b/saltproc/tests/test.json index 7b22f1858..7e164a49f 100644 --- a/saltproc/tests/test.json +++ b/saltproc/tests/test.json @@ -1,31 +1,31 @@ { + "$comment": "File containing processing system objects", + "proc_input_file": "processes.json", + "$comment": "Graph file containing processing system structure", + "dot_input_file": "test.dot", + "$comment": "Path output data storing folder", + "output_path": "./", + "$comment": "Number of steps for constant power and depletion interval case",, + "depsteps": 2, "depcode": { "codename": "serpent", "exec_path": "sss2", "template_path": "tap_test1.serpent", - "npop": "50", - "active_cycles": "20", - "inactive_cycles": "20", - "geo_file": ["347_base.ini"], - - "": "", - "": "", - "": "", - "": "", - "": "", - "": "", - "": "", - "": "", - } - "File containing processing system objects": "processes.json", - "Graph file containing processing system structure": "test.dot", - "Path output data storing folder": "./", - "Output HDF5 database file name": "db_saltproc.h5", - "Restart simulation from the step when it stopped?": false, - "Geometry file/files to use in depletion code runs": "347_base.ini", - "Switch to another geometry when keff drops below 1?": false, - "Salt mass flow rate throughout reactor core (g/s)": 9.92E+6, - "Number of steps for constant power and depletion interval case": 2, - "Depletion step interval or Cumulative time (end of step) (d)": 5, - "Reactor power or power step list during depletion step (W)": 1.250E+9 + "npop": 50, + "active_cycles": 20, + "inactive_cycles": 20, + "geo_file": ["347_base.ini"] + }, + "simulation": { + "sim_name": "test_simulation", + "db_path": "db_saltproc.h5", + "restart_flag": false, + "" + }, + "reactor": { + "volume": 1.0, + "mass_flowrate": 9.92E+6, + "power_levels": [ 1.250E+9 ], + "depl_hist": [ 5 ] + } } From 19fcbf33da8030d47978f4683094e0ae94571712 Mon Sep 17 00:00:00 2001 From: yardasol Date: Tue, 25 Jan 2022 14:43:38 -0600 Subject: [PATCH 036/118] create actual JSON schema for input file; move comments to input_schema.json --- saltproc/input_schema.json | 45 ++++++++++++++++++++++++++++++++++++++ saltproc/tests/test.json | 7 +----- 2 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 saltproc/input_schema.json diff --git a/saltproc/input_schema.json b/saltproc/input_schema.json new file mode 100644 index 000000000..b61d72525 --- /dev/null +++ b/saltproc/input_schema.json @@ -0,0 +1,45 @@ +{ + "type": "object", + "properties": { + "$comment": "File containing processing system objects", + "proc_input_file": { "type": "string" }, + "$comment": "Graph file containing processing system structure", + "dot_input_file": { "type": "string" }, + "$comment": "Path output data storing folder", + "output_path": { "type": "string" }, + "$comment": "Number of steps for constant power and depletion interval case", + "depsteps": { "type": "number" }, + "depcode": { "type": "object", + "properties": { + "codename": { "type": "string" }, + "exec_path": { "type": "string" },"sss2", + "template_path": { "type": "string" },"tap_test1.serpent", + "npop": 50, + "active_cycles": 20, + "inactive_cycles": 20, + "geo_file": { "type": "array", + "items": { "type": "string"} + } + } + }, + "simulation": { "type": "object", + "properties": { + "sim_name": { "type": "string"}, + "db_path": { "type": "string"}, + "restart_flag": { "type": "boolean"} + } + }, + "reactor": { "type": "object", + "properties": { + "volume": { "type": "number" }, + "mass_flowrate": { "type": "number" }, + "power_levels": { "type": "array", + "items": { "type": "number"} + }, + "depl_hist": { "type": "array", + "items": { "type": "number"} + } + } + } + } +} diff --git a/saltproc/tests/test.json b/saltproc/tests/test.json index 7e164a49f..980da3543 100644 --- a/saltproc/tests/test.json +++ b/saltproc/tests/test.json @@ -1,11 +1,7 @@ { - "$comment": "File containing processing system objects", "proc_input_file": "processes.json", - "$comment": "Graph file containing processing system structure", "dot_input_file": "test.dot", - "$comment": "Path output data storing folder", "output_path": "./", - "$comment": "Number of steps for constant power and depletion interval case",, "depsteps": 2, "depcode": { "codename": "serpent", @@ -19,8 +15,7 @@ "simulation": { "sim_name": "test_simulation", "db_path": "db_saltproc.h5", - "restart_flag": false, - "" + "restart_flag": false }, "reactor": { "volume": 1.0, From d1e6e082a704490a872a86129abd16cabbfed029 Mon Sep 17 00:00:00 2001 From: yardasol Date: Tue, 25 Jan 2022 14:45:33 -0600 Subject: [PATCH 037/118] add jsonschema package to environment.yml --- environment.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/environment.yml b/environment.yml index 2b85c7459..98f128ab5 100644 --- a/environment.yml +++ b/environment.yml @@ -7,3 +7,4 @@ dependencies: - networkx - pydotplus - pytest + - jsonschema From 2e1ad8745159f0b41356d84138af64434c7277a3 Mon Sep 17 00:00:00 2001 From: yardasol Date: Tue, 25 Jan 2022 15:57:40 -0600 Subject: [PATCH 038/118] apply JSON schema input file changes to app.py --- saltproc/app.py | 118 ++++++++++++++++++++++++------------------------ 1 file changed, 58 insertions(+), 60 deletions(-) diff --git a/saltproc/app.py b/saltproc/app.py index 6bd2e8bd5..4af3918ce 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -10,7 +10,7 @@ # from materialflow import Materialflow import os import copy -import json +import json, jsonschema from collections import OrderedDict import gc import networkx as nx @@ -24,6 +24,7 @@ input_file = os.path.join(input_path, 'data/saltproc_serpent') iter_matfile = os.path.join(input_path, 'data/saltproc_mat') +input_schema = os.path.join(input_path, 'saltproc/input_schema.json') def check_restart(restart_flag): """If the user set `Restart simulation from the step when it stopped?` @@ -36,7 +37,7 @@ def check_restart(restart_flag): """ if not restart_flag: try: - os.remove(db_file) + os.remove(simulation_inp['db_path']) os.remove(iter_matfile) os.remove(input_file) print("Previous run output files were deleted.") @@ -87,49 +88,44 @@ def read_main_input(main_inp_file): """ with open(main_inp_file) as f: j = json.load(f) - global codename, exec_path, spc_inp_file, dot_inp_file, \ - template_file, db_file - codename = j["Name of depletion code"].lower() - exec_path = j["Path to depletion code executable"] + with open(input_schema) as v: + s = json.load(v) + jsonschema.validate(instance=j,schema=s) + + global depcode_inp, simulation_inp, reactor_inp + depcode_inp = j['depcode'] + simulation_inp = j['simulationt'] + reactor_inp = j['reactor'] + + depcode_inp['template_path'] = os.path.join( + os.path.dirname(f.name), depcode_inp['template_path']) + geo_list = depcode_inp['geo_files'] + geo_files = [g for g in geo_list] + depcode_inp['geo_files'] = geo_list + + + db_path = os.path.join( + os.path.dirname(f.name), + output_path, simulation_inp['db_path']) + simulation_inp['db_path'] = db_path + + global spc_inp_file, dot_inp_file, output_path, depsteps spc_inp_file = os.path.join( os.path.dirname(f.name), - j["File containing processing system objects"]) + j['proc_input_file']) dot_inp_file = os.path.join( os.path.dirname(f.name), - j["Graph file containing processing system structure"]) - template_file = os.path.join( - os.path.dirname(f.name), - j["User's depletion code input file with reactor model"]) - db_path = j["Path output data storing folder"] - db_file = os.path.join( - os.path.dirname(f.name), - db_path, - j["Output HDF5 database file name"]) - # Read Monte Carlo setups - global neutron_pop, active_cycles, inactive_cycles - neutron_pop = j["Number of neutrons per generation"] - active_cycles = j["Number of active generations"] - inactive_cycles = j["Number of inactive generations"] - # Read advanced simulatiion parameters - global adjust_geo, restart_flag, core_massflow_rate - adjust_geo = j["Switch to another geometry when keff drops below 1?"] - restart_flag = j["Restart simulation from the step when it stopped?"] - # Read paths to geometry files - global geo_file - if adjust_geo: - geo_list = j["Geometry file/files to use in depletion code runs"] - geo_file = [g for g in geo_list] - elif not adjust_geo: - geo_file = [j["Geometry file/files to use in depletion code runs"]] - core_massflow_rate = \ - j["Salt mass flow rate throughout reactor core (g/s)"] - global depl_hist, power_hist - depl_hist = \ - j["Depletion step interval or Cumulative time (end of step) (d)"] - power_hist = \ - j["Reactor power or power step list during depletion step (W)"] - depsteps = \ - j["Number of steps for constant power and depletion interval case"] + j['dot_input_file']) + output_path = j['output_path'] + depsteps = reactor_inp['depsteps'] + + # Read advanced simulation parameters + global restart_flag, adjust_geo + adjust_geo = simulation_inp['adjust_geo'] + restart_flag = simulation_inp['restart_flag'] + + depl_hist = reactor_inp['depl_hist'] + power_hist = reactor_inp['power_hist '] if depsteps is not None and isinstance(depl_hist, (float, int)): if depsteps < 0.0 or not int: raise ValueError('Depletion step interval cannot be negative') @@ -138,6 +134,8 @@ def read_main_input(main_inp_file): deptot = float(depl_hist) * step depl_hist = np.linspace(float(depl_hist), deptot, num=step) power_hist = float(power_hist) * np.ones_like(depl_hist) + reactor_inp['depl_hist'] = depl_hist + reactor_inp['power_hist'] = power_hist elif depsteps is None and isinstance(depl_hist, (np.ndarray, list)): if len(depl_hist) != len(power_hist): raise ValueError( @@ -383,45 +381,45 @@ def run(): read_main_input(sp_input) # Print out input information print('Initiating Saltproc:\n' - '\tRestart = ' + str(restart_flag) + '\n' - '\tTemplate File Path = ' + os.path.abspath(template_file) + '\n' + '\tRestart = ' + str(simulation_inp['restart_flag']) + '\n' + '\tTemplate File Path = ' + os.path.abspath(depcode_inp['template_path']) + '\n' '\tInput File Path = ' + os.path.abspath(input_file) + '\n' '\tMaterial File Path = ' + os.path.abspath(iter_matfile) + '\n' - '\tOutput HDF5 DB Path = ' + os.path.abspath(db_file) + '\n' + '\tOutput HDF5 DB Path = ' + os.path.abspath(simulation_inp['db_path']) + '\n' ) # Intializing objects - if codename == 'serpent': + if depcode_inp['codename'] == 'serpent': depcode = DepcodeSerpent( - exec_path=exec_path, - template_path=template_file, + exec_path=depcode_inp['exec_path'], + template_path=depcode_inp['template_path'], input_path=input_file, iter_matfile=iter_matfile, - geo_file=geo_file, - npop=neutron_pop, - active_cycles=active_cycles, - inactive_cycles=inactive_cycles) + geo_files=depcode_inp['geo_files'], + npop=depcode_inp['npop'], + active_cycles=depcode_inp['active_cycles'], + inactive_cycles=depcode_inp['inactive_cycles']) else: - raise ValueError(f'{codename} is not a supported depletion code') + raise ValueError(f'{depcode_inp['codename']} is not a supported depletion code') simulation = Simulation( sim_name='Super test', sim_depcode=depcode, core_number=cores, node_number=nodes, - db_path=db_file, + db_path=simulation_inp['db_path'], iter_matfile=iter_matfile) msr = Reactor( - volume=1.0, - mass_flowrate=core_massflow_rate, - power_levels=power_hist, - depl_hist=depl_hist) + volume=reactor_inp['volume'], + mass_flowrate=reactor_inp['mass_flowrate'], + power_levels=reactor_inp['power_levels'], + depl_hist=reactor_inp['depl_hist']) # Check: Restarting previous simulation or starting new? check_restart(restart_flag) # Run sequence # Start sequence - for dep_step in range(len(depl_hist)): + for dep_step in range(len(reactor.depl_hist)): print("\n\n\nStep #%i has been started" % (dep_step + 1)) - depcode.write_depcode_input(template_file, + depcode.write_depcode_input(depcode.template_path, input_file, msr, dep_step, @@ -466,7 +464,7 @@ def run(): del mats, waste_st, waste_feed_st, rem_mass gc.collect() # Switch to another geometry? - if adjust_geo and simulation.read_k_eds_delta(dep_step, restart_flag): + if adjust_geo and simulation.read_k_eds_delta(dep_step): simulation.switch_to_next_geometry() print("\nTime at the end of current depletion step %fd" % simulation.burn_time) From 863a840ea610cbec3ecb9235e32af5694a00aa25 Mon Sep 17 00:00:00 2001 From: yardasol Date: Tue, 25 Jan 2022 16:19:03 -0600 Subject: [PATCH 039/118] rename input_path -> rerun_path in depcode.py; doc adjustments --- saltproc/depcode.py | 60 +++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 35 deletions(-) diff --git a/saltproc/depcode.py b/saltproc/depcode.py index b5bfb92eb..b6fbb8f24 100644 --- a/saltproc/depcode.py +++ b/saltproc/depcode.py @@ -21,9 +21,9 @@ def __init__(self, codename, exec_path, template_path, - input_path, + rerun_path, iter_matfile, - geo_file=None, + geo_files=None, npop=50, active_cycles=20, inactive_cycles=20): @@ -36,13 +36,13 @@ def __init__(self, exec_path : str Path to depletion code executable. template_path : str - Path to user input file for depletion code. - input_path : str - Name of input file for depletion code rerunning. + Path to depletion code input file template. + rerun_path : str + Name of depletion code input file for depletion code rerunning. iter_matfile : str Name of iterative, rewritable material file for depletion code rerunning. This file is modified during the simulation. - geo_file : str or list, optional + geo_files : str or list, optional Path to file that contains the reactor geometry. List of `str` if reactivity control by switching geometry is `On` or just `str` otherwise. @@ -57,9 +57,9 @@ def __init__(self, self.codename = codename self.exec_path = exec_path self.template_path = template_path - self.input_path = input_path + self.rerun_path = rerun_path self.iter_matfile = iter_matfile - self.geo_file = geo_file + self.geo_files = geo_files self.npop = npop self.active_cycles = active_cycles self.inactive_cycles = inactive_cycles @@ -107,15 +107,11 @@ def run_depcode(self, cores, nodes): """ @abstractmethod - def write_depcode_input(self, temp, inp, reactor, dep_step, restart): + def write_depcode_input(self, reactor, dep_step, restart): """ Writes prepared data into depletion code input file(s). Parameters ---------- - temp : str - Path to depletion code template file - inp : str - Path to input file for depletion code rerunning reactor : Reactor Contains information about power load curve and cumulative depletion time for the integration test. @@ -160,9 +156,9 @@ class DepcodeSerpent(Depcode): def __init__(self, exec_path="sss2", template_path="reactor.serpent", - input_path="data/saltproc_reactor", + rerun_path="data/saltproc_reactor", iter_matfile="data/saltproc_mat", - geo_file=None, + geo_files=None, npop=50, active_cycles=20, inactive_cycles=20): @@ -174,12 +170,12 @@ def __init__(self, Path to Serpent2 executable. template_path : str Path to user input file for Serpent2. - input_path : str - Name of input file for Serpent2 rerunning. + rerun_path : str + Name of Serpent2 input file for Serpent2 rerunning. iter_matfile : str Name of iterative, rewritable material file for Serpent2 rerunning. This file is modified during the simulation. - geo_file : str or list, optional + geo_files : str or list, optional Path to file that contains the reactor geometry. List of `str` if reactivity control by switching geometry is `On` or just `str` otherwise. @@ -194,9 +190,9 @@ def __init__(self, super().__init__("serpent", exec_path, template_path, - input_path, + rerun_path, iter_matfile, - geo_file, + geo_files, npop, active_cycles, inactive_cycles) @@ -381,7 +377,7 @@ def insert_path_to_geometry(self, template_data): """ template_data.insert(5, # Inserts on 6th line - 'include \"' + str(self.geo_file[0]) + '\"\n') + 'include \"' + str(self.geo_files[0]) + '\"\n') return template_data def read_dep_comp(self, input_file, read_at_end=False): @@ -435,14 +431,14 @@ def read_dep_comp(self, input_file, read_at_end=False): mats[m].mass = mats[m].density * volume mats[m].vol = volume mats[m].burnup = dep['MAT_' + m + '_BURNUP'][moment] - self.get_tra_or_dec(self.input_path) + self.get_tra_or_dec(self.rerun_path) return mats def read_depcode_info(self): """Parses initial simulation info data from Serpent2 output and stores it in the `DepcodeSerpent` object's ``sim_info`` attributes. """ - res = serpent.parse_res(self.input_path + "_res.m") + res = serpent.parse_res(self.rerun_path + "_res.m") self.sim_info['serpent_version'] = \ res['VERSION'][0].decode('utf-8') self.sim_info['title'] = res['TITLE'][0].decode('utf-8') @@ -462,7 +458,7 @@ def read_depcode_step_param(self): """Parses data from Serpent2 output for each step and stores it in `DepcodeSerpent` object's ``param`` attributes. """ - res = serpent.parse_res(self.input_path + "_res.m") + res = serpent.parse_res(self.rerun_path + "_res.m") self.param['keff_bds'] = res['IMP_KEFF'][0] self.param['keff_eds'] = res['IMP_KEFF'][1] self.param['breeding_ratio'] = res['CONVERSION_RATIO'][1] @@ -562,16 +558,16 @@ def run_depcode(self, cores, nodes): self.exec_path, '-omp', str(cores), - self.input_path) + self.rerun_path) elif self.exec_path.startswith('/apps/exp_ctl/'): # check if Falcon args = ( 'mpiexec', self.exec_path, - self.input_path, + self.rerun_path, '-omp', str(18)) else: - args = (self.exec_path, '-omp', str(cores), self.input_path) + args = (self.exec_path, '-omp', str(cores), self.rerun_path) print('Running %s' % (self.codename)) try: subprocess.check_output( @@ -614,8 +610,6 @@ def sss_meta_zzz(self, nuc_code): def write_depcode_input( self, - temp_file, - inp_file, reactor, dep_step, restart): @@ -623,10 +617,6 @@ def write_depcode_input( Parameters ---------- - template_file : str - Path to Serpent2 template file. - input_file : str - Path to input file for Serpent2 rerunning. reactor : Reactor Contains information about power load curve and cumulative depletion time for the integration test. @@ -638,12 +628,12 @@ def write_depcode_input( """ if dep_step == 0 and not restart: - data = self.read_depcode_template(temp_file) + data = self.read_depcode_template(self.template_path) data = self.insert_path_to_geometry(data) data = self.change_sim_par(data) data = self.create_iter_matfile(data) else: - data = self.read_depcode_template(inp_file) + data = self.read_depcode_template(self.rerun_path) data = self.replace_burnup_parameters(data, reactor, dep_step) if data: From 61176057894d14b2b02783939b3a726fad3c15ee Mon Sep 17 00:00:00 2001 From: yardasol Date: Tue, 25 Jan 2022 16:20:49 -0600 Subject: [PATCH 040/118] move check_restart from app.py to simulation.py --- saltproc/simulation.py | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/saltproc/simulation.py b/saltproc/simulation.py index c50db5cef..f66d28e59 100644 --- a/saltproc/simulation.py +++ b/saltproc/simulation.py @@ -21,6 +21,8 @@ def __init__( core_number=1, node_number=1, db_path="db_saltproc.h5", + restart_flag=True, + adjust_geo=False, compression_params=tb.Filters(complevel=9, complib='blosc', fletcher32=True), @@ -44,6 +46,16 @@ def __init__( db_path : str Path of HDF5 database that stores simulation information and data. + restart_flag : bool + This value determines our initial condition. If `True`, then + then we run the simulation starting from the inital material + composition in the material input file inside our `depcode` + object. If `False`, then we runthe simulation starting from + the final material composition resulting within the `.h5` + database. + adjust_geo : bool + This value determines if we switch reactor geometry when keff + drops below 1.0 compression_params : Pytables filter object Compression parameters for HDF5 database. iter_matfile : str @@ -57,9 +69,30 @@ def __init__( self.core_number = core_number self.node_number = node_number self.db_path = db_path + self.restart_flag = restart_flag + self.adjust_geo = adjust_geo self.compression_params = compression_params self.iter_matfile = iter_matfile + def check_restart(self): + """If the user set `restart_flag` + for `False` clean out iteration files and database from previous run. + + Parameters + ---------- + restart_flag : bool + Is the current simulation restarted? + """ + if not self.restart_flag: + try: + os.remove(self.db_path) + os.remove(self.sim_depcode.iter_matfile) + os.remove(self.sim_depcode.rerun_path) + print("Previous run output files were deleted.") + except OSError as e: + pass + + def runsim_no_reproc(self, reactor, nsteps): """Run simulation sequence for integration test. No reprocessing involved, just re-running depletion code for comparision with model @@ -446,7 +479,7 @@ def switch_to_next_geometry(self): f.writelines(new_data) f.close() - def read_k_eds_delta(self, current_timestep, restart): + def read_k_eds_delta(self, current_timestep): """Reads from database delta between previous and current `keff` at the end of depletion step and returns `True` if predicted `keff` at the next depletion step drops below 1. @@ -455,8 +488,6 @@ def read_k_eds_delta(self, current_timestep, restart): ---------- current_timestep : int Number of current depletion time step. - restart : bool - Was this simulation restarted? Returns ------- @@ -465,7 +496,7 @@ def read_k_eds_delta(self, current_timestep, restart): """ - if current_timestep > 3 or restart: + if current_timestep > 3 or self.restart_flag: # Open or restore db and read data db = tb.open_file(self.db_path, mode='r') sim_param = db.root.simulation_parameters From 7d0f3ff26b7fb64a454f480708cf62ad39dd43fe Mon Sep 17 00:00:00 2001 From: yardasol Date: Tue, 25 Jan 2022 16:37:29 -0600 Subject: [PATCH 041/118] move integration test function to the integration tests --- saltproc/simulation.py | 51 ------------------ .../no_repro/test_no_reproc_run.py | 54 ++++++++++++++++++- 2 files changed, 53 insertions(+), 52 deletions(-) diff --git a/saltproc/simulation.py b/saltproc/simulation.py index f66d28e59..1b0d099b1 100644 --- a/saltproc/simulation.py +++ b/saltproc/simulation.py @@ -93,57 +93,6 @@ def check_restart(self): pass - def runsim_no_reproc(self, reactor, nsteps): - """Run simulation sequence for integration test. No reprocessing - involved, just re-running depletion code for comparision with model - output. - - Parameters - ---------- - reactor : `Reactor` - Contains information about power load curve and cumulative - depletion time for the integration test. - nsteps : int - Number of depletion time steps in integration test run. - - """ - - ###################################################################### - # Start sequence - for dep_step in range(nsteps): - print("\nStep #%i has been started" % (dep_step + 1)) - if dep_step == 0: # First step - self.sim_depcode.write_depcode_input( - self.sim_depcode.template_path, - self.sim_depcode.input_path, - reactor, - dep_step, - False) - self.sim_depcode.run_depcode( - self.core_number, - self.node_number) - # Read general simulation data which never changes - self.store_run_init_info() - # Parse and store data for initial state (beginning of dep_step) - mats = self.sim_depcode.read_dep_comp( - self.sim_depcode.input_path, - False) - self.store_mat_data(mats, dep_step, False) - # Finish of First step - # Main sequence - else: - self.sim_depcode.run_depcode( - self.core_number, - self.node_number) - mats = self.sim_depcode.read_dep_comp( - self.sim_depcode.input_path, - True) - self.store_mat_data(mats, dep_step, False) - self.store_run_step_info() - self.sim_depcode.write_mat_file( - mats, - self.iter_matfile, - self.burn_time) def store_after_repr(self, after_mats, waste_dict, dep_step): """Add data for waste streams [grams per depletion step] of each diff --git a/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py b/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py index 23921c6c0..7c0e2afbc 100644 --- a/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py +++ b/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py @@ -43,11 +43,63 @@ power_levels=[1.250E+09], depl_hist=[3]) +def runsim_no_reproc(simulation, reactor, nsteps): + """Run simulation sequence for integration test. No reprocessing + involved, just re-running depletion code for comparision with model + output. + + Parameters + ---------- + reactor : `Reactor` + Contains information about power load curve and cumulative + depletion time for the integration test. + nsteps : int + Number of depletion time steps in integration test run. + + """ + + ###################################################################### + # Start sequence + for dep_step in range(nsteps): + print("\nStep #%i has been started" % (dep_step + 1)) + if dep_step == 0: # First step + simulation.sim_depcode.write_depcode_input( + simulation.sim_depcode.template_path, + siumulation.sim_depcode.input_path, + reactor, + dep_step, + False) + simulation.sim_depcode.run_depcode( + simulation.core_number, + simulation.node_number) + # Read general simulation data which never changes + simulation.store_run_init_info() + # Parse and store data for initial state (beginning of dep_step) + mats = simulation.sim_depcode.read_dep_comp( + simulation.sim_depcode.input_path, + False) + simulation.store_mat_data(mats, dep_step, False) + # Finish of First step + # Main sequence + else: + simulation.sim_depcode.run_depcode( + simulation.core_number, + simulation.node_number) + mats = simulation.sim_depcode.read_dep_comp( + simulation.sim_depcode.input_path, + True) + simulation.store_mat_data(mats, dep_step, False) + simulation.store_run_step_info() + simulation.sim_depcode.write_mat_file( + mats, + simulation.sim_depcode.iter_matfile, + simulation.burn_time) + @pytest.mark.slow # @pytest.mark.skip def test_integration_3step_saltproc_no_reproc_heavy(): - simulation.runsim_no_reproc(tap, 2) + runsim_no_reproc(simulation, tap, 2) saltproc_out = sss_file + '_dep.m' dep_ser = serpent.parse_dep( directory + '/serpent_9d_dep.m', From 0431fd41e2bded33edd0f5fed6d847b1043b1b14 Mon Sep 17 00:00:00 2001 From: yardasol Date: Tue, 25 Jan 2022 16:40:00 -0600 Subject: [PATCH 042/118] remove iter_matfile from simulation.py --- saltproc/simulation.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/saltproc/simulation.py b/saltproc/simulation.py index 1b0d099b1..f6222c90a 100644 --- a/saltproc/simulation.py +++ b/saltproc/simulation.py @@ -26,7 +26,7 @@ def __init__( compression_params=tb.Filters(complevel=9, complib='blosc', fletcher32=True), - iter_matfile="./saltproc_mat"): + ): """Initializes the Simulation object. Parameters @@ -58,9 +58,6 @@ def __init__( drops below 1.0 compression_params : Pytables filter object Compression parameters for HDF5 database. - iter_matfile : str - Name of iterative, rewritable material file for depletion code - rerunning. This file is modified during the simulation. """ # initialize all object attributes @@ -72,7 +69,6 @@ def __init__( self.restart_flag = restart_flag self.adjust_geo = adjust_geo self.compression_params = compression_params - self.iter_matfile = iter_matfile def check_restart(self): """If the user set `restart_flag` From 72c49cf7748aba3ab9e8a70f135e9c727a3df2f9 Mon Sep 17 00:00:00 2001 From: yardasol Date: Tue, 25 Jan 2022 16:57:00 -0600 Subject: [PATCH 043/118] input_file->iter_input_file; move iter_input_file and iter_matfile to depcode; corresponding changes in input and other modules --- saltproc/app.py | 83 +++++++++++++------------------------- saltproc/depcode.py | 44 +++++++++----------- saltproc/input_schema.json | 42 +++++++++++-------- saltproc/tests/test.json | 7 +++- 4 files changed, 79 insertions(+), 97 deletions(-) diff --git a/saltproc/app.py b/saltproc/app.py index 4af3918ce..752e1e10f 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -21,30 +21,8 @@ input_path = os.getcwd() -input_file = os.path.join(input_path, 'data/saltproc_serpent') -iter_matfile = os.path.join(input_path, 'data/saltproc_mat') - input_schema = os.path.join(input_path, 'saltproc/input_schema.json') -def check_restart(restart_flag): - """If the user set `Restart simulation from the step when it stopped?` - for `False` clean out iteration files and database from previous run. - - Parameters - ---------- - restart_flag : bool - Is the current simulation restarted? - """ - if not restart_flag: - try: - os.remove(simulation_inp['db_path']) - os.remove(iter_matfile) - os.remove(input_file) - print("Previous run output files were deleted.") - except OSError as e: - pass - - def parse_arguments(): """Parses arguments from command line. @@ -92,6 +70,18 @@ def read_main_input(main_inp_file): s = json.load(v) jsonschema.validate(instance=j,schema=s) + # Saltproc settings + global spc_inp_file, dot_inp_file, output_path, depsteps + spc_inp_file = os.path.join( + os.path.dirname(f.name), + j['proc_input_file']) + dot_inp_file = os.path.join( + os.path.dirname(f.name), + j['dot_input_file']) + output_path = j['output_path'] + depsteps = reactor_inp['depsteps'] + + # Class settings global depcode_inp, simulation_inp, reactor_inp depcode_inp = j['depcode'] simulation_inp = j['simulationt'] @@ -102,28 +92,14 @@ def read_main_input(main_inp_file): geo_list = depcode_inp['geo_files'] geo_files = [g for g in geo_list] depcode_inp['geo_files'] = geo_list - + depcode_inp['iter_input_file'] = os.path.join(input_path, depcode_inp['iter_input_file']) + depcode_inp['iter_matfile'] = os.path.join(input_path, depcode_inp['iter_matfile']) db_path = os.path.join( os.path.dirname(f.name), output_path, simulation_inp['db_path']) simulation_inp['db_path'] = db_path - global spc_inp_file, dot_inp_file, output_path, depsteps - spc_inp_file = os.path.join( - os.path.dirname(f.name), - j['proc_input_file']) - dot_inp_file = os.path.join( - os.path.dirname(f.name), - j['dot_input_file']) - output_path = j['output_path'] - depsteps = reactor_inp['depsteps'] - - # Read advanced simulation parameters - global restart_flag, adjust_geo - adjust_geo = simulation_inp['adjust_geo'] - restart_flag = simulation_inp['restart_flag'] - depl_hist = reactor_inp['depl_hist'] power_hist = reactor_inp['power_hist '] if depsteps is not None and isinstance(depl_hist, (float, int)): @@ -383,8 +359,9 @@ def run(): print('Initiating Saltproc:\n' '\tRestart = ' + str(simulation_inp['restart_flag']) + '\n' '\tTemplate File Path = ' + os.path.abspath(depcode_inp['template_path']) + '\n' - '\tInput File Path = ' + os.path.abspath(input_file) + '\n' - '\tMaterial File Path = ' + os.path.abspath(iter_matfile) + '\n' + '\tInput File Path = ' + os.path.abspath(depcode_inp['iter_input_file'] + '\n' + '\tMaterial File Path = ' + os.path.abspath(depcode_inp['iter_matfile'] + ]) + '\n' '\tOutput HDF5 DB Path = ' + os.path.abspath(simulation_inp['db_path']) + '\n' ) # Intializing objects @@ -392,8 +369,8 @@ def run(): depcode = DepcodeSerpent( exec_path=depcode_inp['exec_path'], template_path=depcode_inp['template_path'], - input_path=input_file, - iter_matfile=iter_matfile, + iter_input_file=depecode_inp['iter_input_file'], + iter_matfile=depcode_inp['iter_matfile'], geo_files=depcode_inp['geo_files'], npop=depcode_inp['npop'], active_cycles=depcode_inp['active_cycles'], @@ -406,34 +383,32 @@ def run(): sim_depcode=depcode, core_number=cores, node_number=nodes, - db_path=simulation_inp['db_path'], - iter_matfile=iter_matfile) + db_path=simulation_inp['db_path']) + msr = Reactor( volume=reactor_inp['volume'], mass_flowrate=reactor_inp['mass_flowrate'], power_levels=reactor_inp['power_levels'], depl_hist=reactor_inp['depl_hist']) # Check: Restarting previous simulation or starting new? - check_restart(restart_flag) + simulation.check_restart() # Run sequence # Start sequence for dep_step in range(len(reactor.depl_hist)): print("\n\n\nStep #%i has been started" % (dep_step + 1)) - depcode.write_depcode_input(depcode.template_path, - input_file, - msr, + simulation.depcode.write_depcode_input(msr, dep_step, - restart_flag) + simulation.restart_flag) depcode.run_depcode(cores, nodes) - if dep_step == 0 and restart_flag is False: # First step + if dep_step == 0 and simulation.restart_flag is False: # First step # Read general simulation data which never changes simulation.store_run_init_info() # Parse and store data for initial state (beginning of dep_step) - mats = depcode.read_dep_comp(input_file, False) + mats = depcode.read_dep_comp(False) simulation.store_mat_data(mats, dep_step - 1, False) # Finish of First step # Main sequence - mats = depcode.read_dep_comp(input_file, True) + mats = depcode.read_dep_comp(True) simulation.store_mat_data(mats, dep_step, True) simulation.store_run_step_info() # Reprocessing here @@ -460,11 +435,11 @@ def run(): print("Removed mass [g]:", rem_mass) # Store in DB after reprocessing and refill (right before next depl) simulation.store_after_repr(mats, waste_feed_st, dep_step) - serpent.write_mat_file(mats, iter_matfile, simulation.burn_time) + depcode.write_mat_file(mats, simulation.burn_time) del mats, waste_st, waste_feed_st, rem_mass gc.collect() # Switch to another geometry? - if adjust_geo and simulation.read_k_eds_delta(dep_step): + if simulation.adjust_geo and simulation.read_k_eds_delta(dep_step): simulation.switch_to_next_geometry() print("\nTime at the end of current depletion step %fd" % simulation.burn_time) diff --git a/saltproc/depcode.py b/saltproc/depcode.py index b6fbb8f24..0f8698cef 100644 --- a/saltproc/depcode.py +++ b/saltproc/depcode.py @@ -21,7 +21,7 @@ def __init__(self, codename, exec_path, template_path, - rerun_path, + iter_input_file, iter_matfile, geo_files=None, npop=50, @@ -37,7 +37,7 @@ def __init__(self, Path to depletion code executable. template_path : str Path to depletion code input file template. - rerun_path : str + iter_input_file : str Name of depletion code input file for depletion code rerunning. iter_matfile : str Name of iterative, rewritable material file for depletion code @@ -57,7 +57,7 @@ def __init__(self, self.codename = codename self.exec_path = exec_path self.template_path = template_path - self.rerun_path = rerun_path + self.iter_input_file = iter_input_file self.iter_matfile = iter_matfile self.geo_files = geo_files self.npop = npop @@ -67,15 +67,13 @@ def __init__(self, self.sim_info = {} @abstractmethod - def read_dep_comp(self, dep_file, read_at_end=False): + def read_dep_comp(self, read_at_end=False): """Reads the depleted material data from the depcode simulation and returns a dictionary with a `Materialflow` object for each burnable material. Parameters ---------- - dep_file : str - Path to file containing results of depletion simulation read_at_end : bool, optional Controls at which moment in the depletion step to read the data. If `True`, the function reads data at the end of the @@ -122,7 +120,7 @@ def write_depcode_input(self, reactor, dep_step, restart): """ @abstractmethod - def write_mat_file(self, dep_dict, mat_file, dep_end_time): + def write_mat_file(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. @@ -136,8 +134,6 @@ def write_mat_file(self, dep_dict, mat_file, dep_end_time): Name of burnable material. ``value`` `Materialflow` object holding composition and properties. - mat_file : str - Path to file containing burnable materials composition. dep_end_time : float Current time at the end of the depletion step (d). @@ -156,7 +152,7 @@ class DepcodeSerpent(Depcode): def __init__(self, exec_path="sss2", template_path="reactor.serpent", - rerun_path="data/saltproc_reactor", + iter_input_file="data/saltproc_reactor", iter_matfile="data/saltproc_mat", geo_files=None, npop=50, @@ -170,7 +166,7 @@ def __init__(self, Path to Serpent2 executable. template_path : str Path to user input file for Serpent2. - rerun_path : str + iter_input_file : str Name of Serpent2 input file for Serpent2 rerunning. iter_matfile : str Name of iterative, rewritable material file for Serpent2 @@ -190,7 +186,7 @@ def __init__(self, super().__init__("serpent", exec_path, template_path, - rerun_path, + iter_input_file, iter_matfile, geo_files, npop, @@ -380,14 +376,12 @@ def insert_path_to_geometry(self, template_data): 'include \"' + str(self.geo_files[0]) + '\"\n') return template_data - def read_dep_comp(self, input_file, read_at_end=False): + def read_dep_comp(self, read_at_end=False): """Reads the Serpent2 `*_dep.m` file and returns a dictionary with a `Materialflow` object for each burnable material. Parameters ---------- - input_file : str - Path to Serpent2 input file. read_at_end : bool, optional Controls at which moment in the depletion step to read the data. If `True`, the function reads data at the end of the @@ -411,7 +405,7 @@ def read_dep_comp(self, input_file, read_at_end=False): else: moment = 0 - dep_file = os.path.join('%s_dep.m' % input_file) + dep_file = os.path.join('%s_dep.m' % self.iter_input_file) dep = serpent.parse_dep(dep_file, make_mats=False) self.days = dep['DAYS'][moment] # Read materials names from the file @@ -431,14 +425,14 @@ def read_dep_comp(self, input_file, read_at_end=False): mats[m].mass = mats[m].density * volume mats[m].vol = volume mats[m].burnup = dep['MAT_' + m + '_BURNUP'][moment] - self.get_tra_or_dec(self.rerun_path) + self.get_tra_or_dec(self.iter_input_file) return mats def read_depcode_info(self): """Parses initial simulation info data from Serpent2 output and stores it in the `DepcodeSerpent` object's ``sim_info`` attributes. """ - res = serpent.parse_res(self.rerun_path + "_res.m") + res = serpent.parse_res(self.iter_input_file + "_res.m") self.sim_info['serpent_version'] = \ res['VERSION'][0].decode('utf-8') self.sim_info['title'] = res['TITLE'][0].decode('utf-8') @@ -458,7 +452,7 @@ def read_depcode_step_param(self): """Parses data from Serpent2 output for each step and stores it in `DepcodeSerpent` object's ``param`` attributes. """ - res = serpent.parse_res(self.rerun_path + "_res.m") + res = serpent.parse_res(self.iter_input_file + "_res.m") self.param['keff_bds'] = res['IMP_KEFF'][0] self.param['keff_eds'] = res['IMP_KEFF'][1] self.param['breeding_ratio'] = res['CONVERSION_RATIO'][1] @@ -558,16 +552,16 @@ def run_depcode(self, cores, nodes): self.exec_path, '-omp', str(cores), - self.rerun_path) + self.iter_input_file) elif self.exec_path.startswith('/apps/exp_ctl/'): # check if Falcon args = ( 'mpiexec', self.exec_path, - self.rerun_path, + self.iter_input_file, '-omp', str(18)) else: - args = (self.exec_path, '-omp', str(cores), self.rerun_path) + args = (self.exec_path, '-omp', str(cores), self.iter_input_file) print('Running %s' % (self.codename)) try: subprocess.check_output( @@ -633,7 +627,7 @@ def write_depcode_input( data = self.change_sim_par(data) data = self.create_iter_matfile(data) else: - data = self.read_depcode_template(self.rerun_path) + data = self.read_depcode_template(self.iter_input_file) data = self.replace_burnup_parameters(data, reactor, dep_step) if data: @@ -641,7 +635,7 @@ def write_depcode_input( out_file.writelines(data) out_file.close() - def write_mat_file(self, dep_dict, mat_file, dep_end_time): + 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. @@ -662,7 +656,7 @@ def write_mat_file(self, dep_dict, mat_file, dep_end_time): """ - matf = open(mat_file, 'w') + matf = open(self.iter_matfile, 'w') matf.write('%% Material compositions (after %f days)\n\n' % dep_end_time) for key, value in dep_dict.items(): diff --git a/saltproc/input_schema.json b/saltproc/input_schema.json index b61d72525..3d13fd8bb 100644 --- a/saltproc/input_schema.json +++ b/saltproc/input_schema.json @@ -1,23 +1,32 @@ { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/arfc/saltproc", + "title": "SaltProc input file schema", "type": "object", "properties": { - "$comment": "File containing processing system objects", - "proc_input_file": { "type": "string" }, - "$comment": "Graph file containing processing system structure", - "dot_input_file": { "type": "string" }, - "$comment": "Path output data storing folder", - "output_path": { "type": "string" }, - "$comment": "Number of steps for constant power and depletion interval case", - "depsteps": { "type": "number" }, + "proc_input_file": { "type": "string", + "$comment": "File containing processing system objects" + }, + "dot_input_file": { "type": "string", + "$comment": "Graph file containing processing system structure" + }, + "output_path": { "type": "string", + "$comment": "Path output data storing folder" + }, + "depsteps": { "type": "number", + "$comment": "Number of steps for constant power and depletion interval case" + }, "depcode": { "type": "object", "properties": { "codename": { "type": "string" }, - "exec_path": { "type": "string" },"sss2", - "template_path": { "type": "string" },"tap_test1.serpent", - "npop": 50, - "active_cycles": 20, - "inactive_cycles": 20, - "geo_file": { "type": "array", + "exec_path": { "type": "string" }, + "template_path": { "type": "string" }, + "iter_input_file": { "type": "string" }, + "iter_matfile": { "type": "string" }, + "npop": { "type": "number"}, + "active_cycles": { "type": "number"}, + "inactive_cycles": { "type": "number"}, + "geo_files": { "type": "array", "items": { "type": "string"} } } @@ -26,14 +35,15 @@ "properties": { "sim_name": { "type": "string"}, "db_path": { "type": "string"}, - "restart_flag": { "type": "boolean"} + "restart_flag": { "type": "boolean"}, + "adjust_geo": { "type": "boolean"} } }, "reactor": { "type": "object", "properties": { "volume": { "type": "number" }, "mass_flowrate": { "type": "number" }, - "power_levels": { "type": "array", + "power_levels": { "type": "array", "items": { "type": "number"} }, "depl_hist": { "type": "array", diff --git a/saltproc/tests/test.json b/saltproc/tests/test.json index 980da3543..589991cb6 100644 --- a/saltproc/tests/test.json +++ b/saltproc/tests/test.json @@ -7,15 +7,18 @@ "codename": "serpent", "exec_path": "sss2", "template_path": "tap_test1.serpent", + "iter_input_file": "data/saltproc_serpetn", + "iter_material_file": "data/saltproc_mat", "npop": 50, "active_cycles": 20, "inactive_cycles": 20, - "geo_file": ["347_base.ini"] + "geo_files": ["347_base.ini"] }, "simulation": { "sim_name": "test_simulation", "db_path": "db_saltproc.h5", - "restart_flag": false + "restart_flag": false, + "adjust_geo": false }, "reactor": { "volume": 1.0, From 5fdef26c63a5e32af50efb089c46851dd0e513bb Mon Sep 17 00:00:00 2001 From: yardasol Date: Tue, 25 Jan 2022 17:21:48 -0600 Subject: [PATCH 044/118] update unit tests to show where we need to fix them --- saltproc/tests/test_app.py | 6 +++--- saltproc/tests/test_depcode.py | 4 ++-- saltproc/tests/test_materialflow.py | 6 +++--- saltproc/tests/test_process.py | 8 ++++---- saltproc/tests/test_separator.py | 8 ++++---- saltproc/tests/test_simulation.py | 31 ++++++++++++++--------------- saltproc/tests/test_sparger.py | 8 ++++---- 7 files changed, 35 insertions(+), 36 deletions(-) diff --git a/saltproc/tests/test_app.py b/saltproc/tests/test_app.py index c243ebe28..7ca08427d 100644 --- a/saltproc/tests/test_app.py +++ b/saltproc/tests/test_app.py @@ -8,15 +8,15 @@ sys.path.append(os.path.dirname(os.path.dirname(path))) # global class object directory = os.path.dirname(path) -input_file = directory + '/test' +iter_input_file = directory + '/test' main_input = directory + '/test.json' dot_input = directory + '/test.dot' serpent = DepcodeSerpent(exec_path='sss2', template_path=directory + '/template.inp', - input_path=input_file, + iter_input_file=iter_input_file, iter_matfile=directory + '/material', - geo_file=None) + geo_files=None) def test_read_main_input(): diff --git a/saltproc/tests/test_depcode.py b/saltproc/tests/test_depcode.py index 58ff7ffc6..c82d7d360 100644 --- a/saltproc/tests/test_depcode.py +++ b/saltproc/tests/test_depcode.py @@ -13,9 +13,9 @@ serpent = DepcodeSerpent(exec_path='sss2', template_path=directory + '/template.inp', - input_path=directory + '/test', + iter_input_file=directory + '/test', iter_matfile=directory + '/material', - geo_file=[os.path.join(directory, '../test_geo.inp')]) + geo_files=[os.path.join(directory, '../test_geo.inp')]) msr = Reactor(volume=1.0, power_levels=[1.250E+09, 1.250E+09, 5.550E+09], diff --git a/saltproc/tests/test_materialflow.py b/saltproc/tests/test_materialflow.py index 303a4d7d1..38b0bc95d 100644 --- a/saltproc/tests/test_materialflow.py +++ b/saltproc/tests/test_materialflow.py @@ -6,16 +6,16 @@ sys.path.append(os.path.dirname(os.path.dirname(path))) # global class object directory = os.path.dirname(path) -input_file = directory + '/test' +iter_input_file = directory + '/test' serpent = DepcodeSerpent( exec_path='/home/andrei2/serpent/serpent2/src_2131/sss2', template_path=directory + '/template.inp', - input_path=input_file, + iter_input_file=iter_input_file, iter_matfile=directory + '/material', - geo_file=None) + geo_files=None) def test_get_mass(): diff --git a/saltproc/tests/test_process.py b/saltproc/tests/test_process.py index 6e3fd5b3d..f9fe4b92d 100644 --- a/saltproc/tests/test_process.py +++ b/saltproc/tests/test_process.py @@ -8,16 +8,16 @@ sys.path.append(os.path.dirname(os.path.dirname(path))) # global class object directory = os.path.dirname(path) -input_file = directory + '/test' +iter_input_file = directory + '/test' serpent = DepcodeSerpent( exec_path='/home/andrei2/serpent/serpent2/src_2131/sss2', template_path=directory + '/template.inp', - input_path=input_file, + iter_input_file=iter_input_file, iter_matfile=directory + '/material', - geo_file=None) + geo_files=None) process = Process(mass_flowrate=10, capacity=99.0, @@ -26,7 +26,7 @@ def test_rem_elements(): - mats = serpent.read_dep_comp(input_file, True) + mats = serpent.read_dep_comp(iter_inpit_file, True) waste = process.rem_elements(mats['fuel']) np.testing.assert_almost_equal(waste[541350000], 19.79776930513891) np.testing.assert_almost_equal(waste[541360000], 176.44741987005173) diff --git a/saltproc/tests/test_separator.py b/saltproc/tests/test_separator.py index 6438c441c..6d91bcd1c 100644 --- a/saltproc/tests/test_separator.py +++ b/saltproc/tests/test_separator.py @@ -8,16 +8,16 @@ sys.path.append(os.path.dirname(os.path.dirname(path))) # global class object directory = os.path.dirname(path) -input_file = directory + '/test' +iter_input_file = directory + '/test' serpent = DepcodeSerpent( exec_path='/home/andrei2/serpent/serpent2/src_2131/sss2', template_path=directory + '/template.inp', - input_path=input_file, + iter_input_file=iter_input_file, iter_matfile=directory + '/material', - geo_file=None) + geo_files=None) process = Separator(mass_flowrate=10, capacity=99.0, @@ -26,7 +26,7 @@ def test_rem_elements(): - mats = serpent.read_dep_comp(input_file, True) + mats = serpent.read_dep_comp(iter_inpit_file, True) waste = process.rem_elements(mats['fuel']) np.testing.assert_almost_equal(waste[541350000], 19.5320018359295) np.testing.assert_almost_equal(waste[541360000], 174.0787699729534) diff --git a/saltproc/tests/test_simulation.py b/saltproc/tests/test_simulation.py index 4b62ea67a..7c5778d02 100644 --- a/saltproc/tests/test_simulation.py +++ b/saltproc/tests/test_simulation.py @@ -11,7 +11,7 @@ sys.path.append(os.path.dirname(os.path.dirname(path))) # global class object directory = os.path.dirname(path) -input_file = directory + '/test' +iter_input_file = directory + '/test' main_input = directory + '/test.json' dot_input = directory + '/test.dot' @@ -20,9 +20,9 @@ serpent = DepcodeSerpent( exec_path='/home/andrei2/serpent/serpent2/src_2131/sss2', template_path=directory + '/template.inp', - input_path=input_file, + iter_input_file=iter_input_file, iter_matfile=directory + '/material', - geo_file=[ + geo_files=[ '../../examples/406.inp', '../../examples/988.inp']) @@ -30,8 +30,7 @@ sim_depcode=serpent, core_number=1, node_number=1, - db_path=directory + '/test_db.h5', - iter_matfile=serpent.iter_matfile) + db_path=directory + '/test_db.h5') def test_check_switch_geo_trigger(): """ @@ -69,7 +68,7 @@ def test_store_after_repr(): # read data mats = simulation.sim_depcode.read_dep_comp( - simulation.sim_depcode.input_path, + simulation.sim_depcode.iter_input_file, True) waste_st, rem_mass = saltproc.app.reprocessing(mats) m_after_refill = saltproc.app.refill(mats, rem_mass, waste_st) @@ -85,7 +84,7 @@ def test_store_after_repr(): # we want to keep the old path for other sims, but for this # test we'll want a fresh db db_path_old = simulation.db_path - db_file = serpent.input_path + '.h5' + db_file = serpent.iter_input_file + '.h5' simulation.db_path = db_file # store data @@ -162,10 +161,10 @@ def test_store_mat_data(): """ # read data mats_before = simulation.sim_depcode.read_dep_comp( - simulation.sim_depcode.input_path, + simulation.sim_depcode.iter_input_file, False) mats_after = simulation.sim_depcode.read_dep_comp( - simulation.sim_depcode.input_path, + simulation.sim_depcode.iter_input_file, True) fuel_before = mats_before['fuel'] @@ -177,7 +176,7 @@ def test_store_mat_data(): # we want to keep the old path for other sims, but for this # test we'll want a fresh db db_path_old = simulation.db_path - db_file = serpent.input_path + '.h5' + db_file = serpent.iter_input_file + '.h5' simulation.db_path = db_file # store data at end @@ -286,7 +285,7 @@ def test_store_run_init_info(): # we want to keep the old path for other sims, but for this # test we'll want a fresh db db_path_old = simulation.db_path - db_file = serpent.input_path + '.h5' + db_file = serpent.iter_input_file + '.h5' simulation.db_path = db_file # store data at @@ -343,7 +342,7 @@ def test_store_run_step_info(): # we want to keep the old path for other sims, but for this # test we'll want a fresh db db_path_old = simulation.db_path - db_file = serpent.input_path + '.h5' + db_file = serpent.iter_input_file + '.h5' simulation.db_path = db_file # store data at @@ -397,9 +396,9 @@ def test_read_k_eds_delta(): def test_switch_to_next_geometry(): - shutil.copy2(geo_test_input, serpent.input_path + '_test') - serpent.input_path = serpent.input_path + '_test' + shutil.copy2(geo_test_input, serpent.iter_input_file + '_test') + serpent.iter_input_file = serpent.iter_input_file + '_test' simulation.switch_to_next_geometry() - d = serpent.read_depcode_template(serpent.input_path) + d = serpent.read_depcode_template(serpent.iter_input_file) assert d[5].split('/')[-1] == '988.inp"\n' - os.remove(serpent.input_path) + os.remove(serpent.iter_input_file) diff --git a/saltproc/tests/test_sparger.py b/saltproc/tests/test_sparger.py index 70ff5b325..768c69322 100644 --- a/saltproc/tests/test_sparger.py +++ b/saltproc/tests/test_sparger.py @@ -8,16 +8,16 @@ sys.path.append(os.path.dirname(os.path.dirname(path))) # global class object directory = os.path.dirname(path) -input_file = directory + '/test' +iter_input_file = directory + '/test' serpent = DepcodeSerpent( exec_path='/home/andrei2/serpent/serpent2/src_2131/sss2', template_path=directory + '/template.inp', - input_path=input_file, + iter_input_file=iter_input_file, iter_matfile=directory + '/material', - geo_file=None) + geo_files=None) process = Sparger(mass_flowrate=10, capacity=99.0, @@ -26,7 +26,7 @@ def test_rem_elements(): - mats = serpent.read_dep_comp(input_file, True) + mats = serpent.read_dep_comp(iter_input_file, True) waste = process.rem_elements(mats['fuel']) np.testing.assert_almost_equal(waste[541350000], 8.061014535231715) np.testing.assert_almost_equal(waste[541360000], 71.8437109936129) From 72a18160fa8f397bdd56d96d40742f86dfc3e79a Mon Sep 17 00:00:00 2001 From: yardasol Date: Tue, 25 Jan 2022 17:22:00 -0600 Subject: [PATCH 045/118] typo fixes in app.py --- saltproc/app.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/saltproc/app.py b/saltproc/app.py index 752e1e10f..a37aed3b0 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -79,7 +79,7 @@ def read_main_input(main_inp_file): os.path.dirname(f.name), j['dot_input_file']) output_path = j['output_path'] - depsteps = reactor_inp['depsteps'] + depsteps = j['depsteps'] # Class settings global depcode_inp, simulation_inp, reactor_inp @@ -359,9 +359,8 @@ def run(): print('Initiating Saltproc:\n' '\tRestart = ' + str(simulation_inp['restart_flag']) + '\n' '\tTemplate File Path = ' + os.path.abspath(depcode_inp['template_path']) + '\n' - '\tInput File Path = ' + os.path.abspath(depcode_inp['iter_input_file'] + '\n' - '\tMaterial File Path = ' + os.path.abspath(depcode_inp['iter_matfile'] - ]) + '\n' + '\tInput File Path = ' + os.path.abspath(depcode_inp['iter_input_file']) + '\n' + '\tMaterial File Path = ' + os.path.abspath(depcode_inp['iter_matfile']) + '\n' '\tOutput HDF5 DB Path = ' + os.path.abspath(simulation_inp['db_path']) + '\n' ) # Intializing objects @@ -376,7 +375,7 @@ def run(): active_cycles=depcode_inp['active_cycles'], inactive_cycles=depcode_inp['inactive_cycles']) else: - raise ValueError(f'{depcode_inp['codename']} is not a supported depletion code') + raise ValueError(f'{depcode_inp["codename"]} is not a supported depletion code') simulation = Simulation( sim_name='Super test', From 4b7356cd175573ad6ad443651a777088423600d8 Mon Sep 17 00:00:00 2001 From: yardasol Date: Wed, 26 Jan 2022 11:10:15 -0600 Subject: [PATCH 046/118] make unit + integration tests work with new input format + varnames --- saltproc/app.py | 26 +++-- saltproc/depcode.py | 4 +- saltproc/input_schema.json | 100 +++++++++++++----- saltproc/simulation.py | 8 +- .../no_repro/test_no_reproc_run.py | 12 +-- saltproc/tests/test.json | 6 +- saltproc/tests/test_app.py | 22 ++-- saltproc/tests/test_depcode.py | 28 ++--- saltproc/tests/test_materialflow.py | 6 +- saltproc/tests/test_process.py | 2 +- saltproc/tests/test_separator.py | 2 +- saltproc/tests/test_simulation.py | 5 +- saltproc/tests/test_sparger.py | 2 +- 13 files changed, 132 insertions(+), 91 deletions(-) diff --git a/saltproc/app.py b/saltproc/app.py index a37aed3b0..8a81f415c 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -68,7 +68,11 @@ def read_main_input(main_inp_file): j = json.load(f) with open(input_schema) as v: s = json.load(v) - jsonschema.validate(instance=j,schema=s) + try: + jsonschema.validate(instance=j,schema=s) + except jsonschema.exceptions.ValidationError: + print("Your input file improperly structured. \ + Please see saltproc/tests/test.json for an example.") # Saltproc settings global spc_inp_file, dot_inp_file, output_path, depsteps @@ -84,7 +88,7 @@ def read_main_input(main_inp_file): # Class settings global depcode_inp, simulation_inp, reactor_inp depcode_inp = j['depcode'] - simulation_inp = j['simulationt'] + simulation_inp = j['simulation'] reactor_inp = j['reactor'] depcode_inp['template_path'] = os.path.join( @@ -95,13 +99,13 @@ def read_main_input(main_inp_file): depcode_inp['iter_input_file'] = os.path.join(input_path, depcode_inp['iter_input_file']) depcode_inp['iter_matfile'] = os.path.join(input_path, depcode_inp['iter_matfile']) - db_path = os.path.join( + db_name = os.path.join( os.path.dirname(f.name), - output_path, simulation_inp['db_path']) - simulation_inp['db_path'] = db_path + output_path, simulation_inp['db_name']) + simulation_inp['db_name'] = db_name depl_hist = reactor_inp['depl_hist'] - power_hist = reactor_inp['power_hist '] + power_levels = reactor_inp['power_levels'] if depsteps is not None and isinstance(depl_hist, (float, int)): if depsteps < 0.0 or not int: raise ValueError('Depletion step interval cannot be negative') @@ -109,11 +113,11 @@ def read_main_input(main_inp_file): step = int(depsteps) deptot = float(depl_hist) * step depl_hist = np.linspace(float(depl_hist), deptot, num=step) - power_hist = float(power_hist) * np.ones_like(depl_hist) + power_levels = float(power_levels) * np.ones_like(depl_hist) reactor_inp['depl_hist'] = depl_hist - reactor_inp['power_hist'] = power_hist + reactor_inp['power_levels'] = power_levels elif depsteps is None and isinstance(depl_hist, (np.ndarray, list)): - if len(depl_hist) != len(power_hist): + if len(depl_hist) != len(power_levels): raise ValueError( 'Depletion step list and power list shape mismatch') @@ -361,7 +365,7 @@ def run(): '\tTemplate File Path = ' + os.path.abspath(depcode_inp['template_path']) + '\n' '\tInput File Path = ' + os.path.abspath(depcode_inp['iter_input_file']) + '\n' '\tMaterial File Path = ' + os.path.abspath(depcode_inp['iter_matfile']) + '\n' - '\tOutput HDF5 DB Path = ' + os.path.abspath(simulation_inp['db_path']) + '\n' + '\tOutput HDF5 DB Path = ' + os.path.abspath(simulation_inp['db_name']) + '\n' ) # Intializing objects if depcode_inp['codename'] == 'serpent': @@ -382,7 +386,7 @@ def run(): sim_depcode=depcode, core_number=cores, node_number=nodes, - db_path=simulation_inp['db_path']) + db_path=simulation_inp['db_name']) msr = Reactor( volume=reactor_inp['volume'], diff --git a/saltproc/depcode.py b/saltproc/depcode.py index 0f8698cef..c552ae5ba 100644 --- a/saltproc/depcode.py +++ b/saltproc/depcode.py @@ -631,7 +631,7 @@ def write_depcode_input( data = self.replace_burnup_parameters(data, reactor, dep_step) if data: - out_file = open(inp_file, 'w') + out_file = open(self.iter_input_file, 'w') out_file.writelines(data) out_file.close() @@ -649,8 +649,6 @@ def write_mat_file(self, dep_dict, dep_end_time): Name of burnable material. ``value`` `Materialflow` object holding composition and properties. - mat_file : str - Path to file containing burnable materials composition. dep_end_time : float Current time at the end of the depletion step (d). diff --git a/saltproc/input_schema.json b/saltproc/input_schema.json index 3d13fd8bb..a5bb6b099 100644 --- a/saltproc/input_schema.json +++ b/saltproc/input_schema.json @@ -4,49 +4,93 @@ "title": "SaltProc input file schema", "type": "object", "properties": { - "proc_input_file": { "type": "string", - "$comment": "File containing processing system objects" + "proc_input_file": { + "description": "File containing processing system objects", + "type": "string" }, - "dot_input_file": { "type": "string", - "$comment": "Graph file containing processing system structure" + "dot_input_file": { + "description": "Graph file containing processing system structure", + "type": "string" }, - "output_path": { "type": "string", - "$comment": "Path output data storing folder" + "output_path": { + "description": "Path output data storing folder", + "type": "string" }, - "depsteps": { "type": "number", - "$comment": "Number of steps for constant power and depletion interval case" + "depsteps": { + "description": "Number of steps for constant power and depletion interval case", + "type": "number" }, - "depcode": { "type": "object", + "depcode": { + "description": "Depcode class input parameters", + "type": "object", "properties": { - "codename": { "type": "string" }, - "exec_path": { "type": "string" }, - "template_path": { "type": "string" }, - "iter_input_file": { "type": "string" }, - "iter_matfile": { "type": "string" }, - "npop": { "type": "number"}, - "active_cycles": { "type": "number"}, - "inactive_cycles": { "type": "number"}, - "geo_files": { "type": "array", + "codename": { + "description": "Name of depletion code", + "type": "string" }, + "exec_path": { + "description": "Path to depletion code executable", + "type": "string" }, + "template_path": { + "description": "User's depletion code input file with reactor model", + "type": "string" }, + "iter_input_file": { + "description": "", + "type": "string" }, + "iter_matfile": { + "description": "", + "type": "string" }, + "npop": { + "description": "Number of neutrons per generation", + "type": "number"}, + "active_cycles": { + "description": "number of active generations", + "type": "number"}, + "inactive_cycles": { + "description": "Number of inactive generations", + "type": "number"}, + "geo_files": { + "description": "Geometry file/files to swtich ust in depletion code runs", + "type": "array", "items": { "type": "string"} } } }, - "simulation": { "type": "object", + "simulation": { + "description": "Simulation class input parameters", + "type": "object", "properties": { - "sim_name": { "type": "string"}, - "db_path": { "type": "string"}, - "restart_flag": { "type": "boolean"}, - "adjust_geo": { "type": "boolean"} + "sim_name": { + "description": "Name of simulation", + "type": "string"}, + "db_name": { + "description": "Output HDF5 database file name", + "type": "string"}, + "restart_flag": { + "description": "Restart simulation from the step when it stopped?", + "type": "boolean"}, + "adjust_geo": { + "description": "switch to another geometry when keff drops below 1?", + "type": "boolean"} } }, - "reactor": { "type": "object", + "reactor": { + "description": "Reactor class input parameters", + "type": "object", "properties": { - "volume": { "type": "number" }, - "mass_flowrate": { "type": "number" }, - "power_levels": { "type": "array", + "volume": { + "description": "reactor core volume [cm^3]", + "type": "number" }, + "mass_flowrate": { + "description": "Salt mass flowrate through reactor core [g/s]", + "type": "number" }, + "power_levels": { + "description": "Reactor power or power step list durng depletion step [W]", + "type": "array", "items": { "type": "number"} }, - "depl_hist": { "type": "array", + "depl_hist": { + "description": "Depletion step interval or cumulative time (end of step) [d]", + "type": "array", "items": { "type": "number"} } } diff --git a/saltproc/simulation.py b/saltproc/simulation.py index f6222c90a..e07b8bde1 100644 --- a/saltproc/simulation.py +++ b/saltproc/simulation.py @@ -404,14 +404,14 @@ def switch_to_next_geometry(self): beginning of the Serpent iteration input file. """ geo_line_n = 5 - f = open(self.sim_depcode.input_path, 'r') + f = open(self.sim_depcode.iter_input_file, 'r') data = f.readlines() f.close() current_geo_file = data[geo_line_n].split('\"')[1] - current_geo_idx = self.sim_depcode.geo_file.index(current_geo_file) + current_geo_idx = self.sim_depcode.geo_files.index(current_geo_file) try: - new_geo_file = self.sim_depcode.geo_file[current_geo_idx + 1] + new_geo_file = self.sim_depcode.geo_files[current_geo_idx + 1] except IndexError: print('No more geometry files available \ and the system went subcritical \n\n') @@ -420,7 +420,7 @@ def switch_to_next_geometry(self): new_data = [d.replace(current_geo_file, new_geo_file) for d in data] print('Switching to next geometry file: ', new_geo_file) - f = open(self.sim_depcode.input_path, 'w') + f = open(self.sim_depcode.iter_input_file, 'w') f.writelines(new_data) f.close() diff --git a/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py b/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py index 7c0e2afbc..b4345c98d 100644 --- a/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py +++ b/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py @@ -23,9 +23,9 @@ exec_path='sss2', template_path=directory + '/saltproc_9d.inp', - input_path=sss_file, + iter_input_file=sss_file, iter_matfile=iter_matfile, - geo_file=[ + geo_files=[ os.path.join( directory, '../../test_geo.inp')], @@ -36,8 +36,7 @@ sim_depcode=depcode, core_number=1, node_number=1, - db_path=db_file, - iter_matfile=iter_matfile) + db_path=db_file) tap = Reactor(volume=1.0, power_levels=[1.250E+09], @@ -64,8 +63,6 @@ def runsim_no_reproc(simulation, reactor, nsteps): print("\nStep #%i has been started" % (dep_step + 1)) if dep_step == 0: # First step simulation.sim_depcode.write_depcode_input( - simulation.sim_depcode.template_path, - siumulation.sim_depcode.input_path, reactor, dep_step, False) @@ -76,7 +73,6 @@ def runsim_no_reproc(simulation, reactor, nsteps): simulation.store_run_init_info() # Parse and store data for initial state (beginning of dep_step) mats = simulation.sim_depcode.read_dep_comp( - simulation.sim_depcode.input_path, False) simulation.store_mat_data(mats, dep_step, False) # Finish of First step @@ -86,13 +82,11 @@ def runsim_no_reproc(simulation, reactor, nsteps): simulation.core_number, simulation.node_number) mats = simulation.sim_depcode.read_dep_comp( - simulation.sim_depcode.input_path, True) simulation.store_mat_data(mats, dep_step, False) simulation.store_run_step_info() simulation.sim_depcode.write_mat_file( mats, - simulation.sim_depcode.iter_matfile, simulation.burn_time) diff --git a/saltproc/tests/test.json b/saltproc/tests/test.json index 589991cb6..e5855e0f8 100644 --- a/saltproc/tests/test.json +++ b/saltproc/tests/test.json @@ -1,14 +1,14 @@ { "proc_input_file": "processes.json", "dot_input_file": "test.dot", - "output_path": "./", + "output_path": "./data", "depsteps": 2, "depcode": { "codename": "serpent", "exec_path": "sss2", "template_path": "tap_test1.serpent", - "iter_input_file": "data/saltproc_serpetn", - "iter_material_file": "data/saltproc_mat", + "iter_input_file": "saltproc_serpent", + "iter_matfile": "saltproc_mat", "npop": 50, "active_cycles": 20, "inactive_cycles": 20, diff --git a/saltproc/tests/test_app.py b/saltproc/tests/test_app.py index 7ca08427d..1bbda8617 100644 --- a/saltproc/tests/test_app.py +++ b/saltproc/tests/test_app.py @@ -21,15 +21,15 @@ def test_read_main_input(): app.read_main_input(main_input) - assert app.codename == "serpent" - assert app.neutron_pop == 50 - assert app.active_cycles == 20 - assert app.active_cycles == 20 - assert app.db_file == directory + '/./db_saltproc.h5' - assert app.geo_file == ['347_base.ini'] - assert app.restart_flag is False - np.testing.assert_equal(app.power_hist, [1.250E+9, 1.250E+9]) - np.testing.assert_equal(app.depl_hist, [5, 10]) + assert app.depcode_inp['codename'] == "serpent" + assert app.depcode_inp['npop'] == 50 + assert app.depcode_inp['active_cycles'] == 20 + assert app.depcode_inp['active_cycles'] == 20 + assert app.simulation_inp['db_path'] == directory + '/./db_saltproc.h5' + assert app.depcode_inp['geo_files'] == ['347_base.ini'] + assert app.simulation_inp['restart_flag'] is False + np.testing.assert_equal(app.reactor_inp['power_levels'], [1.250E+9, 1.250E+9]) + np.testing.assert_equal(app.reactor_inp['depl_hist'], [5, 10]) def test_read_processes_from_input(): @@ -64,7 +64,7 @@ def test_read_dot(): def test_reprocessing(): - mats = serpent.read_dep_comp(input_file, True) + mats = serpent.read_dep_comp(True) waste_st, rem_mass = app.reprocessing(mats) assert rem_mass['fuel'] == 1401.0846504569054 assert rem_mass['ctrlPois'] == 0.0 @@ -74,7 +74,7 @@ def test_reprocessing(): def test_refill(): - mats = serpent.read_dep_comp(input_file, True) + mats = serpent.read_dep_comp(True) waste_st, rem_mass = app.reprocessing(mats) m_after_refill = app.refill(mats, rem_mass, waste_st) assert m_after_refill['fuel']['feed_leu']['U235'] == 43.573521906078334 diff --git a/saltproc/tests/test_depcode.py b/saltproc/tests/test_depcode.py index c82d7d360..1b3884a99 100644 --- a/saltproc/tests/test_depcode.py +++ b/saltproc/tests/test_depcode.py @@ -23,7 +23,7 @@ def test_get_tra_or_dec(): - serpent.get_tra_or_dec(serpent.input_path) + serpent.get_tra_or_dec(serpent.iter_input_file) assert serpent.iso_map[380880] == '38088.09c' assert serpent.iso_map[962400] == '96240.09c' assert serpent.iso_map[952421] == '95342.09c' @@ -103,7 +103,7 @@ def test_read_depcode_step_param(): def test_read_dep_comp(): - mats = serpent.read_dep_comp(serpent.input_path, True) + mats = serpent.read_dep_comp(True) assert mats['fuel']['U235'] == 3499538.3359278883 assert mats['fuel']['U238'] == 66580417.24509208 assert mats['fuel']['F19'] == 37145139.35897285 @@ -115,10 +115,11 @@ def test_read_dep_comp(): def test_write_mat_file(): - mats = serpent.read_dep_comp(serpent.input_path, True) - mat_file = serpent.input_path + '.mat' - serpent.write_mat_file(mats, mat_file, 12.0) - mat_str = serpent.read_depcode_template(mat_file) + mats = serpent.read_dep_comp(True) + iter_matfile_old = serpent.iter_matfile + serpent.iter_input_file = serpent.iter_input_file + '.mat' + serpent.write_mat_file(mats, 12.0) + mat_str = serpent.read_depcode_template(serpent.iter_matfile) assert mat_str[0] == '% Material compositions (after 12.000000 days)\n' if 'fuel' in mat_str[3]: assert mat_str[3].split()[-1] == '2.27175E+07' @@ -128,7 +129,8 @@ def test_write_mat_file(): elif 'ctrlPois' in mat_str[3]: assert mat_str[3].split()[-1] == '1.11635E+04' assert mat_str[4] == ' 1001.09c -1.21000137902945E-35\n' - os.remove(mat_file) + os.remove(serpent.iter_matfile) + serpent.iter_matfile = iter_matfile_old def test_insert_path_to_geometry(): @@ -165,12 +167,12 @@ def test_create_iter_matfile(): def test_write_depcode_input(): - serpent.write_depcode_input(serpent.template_path, - serpent.input_path + '_write_test', - msr, + iter_input_file_old = serpent.iter_input_file + serpent.iter_input_file = serpent.iter_input_file + '_write_test' + serpent.write_depcode_input(msr, 0, False) - d = serpent.read_depcode_template(serpent.input_path + '_write_test') + d = serpent.read_depcode_template(serpent.iter_input_file) print(d[0]) assert d[0].split('/')[-2] == 'tests' assert d[0].split('/')[-1] == 'material"\n' @@ -178,5 +180,7 @@ def test_write_depcode_input(): assert d[8].split()[4] == 'daystep' assert d[8].split()[-1] == '1.11111E+02' assert d[20] == 'set pop 1111 101 33\n' - os.remove(serpent.input_path + '_write_test') + os.remove(serpent.iter_input_file) os.remove(serpent.iter_matfile) + + serpent.iter_input_file = iter_input_file_old diff --git a/saltproc/tests/test_materialflow.py b/saltproc/tests/test_materialflow.py index 38b0bc95d..70ebf469f 100644 --- a/saltproc/tests/test_materialflow.py +++ b/saltproc/tests/test_materialflow.py @@ -19,7 +19,7 @@ def test_get_mass(): - mats = serpent.read_dep_comp(input_file, True) + mats = serpent.read_dep_comp(True) assert mats['fuel'].get_mass() == 112683343.50000001 assert mats['fuel']['U235'] == 3499538.3359278883 assert mats['fuel']['U238'] == 66580417.24509208 @@ -33,7 +33,7 @@ def test_get_mass(): def test_scale_matflow(): - mats = serpent.read_dep_comp(input_file, True) + mats = serpent.read_dep_comp(True) scale_factor = 0.7 scaled_matflow = mats['fuel'].scale_matflow(scale_factor) assert scaled_matflow[922350000] == scale_factor * 3499538.3359278883 @@ -43,7 +43,7 @@ def test_scale_matflow(): def test_copy_pymat_attrs(): - mats = serpent.read_dep_comp(input_file, True) + mats = serpent.read_dep_comp(True) target_mat = mats['fuel'] target_mat.copy_pymat_attrs(mats['ctrlPois']) assert target_mat.density == 5.873 diff --git a/saltproc/tests/test_process.py b/saltproc/tests/test_process.py index f9fe4b92d..2b163c7e7 100644 --- a/saltproc/tests/test_process.py +++ b/saltproc/tests/test_process.py @@ -26,7 +26,7 @@ def test_rem_elements(): - mats = serpent.read_dep_comp(iter_inpit_file, True) + mats = serpent.read_dep_comp(True) waste = process.rem_elements(mats['fuel']) np.testing.assert_almost_equal(waste[541350000], 19.79776930513891) np.testing.assert_almost_equal(waste[541360000], 176.44741987005173) diff --git a/saltproc/tests/test_separator.py b/saltproc/tests/test_separator.py index 6d91bcd1c..cfaae3411 100644 --- a/saltproc/tests/test_separator.py +++ b/saltproc/tests/test_separator.py @@ -26,7 +26,7 @@ def test_rem_elements(): - mats = serpent.read_dep_comp(iter_inpit_file, True) + mats = serpent.read_dep_comp(True) waste = process.rem_elements(mats['fuel']) np.testing.assert_almost_equal(waste[541350000], 19.5320018359295) np.testing.assert_almost_equal(waste[541360000], 174.0787699729534) diff --git a/saltproc/tests/test_simulation.py b/saltproc/tests/test_simulation.py index 7c5778d02..b4ab4accf 100644 --- a/saltproc/tests/test_simulation.py +++ b/saltproc/tests/test_simulation.py @@ -68,7 +68,6 @@ def test_store_after_repr(): # read data mats = simulation.sim_depcode.read_dep_comp( - simulation.sim_depcode.iter_input_file, True) waste_st, rem_mass = saltproc.app.reprocessing(mats) m_after_refill = saltproc.app.refill(mats, rem_mass, waste_st) @@ -161,10 +160,8 @@ def test_store_mat_data(): """ # read data mats_before = simulation.sim_depcode.read_dep_comp( - simulation.sim_depcode.iter_input_file, False) mats_after = simulation.sim_depcode.read_dep_comp( - simulation.sim_depcode.iter_input_file, True) fuel_before = mats_before['fuel'] @@ -392,7 +389,7 @@ def test_store_run_step_info(): def test_read_k_eds_delta(): - assert simulation.read_k_eds_delta(7, False) is False + assert simulation.read_k_eds_delta(7) is False def test_switch_to_next_geometry(): diff --git a/saltproc/tests/test_sparger.py b/saltproc/tests/test_sparger.py index 768c69322..3c09ea35f 100644 --- a/saltproc/tests/test_sparger.py +++ b/saltproc/tests/test_sparger.py @@ -26,7 +26,7 @@ def test_rem_elements(): - mats = serpent.read_dep_comp(iter_input_file, True) + mats = serpent.read_dep_comp(True) waste = process.rem_elements(mats['fuel']) np.testing.assert_almost_equal(waste[541350000], 8.061014535231715) np.testing.assert_almost_equal(waste[541360000], 71.8437109936129) From 21172216dfd7717e078eb83ecb0eaf53baa52f86 Mon Sep 17 00:00:00 2001 From: yardasol Date: Wed, 26 Jan 2022 12:03:05 -0600 Subject: [PATCH 047/118] fix first integration test failing --- saltproc/app.py | 42 +++++++++++++++++++++++--------------- saltproc/tests/test_app.py | 4 ++-- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/saltproc/app.py b/saltproc/app.py index 8a81f415c..e53b727a0 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -19,10 +19,6 @@ import numpy as np -input_path = os.getcwd() - -input_schema = os.path.join(input_path, 'saltproc/input_schema.json') - def parse_arguments(): """Parses arguments from command line. @@ -64,6 +60,9 @@ def read_main_input(main_inp_file): main_inp_file : str Path to SaltProc main input file and name of this file. """ + + input_schema = os.path.join(os.path.dirname(os.path.realpath(__file__)), + './input_schema.json') with open(main_inp_file) as f: j = json.load(f) with open(input_schema) as v: @@ -74,6 +73,9 @@ def read_main_input(main_inp_file): print("Your input file improperly structured. \ Please see saltproc/tests/test.json for an example.") + # Global input path + input_path = os.path.dirname(f.name) + # Saltproc settings global spc_inp_file, dot_inp_file, output_path, depsteps spc_inp_file = os.path.join( @@ -85,35 +87,43 @@ def read_main_input(main_inp_file): output_path = j['output_path'] depsteps = j['depsteps'] + # Global output path + output_path = os.path.join(input_path, output_path) + j['output_path'] = output_path + # Class settings global depcode_inp, simulation_inp, reactor_inp depcode_inp = j['depcode'] simulation_inp = j['simulation'] reactor_inp = j['reactor'] - depcode_inp['template_path'] = os.path.join( - os.path.dirname(f.name), depcode_inp['template_path']) - geo_list = depcode_inp['geo_files'] - geo_files = [g for g in geo_list] - depcode_inp['geo_files'] = geo_list - depcode_inp['iter_input_file'] = os.path.join(input_path, depcode_inp['iter_input_file']) - depcode_inp['iter_matfile'] = os.path.join(input_path, depcode_inp['iter_matfile']) + depcode_inp['template_input_path'] = os.path.join( + input_path, depcode_inp['template_input_path']) + geo_list = depcode_inp['geo_file_paths'] + + # Global geometry file paths + geo_file_paths = [] + for g in geo_list: + geo_file_paths += [os.path.join(input_path, g)] + depcode_inp['geo_file_paths'] = geo_file_paths + # Global output file paths + depcode_inp['iter_input_file'] = os.path.join(output_path, depcode_inp['iter_input_file']) + depcode_inp['iter_matfile'] = os.path.join(output_path, depcode_inp['iter_matfile']) db_name = os.path.join( - os.path.dirname(f.name), output_path, simulation_inp['db_name']) simulation_inp['db_name'] = db_name depl_hist = reactor_inp['depl_hist'] power_levels = reactor_inp['power_levels'] - if depsteps is not None and isinstance(depl_hist, (float, int)): + if depsteps is not None and len(depl_hist) == 1: if depsteps < 0.0 or not int: raise ValueError('Depletion step interval cannot be negative') else: step = int(depsteps) - deptot = float(depl_hist) * step - depl_hist = np.linspace(float(depl_hist), deptot, num=step) - power_levels = float(power_levels) * np.ones_like(depl_hist) + deptot = float(depl_hist[0]) * step + depl_hist = np.linspace(float(depl_hist[0]), deptot, num=step) + power_levels = float(power_levels[0]) * np.ones_like(depl_hist) reactor_inp['depl_hist'] = depl_hist reactor_inp['power_levels'] = power_levels elif depsteps is None and isinstance(depl_hist, (np.ndarray, list)): diff --git a/saltproc/tests/test_app.py b/saltproc/tests/test_app.py index 1bbda8617..35b854c9a 100644 --- a/saltproc/tests/test_app.py +++ b/saltproc/tests/test_app.py @@ -25,8 +25,8 @@ def test_read_main_input(): assert app.depcode_inp['npop'] == 50 assert app.depcode_inp['active_cycles'] == 20 assert app.depcode_inp['active_cycles'] == 20 - assert app.simulation_inp['db_path'] == directory + '/./db_saltproc.h5' - assert app.depcode_inp['geo_files'] == ['347_base.ini'] + assert app.simulation_inp['db_name'] == directory + '/./data/db_saltproc.h5' + assert app.depcode_inp['geo_file_paths'] == [ directory + '/./347_base.ini'] assert app.simulation_inp['restart_flag'] is False np.testing.assert_equal(app.reactor_inp['power_levels'], [1.250E+9, 1.250E+9]) np.testing.assert_equal(app.reactor_inp['depl_hist'], [5, 10]) From 1feb332d0d54b95df46beeeb1b300063a9a6e810 Mon Sep 17 00:00:00 2001 From: yardasol Date: Wed, 26 Jan 2022 12:03:28 -0600 Subject: [PATCH 048/118] rename input parmaeters --- saltproc/input_schema.json | 8 ++++---- saltproc/tests/test.json | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/saltproc/input_schema.json b/saltproc/input_schema.json index a5bb6b099..d29d7f89c 100644 --- a/saltproc/input_schema.json +++ b/saltproc/input_schema.json @@ -30,8 +30,8 @@ "exec_path": { "description": "Path to depletion code executable", "type": "string" }, - "template_path": { - "description": "User's depletion code input file with reactor model", + "input_template_path": { + "description": "Path to user's template depletion code input file with reactor model", "type": "string" }, "iter_input_file": { "description": "", @@ -48,8 +48,8 @@ "inactive_cycles": { "description": "Number of inactive generations", "type": "number"}, - "geo_files": { - "description": "Geometry file/files to swtich ust in depletion code runs", + "geo_file_paths": { + "description": "Path(s) to geometry file(s) to swtich to in depletion code runs", "type": "array", "items": { "type": "string"} } diff --git a/saltproc/tests/test.json b/saltproc/tests/test.json index e5855e0f8..8f9f42e55 100644 --- a/saltproc/tests/test.json +++ b/saltproc/tests/test.json @@ -6,17 +6,17 @@ "depcode": { "codename": "serpent", "exec_path": "sss2", - "template_path": "tap_test1.serpent", + "template_input_path": "./tap_test1.serpent", "iter_input_file": "saltproc_serpent", "iter_matfile": "saltproc_mat", "npop": 50, "active_cycles": 20, "inactive_cycles": 20, - "geo_files": ["347_base.ini"] + "geo_file_paths": ["./347_base.ini"] }, "simulation": { "sim_name": "test_simulation", - "db_path": "db_saltproc.h5", + "db_name": "db_saltproc.h5", "restart_flag": false, "adjust_geo": false }, From 3447d2040b75a154c263dec5cbaed151757c1e1d Mon Sep 17 00:00:00 2001 From: yardasol Date: Wed, 26 Jan 2022 12:44:34 -0600 Subject: [PATCH 049/118] add validation keywords to input_schema.json --- saltproc/input_schema.json | 52 ++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/saltproc/input_schema.json b/saltproc/input_schema.json index d29d7f89c..57a4e3504 100644 --- a/saltproc/input_schema.json +++ b/saltproc/input_schema.json @@ -14,7 +14,8 @@ }, "output_path": { "description": "Path output data storing folder", - "type": "string" + "type": "string", + "pattern": "^\./([.]*)$" }, "depsteps": { "description": "Number of steps for constant power and depletion interval case", @@ -32,28 +33,35 @@ "type": "string" }, "input_template_path": { "description": "Path to user's template depletion code input file with reactor model", - "type": "string" }, + "type": "string", + "pattern": "^\./([.]*)$"}, "iter_input_file": { - "description": "", + "description": "Name of ", "type": "string" }, "iter_matfile": { "description": "", "type": "string" }, "npop": { "description": "Number of neutrons per generation", - "type": "number"}, + "type": "number", + "minimum": 0}, "active_cycles": { "description": "number of active generations", - "type": "number"}, + "type": "number", + "minimum": 0}, "inactive_cycles": { "description": "Number of inactive generations", - "type": "number"}, + "type": "number", + "minimum": 0}, "geo_file_paths": { "description": "Path(s) to geometry file(s) to swtich to in depletion code runs", "type": "array", - "items": { "type": "string"} + "items": { "type": "string"}, + "minItems": 1, + "uniqueItems": false } - } + }, + "required": ["codename", "exec_path", "input_template_path", "inter_input_file", "iter_matfile", "npop", "active_cycles","inactive_cycles", "geo_file_paths"] }, "simulation": { "description": "Simulation class input parameters", @@ -64,14 +72,16 @@ "type": "string"}, "db_name": { "description": "Output HDF5 database file name", - "type": "string"}, + "type": "string", + "pattern": "^([.]*)\.h5$"}, "restart_flag": { "description": "Restart simulation from the step when it stopped?", "type": "boolean"}, "adjust_geo": { "description": "switch to another geometry when keff drops below 1?", "type": "boolean"} - } + }, + "requires": ["sim_name", "db_name", "restart_flag", "adjust_geo"] }, "reactor": { "description": "Reactor class input parameters", @@ -79,21 +89,31 @@ "properties": { "volume": { "description": "reactor core volume [cm^3]", - "type": "number" }, + "type": "number", + "minimum": 0}, "mass_flowrate": { "description": "Salt mass flowrate through reactor core [g/s]", - "type": "number" }, + "type": "number", + "minimum": 0 }, "power_levels": { "description": "Reactor power or power step list durng depletion step [W]", "type": "array", - "items": { "type": "number"} + "items": { "type": "number", + "minimum": 0}, + "minItems": 1, + "uniqueItems": false }, "depl_hist": { "description": "Depletion step interval or cumulative time (end of step) [d]", "type": "array", - "items": { "type": "number"} + "items": { "type": "number", + "minimum": 0}, + "minItems": 1, + "uniqueItems": false } - } + }, + "required": ["volume", "mass_flowrate", "power_levels", "depl_hist"] } - } + }, + "required": ["proc_input_file", "dot_input_file", "output_path", "depsteps", "depcode", "simulation", "reactor"] } From 62f9c1f59a0b6dd920716645c78d08c38ca2f2cb Mon Sep 17 00:00:00 2001 From: yardasol Date: Wed, 26 Jan 2022 12:45:21 -0600 Subject: [PATCH 050/118] template_path -> input_template_path --- saltproc/app.py | 4 ++-- saltproc/depcode.py | 32 ++++++++++++++++---------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/saltproc/app.py b/saltproc/app.py index e53b727a0..9d2214a0a 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -372,7 +372,7 @@ def run(): # Print out input information print('Initiating Saltproc:\n' '\tRestart = ' + str(simulation_inp['restart_flag']) + '\n' - '\tTemplate File Path = ' + os.path.abspath(depcode_inp['template_path']) + '\n' + '\tTemplate File Path = ' + os.path.abspath(depcode_inp['input_tempate_path']) + '\n' '\tInput File Path = ' + os.path.abspath(depcode_inp['iter_input_file']) + '\n' '\tMaterial File Path = ' + os.path.abspath(depcode_inp['iter_matfile']) + '\n' '\tOutput HDF5 DB Path = ' + os.path.abspath(simulation_inp['db_name']) + '\n' @@ -381,7 +381,7 @@ def run(): if depcode_inp['codename'] == 'serpent': depcode = DepcodeSerpent( exec_path=depcode_inp['exec_path'], - template_path=depcode_inp['template_path'], + input_tempate_path=depcode_inp['input_tempate_path'], iter_input_file=depecode_inp['iter_input_file'], iter_matfile=depcode_inp['iter_matfile'], geo_files=depcode_inp['geo_files'], diff --git a/saltproc/depcode.py b/saltproc/depcode.py index c552ae5ba..3c28e6bf5 100644 --- a/saltproc/depcode.py +++ b/saltproc/depcode.py @@ -20,7 +20,7 @@ class Depcode(ABC): def __init__(self, codename, exec_path, - template_path, + input_tempate_path, iter_input_file, iter_matfile, geo_files=None, @@ -35,7 +35,7 @@ def __init__(self, Name of depletion code. exec_path : str Path to depletion code executable. - template_path : str + input_tempate_path : str Path to depletion code input file template. iter_input_file : str Name of depletion code input file for depletion code rerunning. @@ -56,7 +56,7 @@ def __init__(self, """ self.codename = codename self.exec_path = exec_path - self.template_path = template_path + self.input_tempate_path = input_tempate_path self.iter_input_file = iter_input_file self.iter_matfile = iter_matfile self.geo_files = geo_files @@ -151,7 +151,7 @@ class DepcodeSerpent(Depcode): def __init__(self, exec_path="sss2", - template_path="reactor.serpent", + input_tempate_path="reactor.serpent", iter_input_file="data/saltproc_reactor", iter_matfile="data/saltproc_mat", geo_files=None, @@ -164,7 +164,7 @@ def __init__(self, ---------- exec_path : str Path to Serpent2 executable. - template_path : str + input_tempate_path : str Path to user input file for Serpent2. iter_input_file : str Name of Serpent2 input file for Serpent2 rerunning. @@ -185,7 +185,7 @@ def __init__(self, """ super().__init__("serpent", exec_path, - template_path, + input_tempate_path, iter_input_file, iter_matfile, geo_files, @@ -215,11 +215,11 @@ def change_sim_par(self, template_data): if len(sim_param) > 1: print('ERROR: Template file %s contains multiple lines with ' 'simulation parameters:\n' - % (self.template_path), sim_param) + % (self.input_tempate_path), sim_param) return elif len(sim_param) < 1: print('ERROR: Template file %s does not contain line with ' - 'simulation parameters.' % (self.template_path)) + 'simulation parameters.' % (self.input_tempate_path)) return args = 'set pop %i %i %i\n' % (self.npop, self.active_cycles, self.inactive_cycles) @@ -241,11 +241,11 @@ def create_iter_matfile(self, template_data): List of strings containing modified user template file. """ - data_dir = os.path.dirname(self.template_path) + data_dir = os.path.dirname(self.input_tempate_path) include_str = [s for s in template_data if s.startswith("include ")] if not include_str: print('ERROR: Template file %s has no ' - ' statements ' % (self.template_path)) + ' statements ' % (self.input_tempate_path)) return src_file = include_str[0].split()[1][1:-1] if not os.path.isabs(src_file): @@ -257,7 +257,7 @@ def create_iter_matfile(self, template_data): ' materials description or ' ' statement is not appears' ' as first statement\n' - % (self.template_path)) + % (self.input_tempate_path)) return # Create data directory try: @@ -467,13 +467,13 @@ def read_depcode_step_param(self): self.param['fission_mass_bds'] = res['INI_FMASS'][1] self.param['fission_mass_eds'] = res['TOT_FMASS'][1] - def read_depcode_template(self, template_path): + def read_depcode_template(self, input_tempate_path): """Reads prepared Serpent2 template (input) file for use in other class functions that prepare the input file for multiple runs. Parameters ---------- - template_path : str + input_tempate_path : str Path to user template file for depletion code. Returns @@ -482,7 +482,7 @@ def read_depcode_template(self, template_path): List of strings containing user template file. """ - file = open(template_path, 'r') + file = open(input_tempate_path, 'r') template_data = file.readlines() return template_data @@ -566,7 +566,7 @@ def run_depcode(self, cores, nodes): try: subprocess.check_output( args, - cwd=os.path.split(self.template_path)[0], + cwd=os.path.split(self.input_tempate_path)[0], stderr=subprocess.STDOUT) except subprocess.CalledProcessError as error: print(error.output.decode("utf-8")) @@ -622,7 +622,7 @@ def write_depcode_input( """ if dep_step == 0 and not restart: - data = self.read_depcode_template(self.template_path) + data = self.read_depcode_template(self.input_tempate_path) data = self.insert_path_to_geometry(data) data = self.change_sim_par(data) data = self.create_iter_matfile(data) From fea00cd8090087d517d096b73493aea39f58f907 Mon Sep 17 00:00:00 2001 From: yardasol Date: Wed, 26 Jan 2022 12:54:55 -0600 Subject: [PATCH 051/118] template_path->input_template_path --- .../no_repro/test_no_reproc_run.py | 2 +- saltproc/tests/test_app.py | 2 +- saltproc/tests/test_depcode.py | 18 +++++++++--------- saltproc/tests/test_materialflow.py | 2 +- saltproc/tests/test_process.py | 2 +- saltproc/tests/test_separator.py | 2 +- saltproc/tests/test_simulation.py | 2 +- saltproc/tests/test_sparger.py | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py b/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py index b4345c98d..37f41da20 100644 --- a/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py +++ b/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py @@ -21,7 +21,7 @@ depcode = DepcodeSerpent( exec_path='sss2', - template_path=directory + + input_template_path=directory + '/saltproc_9d.inp', iter_input_file=sss_file, iter_matfile=iter_matfile, diff --git a/saltproc/tests/test_app.py b/saltproc/tests/test_app.py index 35b854c9a..98a1c7f20 100644 --- a/saltproc/tests/test_app.py +++ b/saltproc/tests/test_app.py @@ -13,7 +13,7 @@ dot_input = directory + '/test.dot' serpent = DepcodeSerpent(exec_path='sss2', - template_path=directory + '/template.inp', + input_template_path=directory + '/template.inp', iter_input_file=iter_input_file, iter_matfile=directory + '/material', geo_files=None) diff --git a/saltproc/tests/test_depcode.py b/saltproc/tests/test_depcode.py index 1b3884a99..6e2917f3d 100644 --- a/saltproc/tests/test_depcode.py +++ b/saltproc/tests/test_depcode.py @@ -12,7 +12,7 @@ directory = os.path.dirname(path) serpent = DepcodeSerpent(exec_path='sss2', - template_path=directory + '/template.inp', + input_template_path=directory + '/template.inp', iter_input_file=directory + '/test', iter_matfile=directory + '/material', geo_files=[os.path.join(directory, '../test_geo.inp')]) @@ -45,7 +45,7 @@ def test_sss_meta_zzz(): def test_read_depcode_template(): - template_str = serpent.read_depcode_template(serpent.template_path) + template_str = serpent.read_depcode_template(serpent.input_template_path) assert template_str[6] == '%therm zrh_h 900 hzr05.32t hzr06.32t\n' assert template_str[18] == 'set pop 30 20 10\n' assert template_str[22] == 'set bumode 2\n' @@ -57,7 +57,7 @@ def test_change_sim_par(): serpent.active_cycles = 101 serpent.inactive_cycles = 33 out = serpent.change_sim_par( - serpent.read_depcode_template(serpent.template_path) + serpent.read_depcode_template(serpent.input_template_path) ) assert out[18] == 'set pop %i %i %i\n' % ( serpent.npop, @@ -134,7 +134,7 @@ def test_write_mat_file(): def test_insert_path_to_geometry(): - d = serpent.read_depcode_template(serpent.template_path) + d = serpent.read_depcode_template(serpent.input_template_path) d_new = serpent.insert_path_to_geometry(d) assert d_new[5].split('/')[-1] == 'test_geo.inp"\n' @@ -143,24 +143,24 @@ def test_replace_burnup_parameters(): time = msr.depl_hist.copy() time.insert(0, 0.0) depsteps = np.diff(time) - d = serpent.read_depcode_template(serpent.template_path) + d = serpent.read_depcode_template(serpent.input_template_path) for idx in range(len(msr.power_levels)): d = serpent.replace_burnup_parameters(d, msr, idx) - out_file = open(serpent.template_path + str(idx), 'w') + out_file = open(serpent.input_template_path + str(idx), 'w') out_file.writelines(d) out_file.close() d_new = serpent.read_depcode_template( - serpent.template_path + str(idx)) + serpent.input_template_path + str(idx)) assert d_new[8].split()[4] == 'daystep' assert d_new[8].split()[2] == str("%5.9E" % msr.power_levels[idx]) assert d_new[8].split()[5] == str("%7.5E" % depsteps[idx]) - os.remove(serpent.template_path + str(idx)) + os.remove(serpent.input_template_path + str(idx)) def test_create_iter_matfile(): - d = serpent.read_depcode_template(serpent.template_path) + d = serpent.read_depcode_template(serpent.input_template_path) out = serpent.create_iter_matfile(d) assert out[0].split()[-1] == '\"' + serpent.iter_matfile + '\"' os.remove(serpent.iter_matfile) diff --git a/saltproc/tests/test_materialflow.py b/saltproc/tests/test_materialflow.py index 70ebf469f..b24254a44 100644 --- a/saltproc/tests/test_materialflow.py +++ b/saltproc/tests/test_materialflow.py @@ -10,7 +10,7 @@ serpent = DepcodeSerpent( exec_path='/home/andrei2/serpent/serpent2/src_2131/sss2', - template_path=directory + + input_template_path=directory + '/template.inp', iter_input_file=iter_input_file, iter_matfile=directory + diff --git a/saltproc/tests/test_process.py b/saltproc/tests/test_process.py index 2b163c7e7..aae37bac9 100644 --- a/saltproc/tests/test_process.py +++ b/saltproc/tests/test_process.py @@ -12,7 +12,7 @@ serpent = DepcodeSerpent( exec_path='/home/andrei2/serpent/serpent2/src_2131/sss2', - template_path=directory + + input_template_path=directory + '/template.inp', iter_input_file=iter_input_file, iter_matfile=directory + diff --git a/saltproc/tests/test_separator.py b/saltproc/tests/test_separator.py index cfaae3411..71b6bdd0b 100644 --- a/saltproc/tests/test_separator.py +++ b/saltproc/tests/test_separator.py @@ -12,7 +12,7 @@ serpent = DepcodeSerpent( exec_path='/home/andrei2/serpent/serpent2/src_2131/sss2', - template_path=directory + + input_template_path=directory + '/template.inp', iter_input_file=iter_input_file, iter_matfile=directory + diff --git a/saltproc/tests/test_simulation.py b/saltproc/tests/test_simulation.py index b4ab4accf..889c7ff0a 100644 --- a/saltproc/tests/test_simulation.py +++ b/saltproc/tests/test_simulation.py @@ -19,7 +19,7 @@ serpent = DepcodeSerpent( exec_path='/home/andrei2/serpent/serpent2/src_2131/sss2', - template_path=directory + '/template.inp', + input_template_path=directory + '/template.inp', iter_input_file=iter_input_file, iter_matfile=directory + '/material', geo_files=[ diff --git a/saltproc/tests/test_sparger.py b/saltproc/tests/test_sparger.py index 3c09ea35f..5fbfe1c65 100644 --- a/saltproc/tests/test_sparger.py +++ b/saltproc/tests/test_sparger.py @@ -12,7 +12,7 @@ serpent = DepcodeSerpent( exec_path='/home/andrei2/serpent/serpent2/src_2131/sss2', - template_path=directory + + input_template_path=directory + '/template.inp', iter_input_file=iter_input_file, iter_matfile=directory + From b727840ca88dc6c09e47c9d3ca49ebe4cd2033b1 Mon Sep 17 00:00:00 2001 From: yardasol Date: Wed, 26 Jan 2022 13:05:58 -0600 Subject: [PATCH 052/118] typo fixes in input_schema.json --- saltproc/input_schema.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/saltproc/input_schema.json b/saltproc/input_schema.json index 57a4e3504..48b7682e3 100644 --- a/saltproc/input_schema.json +++ b/saltproc/input_schema.json @@ -15,7 +15,7 @@ "output_path": { "description": "Path output data storing folder", "type": "string", - "pattern": "^\./([.]*)$" + "pattern": "^\\./([.]*)$" }, "depsteps": { "description": "Number of steps for constant power and depletion interval case", @@ -34,12 +34,12 @@ "input_template_path": { "description": "Path to user's template depletion code input file with reactor model", "type": "string", - "pattern": "^\./([.]*)$"}, + "pattern": "^\\./([.]*)$"}, "iter_input_file": { - "description": "Name of ", + "description": "Name of depletion code input file for depletion code rerunning", "type": "string" }, "iter_matfile": { - "description": "", + "description": "Name of iteratvie, rewritable material file for depletion code rerunning", "type": "string" }, "npop": { "description": "Number of neutrons per generation", @@ -73,7 +73,7 @@ "db_name": { "description": "Output HDF5 database file name", "type": "string", - "pattern": "^([.]*)\.h5$"}, + "pattern": "^([.]*)\\.h5$"}, "restart_flag": { "description": "Restart simulation from the step when it stopped?", "type": "boolean"}, From 6cdacfb764151e9c1d01906485f84c259f9c0d6d Mon Sep 17 00:00:00 2001 From: yardasol Date: Wed, 26 Jan 2022 13:45:33 -0600 Subject: [PATCH 053/118] added saltprocjsonschema package to store the input schema --- saltproc/app.py | 25 ++++--- saltproc/depcode.py | 32 ++++----- saltproc/input_schema.json | 8 +-- saltproc/saltprocinputschema.py | 119 ++++++++++++++++++++++++++++++++ saltproc/tests/test.json | 2 +- 5 files changed, 152 insertions(+), 34 deletions(-) create mode 100644 saltproc/saltprocinputschema.py diff --git a/saltproc/app.py b/saltproc/app.py index 9d2214a0a..82b3b0579 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -11,6 +11,7 @@ import os import copy import json, jsonschema +from saltproc.saltprocinputschema import input_schema from collections import OrderedDict import gc import networkx as nx @@ -61,17 +62,15 @@ def read_main_input(main_inp_file): Path to SaltProc main input file and name of this file. """ - input_schema = os.path.join(os.path.dirname(os.path.realpath(__file__)), - './input_schema.json') + #input_schema = os.path.join(os.path.dirname(os.path.realpath(__file__)), + # './input_schema.json') with open(main_inp_file) as f: j = json.load(f) - with open(input_schema) as v: - s = json.load(v) - try: - jsonschema.validate(instance=j,schema=s) - except jsonschema.exceptions.ValidationError: - print("Your input file improperly structured. \ - Please see saltproc/tests/test.json for an example.") + try: + jsonschema.validate(instance=j,schema=input_schema) + except jsonschema.exceptions.ValidationError: + print("Your input file improperly structured. + Please see saltproc/tests/test.json for an example.") # Global input path input_path = os.path.dirname(f.name) @@ -97,8 +96,8 @@ def read_main_input(main_inp_file): simulation_inp = j['simulation'] reactor_inp = j['reactor'] - depcode_inp['template_input_path'] = os.path.join( - input_path, depcode_inp['template_input_path']) + depcode_inp['input_template_path'] = os.path.join( + input_path, depcode_inp['input_template_path']) geo_list = depcode_inp['geo_file_paths'] # Global geometry file paths @@ -372,7 +371,7 @@ def run(): # Print out input information print('Initiating Saltproc:\n' '\tRestart = ' + str(simulation_inp['restart_flag']) + '\n' - '\tTemplate File Path = ' + os.path.abspath(depcode_inp['input_tempate_path']) + '\n' + '\tTemplate File Path = ' + os.path.abspath(depcode_inp['input_template_path']) + '\n' '\tInput File Path = ' + os.path.abspath(depcode_inp['iter_input_file']) + '\n' '\tMaterial File Path = ' + os.path.abspath(depcode_inp['iter_matfile']) + '\n' '\tOutput HDF5 DB Path = ' + os.path.abspath(simulation_inp['db_name']) + '\n' @@ -381,7 +380,7 @@ def run(): if depcode_inp['codename'] == 'serpent': depcode = DepcodeSerpent( exec_path=depcode_inp['exec_path'], - input_tempate_path=depcode_inp['input_tempate_path'], + input_template_path=depcode_inp['input_template_path'], iter_input_file=depecode_inp['iter_input_file'], iter_matfile=depcode_inp['iter_matfile'], geo_files=depcode_inp['geo_files'], diff --git a/saltproc/depcode.py b/saltproc/depcode.py index 3c28e6bf5..0552f3d10 100644 --- a/saltproc/depcode.py +++ b/saltproc/depcode.py @@ -20,7 +20,7 @@ class Depcode(ABC): def __init__(self, codename, exec_path, - input_tempate_path, + input_template_path, iter_input_file, iter_matfile, geo_files=None, @@ -35,7 +35,7 @@ def __init__(self, Name of depletion code. exec_path : str Path to depletion code executable. - input_tempate_path : str + input_template_path : str Path to depletion code input file template. iter_input_file : str Name of depletion code input file for depletion code rerunning. @@ -56,7 +56,7 @@ def __init__(self, """ self.codename = codename self.exec_path = exec_path - self.input_tempate_path = input_tempate_path + self.input_template_path = input_template_path self.iter_input_file = iter_input_file self.iter_matfile = iter_matfile self.geo_files = geo_files @@ -151,7 +151,7 @@ class DepcodeSerpent(Depcode): def __init__(self, exec_path="sss2", - input_tempate_path="reactor.serpent", + input_template_path="reactor.serpent", iter_input_file="data/saltproc_reactor", iter_matfile="data/saltproc_mat", geo_files=None, @@ -164,7 +164,7 @@ def __init__(self, ---------- exec_path : str Path to Serpent2 executable. - input_tempate_path : str + input_template_path : str Path to user input file for Serpent2. iter_input_file : str Name of Serpent2 input file for Serpent2 rerunning. @@ -185,7 +185,7 @@ def __init__(self, """ super().__init__("serpent", exec_path, - input_tempate_path, + input_template_path, iter_input_file, iter_matfile, geo_files, @@ -215,11 +215,11 @@ def change_sim_par(self, template_data): if len(sim_param) > 1: print('ERROR: Template file %s contains multiple lines with ' 'simulation parameters:\n' - % (self.input_tempate_path), sim_param) + % (self.input_template_path), sim_param) return elif len(sim_param) < 1: print('ERROR: Template file %s does not contain line with ' - 'simulation parameters.' % (self.input_tempate_path)) + 'simulation parameters.' % (self.input_template_path)) return args = 'set pop %i %i %i\n' % (self.npop, self.active_cycles, self.inactive_cycles) @@ -241,11 +241,11 @@ def create_iter_matfile(self, template_data): List of strings containing modified user template file. """ - data_dir = os.path.dirname(self.input_tempate_path) + data_dir = os.path.dirname(self.input_template_path) include_str = [s for s in template_data if s.startswith("include ")] if not include_str: print('ERROR: Template file %s has no ' - ' statements ' % (self.input_tempate_path)) + ' statements ' % (self.input_template_path)) return src_file = include_str[0].split()[1][1:-1] if not os.path.isabs(src_file): @@ -257,7 +257,7 @@ def create_iter_matfile(self, template_data): ' materials description or ' ' statement is not appears' ' as first statement\n' - % (self.input_tempate_path)) + % (self.input_template_path)) return # Create data directory try: @@ -467,13 +467,13 @@ def read_depcode_step_param(self): self.param['fission_mass_bds'] = res['INI_FMASS'][1] self.param['fission_mass_eds'] = res['TOT_FMASS'][1] - def read_depcode_template(self, input_tempate_path): + def read_depcode_template(self, input_template_path): """Reads prepared Serpent2 template (input) file for use in other class functions that prepare the input file for multiple runs. Parameters ---------- - input_tempate_path : str + input_template_path : str Path to user template file for depletion code. Returns @@ -482,7 +482,7 @@ def read_depcode_template(self, input_tempate_path): List of strings containing user template file. """ - file = open(input_tempate_path, 'r') + file = open(input_template_path, 'r') template_data = file.readlines() return template_data @@ -566,7 +566,7 @@ def run_depcode(self, cores, nodes): try: subprocess.check_output( args, - cwd=os.path.split(self.input_tempate_path)[0], + cwd=os.path.split(self.input_template_path)[0], stderr=subprocess.STDOUT) except subprocess.CalledProcessError as error: print(error.output.decode("utf-8")) @@ -622,7 +622,7 @@ def write_depcode_input( """ if dep_step == 0 and not restart: - data = self.read_depcode_template(self.input_tempate_path) + data = self.read_depcode_template(self.input_template_path) data = self.insert_path_to_geometry(data) data = self.change_sim_par(data) data = self.create_iter_matfile(data) diff --git a/saltproc/input_schema.json b/saltproc/input_schema.json index 48b7682e3..0314f9086 100644 --- a/saltproc/input_schema.json +++ b/saltproc/input_schema.json @@ -15,7 +15,7 @@ "output_path": { "description": "Path output data storing folder", "type": "string", - "pattern": "^\\./([.]*)$" + "pattern": "^\\.\\/(.*)$" }, "depsteps": { "description": "Number of steps for constant power and depletion interval case", @@ -34,7 +34,7 @@ "input_template_path": { "description": "Path to user's template depletion code input file with reactor model", "type": "string", - "pattern": "^\\./([.]*)$"}, + "pattern": "^\\.\\/(.*)$"}, "iter_input_file": { "description": "Name of depletion code input file for depletion code rerunning", "type": "string" }, @@ -61,7 +61,7 @@ "uniqueItems": false } }, - "required": ["codename", "exec_path", "input_template_path", "inter_input_file", "iter_matfile", "npop", "active_cycles","inactive_cycles", "geo_file_paths"] + "required": ["codename", "exec_path", "input_template_path", "iter_input_file", "iter_matfile", "npop", "active_cycles","inactive_cycles", "geo_file_paths"] }, "simulation": { "description": "Simulation class input parameters", @@ -73,7 +73,7 @@ "db_name": { "description": "Output HDF5 database file name", "type": "string", - "pattern": "^([.]*)\\.h5$"}, + "pattern": "^(.*)\\.h5$"}, "restart_flag": { "description": "Restart simulation from the step when it stopped?", "type": "boolean"}, diff --git a/saltproc/saltprocinputschema.py b/saltproc/saltprocinputschema.py new file mode 100644 index 000000000..02b795c8e --- /dev/null +++ b/saltproc/saltprocinputschema.py @@ -0,0 +1,119 @@ +input_schema = { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/arfc/saltproc", + "title": "SaltProc input file schema", + "type": "object", + "properties": { + "proc_input_file": { + "description": "File containing processing system objects", + "type": "string" + }, + "dot_input_file": { + "description": "Graph file containing processing system structure", + "type": "string" + }, + "output_path": { + "description": "Path output data storing folder", + "type": "string", + "pattern": "^\\.\\/(.*)$" + }, + "depsteps": { + "description": "Number of steps for constant power and depletion interval case", + "type": "number" + }, + "depcode": { + "description": "Depcode class input parameters", + "type": "object", + "properties": { + "codename": { + "description": "Name of depletion code", + "type": "string" }, + "exec_path": { + "description": "Path to depletion code executable", + "type": "string" }, + "input_template_path": { + "description": "Path to user's template depletion code input file with reactor model", + "type": "string", + "pattern": "^\\.\\/(.*)$"}, + "iter_input_file": { + "description": "Name of depletion code input file for depletion code rerunning", + "type": "string" }, + "iter_matfile": { + "description": "Name of iteratvie, rewritable material file for depletion code rerunning", + "type": "string" }, + "npop": { + "description": "Number of neutrons per generation", + "type": "number", + "minimum": 0}, + "active_cycles": { + "description": "number of active generations", + "type": "number", + "minimum": 0}, + "inactive_cycles": { + "description": "Number of inactive generations", + "type": "number", + "minimum": 0}, + "geo_file_paths": { + "description": "Path(s) to geometry file(s) to swtich to in depletion code runs", + "type": "array", + "items": { "type": "string"}, + "minItems": 1, + "uniqueItems": False + } + }, + "required": ["codename", "exec_path", "input_template_path", "iter_input_file", "iter_matfile", "npop", "active_cycles","inactive_cycles", "geo_file_paths"] + }, + "simulation": { + "description": "Simulation class input parameters", + "type": "object", + "properties": { + "sim_name": { + "description": "Name of simulation", + "type": "string"}, + "db_name": { + "description": "Output HDF5 database file name", + "type": "string", + "pattern": "^(.*)\\.h5$"}, + "restart_flag": { + "description": "Restart simulation from the step when it stopped?", + "type": "boolean"}, + "adjust_geo": { + "description": "switch to another geometry when keff drops below 1?", + "type": "boolean"} + }, + "requires": ["sim_name", "db_name", "restart_flag", "adjust_geo"] + }, + "reactor": { + "description": "Reactor class input parameters", + "type": "object", + "properties": { + "volume": { + "description": "reactor core volume [cm^3]", + "type": "number", + "minimum": 0}, + "mass_flowrate": { + "description": "Salt mass flowrate through reactor core [g/s]", + "type": "number", + "minimum": 0 }, + "power_levels": { + "description": "Reactor power or power step list durng depletion step [W]", + "type": "array", + "items": { "type": "number", + "minimum": 0}, + "minItems": 1, + "uniqueItems": False + }, + "depl_hist": { + "description": "Depletion step interval or cumulative time (end of step) [d]", + "type": "array", + "items": { "type": "number", + "minimum": 0}, + "minItems": 1, + "uniqueItems": False + } + }, + "required": ["volume", "mass_flowrate", "power_levels", "depl_hist"] + } + }, + "required": ["proc_input_file", "dot_input_file", "output_path", "depsteps", "depcode", "simulation", "reactor"] +} diff --git a/saltproc/tests/test.json b/saltproc/tests/test.json index 8f9f42e55..92f52ac87 100644 --- a/saltproc/tests/test.json +++ b/saltproc/tests/test.json @@ -6,7 +6,7 @@ "depcode": { "codename": "serpent", "exec_path": "sss2", - "template_input_path": "./tap_test1.serpent", + "input_template_path": "./tap_test1.serpent", "iter_input_file": "saltproc_serpent", "iter_matfile": "saltproc_mat", "npop": 50, From 54f993f883bce31ff972ac83e709975d5af36b58 Mon Sep 17 00:00:00 2001 From: yardasol Date: Wed, 26 Jan 2022 15:31:02 -0600 Subject: [PATCH 054/118] input_template_path -> template_inputfile_path; iter_input_file->iter_inputfile --- saltproc/app.py | 14 ++--- saltproc/depcode.py | 62 +++++++++---------- saltproc/input_schema.json | 4 +- saltproc/saltprocinputschema.py | 6 +- saltproc/simulation.py | 4 +- .../no_repro/test_no_reproc_run.py | 4 +- saltproc/tests/test_app.py | 6 +- saltproc/tests/test_depcode.py | 34 +++++----- saltproc/tests/test_materialflow.py | 6 +- saltproc/tests/test_process.py | 6 +- saltproc/tests/test_separator.py | 6 +- saltproc/tests/test_simulation.py | 22 +++---- saltproc/tests/test_sparger.py | 6 +- 13 files changed, 90 insertions(+), 90 deletions(-) diff --git a/saltproc/app.py b/saltproc/app.py index 82b3b0579..d209c2b25 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -96,8 +96,8 @@ def read_main_input(main_inp_file): simulation_inp = j['simulation'] reactor_inp = j['reactor'] - depcode_inp['input_template_path'] = os.path.join( - input_path, depcode_inp['input_template_path']) + depcode_inp['template_inputfile_path'] = os.path.join( + input_path, depcode_inp['template_inputfile_path']) geo_list = depcode_inp['geo_file_paths'] # Global geometry file paths @@ -107,7 +107,7 @@ def read_main_input(main_inp_file): depcode_inp['geo_file_paths'] = geo_file_paths # Global output file paths - depcode_inp['iter_input_file'] = os.path.join(output_path, depcode_inp['iter_input_file']) + depcode_inp['iter_inputfile'] = os.path.join(output_path, depcode_inp['iter_inputfile']) depcode_inp['iter_matfile'] = os.path.join(output_path, depcode_inp['iter_matfile']) db_name = os.path.join( output_path, simulation_inp['db_name']) @@ -371,8 +371,8 @@ def run(): # Print out input information print('Initiating Saltproc:\n' '\tRestart = ' + str(simulation_inp['restart_flag']) + '\n' - '\tTemplate File Path = ' + os.path.abspath(depcode_inp['input_template_path']) + '\n' - '\tInput File Path = ' + os.path.abspath(depcode_inp['iter_input_file']) + '\n' + '\tTemplate File Path = ' + os.path.abspath(depcode_inp['template_inputfile_path']) + '\n' + '\tInput File Path = ' + os.path.abspath(depcode_inp['iter_inputfile']) + '\n' '\tMaterial File Path = ' + os.path.abspath(depcode_inp['iter_matfile']) + '\n' '\tOutput HDF5 DB Path = ' + os.path.abspath(simulation_inp['db_name']) + '\n' ) @@ -380,8 +380,8 @@ def run(): if depcode_inp['codename'] == 'serpent': depcode = DepcodeSerpent( exec_path=depcode_inp['exec_path'], - input_template_path=depcode_inp['input_template_path'], - iter_input_file=depecode_inp['iter_input_file'], + template_inputfile_path=depcode_inp['template_inputfile_path'], + iter_inputfile=depecode_inp['iter_inputfile'], iter_matfile=depcode_inp['iter_matfile'], geo_files=depcode_inp['geo_files'], npop=depcode_inp['npop'], diff --git a/saltproc/depcode.py b/saltproc/depcode.py index 0552f3d10..7d5006e96 100644 --- a/saltproc/depcode.py +++ b/saltproc/depcode.py @@ -20,8 +20,8 @@ class Depcode(ABC): def __init__(self, codename, exec_path, - input_template_path, - iter_input_file, + template_inputfile_path, + iter_inputfile, iter_matfile, geo_files=None, npop=50, @@ -35,9 +35,9 @@ def __init__(self, Name of depletion code. exec_path : str Path to depletion code executable. - input_template_path : str + template_inputfile_path : str Path to depletion code input file template. - iter_input_file : str + iter_inputfile : str Name of depletion code input file for depletion code rerunning. iter_matfile : str Name of iterative, rewritable material file for depletion code @@ -56,8 +56,8 @@ def __init__(self, """ self.codename = codename self.exec_path = exec_path - self.input_template_path = input_template_path - self.iter_input_file = iter_input_file + self.template_inputfile_path = template_inputfile_path + self.iter_inputfile = iter_inputfile self.iter_matfile = iter_matfile self.geo_files = geo_files self.npop = npop @@ -151,8 +151,8 @@ class DepcodeSerpent(Depcode): def __init__(self, exec_path="sss2", - input_template_path="reactor.serpent", - iter_input_file="data/saltproc_reactor", + template_inputfile_path="reactor.serpent", + iter_inputfile="data/saltproc_reactor", iter_matfile="data/saltproc_mat", geo_files=None, npop=50, @@ -164,9 +164,9 @@ def __init__(self, ---------- exec_path : str Path to Serpent2 executable. - input_template_path : str + template_inputfile_path : str Path to user input file for Serpent2. - iter_input_file : str + iter_inputfile : str Name of Serpent2 input file for Serpent2 rerunning. iter_matfile : str Name of iterative, rewritable material file for Serpent2 @@ -185,8 +185,8 @@ def __init__(self, """ super().__init__("serpent", exec_path, - input_template_path, - iter_input_file, + template_inputfile_path, + iter_inputfile, iter_matfile, geo_files, npop, @@ -215,11 +215,11 @@ def change_sim_par(self, template_data): if len(sim_param) > 1: print('ERROR: Template file %s contains multiple lines with ' 'simulation parameters:\n' - % (self.input_template_path), sim_param) + % (self.template_inputfile_path), sim_param) return elif len(sim_param) < 1: print('ERROR: Template file %s does not contain line with ' - 'simulation parameters.' % (self.input_template_path)) + 'simulation parameters.' % (self.template_inputfile_path)) return args = 'set pop %i %i %i\n' % (self.npop, self.active_cycles, self.inactive_cycles) @@ -241,11 +241,11 @@ def create_iter_matfile(self, template_data): List of strings containing modified user template file. """ - data_dir = os.path.dirname(self.input_template_path) + data_dir = os.path.dirname(self.template_inputfile_path) include_str = [s for s in template_data if s.startswith("include ")] if not include_str: print('ERROR: Template file %s has no ' - ' statements ' % (self.input_template_path)) + ' statements ' % (self.template_inputfile_path)) return src_file = include_str[0].split()[1][1:-1] if not os.path.isabs(src_file): @@ -257,7 +257,7 @@ def create_iter_matfile(self, template_data): ' materials description or ' ' statement is not appears' ' as first statement\n' - % (self.input_template_path)) + % (self.template_inputfile_path)) return # Create data directory try: @@ -405,7 +405,7 @@ def read_dep_comp(self, read_at_end=False): else: moment = 0 - dep_file = os.path.join('%s_dep.m' % self.iter_input_file) + dep_file = os.path.join('%s_dep.m' % self.iter_inputfile) dep = serpent.parse_dep(dep_file, make_mats=False) self.days = dep['DAYS'][moment] # Read materials names from the file @@ -425,14 +425,14 @@ def read_dep_comp(self, read_at_end=False): mats[m].mass = mats[m].density * volume mats[m].vol = volume mats[m].burnup = dep['MAT_' + m + '_BURNUP'][moment] - self.get_tra_or_dec(self.iter_input_file) + self.get_tra_or_dec(self.iter_inputfile) return mats def read_depcode_info(self): """Parses initial simulation info data from Serpent2 output and stores it in the `DepcodeSerpent` object's ``sim_info`` attributes. """ - res = serpent.parse_res(self.iter_input_file + "_res.m") + res = serpent.parse_res(self.iter_inputfile + "_res.m") self.sim_info['serpent_version'] = \ res['VERSION'][0].decode('utf-8') self.sim_info['title'] = res['TITLE'][0].decode('utf-8') @@ -452,7 +452,7 @@ def read_depcode_step_param(self): """Parses data from Serpent2 output for each step and stores it in `DepcodeSerpent` object's ``param`` attributes. """ - res = serpent.parse_res(self.iter_input_file + "_res.m") + res = serpent.parse_res(self.iter_inputfile + "_res.m") self.param['keff_bds'] = res['IMP_KEFF'][0] self.param['keff_eds'] = res['IMP_KEFF'][1] self.param['breeding_ratio'] = res['CONVERSION_RATIO'][1] @@ -467,13 +467,13 @@ def read_depcode_step_param(self): self.param['fission_mass_bds'] = res['INI_FMASS'][1] self.param['fission_mass_eds'] = res['TOT_FMASS'][1] - def read_depcode_template(self, input_template_path): + def read_depcode_template(self, template_inputfile_path): """Reads prepared Serpent2 template (input) file for use in other class functions that prepare the input file for multiple runs. Parameters ---------- - input_template_path : str + template_inputfile_path : str Path to user template file for depletion code. Returns @@ -482,7 +482,7 @@ def read_depcode_template(self, input_template_path): List of strings containing user template file. """ - file = open(input_template_path, 'r') + file = open(template_inputfile_path, 'r') template_data = file.readlines() return template_data @@ -552,21 +552,21 @@ def run_depcode(self, cores, nodes): self.exec_path, '-omp', str(cores), - self.iter_input_file) + self.iter_inputfile) elif self.exec_path.startswith('/apps/exp_ctl/'): # check if Falcon args = ( 'mpiexec', self.exec_path, - self.iter_input_file, + self.iter_inputfile, '-omp', str(18)) else: - args = (self.exec_path, '-omp', str(cores), self.iter_input_file) + args = (self.exec_path, '-omp', str(cores), self.iter_inputfile) print('Running %s' % (self.codename)) try: subprocess.check_output( args, - cwd=os.path.split(self.input_template_path)[0], + cwd=os.path.split(self.template_inputfile_path)[0], stderr=subprocess.STDOUT) except subprocess.CalledProcessError as error: print(error.output.decode("utf-8")) @@ -622,16 +622,16 @@ def write_depcode_input( """ if dep_step == 0 and not restart: - data = self.read_depcode_template(self.input_template_path) + data = self.read_depcode_template(self.template_inputfile_path) data = self.insert_path_to_geometry(data) data = self.change_sim_par(data) data = self.create_iter_matfile(data) else: - data = self.read_depcode_template(self.iter_input_file) + data = self.read_depcode_template(self.iter_inputfile) data = self.replace_burnup_parameters(data, reactor, dep_step) if data: - out_file = open(self.iter_input_file, 'w') + out_file = open(self.iter_inputfile, 'w') out_file.writelines(data) out_file.close() diff --git a/saltproc/input_schema.json b/saltproc/input_schema.json index 0314f9086..62e1ea5ea 100644 --- a/saltproc/input_schema.json +++ b/saltproc/input_schema.json @@ -31,11 +31,11 @@ "exec_path": { "description": "Path to depletion code executable", "type": "string" }, - "input_template_path": { + "template_inputfile_path": { "description": "Path to user's template depletion code input file with reactor model", "type": "string", "pattern": "^\\.\\/(.*)$"}, - "iter_input_file": { + "iter_inputfile": { "description": "Name of depletion code input file for depletion code rerunning", "type": "string" }, "iter_matfile": { diff --git a/saltproc/saltprocinputschema.py b/saltproc/saltprocinputschema.py index 02b795c8e..49ac5071c 100644 --- a/saltproc/saltprocinputschema.py +++ b/saltproc/saltprocinputschema.py @@ -31,11 +31,11 @@ "exec_path": { "description": "Path to depletion code executable", "type": "string" }, - "input_template_path": { + "template_inputfile_path": { "description": "Path to user's template depletion code input file with reactor model", "type": "string", "pattern": "^\\.\\/(.*)$"}, - "iter_input_file": { + "iter_inputfile": { "description": "Name of depletion code input file for depletion code rerunning", "type": "string" }, "iter_matfile": { @@ -61,7 +61,7 @@ "uniqueItems": False } }, - "required": ["codename", "exec_path", "input_template_path", "iter_input_file", "iter_matfile", "npop", "active_cycles","inactive_cycles", "geo_file_paths"] + "required": ["codename", "exec_path", "template_inputfile_path", "iter_inputfile", "iter_matfile", "npop", "active_cycles","inactive_cycles", "geo_file_paths"] }, "simulation": { "description": "Simulation class input parameters", diff --git a/saltproc/simulation.py b/saltproc/simulation.py index e07b8bde1..a61c2d4e8 100644 --- a/saltproc/simulation.py +++ b/saltproc/simulation.py @@ -404,7 +404,7 @@ def switch_to_next_geometry(self): beginning of the Serpent iteration input file. """ geo_line_n = 5 - f = open(self.sim_depcode.iter_input_file, 'r') + f = open(self.sim_depcode.iter_inputfile, 'r') data = f.readlines() f.close() @@ -420,7 +420,7 @@ def switch_to_next_geometry(self): new_data = [d.replace(current_geo_file, new_geo_file) for d in data] print('Switching to next geometry file: ', new_geo_file) - f = open(self.sim_depcode.iter_input_file, 'w') + f = open(self.sim_depcode.iter_inputfile, 'w') f.writelines(new_data) f.close() diff --git a/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py b/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py index 37f41da20..28ea76129 100644 --- a/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py +++ b/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py @@ -21,9 +21,9 @@ depcode = DepcodeSerpent( exec_path='sss2', - input_template_path=directory + + template_inputfile_path=directory + '/saltproc_9d.inp', - iter_input_file=sss_file, + iter_inputfile=sss_file, iter_matfile=iter_matfile, geo_files=[ os.path.join( diff --git a/saltproc/tests/test_app.py b/saltproc/tests/test_app.py index 98a1c7f20..2ae6b33a2 100644 --- a/saltproc/tests/test_app.py +++ b/saltproc/tests/test_app.py @@ -8,13 +8,13 @@ sys.path.append(os.path.dirname(os.path.dirname(path))) # global class object directory = os.path.dirname(path) -iter_input_file = directory + '/test' +iter_inputfile = directory + '/test' main_input = directory + '/test.json' dot_input = directory + '/test.dot' serpent = DepcodeSerpent(exec_path='sss2', - input_template_path=directory + '/template.inp', - iter_input_file=iter_input_file, + template_inputfile_path=directory + '/template.inp', + iter_inputfile=iter_inputfile, iter_matfile=directory + '/material', geo_files=None) diff --git a/saltproc/tests/test_depcode.py b/saltproc/tests/test_depcode.py index 6e2917f3d..c52263e51 100644 --- a/saltproc/tests/test_depcode.py +++ b/saltproc/tests/test_depcode.py @@ -12,8 +12,8 @@ directory = os.path.dirname(path) serpent = DepcodeSerpent(exec_path='sss2', - input_template_path=directory + '/template.inp', - iter_input_file=directory + '/test', + template_inputfile_path=directory + '/template.inp', + iter_inputfile=directory + '/test', iter_matfile=directory + '/material', geo_files=[os.path.join(directory, '../test_geo.inp')]) @@ -23,7 +23,7 @@ def test_get_tra_or_dec(): - serpent.get_tra_or_dec(serpent.iter_input_file) + serpent.get_tra_or_dec(serpent.iter_inputfile) assert serpent.iso_map[380880] == '38088.09c' assert serpent.iso_map[962400] == '96240.09c' assert serpent.iso_map[952421] == '95342.09c' @@ -45,7 +45,7 @@ def test_sss_meta_zzz(): def test_read_depcode_template(): - template_str = serpent.read_depcode_template(serpent.input_template_path) + template_str = serpent.read_depcode_template(serpent.template_inputfile_path) assert template_str[6] == '%therm zrh_h 900 hzr05.32t hzr06.32t\n' assert template_str[18] == 'set pop 30 20 10\n' assert template_str[22] == 'set bumode 2\n' @@ -57,7 +57,7 @@ def test_change_sim_par(): serpent.active_cycles = 101 serpent.inactive_cycles = 33 out = serpent.change_sim_par( - serpent.read_depcode_template(serpent.input_template_path) + serpent.read_depcode_template(serpent.template_inputfile_path) ) assert out[18] == 'set pop %i %i %i\n' % ( serpent.npop, @@ -117,7 +117,7 @@ def test_read_dep_comp(): def test_write_mat_file(): mats = serpent.read_dep_comp(True) iter_matfile_old = serpent.iter_matfile - serpent.iter_input_file = serpent.iter_input_file + '.mat' + serpent.iter_inputfile = serpent.iter_inputfile + '.mat' serpent.write_mat_file(mats, 12.0) mat_str = serpent.read_depcode_template(serpent.iter_matfile) assert mat_str[0] == '% Material compositions (after 12.000000 days)\n' @@ -134,7 +134,7 @@ def test_write_mat_file(): def test_insert_path_to_geometry(): - d = serpent.read_depcode_template(serpent.input_template_path) + d = serpent.read_depcode_template(serpent.template_inputfile_path) d_new = serpent.insert_path_to_geometry(d) assert d_new[5].split('/')[-1] == 'test_geo.inp"\n' @@ -143,36 +143,36 @@ def test_replace_burnup_parameters(): time = msr.depl_hist.copy() time.insert(0, 0.0) depsteps = np.diff(time) - d = serpent.read_depcode_template(serpent.input_template_path) + d = serpent.read_depcode_template(serpent.template_inputfile_path) for idx in range(len(msr.power_levels)): d = serpent.replace_burnup_parameters(d, msr, idx) - out_file = open(serpent.input_template_path + str(idx), 'w') + out_file = open(serpent.template_inputfile_path + str(idx), 'w') out_file.writelines(d) out_file.close() d_new = serpent.read_depcode_template( - serpent.input_template_path + str(idx)) + serpent.template_inputfile_path + str(idx)) assert d_new[8].split()[4] == 'daystep' assert d_new[8].split()[2] == str("%5.9E" % msr.power_levels[idx]) assert d_new[8].split()[5] == str("%7.5E" % depsteps[idx]) - os.remove(serpent.input_template_path + str(idx)) + os.remove(serpent.template_inputfile_path + str(idx)) def test_create_iter_matfile(): - d = serpent.read_depcode_template(serpent.input_template_path) + d = serpent.read_depcode_template(serpent.template_inputfile_path) out = serpent.create_iter_matfile(d) assert out[0].split()[-1] == '\"' + serpent.iter_matfile + '\"' os.remove(serpent.iter_matfile) def test_write_depcode_input(): - iter_input_file_old = serpent.iter_input_file - serpent.iter_input_file = serpent.iter_input_file + '_write_test' + iter_inputfile_old = serpent.iter_inputfile + serpent.iter_inputfile = serpent.iter_inputfile + '_write_test' serpent.write_depcode_input(msr, 0, False) - d = serpent.read_depcode_template(serpent.iter_input_file) + d = serpent.read_depcode_template(serpent.iter_inputfile) print(d[0]) assert d[0].split('/')[-2] == 'tests' assert d[0].split('/')[-1] == 'material"\n' @@ -180,7 +180,7 @@ def test_write_depcode_input(): assert d[8].split()[4] == 'daystep' assert d[8].split()[-1] == '1.11111E+02' assert d[20] == 'set pop 1111 101 33\n' - os.remove(serpent.iter_input_file) + os.remove(serpent.iter_inputfile) os.remove(serpent.iter_matfile) - serpent.iter_input_file = iter_input_file_old + serpent.iter_inputfile = iter_inputfile_old diff --git a/saltproc/tests/test_materialflow.py b/saltproc/tests/test_materialflow.py index b24254a44..fe839dc77 100644 --- a/saltproc/tests/test_materialflow.py +++ b/saltproc/tests/test_materialflow.py @@ -6,13 +6,13 @@ sys.path.append(os.path.dirname(os.path.dirname(path))) # global class object directory = os.path.dirname(path) -iter_input_file = directory + '/test' +iter_inputfile = directory + '/test' serpent = DepcodeSerpent( exec_path='/home/andrei2/serpent/serpent2/src_2131/sss2', - input_template_path=directory + + template_inputfile_path=directory + '/template.inp', - iter_input_file=iter_input_file, + iter_inputfile=iter_inputfile, iter_matfile=directory + '/material', geo_files=None) diff --git a/saltproc/tests/test_process.py b/saltproc/tests/test_process.py index aae37bac9..ee5f58e51 100644 --- a/saltproc/tests/test_process.py +++ b/saltproc/tests/test_process.py @@ -8,13 +8,13 @@ sys.path.append(os.path.dirname(os.path.dirname(path))) # global class object directory = os.path.dirname(path) -iter_input_file = directory + '/test' +iter_inputfile = directory + '/test' serpent = DepcodeSerpent( exec_path='/home/andrei2/serpent/serpent2/src_2131/sss2', - input_template_path=directory + + template_inputfile_path=directory + '/template.inp', - iter_input_file=iter_input_file, + iter_inputfile=iter_inputfile, iter_matfile=directory + '/material', geo_files=None) diff --git a/saltproc/tests/test_separator.py b/saltproc/tests/test_separator.py index 71b6bdd0b..686db7968 100644 --- a/saltproc/tests/test_separator.py +++ b/saltproc/tests/test_separator.py @@ -8,13 +8,13 @@ sys.path.append(os.path.dirname(os.path.dirname(path))) # global class object directory = os.path.dirname(path) -iter_input_file = directory + '/test' +iter_inputfile = directory + '/test' serpent = DepcodeSerpent( exec_path='/home/andrei2/serpent/serpent2/src_2131/sss2', - input_template_path=directory + + template_inputfile_path=directory + '/template.inp', - iter_input_file=iter_input_file, + iter_inputfile=iter_inputfile, iter_matfile=directory + '/material', geo_files=None) diff --git a/saltproc/tests/test_simulation.py b/saltproc/tests/test_simulation.py index 889c7ff0a..103b23b23 100644 --- a/saltproc/tests/test_simulation.py +++ b/saltproc/tests/test_simulation.py @@ -11,7 +11,7 @@ sys.path.append(os.path.dirname(os.path.dirname(path))) # global class object directory = os.path.dirname(path) -iter_input_file = directory + '/test' +iter_inputfile = directory + '/test' main_input = directory + '/test.json' dot_input = directory + '/test.dot' @@ -19,8 +19,8 @@ serpent = DepcodeSerpent( exec_path='/home/andrei2/serpent/serpent2/src_2131/sss2', - input_template_path=directory + '/template.inp', - iter_input_file=iter_input_file, + template_inputfile_path=directory + '/template.inp', + iter_inputfile=iter_inputfile, iter_matfile=directory + '/material', geo_files=[ '../../examples/406.inp', @@ -83,7 +83,7 @@ def test_store_after_repr(): # we want to keep the old path for other sims, but for this # test we'll want a fresh db db_path_old = simulation.db_path - db_file = serpent.iter_input_file + '.h5' + db_file = serpent.iter_inputfile + '.h5' simulation.db_path = db_file # store data @@ -173,7 +173,7 @@ def test_store_mat_data(): # we want to keep the old path for other sims, but for this # test we'll want a fresh db db_path_old = simulation.db_path - db_file = serpent.iter_input_file + '.h5' + db_file = serpent.iter_inputfile + '.h5' simulation.db_path = db_file # store data at end @@ -282,7 +282,7 @@ def test_store_run_init_info(): # we want to keep the old path for other sims, but for this # test we'll want a fresh db db_path_old = simulation.db_path - db_file = serpent.iter_input_file + '.h5' + db_file = serpent.iter_inputfile + '.h5' simulation.db_path = db_file # store data at @@ -339,7 +339,7 @@ def test_store_run_step_info(): # we want to keep the old path for other sims, but for this # test we'll want a fresh db db_path_old = simulation.db_path - db_file = serpent.iter_input_file + '.h5' + db_file = serpent.iter_inputfile + '.h5' simulation.db_path = db_file # store data at @@ -393,9 +393,9 @@ def test_read_k_eds_delta(): def test_switch_to_next_geometry(): - shutil.copy2(geo_test_input, serpent.iter_input_file + '_test') - serpent.iter_input_file = serpent.iter_input_file + '_test' + shutil.copy2(geo_test_input, serpent.iter_inputfile + '_test') + serpent.iter_inputfile = serpent.iter_inputfile + '_test' simulation.switch_to_next_geometry() - d = serpent.read_depcode_template(serpent.iter_input_file) + d = serpent.read_depcode_template(serpent.iter_inputfile) assert d[5].split('/')[-1] == '988.inp"\n' - os.remove(serpent.iter_input_file) + os.remove(serpent.iter_inputfile) diff --git a/saltproc/tests/test_sparger.py b/saltproc/tests/test_sparger.py index 5fbfe1c65..b80318227 100644 --- a/saltproc/tests/test_sparger.py +++ b/saltproc/tests/test_sparger.py @@ -8,13 +8,13 @@ sys.path.append(os.path.dirname(os.path.dirname(path))) # global class object directory = os.path.dirname(path) -iter_input_file = directory + '/test' +iter_inputfile = directory + '/test' serpent = DepcodeSerpent( exec_path='/home/andrei2/serpent/serpent2/src_2131/sss2', - input_template_path=directory + + template_inputfile_path=directory + '/template.inp', - iter_input_file=iter_input_file, + iter_inputfile=iter_inputfile, iter_matfile=directory + '/material', geo_files=None) From ff63dda839330fb3d7079deff969aad27e3d8ddc Mon Sep 17 00:00:00 2001 From: yardasol Date: Wed, 26 Jan 2022 15:43:38 -0600 Subject: [PATCH 055/118] apply variable changes to the test suite --- saltproc/app.py | 18 ++++++++++-------- saltproc/input_schema.json | 2 +- saltproc/tests/test.json | 4 ++-- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/saltproc/app.py b/saltproc/app.py index d209c2b25..756343bfb 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -11,7 +11,7 @@ import os import copy import json, jsonschema -from saltproc.saltprocinputschema import input_schema +#from saltproc.saltprocinputschema import input_schema from collections import OrderedDict import gc import networkx as nx @@ -62,15 +62,17 @@ def read_main_input(main_inp_file): Path to SaltProc main input file and name of this file. """ - #input_schema = os.path.join(os.path.dirname(os.path.realpath(__file__)), - # './input_schema.json') + input_schema = os.path.join(os.path.dirname(os.path.realpath(__file__)), + './input_schema.json') with open(main_inp_file) as f: j = json.load(f) - try: - jsonschema.validate(instance=j,schema=input_schema) - except jsonschema.exceptions.ValidationError: - print("Your input file improperly structured. - Please see saltproc/tests/test.json for an example.") + with open(input_schema) as s: + v = json.load(s) + try: + jsonschema.validate(instance=j,schema=v) + except jsonschema.exceptions.ValidationError: + print("Your input file improperly structured.\ + Please see saltproc/tests/test.json for an example.") # Global input path input_path = os.path.dirname(f.name) diff --git a/saltproc/input_schema.json b/saltproc/input_schema.json index 62e1ea5ea..7151aed1b 100644 --- a/saltproc/input_schema.json +++ b/saltproc/input_schema.json @@ -61,7 +61,7 @@ "uniqueItems": false } }, - "required": ["codename", "exec_path", "input_template_path", "iter_input_file", "iter_matfile", "npop", "active_cycles","inactive_cycles", "geo_file_paths"] + "required": ["codename", "exec_path", "template_inputfile_path", "iter_inputfile", "iter_matfile", "npop", "active_cycles","inactive_cycles", "geo_file_paths"] }, "simulation": { "description": "Simulation class input parameters", diff --git a/saltproc/tests/test.json b/saltproc/tests/test.json index 92f52ac87..45e84f03b 100644 --- a/saltproc/tests/test.json +++ b/saltproc/tests/test.json @@ -6,8 +6,8 @@ "depcode": { "codename": "serpent", "exec_path": "sss2", - "input_template_path": "./tap_test1.serpent", - "iter_input_file": "saltproc_serpent", + "template_inputfile_path": "./tap_test1.serpent", + "iter_inputfile": "saltproc_serpent", "iter_matfile": "saltproc_mat", "npop": 50, "active_cycles": 20, From eed34c88cd8b038c45f6aa43ed6e01530a111ed0 Mon Sep 17 00:00:00 2001 From: yardasol Date: Wed, 26 Jan 2022 16:55:10 -0600 Subject: [PATCH 056/118] add input_schema.json to the package --- saltproc/version.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/saltproc/version.py b/saltproc/version.py index b4c09766e..e6f92f5f5 100644 --- a/saltproc/version.py +++ b/saltproc/version.py @@ -84,7 +84,8 @@ MINOR = _version_minor MICRO = _version_micro VERSION = __version__ -PACKAGE_DATA = {'saltproc': [pjoin('data', '*')]} +PACKAGE_DATA = {'saltproc': [pjoin('data', '*'), + './input_schema.json']} PACKAGES = ["saltproc", "saltproc.tests"] REQUIRES = ["numpy", @@ -92,4 +93,5 @@ "networkx", "pydotplus", "pytest", - "argparse"] + "argparse", + "jsonschema"] From 5148fc5e35aae762af77b2683e205d9aadf5b8e0 Mon Sep 17 00:00:00 2001 From: yardasol Date: Wed, 26 Jan 2022 17:11:16 -0600 Subject: [PATCH 057/118] apply input changes to const_repr integration test; typo fixes in app.py --- saltproc/app.py | 8 ++-- .../const_repr/tap_main_test.json | 44 ++++++++++++------- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/saltproc/app.py b/saltproc/app.py index 756343bfb..90990dfe8 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -383,9 +383,9 @@ def run(): depcode = DepcodeSerpent( exec_path=depcode_inp['exec_path'], template_inputfile_path=depcode_inp['template_inputfile_path'], - iter_inputfile=depecode_inp['iter_inputfile'], + iter_inputfile=depcode_inp['iter_inputfile'], iter_matfile=depcode_inp['iter_matfile'], - geo_files=depcode_inp['geo_files'], + geo_files=depcode_inp['geo_file_paths'], npop=depcode_inp['npop'], active_cycles=depcode_inp['active_cycles'], inactive_cycles=depcode_inp['inactive_cycles']) @@ -408,9 +408,9 @@ def run(): simulation.check_restart() # Run sequence # Start sequence - for dep_step in range(len(reactor.depl_hist)): + for dep_step in range(len(msr.depl_hist)): print("\n\n\nStep #%i has been started" % (dep_step + 1)) - simulation.depcode.write_depcode_input(msr, + simulation.sim_depcode.write_depcode_input(msr, dep_step, simulation.restart_flag) depcode.run_depcode(cores, nodes) diff --git a/saltproc/tests/integration_tests/const_repr/tap_main_test.json b/saltproc/tests/integration_tests/const_repr/tap_main_test.json index 9c17c912d..a67571f3c 100644 --- a/saltproc/tests/integration_tests/const_repr/tap_main_test.json +++ b/saltproc/tests/integration_tests/const_repr/tap_main_test.json @@ -1,19 +1,29 @@ { - "Name of depletion code" : "serpent", - "Path to depletion code executable": "sss2", - "File containing processing system objects": "input_5leu.json", - "Graph file containing processing system structure": "tap.dot", - "User's depletion code input file with reactor model": "tap_test.serpent", - "Path output data storing folder": "./", - "Output HDF5 database file name": "db_saltproc.h5", - "Number of neutrons per generation": 50, - "Number of active generations": 20, - "Number of inactive generations": 20, - "Restart simulation from the step when it stopped?": false, - "Geometry file/files to use in depletion code runs": "347_base.ini", - "Switch to another geometry when keff drops below 1?": false, - "Salt mass flow rate throughout reactor core (g/s)": 9.92E+6, - "Number of steps for constant power and depletion interval case": 2, - "Depletion step interval or Cumulative time (end of step) (d)": 5, - "Reactor power or power step list during depletion step (W)": 1.250E+9 + "proc_input_file": "input_5leu.json", + "dot_input_file": "tap.dot", + "output_path": "./data", + "depsteps": 2, + "depcode": { + "codename": "serpent", + "exec_path": "sss2", + "template_inputfile_path": "./tap_test.serpent", + "iter_inputfile": "saltproc_serpent", + "iter_matfile": "saltproc_mat", + "npop": 50, + "active_cycles": 20, + "inactive_cycles": 20, + "geo_file_paths": ["./347_base.ini"] + }, + "simulation": { + "sim_name": "tap_integration_test", + "db_name": "db_saltproc.h5", + "restart_flag": false, + "adjust_geo": false + }, + "reactor": { + "volume": 1.0, + "mass_flowrate": 9.92E+6, + "power_levels": [ 1.250E+9 ], + "depl_hist": [ 5 ] + } } From 7af5547e8925643f892831d591b9cce906548c15 Mon Sep 17 00:00:00 2001 From: yardasol Date: Wed, 26 Jan 2022 17:43:05 -0600 Subject: [PATCH 058/118] add adjust_geo and restart_flag setting to simulation object in app.py --- saltproc/app.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/saltproc/app.py b/saltproc/app.py index 90990dfe8..daf36815e 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -397,6 +397,8 @@ def run(): sim_depcode=depcode, core_number=cores, node_number=nodes, + restart_flag=simulation_inp['restart_flag'], + adjust_geo=simulation_inp['adjust_geo'], db_path=simulation_inp['db_name']) msr = Reactor( From 37955ce610f9e149645f9a1ef03306db8b7d05c6 Mon Sep 17 00:00:00 2001 From: yardasol Date: Thu, 27 Jan 2022 13:00:59 -0600 Subject: [PATCH 059/118] added jsonschema to installation instructions and requirements.txt --- doc/installation.rst | 2 ++ requirements.txt | 1 + 2 files changed, 3 insertions(+) diff --git a/doc/installation.rst b/doc/installation.rst index cda9562c6..21a83c4aa 100644 --- a/doc/installation.rst +++ b/doc/installation.rst @@ -10,6 +10,7 @@ SaltProc has the following dependencies: #. `PyTables`_ #. `NetworkX`_ #. `PyDotPlus`_ + #. `jsonschema`_ .. _Serpent: http://montecarlo.vtt.fi .. _PyNE: http://pyne.io @@ -21,6 +22,7 @@ SaltProc has the following dependencies: .. _matplotlib: http://matplotlib.org .. _ViTables: http://vitables.org .. _GitHub: http://github.com/arfc/saltproc +.. _jsonschema: https://github.com/Julian/jsonschema Optional Depenendencies: diff --git a/requirements.txt b/requirements.txt index 9bd617ae1..64f47e02d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,6 +2,7 @@ pyne numpy scipy json +jsonschema pytables networkx pydotplus From f556fab0fb2ecc10cc7994929ccc14cb6a7d03f5 Mon Sep 17 00:00:00 2001 From: yardasol Date: Thu, 27 Jan 2022 13:15:10 -0600 Subject: [PATCH 060/118] make the input path global --- saltproc/app.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/saltproc/app.py b/saltproc/app.py index daf36815e..ca5128fb8 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -75,7 +75,8 @@ def read_main_input(main_inp_file): Please see saltproc/tests/test.json for an example.") # Global input path - input_path = os.path.dirname(f.name) + path_prefix = os.getcwd() + input_path = os.path.join(path_prefix, os.path.dirname(f.name)) # Saltproc settings global spc_inp_file, dot_inp_file, output_path, depsteps From 11f1d5fb2263c27743def9a55b4d41fcf33d8f5a Mon Sep 17 00:00:00 2001 From: yardasol Date: Thu, 27 Jan 2022 13:23:19 -0600 Subject: [PATCH 061/118] update test_const_reproc_run.py to reflect new outpur dir --- .../tests/integration_tests/const_repr/test_const_reproc_run.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saltproc/tests/integration_tests/const_repr/test_const_reproc_run.py b/saltproc/tests/integration_tests/const_repr/test_const_reproc_run.py index 06dc565fe..38631f523 100644 --- a/saltproc/tests/integration_tests/const_repr/test_const_reproc_run.py +++ b/saltproc/tests/integration_tests/const_repr/test_const_reproc_run.py @@ -10,7 +10,7 @@ sys.path.append(os.path.dirname(os.path.dirname(path))) directory = os.path.dirname(path) db_exp_file = directory+'/2step_non_ideal_2.h5' -db_file = directory+'/db_saltproc.h5' +db_file = directory+'/data/db_saltproc.h5' tol = 1e-9 From 84f10d05a43852294d58d0ce7fceac3f3f0c2990 Mon Sep 17 00:00:00 2001 From: yardasol Date: Thu, 27 Jan 2022 13:45:11 -0600 Subject: [PATCH 062/118] typo fix --- saltproc/simulation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saltproc/simulation.py b/saltproc/simulation.py index a61c2d4e8..61ce98750 100644 --- a/saltproc/simulation.py +++ b/saltproc/simulation.py @@ -83,7 +83,7 @@ def check_restart(self): try: os.remove(self.db_path) os.remove(self.sim_depcode.iter_matfile) - os.remove(self.sim_depcode.rerun_path) + os.remove(self.sim_depcode.iter_inputfile) print("Previous run output files were deleted.") except OSError as e: pass From c6d46f3b109272e3e0bb024de9954f6b430aa7ef Mon Sep 17 00:00:00 2001 From: yardasol Date: Thu, 27 Jan 2022 15:08:31 -0600 Subject: [PATCH 063/118] typo fix --- saltproc/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saltproc/app.py b/saltproc/app.py index ca5128fb8..b910d2e61 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -426,7 +426,7 @@ def run(): # Finish of First step # Main sequence mats = depcode.read_dep_comp(True) - simulation.store_mat_data(mats, dep_step, True) + simulation.store_mat_data(mats, dep_step, False) simulation.store_run_step_info() # Reprocessing here print("\nMass and volume of fuel before reproc %f g; %f cm3" % From e00c55b0a7e70390a33986a9b3dcfbaa64b7131f Mon Sep 17 00:00:00 2001 From: yardasol Date: Thu, 27 Jan 2022 15:15:26 -0600 Subject: [PATCH 064/118] update msbr input file --- examples/msbr/msbr_main.json | 45 +++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/examples/msbr/msbr_main.json b/examples/msbr/msbr_main.json index 843a55a6a..7100b3231 100644 --- a/examples/msbr/msbr_main.json +++ b/examples/msbr/msbr_main.json @@ -1,19 +1,32 @@ { - "Name of depletion code": "serpent", - "Path to depletion code executable": "sss2", - "File containing processing system objects": "msbr_objects.json", - "Graph file containing processing system structure": "msbr.dot", - "User's depletion code input file with reactor model": "msbr.serpent", - "Path output data storing folder": "../../saltproc/data/", "Output HDF5 database file name": "msbr_kl_100_saltproc.h5", - "Number of neutrons per generation": 50, - "Number of active generations": 20, - "Number of inactive generations": 20, - "Restart simulation from the step when it stopped?": false, - "Geometry file/files to use in depletion code runs": "geometry/msbr_full.ini", - "Switch to another geometry when keff drops below 1?": false, - "Salt mass flow rate throughout reactor core (g/s)": 9920000, - "Number of steps for constant power and depletion interval case": 12, - "Depletion step interval or Cumulative time (end of step) (d)": 3, - "Reactor power or power step list during depletion step (W)": 2250000000 +} +{ + "proc_input_file": "msbr_objects.json", + "dot_input_file": "msbr.dot", + "output_path": "./data", + "depsteps": 12, + "depcode": { + "codename": "serpent", + "exec_path": "sss2", + "template_inputfile_path": "./msbr.serpent", + "iter_inputfile": "saltproc_serpent", + "iter_matfile": "saltproc_mat", + "npop": 50, + "active_cycles": 20, + "inactive_cycles": 20, + "geo_file_paths": ["./geometry/msbr_full.ini"] + }, + "simulation": { + "sim_name": "msbr_example_simulation", + "db_name": "msbr_kl_100_saltproc.h5", + "restart_flag": false, + "adjust_geo": false + }, + "reactor": { + "volume": 1.0, + "mass_flowrate": 9920000, + "power_levels": [ 2250000000 ], + "depl_hist": [ 3 ] + } } From 0397f4e02a2cd08d4bb6a0d7543d06196e6672ac Mon Sep 17 00:00:00 2001 From: yardasol Date: Thu, 27 Jan 2022 15:24:19 -0600 Subject: [PATCH 065/118] update tap_main.json --- examples/tap/tap_main.json | 76 +++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 33 deletions(-) diff --git a/examples/tap/tap_main.json b/examples/tap/tap_main.json index f6f5c9b62..754f10923 100644 --- a/examples/tap/tap_main.json +++ b/examples/tap/tap_main.json @@ -1,35 +1,45 @@ { - "Name of depletion code": "serpent", - "Path to depletion code executable": "sss2", - "File containing processing system objects": "tap_objects.json", - "Graph file containing processing system structure": "tap.dot", - "User's depletion code input file with reactor model": "tap.serpent", - "Path output data storing folder": "../../saltproc/data/", - "Output HDF5 database file name": "db_saltproc.h5", - "Number of neutrons per generation": 50, - "Number of active generations": 20, - "Number of inactive generations": 20, - "Restart simulation from the step when it stopped?": false, - "Geometry file/files to use in depletion code runs": [ - "geometry/347_base.ini", - "geometry/406.ini", - "geometry/427.ini", - "geometry/505.ini", - "geometry/576.ini", - "geometry/633.ini", - "geometry/681.ini", - "geometry/840.ini", - "geometry/880.ini", - "geometry/900.ini", - "geometry/988.ini", - "geometry/1126.ini", - "geometry/1338.ini", - "geometry/1498.ini", - "geometry/1668_all.ini" - ], - "Switch to another geometry when keff drops below 1?": true, - "Salt mass flow rate throughout reactor core (g/s)": 9920000, - "Number of steps for constant power and depletion interval case": 3, - "Depletion step interval or Cumulative time (end of step) (d)": 2, - "Reactor power or power step list during depletion step (W)": 1250000000 + "proc_input_file": "tap_objects.json", + "dot_input_file": "tap.dot", + "output_path": "./data", + "depsteps": 3, + "depcode": { + "codename": "serpent", + "exec_path": "sss2", + "template_inputfile_path": "./tap.serpent", + "iter_inputfile": "saltproc_serpent", + "iter_matfile": "saltproc_mat", + "npop": 50, + "active_cycles": 20, + "inactive_cycles": 20, + "geo_file_paths": [ + "./geometry/347_base.ini", + "./geometry/406.ini", + "./geometry/427.ini", + "./geometry/505.ini", + "./geometry/576.ini", + "./geometry/633.ini", + "./geometry/681.ini", + "./geometry/840.ini", + "./geometry/880.ini", + "./geometry/900.ini", + "./geometry/988.ini", + "./geometry/1126.ini", + "./geometry/1338.ini", + "./geometry/1498.ini", + "./geometry/1668_all.ini" + ] + }, + "simulation": { + "sim_name": "test_simulation", + "db_name": "db_saltproc.h5", + "restart_flag": false, + "adjust_geo": true + }, + "reactor": { + "volume": 1.0, + "mass_flowrate": 9920000, + "power_levels": [ 1250000000 ], + "depl_hist": [ 2 ] + } } From 67c031e02efbead926d1f3d9eb04ef29dbec7811 Mon Sep 17 00:00:00 2001 From: yardasol Date: Thu, 27 Jan 2022 15:24:31 -0600 Subject: [PATCH 066/118] update input_schema.json --- saltproc/input_schema.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/saltproc/input_schema.json b/saltproc/input_schema.json index 7151aed1b..152744fa4 100644 --- a/saltproc/input_schema.json +++ b/saltproc/input_schema.json @@ -6,11 +6,13 @@ "properties": { "proc_input_file": { "description": "File containing processing system objects", - "type": "string" + "type": "string", + "pattern": "^(.*)\\.json$" }, "dot_input_file": { "description": "Graph file containing processing system structure", - "type": "string" + "type": "string", + "pattern": "^(.*)\\.dot$" }, "output_path": { "description": "Path output data storing folder", From 42c07a6e9401e7a2700477e94a8fc5f1dc4f86f1 Mon Sep 17 00:00:00 2001 From: yardasol Date: Thu, 27 Jan 2022 15:25:38 -0600 Subject: [PATCH 067/118] remove saltprocinputschema.py --- saltproc/saltprocinputschema.py | 119 -------------------------------- 1 file changed, 119 deletions(-) delete mode 100644 saltproc/saltprocinputschema.py diff --git a/saltproc/saltprocinputschema.py b/saltproc/saltprocinputschema.py deleted file mode 100644 index 49ac5071c..000000000 --- a/saltproc/saltprocinputschema.py +++ /dev/null @@ -1,119 +0,0 @@ -input_schema = { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/arfc/saltproc", - "title": "SaltProc input file schema", - "type": "object", - "properties": { - "proc_input_file": { - "description": "File containing processing system objects", - "type": "string" - }, - "dot_input_file": { - "description": "Graph file containing processing system structure", - "type": "string" - }, - "output_path": { - "description": "Path output data storing folder", - "type": "string", - "pattern": "^\\.\\/(.*)$" - }, - "depsteps": { - "description": "Number of steps for constant power and depletion interval case", - "type": "number" - }, - "depcode": { - "description": "Depcode class input parameters", - "type": "object", - "properties": { - "codename": { - "description": "Name of depletion code", - "type": "string" }, - "exec_path": { - "description": "Path to depletion code executable", - "type": "string" }, - "template_inputfile_path": { - "description": "Path to user's template depletion code input file with reactor model", - "type": "string", - "pattern": "^\\.\\/(.*)$"}, - "iter_inputfile": { - "description": "Name of depletion code input file for depletion code rerunning", - "type": "string" }, - "iter_matfile": { - "description": "Name of iteratvie, rewritable material file for depletion code rerunning", - "type": "string" }, - "npop": { - "description": "Number of neutrons per generation", - "type": "number", - "minimum": 0}, - "active_cycles": { - "description": "number of active generations", - "type": "number", - "minimum": 0}, - "inactive_cycles": { - "description": "Number of inactive generations", - "type": "number", - "minimum": 0}, - "geo_file_paths": { - "description": "Path(s) to geometry file(s) to swtich to in depletion code runs", - "type": "array", - "items": { "type": "string"}, - "minItems": 1, - "uniqueItems": False - } - }, - "required": ["codename", "exec_path", "template_inputfile_path", "iter_inputfile", "iter_matfile", "npop", "active_cycles","inactive_cycles", "geo_file_paths"] - }, - "simulation": { - "description": "Simulation class input parameters", - "type": "object", - "properties": { - "sim_name": { - "description": "Name of simulation", - "type": "string"}, - "db_name": { - "description": "Output HDF5 database file name", - "type": "string", - "pattern": "^(.*)\\.h5$"}, - "restart_flag": { - "description": "Restart simulation from the step when it stopped?", - "type": "boolean"}, - "adjust_geo": { - "description": "switch to another geometry when keff drops below 1?", - "type": "boolean"} - }, - "requires": ["sim_name", "db_name", "restart_flag", "adjust_geo"] - }, - "reactor": { - "description": "Reactor class input parameters", - "type": "object", - "properties": { - "volume": { - "description": "reactor core volume [cm^3]", - "type": "number", - "minimum": 0}, - "mass_flowrate": { - "description": "Salt mass flowrate through reactor core [g/s]", - "type": "number", - "minimum": 0 }, - "power_levels": { - "description": "Reactor power or power step list durng depletion step [W]", - "type": "array", - "items": { "type": "number", - "minimum": 0}, - "minItems": 1, - "uniqueItems": False - }, - "depl_hist": { - "description": "Depletion step interval or cumulative time (end of step) [d]", - "type": "array", - "items": { "type": "number", - "minimum": 0}, - "minItems": 1, - "uniqueItems": False - } - }, - "required": ["volume", "mass_flowrate", "power_levels", "depl_hist"] - } - }, - "required": ["proc_input_file", "dot_input_file", "output_path", "depsteps", "depcode", "simulation", "reactor"] -} From 8aaf281049d5785801e5d346b41cc218652ab587 Mon Sep 17 00:00:00 2001 From: yardasol Date: Thu, 27 Jan 2022 15:28:55 -0600 Subject: [PATCH 068/118] typo fix in msbr_main.json --- examples/msbr/msbr_main.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/examples/msbr/msbr_main.json b/examples/msbr/msbr_main.json index 7100b3231..4ac5f64af 100644 --- a/examples/msbr/msbr_main.json +++ b/examples/msbr/msbr_main.json @@ -1,6 +1,3 @@ -{ - "Output HDF5 database file name": "msbr_kl_100_saltproc.h5", -} { "proc_input_file": "msbr_objects.json", "dot_input_file": "msbr.dot", From 03b9c54d0c8d13bc836c7cd87459bcd1c318e54b Mon Sep 17 00:00:00 2001 From: yardasol Date: Thu, 27 Jan 2022 20:38:28 -0600 Subject: [PATCH 069/118] + test_switch_to_next_geometry to test_depcode.py --- saltproc/tests/test_depcode.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/saltproc/tests/test_depcode.py b/saltproc/tests/test_depcode.py index c52263e51..c555d63a1 100644 --- a/saltproc/tests/test_depcode.py +++ b/saltproc/tests/test_depcode.py @@ -21,6 +21,7 @@ power_levels=[1.250E+09, 1.250E+09, 5.550E+09], depl_hist=[111.111, 2101.9, 3987.5]) +geo_test_input = directory + '/test_geometry_switch.inp' def test_get_tra_or_dec(): serpent.get_tra_or_dec(serpent.iter_inputfile) @@ -184,3 +185,11 @@ def test_write_depcode_input(): os.remove(serpent.iter_matfile) serpent.iter_inputfile = iter_inputfile_old + +def test_switch_to_next_geometry(): + shutil.copy2(geo_test_input, serpent.iter_inputfile + '_test') + serpent.iter_inputfile = serpent.iter_inputfile + '_test' + serpent.switch_to_next_geometry() + d = serpent.read_depcode_template(serpent.iter_inputfile) + assert d[5].split('/')[-1] == '988.inp"\n' + os.remove(serpent.iter_inputfile) From f69497394c5d972f7e2deb2014e5f18b4f9f7060 Mon Sep 17 00:00:00 2001 From: yardasol Date: Thu, 27 Jan 2022 20:40:42 -0600 Subject: [PATCH 070/118] + switch_to_next_geometry to depcode.py --- saltproc/depcode.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/saltproc/depcode.py b/saltproc/depcode.py index 7d5006e96..e57ab9a63 100644 --- a/saltproc/depcode.py +++ b/saltproc/depcode.py @@ -602,6 +602,32 @@ def sss_meta_zzz(self, nuc_code): zzaaam = nuc_code return int(zzaaam) + def switch_to_next_geometry(self): + """Inserts line with path to next Serpent geometry file at the + beginning of the Serpent iteration input file. + """ + geo_line_n = 5 + f = open(self.iter_inputfile, 'r') + data = f.readlines() + f.close() + + current_geo_file = data[geo_line_n].split('\"')[1] + current_geo_idx = self.geo_files.index(current_geo_file) + try: + new_geo_file = self.geo_files[current_geo_idx + 1] + except IndexError: + print('No more geometry files available \ + and the system went subcritical \n\n') + print('Aborting simulation') + return + new_data = [d.replace(current_geo_file, new_geo_file) for d in data] + print('Switching to next geometry file: ', new_geo_file) + + f = open(self.iter_inputfile, 'w') + f.writelines(new_data) + f.close() + + def write_depcode_input( self, reactor, From 7b4526acbe43073057f735c5c4bd72df6fdf16aa Mon Sep 17 00:00:00 2001 From: yardasol Date: Thu, 27 Jan 2022 20:47:50 -0600 Subject: [PATCH 071/118] Add abstract function for switch_to_next_geometry --- saltproc/depcode.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/saltproc/depcode.py b/saltproc/depcode.py index e57ab9a63..43ed350ac 100644 --- a/saltproc/depcode.py +++ b/saltproc/depcode.py @@ -104,6 +104,12 @@ def run_depcode(self, cores, nodes): Number of nodes to use for depletion code run. """ + @abstractmethod + def switch_to_next_geometry(self): + """Inserts line with path to next depletion code geometry file at the + beginning of the depletion code iteration input file. + """ + @abstractmethod def write_depcode_input(self, reactor, dep_step, restart): """ Writes prepared data into depletion code input file(s). From d44e8a8717b1ec41c015d1a748a60e32e62965f8 Mon Sep 17 00:00:00 2001 From: yardasol Date: Thu, 27 Jan 2022 20:49:52 -0600 Subject: [PATCH 072/118] Add abstract function for read_depcode_sim_info --- saltproc/depcode.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/saltproc/depcode.py b/saltproc/depcode.py index 43ed350ac..5a977f515 100644 --- a/saltproc/depcode.py +++ b/saltproc/depcode.py @@ -66,6 +66,12 @@ def __init__(self, self.param = {} self.sim_info = {} + @abstractmethod + def read_depcode_info(self): + """Parses initial depletion code info data from depletion code + output and stores it in the `Depcode` object's ``sim_info`` attribute. + """ + @abstractmethod def read_dep_comp(self, read_at_end=False): """Reads the depleted material data from the depcode simulation From daf86f21405fcceb552c89e5c518b9af8f0d7f53 Mon Sep 17 00:00:00 2001 From: yardasol Date: Thu, 27 Jan 2022 21:04:33 -0600 Subject: [PATCH 073/118] added abstract method for read_depcode_step_info --- saltproc/depcode.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/saltproc/depcode.py b/saltproc/depcode.py index 5a977f515..a58997d08 100644 --- a/saltproc/depcode.py +++ b/saltproc/depcode.py @@ -72,6 +72,13 @@ def read_depcode_info(self): output and stores it in the `Depcode` object's ``sim_info`` attribute. """ + @abstractmethod + def read_depcode_step_param(self): + """Parses data from depletion code output for each step and stores + it in `Depcode` object's ``param`` attributes. + """ + + @abstractmethod def read_dep_comp(self, read_at_end=False): """Reads the depleted material data from the depcode simulation From c420c1429ac32af843b30d3c3ec431ed1c5eb05b Mon Sep 17 00:00:00 2001 From: yardasol Date: Thu, 27 Jan 2022 21:42:09 -0600 Subject: [PATCH 074/118] add psudocode for generalizing store_info and store_step_info methods --- saltproc/simulation.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/saltproc/simulation.py b/saltproc/simulation.py index 61ce98750..0fa58f1b8 100644 --- a/saltproc/simulation.py +++ b/saltproc/simulation.py @@ -289,6 +289,8 @@ def store_run_step_info(self): b_g = len(self.sim_depcode.param['beta_eff']) # numpy array row storage for run info + # delete this and define class in + # Depcode subclasses class Step_info(tb.IsDescription): keff_bds = tb.Float32Col((2,)) keff_eds = tb.Float32Col((2,)) @@ -301,7 +303,7 @@ class Step_info(tb.IsDescription): delayed_neutrons_lambda_eds = tb.Float32Col((b_g, 2)) fission_mass_bds = tb.Float32Col() fission_mass_eds = tb.Float32Col() - # Open or restore db and append data to it + #### Open or restore db and append data to it db = tb.open_file(self.db_path, mode='a', filters=self.compression_params) try: step_info_table = db.get_node( @@ -313,7 +315,7 @@ class Step_info(tb.IsDescription): step_info_table = db.create_table( db.root, 'simulation_parameters', - Step_info, + Step_info, #### self.sim_depcode.Step_info "Simulation parameters after each timestep") # Intializing burn_time array at the first depletion step self.burn_time = 0.0 @@ -321,6 +323,11 @@ class Step_info(tb.IsDescription): # Define row of table as step_info step_info = step_info_table.row # Define all values in the row + + #### in depcode.py: + #### def store_step_info(step_info): + #### """ do the below """ + #### ... step_info['keff_bds'] = self.sim_depcode.param['keff_bds'] step_info['keff_eds'] = self.sim_depcode.param['keff_eds'] step_info['breeding_ratio'] = self.sim_depcode.param[ @@ -339,6 +346,8 @@ class Step_info(tb.IsDescription): 'fission_mass_bds'] step_info['fission_mass_eds'] = self.sim_depcode.param[ 'fission_mass_eds'] + #### return step_info + # Inject the Record value into the table step_info.append() step_info_table.flush() @@ -353,7 +362,9 @@ def store_run_init_info(self): memory optimization mode (Serpent), depletion timestep size. """ - # numpy arraw row storage for run info + #### numpy arraw row storage for run info + #### delete and make this datatype specific + #### to Depcode subclasses sim_info_dtype = np.dtype([ ('neutron_population', int), ('active_cycles', int), @@ -374,7 +385,7 @@ def store_run_init_info(self): sim_info_row = ( self.sim_depcode.npop, self.sim_depcode.active_cycles, - self.sim_depcode.inactive_cycles, + self.sim_depcode.inactive_cycles, #### delete the below self.sim_depcode.sim_info['serpent_version'], self.sim_depcode.sim_info['title'], self.sim_depcode.sim_info['serpent_input_filename'], @@ -385,7 +396,11 @@ def store_run_init_info(self): self.sim_depcode.sim_info['memory_optimization_mode'], self.sim_depcode.sim_info['depletion_timestep'] ) - sim_info_array = np.array([sim_info_row], dtype=sim_info_dtype) + #### replace with this + #### for i in sim_depcode.sim_info: + #### sim_info_row += (i,) + + sim_info_array = np.array([sim_info_row], dtype=sim_info_dtype) #### dtype=sim_depcode.sim_info_dtype # Open or restore db and append datat to it db = tb.open_file(self.db_path, mode='a', filters=self.compression_params) try: From 234f2d18506b9c6699e050bd485bca12dcac8edd Mon Sep 17 00:00:00 2001 From: yardasol Date: Thu, 27 Jan 2022 21:46:21 -0600 Subject: [PATCH 075/118] import shutil in test_depcode.py --- saltproc/tests/test_depcode.py | 1 + 1 file changed, 1 insertion(+) diff --git a/saltproc/tests/test_depcode.py b/saltproc/tests/test_depcode.py index c555d63a1..9d55a388f 100644 --- a/saltproc/tests/test_depcode.py +++ b/saltproc/tests/test_depcode.py @@ -3,6 +3,7 @@ from saltproc import Reactor import os import sys +import shutil import numpy as np path = os.path.realpath(__file__) From e99c2cc9ccb763b95a73d2611c8fb8f029c5ca7a Mon Sep 17 00:00:00 2001 From: yardasol Date: Thu, 27 Jan 2022 22:11:01 -0600 Subject: [PATCH 076/118] get test_switch_to_next_geometry working in test_depcode.py --- saltproc/tests/test_depcode.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/saltproc/tests/test_depcode.py b/saltproc/tests/test_depcode.py index 9d55a388f..5c3bd869b 100644 --- a/saltproc/tests/test_depcode.py +++ b/saltproc/tests/test_depcode.py @@ -189,8 +189,11 @@ def test_write_depcode_input(): def test_switch_to_next_geometry(): shutil.copy2(geo_test_input, serpent.iter_inputfile + '_test') + iter_inputfile_old = serpent.iter_inputfile serpent.iter_inputfile = serpent.iter_inputfile + '_test' + serpent.geo_files += ['../../examples/406.inp', '../../examples/988.inp'] serpent.switch_to_next_geometry() d = serpent.read_depcode_template(serpent.iter_inputfile) assert d[5].split('/')[-1] == '988.inp"\n' os.remove(serpent.iter_inputfile) + serpent.iter_inputfile = iter_inputfile_old From 0e32b6d4168bc7956efcb48ebc0eea3c96730544 Mon Sep 17 00:00:00 2001 From: yardasol Date: Thu, 27 Jan 2022 22:12:34 -0600 Subject: [PATCH 077/118] remove switch_to_next_geometry from simulation.py --- saltproc/simulation.py | 25 ------------------------- saltproc/tests/test_simulation.py | 12 ------------ 2 files changed, 37 deletions(-) diff --git a/saltproc/simulation.py b/saltproc/simulation.py index 0fa58f1b8..d7cefcc58 100644 --- a/saltproc/simulation.py +++ b/saltproc/simulation.py @@ -414,31 +414,6 @@ def store_run_init_info(self): sim_info_table.flush() db.close() - def switch_to_next_geometry(self): - """Inserts line with path to next Serpent geometry file at the - beginning of the Serpent iteration input file. - """ - geo_line_n = 5 - f = open(self.sim_depcode.iter_inputfile, 'r') - data = f.readlines() - f.close() - - current_geo_file = data[geo_line_n].split('\"')[1] - current_geo_idx = self.sim_depcode.geo_files.index(current_geo_file) - try: - new_geo_file = self.sim_depcode.geo_files[current_geo_idx + 1] - except IndexError: - print('No more geometry files available \ - and the system went subcritical \n\n') - print('Simulation ended') - return - new_data = [d.replace(current_geo_file, new_geo_file) for d in data] - print('Switching to next geometry file: ', new_geo_file) - - f = open(self.sim_depcode.iter_inputfile, 'w') - f.writelines(new_data) - f.close() - def read_k_eds_delta(self, current_timestep): """Reads from database delta between previous and current `keff` at the end of depletion step and returns `True` if predicted `keff` at the diff --git a/saltproc/tests/test_simulation.py b/saltproc/tests/test_simulation.py index 103b23b23..b1f6e89f5 100644 --- a/saltproc/tests/test_simulation.py +++ b/saltproc/tests/test_simulation.py @@ -4,7 +4,6 @@ import saltproc.app import os import sys -import shutil import numpy as np import tables as tb path = os.path.realpath(__file__) @@ -15,8 +14,6 @@ main_input = directory + '/test.json' dot_input = directory + '/test.dot' -geo_test_input = directory + '/test_geometry_switch.inp' - serpent = DepcodeSerpent( exec_path='/home/andrei2/serpent/serpent2/src_2131/sss2', template_inputfile_path=directory + '/template.inp', @@ -390,12 +387,3 @@ def test_store_run_step_info(): def test_read_k_eds_delta(): assert simulation.read_k_eds_delta(7) is False - - -def test_switch_to_next_geometry(): - shutil.copy2(geo_test_input, serpent.iter_inputfile + '_test') - serpent.iter_inputfile = serpent.iter_inputfile + '_test' - simulation.switch_to_next_geometry() - d = serpent.read_depcode_template(serpent.iter_inputfile) - assert d[5].split('/')[-1] == '988.inp"\n' - os.remove(serpent.iter_inputfile) From 2fb91992e6966d70baef3215506f80ca2ba8349a Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 28 Jan 2022 08:46:00 -0600 Subject: [PATCH 078/118] simulation.switch_to_next_geometry -> depcode.switch_to_next_geometry in app.py --- saltproc/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saltproc/app.py b/saltproc/app.py index b910d2e61..b77f3376f 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -457,7 +457,7 @@ def run(): gc.collect() # Switch to another geometry? if simulation.adjust_geo and simulation.read_k_eds_delta(dep_step): - simulation.switch_to_next_geometry() + depcode.switch_to_next_geometry() print("\nTime at the end of current depletion step %fd" % simulation.burn_time) print("Simulation succeeded.\n") From 961dfe8f5fed43d2d6d38ade79d709ee662b8277 Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 28 Jan 2022 08:59:18 -0600 Subject: [PATCH 079/118] add Step_info class to Depcode --- saltproc/depcode.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/saltproc/depcode.py b/saltproc/depcode.py index a58997d08..49173ea33 100644 --- a/saltproc/depcode.py +++ b/saltproc/depcode.py @@ -3,6 +3,7 @@ import os import shutil import re +import tables as tb from pyne import nucname as pyname from pyne import serpent from abc import ABC, abstractmethod @@ -16,6 +17,18 @@ class Depcode(ABC): and output files, and write new input files for the depletion code. """ + class Step_info(tb.IsDescription): + keff_bds = tb.Float32Col((2,)) + keff_eds = tb.Float32Col((2,)) + breeding_ratio = tb.Float32Col((2,)) + step_execution_time = tb.Float32Col() + cumulative_time_at_eds = tb.Float32Col() + power_level = tb.Float32Col() + memory_usage = tb.Float32Col() + beta_eff_eds = tb.Float32Col((b_g, 2)) + delayed_neutrons_lambda_eds = tb.Float32Col((b_g, 2)) + fission_mass_bds = tb.Float32Col() + fission_mass_eds = tb.Float32Col() def __init__(self, codename, From 8806c3c94e2101130400c5c63161b02808e3900a Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 28 Jan 2022 09:00:33 -0600 Subject: [PATCH 080/118] Step_info -> self.sim_depcode.Step_info --- saltproc/simulation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saltproc/simulation.py b/saltproc/simulation.py index d7cefcc58..5ca178f9c 100644 --- a/saltproc/simulation.py +++ b/saltproc/simulation.py @@ -315,7 +315,7 @@ class Step_info(tb.IsDescription): step_info_table = db.create_table( db.root, 'simulation_parameters', - Step_info, #### self.sim_depcode.Step_info + self.sim_depcode.Step_info, ### Step_info, "Simulation parameters after each timestep") # Intializing burn_time array at the first depletion step self.burn_time = 0.0 From 97a481c31b7b72d659b5ebeb6f48c8bf40086669 Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 28 Jan 2022 09:03:44 -0600 Subject: [PATCH 081/118] fix indentation in Depcode.Step_info --- saltproc/depcode.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/saltproc/depcode.py b/saltproc/depcode.py index 49173ea33..972ec59de 100644 --- a/saltproc/depcode.py +++ b/saltproc/depcode.py @@ -16,19 +16,19 @@ class Depcode(ABC): population, active, and inactive cycles. Contains methods to read template and output files, and write new input files for the depletion code. - """ - class Step_info(tb.IsDescription): - keff_bds = tb.Float32Col((2,)) - keff_eds = tb.Float32Col((2,)) - breeding_ratio = tb.Float32Col((2,)) - step_execution_time = tb.Float32Col() - cumulative_time_at_eds = tb.Float32Col() - power_level = tb.Float32Col() - memory_usage = tb.Float32Col() - beta_eff_eds = tb.Float32Col((b_g, 2)) - delayed_neutrons_lambda_eds = tb.Float32Col((b_g, 2)) - fission_mass_bds = tb.Float32Col() - fission_mass_eds = tb.Float32Col() + """ + class Step_info(tb.IsDescription): + keff_bds = tb.Float32Col((2,)) + keff_eds = tb.Float32Col((2,)) + breeding_ratio = tb.Float32Col((2,)) + step_execution_time = tb.Float32Col() + cumulative_time_at_eds = tb.Float32Col() + power_level = tb.Float32Col() + memory_usage = tb.Float32Col() + beta_eff_eds = tb.Float32Col((b_g, 2)) + delayed_neutrons_lambda_eds = tb.Float32Col((b_g, 2)) + fission_mass_bds = tb.Float32Col() + fission_mass_eds = tb.Float32Col() def __init__(self, codename, From 51a005fc622993427efd1600e0ad6c951e352271 Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 28 Jan 2022 09:06:46 -0600 Subject: [PATCH 082/118] undo adding Step_info to Depcode --- saltproc/depcode.py | 24 ++++++++++++------------ saltproc/simulation.py | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/saltproc/depcode.py b/saltproc/depcode.py index 972ec59de..189b4e90d 100644 --- a/saltproc/depcode.py +++ b/saltproc/depcode.py @@ -17,18 +17,18 @@ class Depcode(ABC): and output files, and write new input files for the depletion code. """ - class Step_info(tb.IsDescription): - keff_bds = tb.Float32Col((2,)) - keff_eds = tb.Float32Col((2,)) - breeding_ratio = tb.Float32Col((2,)) - step_execution_time = tb.Float32Col() - cumulative_time_at_eds = tb.Float32Col() - power_level = tb.Float32Col() - memory_usage = tb.Float32Col() - beta_eff_eds = tb.Float32Col((b_g, 2)) - delayed_neutrons_lambda_eds = tb.Float32Col((b_g, 2)) - fission_mass_bds = tb.Float32Col() - fission_mass_eds = tb.Float32Col() + #class Step_info(tb.IsDescription): + # keff_bds = tb.Float32Col((2,)) + # keff_eds = tb.Float32Col((2,)) + # breeding_ratio = tb.Float32Col((2,)) + # step_execution_time = tb.Float32Col() + # cumulative_time_at_eds = tb.Float32Col() + # power_level = tb.Float32Col() + # memory_usage = tb.Float32Col() + # beta_eff_eds = tb.Float32Col((b_g, 2)) + # delayed_neutrons_lambda_eds = tb.Float32Col((b_g, 2)) + # fission_mass_bds = tb.Float32Col() + # fission_mass_eds = tb.Float32Col() def __init__(self, codename, diff --git a/saltproc/simulation.py b/saltproc/simulation.py index 5ca178f9c..844a0eabf 100644 --- a/saltproc/simulation.py +++ b/saltproc/simulation.py @@ -315,7 +315,7 @@ class Step_info(tb.IsDescription): step_info_table = db.create_table( db.root, 'simulation_parameters', - self.sim_depcode.Step_info, ### Step_info, + Step_info, #### self.sim_depcode.Step_info, "Simulation parameters after each timestep") # Intializing burn_time array at the first depletion step self.burn_time = 0.0 From 96846bac9da3f8831d220271d1e6bfb98f3dec61 Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 28 Jan 2022 09:21:14 -0600 Subject: [PATCH 083/118] add 'depcode_name' field to 'sim_info_dtype'; serpent->depcode in sim_info_dtype --- saltproc/simulation.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/saltproc/simulation.py b/saltproc/simulation.py index 844a0eabf..28355fadb 100644 --- a/saltproc/simulation.py +++ b/saltproc/simulation.py @@ -369,10 +369,11 @@ def store_run_init_info(self): ('neutron_population', int), ('active_cycles', int), ('inactive_cycles', int), - ('serpent_version', 'S20'), + ('depcode_name', 'S20') + ('depcode_version', 'S20'), ('title', 'S90'), - ('serpent_input_filename', 'S90'), - ('serpent_working_dir', 'S90'), + ('depcode_input_filename', 'S90'), + ('depcode_working_dir', 'S90'), ('xs_data_path', 'S90'), ('OMP_threads', int), ('MPI_tasks', int), @@ -386,10 +387,11 @@ def store_run_init_info(self): self.sim_depcode.npop, self.sim_depcode.active_cycles, self.sim_depcode.inactive_cycles, #### delete the below - self.sim_depcode.sim_info['serpent_version'], + self.sim_depcode.sim_info['depcode_name'] + self.sim_depcode.sim_info['depcode_version'], self.sim_depcode.sim_info['title'], - self.sim_depcode.sim_info['serpent_input_filename'], - self.sim_depcode.sim_info['serpent_working_dir'], + self.sim_depcode.sim_info['depcode_input_filename'], + self.sim_depcode.sim_info['depcode_working_dir'], self.sim_depcode.sim_info['xs_data_path'], self.sim_depcode.sim_info['OMP_threads'], self.sim_depcode.sim_info['MPI_tasks'], From 7bdbd1a5780bc58f58dbac589dca2339d5510dbc Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 28 Jan 2022 09:28:35 -0600 Subject: [PATCH 084/118] add depcode_name field to read_depcode_info; consistency changes --- saltproc/depcode.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/saltproc/depcode.py b/saltproc/depcode.py index 189b4e90d..01369e553 100644 --- a/saltproc/depcode.py +++ b/saltproc/depcode.py @@ -465,12 +465,13 @@ def read_depcode_info(self): it in the `DepcodeSerpent` object's ``sim_info`` attributes. """ res = serpent.parse_res(self.iter_inputfile + "_res.m") - self.sim_info['serpent_version'] = \ - res['VERSION'][0].decode('utf-8') + depcode_name, depcode_ver = res['VERSION'][0].decode('utf-8').split() + self.sim_info['depcode_name'] = depcode_name + self.sim_info['depcode_version'] = depcode_version self.sim_info['title'] = res['TITLE'][0].decode('utf-8') - self.sim_info['serpent_input_filename'] = \ + self.sim_info['depcode_input_filename'] = \ res['INPUT_FILE_NAME'][0].decode('utf-8') - self.sim_info['serpent_working_dir'] = \ + self.sim_info['depcode_working_dir'] = \ res['WORKING_DIRECTORY'][0].decode('utf-8') self.sim_info['xs_data_path'] = \ res['XS_DATA_FILE_PATH'][0].decode('utf-8') From e181e47308d113de49e60b49b6093e6bb13cf302 Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 28 Jan 2022 09:30:00 -0600 Subject: [PATCH 085/118] typo fix in simulation.py --- saltproc/simulation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saltproc/simulation.py b/saltproc/simulation.py index 28355fadb..52cf664b1 100644 --- a/saltproc/simulation.py +++ b/saltproc/simulation.py @@ -387,7 +387,7 @@ def store_run_init_info(self): self.sim_depcode.npop, self.sim_depcode.active_cycles, self.sim_depcode.inactive_cycles, #### delete the below - self.sim_depcode.sim_info['depcode_name'] + self.sim_depcode.sim_info['depcode_name'], self.sim_depcode.sim_info['depcode_version'], self.sim_depcode.sim_info['title'], self.sim_depcode.sim_info['depcode_input_filename'], From 6d09517333b241656458784eb70af7b4d32d8437 Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 28 Jan 2022 09:32:29 -0600 Subject: [PATCH 086/118] typo fix in simulation.py --- saltproc/simulation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saltproc/simulation.py b/saltproc/simulation.py index 52cf664b1..bbbcd280f 100644 --- a/saltproc/simulation.py +++ b/saltproc/simulation.py @@ -369,7 +369,7 @@ def store_run_init_info(self): ('neutron_population', int), ('active_cycles', int), ('inactive_cycles', int), - ('depcode_name', 'S20') + ('depcode_name', 'S20'), ('depcode_version', 'S20'), ('title', 'S90'), ('depcode_input_filename', 'S90'), From 8a7ac98eca7cd1fbea7ff6d51df99a496e264cb7 Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 28 Jan 2022 09:35:27 -0600 Subject: [PATCH 087/118] typo fix in depcode.py --- saltproc/depcode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saltproc/depcode.py b/saltproc/depcode.py index 01369e553..9f725e6c1 100644 --- a/saltproc/depcode.py +++ b/saltproc/depcode.py @@ -467,7 +467,7 @@ def read_depcode_info(self): res = serpent.parse_res(self.iter_inputfile + "_res.m") depcode_name, depcode_ver = res['VERSION'][0].decode('utf-8').split() self.sim_info['depcode_name'] = depcode_name - self.sim_info['depcode_version'] = depcode_version + self.sim_info['depcode_version'] = depcode_ver self.sim_info['title'] = res['TITLE'][0].decode('utf-8') self.sim_info['depcode_input_filename'] = \ res['INPUT_FILE_NAME'][0].decode('utf-8') From 0d964bd65f71ca2f57f66fde738a2d87ed2cfbc5 Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 28 Jan 2022 09:44:24 -0600 Subject: [PATCH 088/118] update test_read_depcode_info --- saltproc/tests/test_depcode.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/saltproc/tests/test_depcode.py b/saltproc/tests/test_depcode.py index 5c3bd869b..1b43f7d2b 100644 --- a/saltproc/tests/test_depcode.py +++ b/saltproc/tests/test_depcode.py @@ -86,11 +86,20 @@ def test_get_nuc_name(): def test_read_depcode_info(): serpent.read_depcode_info() - assert serpent.sim_info['serpent_version'] == 'Serpent 2.1.31' + assert serpent.sim_info['depcode_name'] == 'Serpent' + assert serpent.sim_info['depcode_version'] == '2.1.31' assert serpent.sim_info['title'] == 'Untitled' + assert serpent.sim_info['depcode_input_filename'] == \ + '/home/andrei2/Desktop/git/saltproc/develop/saltproc/data/saltproc_tap' + assert serpent.sim_info['depcode_working_dir'] == \ + '/home/andrei2/Desktop/git/saltproc/develop/saltproc' + assert serpent.sim_info['xs_data_path'] == \ + '/home/andrei2/serpent/xsdata/jeff312/sss_jeff312.xsdata' + assert serpent.sim_info['MPI_tasks'] == 1 assert serpent.sim_info['OMP_threads'] == 4 assert serpent.sim_info['memory_optimization_mode'] == 4 + assert serpent.sim_info['depletion_timestep'] == 3.0 def test_read_depcode_step_param(): From f99c5d9461f7454fd4ae75bf95be3b2f5268b401 Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 28 Jan 2022 09:47:43 -0600 Subject: [PATCH 089/118] update test_store_run_init_info --- saltproc/tests/test_simulation.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/saltproc/tests/test_simulation.py b/saltproc/tests/test_simulation.py index b1f6e89f5..eeea17f62 100644 --- a/saltproc/tests/test_simulation.py +++ b/saltproc/tests/test_simulation.py @@ -299,15 +299,16 @@ def test_store_run_init_info(): assert tinit_info[0] == simulation.sim_depcode.npop assert tinit_info[1] == simulation.sim_depcode.active_cycles assert tinit_info[2] == simulation.sim_depcode.inactive_cycles - assert str(tinit_info[3])[2:-1] == init_info['serpent_version'] - assert str(tinit_info[4])[2:-1] == init_info['title'] - assert str(tinit_info[5])[2:-1] == init_info['serpent_input_filename'] - assert str(tinit_info[6])[2:-1] == init_info['serpent_working_dir'] - assert str(tinit_info[7])[2:-1] == init_info['xs_data_path'] - assert tinit_info[8] == init_info['OMP_threads'] - assert tinit_info[9] == init_info['MPI_tasks'] - assert tinit_info[10] == init_info['memory_optimization_mode'] - assert tinit_info[11] == init_info['depletion_timestep'] + assert str(tinit_info[3])[2:-1] == init_info['depcode_name'] + assert str(tinit_info[4])[2:-1] == init_info['depcode_version'] + assert str(tinit_info[5])[2:-1] == init_info['title'] + assert str(tinit_info[6])[2:-1] == init_info['depcode_input_filename'] + assert str(tinit_info[7])[2:-1] == init_info['depcode_working_dir'] + assert str(tinit_info[8])[2:-1] == init_info['xs_data_path'] + assert tinit_info[9] == init_info['OMP_threads'] + assert tinit_info[10] == init_info['MPI_tasks'] + assert tinit_info[11] == init_info['memory_optimization_mode'] + assert tinit_info[12] == init_info['depletion_timestep'] except AssertionError: db.close() os.remove(db_file) From a5d7058aa60039d1ce62513719d66184c7a94b18 Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 28 Jan 2022 09:50:55 -0600 Subject: [PATCH 090/118] add db.close statements to except blocks in test_simulation.py --- saltproc/tests/test_simulation.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/saltproc/tests/test_simulation.py b/saltproc/tests/test_simulation.py index eeea17f62..0d9deb144 100644 --- a/saltproc/tests/test_simulation.py +++ b/saltproc/tests/test_simulation.py @@ -92,6 +92,7 @@ def test_store_after_repr(): db = tb.open_file(simulation.db_path, mode='r', filters=simulation.compression_params) except Exception: + db.close() print('Unable to assign correct value to db. See error stack for more info.') tmats = db.root.materials @@ -182,6 +183,7 @@ def test_store_mat_data(): db = tb.open_file(simulation.db_path, mode='r', filters=simulation.compression_params) except Exception: + db.close() print('Unable to assign correct value to db. See error stack for more info.') tmats = db.root.materials @@ -290,6 +292,7 @@ def test_store_run_init_info(): db = tb.open_file(simulation.db_path, mode='r', filters=simulation.compression_params) except Exception: + db.close() print('Unable to assign correct value to db. See error stack for more info.') @@ -348,6 +351,7 @@ def test_store_run_step_info(): db = tb.open_file(simulation.db_path, mode='r', filters=simulation.compression_params) except Exception: + db.close() print('Unable to assign correct value to db. See error stack for more info.') tstep_info = db.root.simulation_parameters[0] From 03ae0abd9cdf8bf39db7850686adb59d48329518 Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 28 Jan 2022 09:57:03 -0600 Subject: [PATCH 091/118] Add more except blocks to tests in test_simulation.py --- saltproc/tests/test_simulation.py | 45 ++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/saltproc/tests/test_simulation.py b/saltproc/tests/test_simulation.py index 0d9deb144..6a00acdfc 100644 --- a/saltproc/tests/test_simulation.py +++ b/saltproc/tests/test_simulation.py @@ -92,7 +92,6 @@ def test_store_after_repr(): db = tb.open_file(simulation.db_path, mode='r', filters=simulation.compression_params) except Exception: - db.close() print('Unable to assign correct value to db. See error stack for more info.') tmats = db.root.materials @@ -140,6 +139,16 @@ def test_store_after_repr(): os.remove(db_file) simulation.db_path = db_path_old raise AssertionError("incorrect Value") + except KeyError: + db.close() + os.remove(db_file) + simulation.db_path = db_path_old + raise KeyError("incorrect key") + except: + db.close() + os.remove(db_file) + simulation.db_path = db_path_old + print("something went wrong. See error stack for details") # close the file db.close() @@ -183,7 +192,6 @@ def test_store_mat_data(): db = tb.open_file(simulation.db_path, mode='r', filters=simulation.compression_params) except Exception: - db.close() print('Unable to assign correct value to db. See error stack for more info.') tmats = db.root.materials @@ -257,6 +265,16 @@ def test_store_mat_data(): os.remove(db_file) simulation.db_path = db_path_old raise AssertionError("incorrect Value") + except KeyError: + db.close() + os.remove(db_file) + simulation.db_path = db_path_old + raise KeyError("incorrect key") + except: + db.close() + os.remove(db_file) + simulation.db_path = db_path_old + print("something went wrong. See error stack for details") # close the file db.close() @@ -317,6 +335,18 @@ def test_store_run_init_info(): os.remove(db_file) simulation.db_path = db_path_old raise AssertionError("incorrect Value") + except KeyError: + db.close() + os.remove(db_file) + simulation.db_path = db_path_old + raise KeyError("incorrect key") + except: + db.close() + os.remove(db_file) + simulation.db_path = db_path_old + print("something went wrong. See error stack for details") + + print("") # close the file db.close() @@ -351,7 +381,6 @@ def test_store_run_step_info(): db = tb.open_file(simulation.db_path, mode='r', filters=simulation.compression_params) except Exception: - db.close() print('Unable to assign correct value to db. See error stack for more info.') tstep_info = db.root.simulation_parameters[0] @@ -378,6 +407,16 @@ def test_store_run_step_info(): os.remove(db_file) simulation.db_path = db_path_old raise AssertionError("incorrect Value") + except KeyError: + db.close() + os.remove(db_file) + simulation.db_path = db_path_old + raise KeyError("incorrect key") + except: + db.close() + os.remove(db_file) + simulation.db_path = db_path_old + print("something went wrong. See error stack for details") # close the file db.close() From 617588c0728fb0b3d0c30c938fef8198adc6f367 Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 28 Jan 2022 10:30:04 -0600 Subject: [PATCH 092/118] remove machine specific paths in msbr example --- examples/msbr/msbr.serpent | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/msbr/msbr.serpent b/examples/msbr/msbr.serpent index acbc8974b..e381a7f18 100644 --- a/examples/msbr/msbr.serpent +++ b/examples/msbr/msbr.serpent @@ -51,9 +51,9 @@ therm gr 900 gre7.18t gre7.20t % 900K C-nat set title "MSBR Saltproc long-term, 91% removal, BOL, fresh fuel, ENDF" -set acelib "/home/andrei2/serpent/xsdata/endfb7/sss_endfb7.xsdata" -set declib "/home/andrei2/serpent/xsdata/endfb7/sss_endfb7.dec" -set nfylib "/home/andrei2/serpent/xsdata/endfb7/sss_endfb7.nfy" +set acelib "sss_endfb7.xsdata" +set declib "sss_endfb7.dec" +set nfylib "sss_endfb7.nfy" %set acelib "sss_jeff312.xsdata" %set declib "sss_jeff33.dec" From 7b4a34ad56f5d92d3fea306a86d492d4895de63e Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 28 Jan 2022 10:32:26 -0600 Subject: [PATCH 093/118] remove some machine specifc paths in tap.serpent and tap_plot.serpent --- examples/tap/tap.serpent | 6 +++--- examples/tap/tap_plot.serpent | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/tap/tap.serpent b/examples/tap/tap.serpent index 5e8501ce1..7f42ab30d 100644 --- a/examples/tap/tap.serpent +++ b/examples/tap/tap.serpent @@ -19,9 +19,9 @@ include "mats/non_burnable_mats.ini" set title "TAP MSR test 5-d step" %therm zrh_h 900 hzr05.32t hzr06.32t % 900K H-Zr -%set acelib "/home/andrei2/serpent/xsdata/endfb7/sss_endfb7.xsdata" -%set declib "/home/andrei2/serpent/xsdata/endfb7/sss_endfb7.dec" -%set nfylib "/home/andrei2/serpent/xsdata/endfb7/sss_endfb7.nfy" +%set acelib "sss_endfb7.xsdata" +%set declib "sss_endfb7.dec" +%set nfylib "sss_endfb7.nfy" set acelib "sss_jeff312.xsdata" set declib "sss_jeff33.dec" diff --git a/examples/tap/tap_plot.serpent b/examples/tap/tap_plot.serpent index 209253d92..830e07db8 100644 --- a/examples/tap/tap_plot.serpent +++ b/examples/tap/tap_plot.serpent @@ -19,9 +19,9 @@ include "geometry/347_base.ini" set title "TAP MSR test 5-d step" %therm zrh_h 900 hzr05.32t hzr06.32t % 900K H-Zr -%set acelib "/home/andrei2/serpent/xsdata/endfb7/sss_endfb7.xsdata" -%set declib "/home/andrei2/serpent/xsdata/endfb7/sss_endfb7.dec" -%set nfylib "/home/andrei2/serpent/xsdata/endfb7/sss_endfb7.nfy" +%set acelib "sss_endfb7.xsdata" +%set declib "sss_endfb7.dec" +%set nfylib "sss_endfb7.nfy" set acelib "sss_jeff312.xsdata" set declib "sss_jeff33.dec" From 3878c548ab5faf51fc91844f281bd9013fe439f7 Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 28 Jan 2022 11:19:17 -0600 Subject: [PATCH 094/118] pep8 fixes --- saltproc/app.py | 42 ++++++---- saltproc/depcode.py | 10 +-- saltproc/simulation.py | 61 ++++++++------ .../const_repr/test_const_reproc_run.py | 4 +- .../no_repro/test_no_reproc_run.py | 81 ++++++++++--------- saltproc/tests/test_app.py | 9 ++- saltproc/tests/test_depcode.py | 22 +++-- saltproc/tests/test_simulation.py | 35 ++++---- 8 files changed, 154 insertions(+), 110 deletions(-) diff --git a/saltproc/app.py b/saltproc/app.py index b77f3376f..23947e824 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -10,7 +10,8 @@ # from materialflow import Materialflow import os import copy -import json, jsonschema +import json +import jsonschema #from saltproc.saltprocinputschema import input_schema from collections import OrderedDict import gc @@ -69,7 +70,7 @@ def read_main_input(main_inp_file): with open(input_schema) as s: v = json.load(s) try: - jsonschema.validate(instance=j,schema=v) + jsonschema.validate(instance=j, schema=v) except jsonschema.exceptions.ValidationError: print("Your input file improperly structured.\ Please see saltproc/tests/test.json for an example.") @@ -110,8 +111,10 @@ def read_main_input(main_inp_file): depcode_inp['geo_file_paths'] = geo_file_paths # Global output file paths - depcode_inp['iter_inputfile'] = os.path.join(output_path, depcode_inp['iter_inputfile']) - depcode_inp['iter_matfile'] = os.path.join(output_path, depcode_inp['iter_matfile']) + depcode_inp['iter_inputfile'] = os.path.join( + output_path, depcode_inp['iter_inputfile']) + depcode_inp['iter_matfile'] = os.path.join( + output_path, depcode_inp['iter_matfile']) db_name = os.path.join( output_path, simulation_inp['db_name']) simulation_inp['db_name'] = db_name @@ -292,7 +295,8 @@ def reprocessing(mats): prcs[mname][p].rem_elements(forked_mats[mname][ctr]) ctr += 1 # Sum all forked material objects together - mats[mname] = forked_mats[mname][0] # initilize correct obj instance + # initilize correct obj instance + mats[mname] = forked_mats[mname][0] for idx in range(1, len(forked_mats[mname])): mats[mname] += forked_mats[mname][idx] print('1 Forked material mass %f' % (forked_mats[mname][0].mass)) @@ -373,12 +377,21 @@ def run(): read_main_input(sp_input) # Print out input information print('Initiating Saltproc:\n' - '\tRestart = ' + str(simulation_inp['restart_flag']) + '\n' - '\tTemplate File Path = ' + os.path.abspath(depcode_inp['template_inputfile_path']) + '\n' - '\tInput File Path = ' + os.path.abspath(depcode_inp['iter_inputfile']) + '\n' - '\tMaterial File Path = ' + os.path.abspath(depcode_inp['iter_matfile']) + '\n' - '\tOutput HDF5 DB Path = ' + os.path.abspath(simulation_inp['db_name']) + '\n' - ) + '\tRestart = ' + + str(simulation_inp['restart_flag']) + + '\n' + '\tTemplate File Path = ' + + os.path.abspath(depcode_inp['template_inputfile_path']) + + '\n' + '\tInput File Path = ' + + os.path.abspath(depcode_inp['iter_inputfile']) + + '\n' + '\tMaterial File Path = ' + + os.path.abspath(depcode_inp['iter_matfile']) + + '\n' + '\tOutput HDF5 DB Path = ' + + os.path.abspath(simulation_inp['db_name']) + + '\n') # Intializing objects if depcode_inp['codename'] == 'serpent': depcode = DepcodeSerpent( @@ -391,7 +404,8 @@ def run(): active_cycles=depcode_inp['active_cycles'], inactive_cycles=depcode_inp['inactive_cycles']) else: - raise ValueError(f'{depcode_inp["codename"]} is not a supported depletion code') + raise ValueError( + f'{depcode_inp["codename"]} is not a supported depletion code') simulation = Simulation( sim_name='Super test', @@ -414,8 +428,8 @@ def run(): for dep_step in range(len(msr.depl_hist)): print("\n\n\nStep #%i has been started" % (dep_step + 1)) simulation.sim_depcode.write_depcode_input(msr, - dep_step, - simulation.restart_flag) + dep_step, + simulation.restart_flag) depcode.run_depcode(cores, nodes) if dep_step == 0 and simulation.restart_flag is False: # First step # Read general simulation data which never changes diff --git a/saltproc/depcode.py b/saltproc/depcode.py index 9f725e6c1..10639e221 100644 --- a/saltproc/depcode.py +++ b/saltproc/depcode.py @@ -17,7 +17,7 @@ class Depcode(ABC): and output files, and write new input files for the depletion code. """ - #class Step_info(tb.IsDescription): + # class Step_info(tb.IsDescription): # keff_bds = tb.Float32Col((2,)) # keff_eds = tb.Float32Col((2,)) # breeding_ratio = tb.Float32Col((2,)) @@ -91,7 +91,6 @@ def read_depcode_step_param(self): it in `Depcode` object's ``param`` attributes. """ - @abstractmethod def read_dep_comp(self, read_at_end=False): """Reads the depleted material data from the depcode simulation @@ -250,8 +249,10 @@ def change_sim_par(self, template_data): % (self.template_inputfile_path), sim_param) return elif len(sim_param) < 1: - print('ERROR: Template file %s does not contain line with ' - 'simulation parameters.' % (self.template_inputfile_path)) + print( + 'ERROR: Template file %s does not contain line with ' + 'simulation parameters.' % + (self.template_inputfile_path)) return args = 'set pop %i %i %i\n' % (self.npop, self.active_cycles, self.inactive_cycles) @@ -660,7 +661,6 @@ def switch_to_next_geometry(self): f.writelines(new_data) f.close() - def write_depcode_input( self, reactor, diff --git a/saltproc/simulation.py b/saltproc/simulation.py index bbbcd280f..214aa56c1 100644 --- a/saltproc/simulation.py +++ b/saltproc/simulation.py @@ -24,9 +24,9 @@ def __init__( restart_flag=True, adjust_geo=False, compression_params=tb.Filters(complevel=9, - complib='blosc', - fletcher32=True), - ): + complib='blosc', + fletcher32=True), + ): """Initializes the Simulation object. Parameters @@ -88,8 +88,6 @@ def check_restart(self): except OSError as e: pass - - def store_after_repr(self, after_mats, waste_dict, dep_step): """Add data for waste streams [grams per depletion step] of each process to the HDF5 database after reprocessing. @@ -113,7 +111,10 @@ def store_after_repr(self, after_mats, waste_dict, dep_step): """ streams_gr = 'in_out_streams' - db = tb.open_file(self.db_path, mode='a', filters=self.compression_params) + db = tb.open_file( + self.db_path, + mode='a', + filters=self.compression_params) for mn in waste_dict.keys(): # iterate over materials mat_node = getattr(db.root.materials, mn) if not hasattr(mat_node, streams_gr): @@ -156,7 +157,7 @@ def store_after_repr(self, after_mats, waste_dict, dep_step): self.store_mat_data(after_mats, dep_step, True) db.close() - def store_mat_data(self, mats, dep_step, store_at_end = False): + def store_mat_data(self, mats, dep_step, store_at_end=False): """Initialize the HDF5/Pytables database (if it doesn't exist) or append the following data at the current depletion step to the database: burnable material composition, mass, density, volume, @@ -199,8 +200,13 @@ def store_mat_data(self, mats, dep_step, store_at_end = False): ('burnup', float) ]) - print('\nStoring material data for depletion step #%i.' % (dep_step + 1)) - db = tb.open_file(self.db_path, mode='a', filters=self.compression_params) + print( + '\nStoring material data for depletion step #%i.' % + (dep_step + 1)) + db = tb.open_file( + self.db_path, + mode='a', + filters=self.compression_params) if not hasattr(db.root, 'materials'): comp_group = db.create_group('/', 'materials', @@ -303,8 +309,11 @@ class Step_info(tb.IsDescription): delayed_neutrons_lambda_eds = tb.Float32Col((b_g, 2)) fission_mass_bds = tb.Float32Col() fission_mass_eds = tb.Float32Col() - #### Open or restore db and append data to it - db = tb.open_file(self.db_path, mode='a', filters=self.compression_params) + # Open or restore db and append data to it + db = tb.open_file( + self.db_path, + mode='a', + filters=self.compression_params) try: step_info_table = db.get_node( db.root, @@ -315,7 +324,7 @@ class Step_info(tb.IsDescription): step_info_table = db.create_table( db.root, 'simulation_parameters', - Step_info, #### self.sim_depcode.Step_info, + Step_info, # self.sim_depcode.Step_info, "Simulation parameters after each timestep") # Intializing burn_time array at the first depletion step self.burn_time = 0.0 @@ -324,10 +333,10 @@ class Step_info(tb.IsDescription): step_info = step_info_table.row # Define all values in the row - #### in depcode.py: - #### def store_step_info(step_info): + # in depcode.py: + # def store_step_info(step_info): #### """ do the below """ - #### ... + # ... step_info['keff_bds'] = self.sim_depcode.param['keff_bds'] step_info['keff_eds'] = self.sim_depcode.param['keff_eds'] step_info['breeding_ratio'] = self.sim_depcode.param[ @@ -346,7 +355,7 @@ class Step_info(tb.IsDescription): 'fission_mass_bds'] step_info['fission_mass_eds'] = self.sim_depcode.param[ 'fission_mass_eds'] - #### return step_info + # return step_info # Inject the Record value into the table step_info.append() @@ -362,9 +371,9 @@ def store_run_init_info(self): memory optimization mode (Serpent), depletion timestep size. """ - #### numpy arraw row storage for run info - #### delete and make this datatype specific - #### to Depcode subclasses + # numpy arraw row storage for run info + # delete and make this datatype specific + # to Depcode subclasses sim_info_dtype = np.dtype([ ('neutron_population', int), ('active_cycles', int), @@ -386,7 +395,7 @@ def store_run_init_info(self): sim_info_row = ( self.sim_depcode.npop, self.sim_depcode.active_cycles, - self.sim_depcode.inactive_cycles, #### delete the below + self.sim_depcode.inactive_cycles, # delete the below self.sim_depcode.sim_info['depcode_name'], self.sim_depcode.sim_info['depcode_version'], self.sim_depcode.sim_info['title'], @@ -398,13 +407,17 @@ def store_run_init_info(self): self.sim_depcode.sim_info['memory_optimization_mode'], self.sim_depcode.sim_info['depletion_timestep'] ) - #### replace with this - #### for i in sim_depcode.sim_info: + # replace with this + # for i in sim_depcode.sim_info: #### sim_info_row += (i,) - sim_info_array = np.array([sim_info_row], dtype=sim_info_dtype) #### dtype=sim_depcode.sim_info_dtype + # dtype=sim_depcode.sim_info_dtype + sim_info_array = np.array([sim_info_row], dtype=sim_info_dtype) # Open or restore db and append datat to it - db = tb.open_file(self.db_path, mode='a', filters=self.compression_params) + db = tb.open_file( + self.db_path, + mode='a', + filters=self.compression_params) try: sim_info_table = db.get_node(db.root, 'initial_depcode_siminfo') except Exception: diff --git a/saltproc/tests/integration_tests/const_repr/test_const_reproc_run.py b/saltproc/tests/integration_tests/const_repr/test_const_reproc_run.py index 38631f523..33023da31 100644 --- a/saltproc/tests/integration_tests/const_repr/test_const_reproc_run.py +++ b/saltproc/tests/integration_tests/const_repr/test_const_reproc_run.py @@ -9,8 +9,8 @@ path = os.path.realpath(__file__) sys.path.append(os.path.dirname(os.path.dirname(path))) directory = os.path.dirname(path) -db_exp_file = directory+'/2step_non_ideal_2.h5' -db_file = directory+'/data/db_saltproc.h5' +db_exp_file = directory + '/2step_non_ideal_2.h5' +db_file = directory + '/data/db_saltproc.h5' tol = 1e-9 diff --git a/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py b/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py index 28ea76129..e49d788fc 100644 --- a/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py +++ b/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py @@ -42,52 +42,53 @@ power_levels=[1.250E+09], depl_hist=[3]) + def runsim_no_reproc(simulation, reactor, nsteps): - """Run simulation sequence for integration test. No reprocessing - involved, just re-running depletion code for comparision with model - output. + """Run simulation sequence for integration test. No reprocessing + involved, just re-running depletion code for comparision with model + output. - Parameters - ---------- - reactor : `Reactor` - Contains information about power load curve and cumulative - depletion time for the integration test. - nsteps : int - Number of depletion time steps in integration test run. + Parameters + ---------- + reactor : `Reactor` + Contains information about power load curve and cumulative + depletion time for the integration test. + nsteps : int + Number of depletion time steps in integration test run. - """ + """ - ###################################################################### - # Start sequence - for dep_step in range(nsteps): - print("\nStep #%i has been started" % (dep_step + 1)) - if dep_step == 0: # First step - simulation.sim_depcode.write_depcode_input( - reactor, - dep_step, - False) - simulation.sim_depcode.run_depcode( - simulation.core_number, - simulation.node_number) - # Read general simulation data which never changes - simulation.store_run_init_info() - # Parse and store data for initial state (beginning of dep_step) - mats = simulation.sim_depcode.read_dep_comp( - False) - simulation.store_mat_data(mats, dep_step, False) - # Finish of First step - # Main sequence - else: - simulation.sim_depcode.run_depcode( - simulation.core_number, - simulation.node_number) + ###################################################################### + # Start sequence + for dep_step in range(nsteps): + print("\nStep #%i has been started" % (dep_step + 1)) + if dep_step == 0: # First step + simulation.sim_depcode.write_depcode_input( + reactor, + dep_step, + False) + simulation.sim_depcode.run_depcode( + simulation.core_number, + simulation.node_number) + # Read general simulation data which never changes + simulation.store_run_init_info() + # Parse and store data for initial state (beginning of dep_step) mats = simulation.sim_depcode.read_dep_comp( - True) + False) simulation.store_mat_data(mats, dep_step, False) - simulation.store_run_step_info() - simulation.sim_depcode.write_mat_file( - mats, - simulation.burn_time) + # Finish of First step + # Main sequence + else: + simulation.sim_depcode.run_depcode( + simulation.core_number, + simulation.node_number) + mats = simulation.sim_depcode.read_dep_comp( + True) + simulation.store_mat_data(mats, dep_step, False) + simulation.store_run_step_info() + simulation.sim_depcode.write_mat_file( + mats, + simulation.burn_time) @pytest.mark.slow diff --git a/saltproc/tests/test_app.py b/saltproc/tests/test_app.py index 2ae6b33a2..3888337cd 100644 --- a/saltproc/tests/test_app.py +++ b/saltproc/tests/test_app.py @@ -25,10 +25,13 @@ def test_read_main_input(): assert app.depcode_inp['npop'] == 50 assert app.depcode_inp['active_cycles'] == 20 assert app.depcode_inp['active_cycles'] == 20 - assert app.simulation_inp['db_name'] == directory + '/./data/db_saltproc.h5' - assert app.depcode_inp['geo_file_paths'] == [ directory + '/./347_base.ini'] + assert app.simulation_inp['db_name'] == directory + \ + '/./data/db_saltproc.h5' + assert app.depcode_inp['geo_file_paths'] == [directory + '/./347_base.ini'] assert app.simulation_inp['restart_flag'] is False - np.testing.assert_equal(app.reactor_inp['power_levels'], [1.250E+9, 1.250E+9]) + np.testing.assert_equal( + app.reactor_inp['power_levels'], [ + 1.250E+9, 1.250E+9]) np.testing.assert_equal(app.reactor_inp['depl_hist'], [5, 10]) diff --git a/saltproc/tests/test_depcode.py b/saltproc/tests/test_depcode.py index 1b43f7d2b..166b2018d 100644 --- a/saltproc/tests/test_depcode.py +++ b/saltproc/tests/test_depcode.py @@ -12,11 +12,18 @@ # global class object directory = os.path.dirname(path) -serpent = DepcodeSerpent(exec_path='sss2', - template_inputfile_path=directory + '/template.inp', - iter_inputfile=directory + '/test', - iter_matfile=directory + '/material', - geo_files=[os.path.join(directory, '../test_geo.inp')]) +serpent = DepcodeSerpent( + exec_path='sss2', + template_inputfile_path=directory + + '/template.inp', + iter_inputfile=directory + + '/test', + iter_matfile=directory + + '/material', + geo_files=[ + os.path.join( + directory, + '../test_geo.inp')]) msr = Reactor(volume=1.0, power_levels=[1.250E+09, 1.250E+09, 5.550E+09], @@ -24,6 +31,7 @@ geo_test_input = directory + '/test_geometry_switch.inp' + def test_get_tra_or_dec(): serpent.get_tra_or_dec(serpent.iter_inputfile) assert serpent.iso_map[380880] == '38088.09c' @@ -47,7 +55,8 @@ def test_sss_meta_zzz(): def test_read_depcode_template(): - template_str = serpent.read_depcode_template(serpent.template_inputfile_path) + template_str = serpent.read_depcode_template( + serpent.template_inputfile_path) assert template_str[6] == '%therm zrh_h 900 hzr05.32t hzr06.32t\n' assert template_str[18] == 'set pop 30 20 10\n' assert template_str[22] == 'set bumode 2\n' @@ -196,6 +205,7 @@ def test_write_depcode_input(): serpent.iter_inputfile = iter_inputfile_old + def test_switch_to_next_geometry(): shutil.copy2(geo_test_input, serpent.iter_inputfile + '_test') iter_inputfile_old = serpent.iter_inputfile diff --git a/saltproc/tests/test_simulation.py b/saltproc/tests/test_simulation.py index 6a00acdfc..01c5e2038 100644 --- a/saltproc/tests/test_simulation.py +++ b/saltproc/tests/test_simulation.py @@ -29,6 +29,7 @@ node_number=1, db_path=directory + '/test_db.h5') + def test_check_switch_geo_trigger(): """ This unit test checks that ``check_switch_geo_trigger`` functions @@ -47,6 +48,7 @@ def test_check_switch_geo_trigger(): assert simulation.check_switch_geo_trigger("two o clock", switch_times) is True + def test_store_after_repr(): """ This unit test checks that select entries that ``store_after_repr_()` @@ -84,13 +86,13 @@ def test_store_after_repr(): simulation.db_path = db_file # store data - simulation.store_mat_data(mats,0,False) + simulation.store_mat_data(mats, 0, False) simulation.store_after_repr(mats, m_after_refill, 0) # read stored data try: db = tb.open_file(simulation.db_path, mode='r', - filters=simulation.compression_params) + filters=simulation.compression_params) except Exception: print('Unable to assign correct value to db. See error stack for more info.') @@ -144,7 +146,7 @@ def test_store_after_repr(): os.remove(db_file) simulation.db_path = db_path_old raise KeyError("incorrect key") - except: + except BaseException: db.close() os.remove(db_file) simulation.db_path = db_path_old @@ -156,9 +158,10 @@ def test_store_after_repr(): # delete test file os.remove(db_file) - #use original db path + # use original db path simulation.db_path = db_path_old + def test_store_mat_data(): """ This unit test checks that select entries that ``store_mat_data_()` @@ -190,7 +193,7 @@ def test_store_mat_data(): # read stored data try: db = tb.open_file(simulation.db_path, mode='r', - filters=simulation.compression_params) + filters=simulation.compression_params) except Exception: print('Unable to assign correct value to db. See error stack for more info.') @@ -270,7 +273,7 @@ def test_store_mat_data(): os.remove(db_file) simulation.db_path = db_path_old raise KeyError("incorrect key") - except: + except BaseException: db.close() os.remove(db_file) simulation.db_path = db_path_old @@ -282,9 +285,10 @@ def test_store_mat_data(): # delete test file os.remove(db_file) - #use original db path + # use original db path simulation.db_path = db_path_old + def test_store_run_init_info(): """ This unit test checks that the entries ``store_run_init_info()` @@ -308,12 +312,11 @@ def test_store_run_init_info(): # read stored data try: db = tb.open_file(simulation.db_path, mode='r', - filters=simulation.compression_params) + filters=simulation.compression_params) except Exception: db.close() print('Unable to assign correct value to db. See error stack for more info.') - tinit_info = db.root.initial_depcode_siminfo[0] try: @@ -340,7 +343,7 @@ def test_store_run_init_info(): os.remove(db_file) simulation.db_path = db_path_old raise KeyError("incorrect key") - except: + except BaseException: db.close() os.remove(db_file) simulation.db_path = db_path_old @@ -354,9 +357,10 @@ def test_store_run_init_info(): # delete test file os.remove(db_file) - #use original db path + # use original db path simulation.db_path = db_path_old + def test_store_run_step_info(): """ This unit test checks that the entries ``store_run_step_info()` @@ -379,7 +383,7 @@ def test_store_run_step_info(): # read stored data try: db = tb.open_file(simulation.db_path, mode='r', - filters=simulation.compression_params) + filters=simulation.compression_params) except Exception: print('Unable to assign correct value to db. See error stack for more info.') @@ -391,7 +395,7 @@ def test_store_run_step_info(): step_info['breeding_ratio'].astype('float32')) assert tstep_info[2] == simulation.burn_time assert np.array_equal(tstep_info[3], - step_info['delayed_neutrons_lambda'].\ + step_info['delayed_neutrons_lambda']. astype('float32')) assert tstep_info[4] == step_info['fission_mass_bds'].astype('float32') assert tstep_info[5] == step_info['fission_mass_eds'].astype('float32') @@ -412,7 +416,7 @@ def test_store_run_step_info(): os.remove(db_file) simulation.db_path = db_path_old raise KeyError("incorrect key") - except: + except BaseException: db.close() os.remove(db_file) simulation.db_path = db_path_old @@ -424,10 +428,9 @@ def test_store_run_step_info(): # delete test file os.remove(db_file) - #use original db path + # use original db path simulation.db_path = db_path_old - def test_read_k_eds_delta(): assert simulation.read_k_eds_delta(7) is False From 4e7e820fd11dc6165be41df3b5befb913ee54fba Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 28 Jan 2022 11:22:39 -0600 Subject: [PATCH 095/118] more pep8 fixes; remove cruft --- saltproc/app.py | 1 - saltproc/simulation.py | 14 +------------- saltproc/tests/test_simulation.py | 12 ++++++++---- 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/saltproc/app.py b/saltproc/app.py index 23947e824..fbe18349a 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -12,7 +12,6 @@ import copy import json import jsonschema -#from saltproc.saltprocinputschema import input_schema from collections import OrderedDict import gc import networkx as nx diff --git a/saltproc/simulation.py b/saltproc/simulation.py index 214aa56c1..d65b7cd56 100644 --- a/saltproc/simulation.py +++ b/saltproc/simulation.py @@ -294,9 +294,6 @@ def store_run_step_info(self): # Initialize beta groups number b_g = len(self.sim_depcode.param['beta_eff']) # numpy array row storage for run info - - # delete this and define class in - # Depcode subclasses class Step_info(tb.IsDescription): keff_bds = tb.Float32Col((2,)) keff_eds = tb.Float32Col((2,)) @@ -333,10 +330,6 @@ class Step_info(tb.IsDescription): step_info = step_info_table.row # Define all values in the row - # in depcode.py: - # def store_step_info(step_info): - #### """ do the below """ - # ... step_info['keff_bds'] = self.sim_depcode.param['keff_bds'] step_info['keff_eds'] = self.sim_depcode.param['keff_eds'] step_info['breeding_ratio'] = self.sim_depcode.param[ @@ -355,7 +348,6 @@ class Step_info(tb.IsDescription): 'fission_mass_bds'] step_info['fission_mass_eds'] = self.sim_depcode.param[ 'fission_mass_eds'] - # return step_info # Inject the Record value into the table step_info.append() @@ -407,12 +399,8 @@ def store_run_init_info(self): self.sim_depcode.sim_info['memory_optimization_mode'], self.sim_depcode.sim_info['depletion_timestep'] ) - # replace with this - # for i in sim_depcode.sim_info: - #### sim_info_row += (i,) - - # dtype=sim_depcode.sim_info_dtype sim_info_array = np.array([sim_info_row], dtype=sim_info_dtype) + # Open or restore db and append datat to it db = tb.open_file( self.db_path, diff --git a/saltproc/tests/test_simulation.py b/saltproc/tests/test_simulation.py index 01c5e2038..538d59e33 100644 --- a/saltproc/tests/test_simulation.py +++ b/saltproc/tests/test_simulation.py @@ -94,7 +94,8 @@ def test_store_after_repr(): db = tb.open_file(simulation.db_path, mode='r', filters=simulation.compression_params) except Exception: - print('Unable to assign correct value to db. See error stack for more info.') + print('Unable to assign correct value to db.\ + See error stack for more info.') tmats = db.root.materials tfuel_st = tmats.fuel.in_out_streams @@ -195,7 +196,8 @@ def test_store_mat_data(): db = tb.open_file(simulation.db_path, mode='r', filters=simulation.compression_params) except Exception: - print('Unable to assign correct value to db. See error stack for more info.') + print('Unable to assign correct value to db.\ + See error stack for more info.') tmats = db.root.materials @@ -315,7 +317,8 @@ def test_store_run_init_info(): filters=simulation.compression_params) except Exception: db.close() - print('Unable to assign correct value to db. See error stack for more info.') + print('Unable to assign correct value to db.\ + See error stack for more info.') tinit_info = db.root.initial_depcode_siminfo[0] @@ -385,7 +388,8 @@ def test_store_run_step_info(): db = tb.open_file(simulation.db_path, mode='r', filters=simulation.compression_params) except Exception: - print('Unable to assign correct value to db. See error stack for more info.') + print('Unable to assign correct value to db.\ + See error stack for more info.') tstep_info = db.root.simulation_parameters[0] try: From a773119d7c4216b7e29a9200b128e4e545e3af72 Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 28 Jan 2022 11:25:01 -0600 Subject: [PATCH 096/118] even more pep8 fixes --- saltproc/simulation.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/saltproc/simulation.py b/saltproc/simulation.py index d65b7cd56..64998e222 100644 --- a/saltproc/simulation.py +++ b/saltproc/simulation.py @@ -357,10 +357,10 @@ class Step_info(tb.IsDescription): def store_run_init_info(self): """Adds the following depletion code and SaltProc simulation parameters to the database: - neutron population, active cycles, inactive cycles, depletion code version - simulation title, depetion code input file path, depletion code working - directory, cross section data path, # of OMP threads, # of MPI tasks, - memory optimization mode (Serpent), depletion timestep size. + neutron population, active cycles, inactive cycles, depletion code + version simulation title, depetion code input file path, depletion code + working directory, cross section data path, # of OMP threads, # of MPI + tasks, memory optimization mode (Serpent), depletion timestep size. """ # numpy arraw row storage for run info From b33b24743e7eb19a786cdaebcf759274685df8e4 Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 28 Jan 2022 11:50:57 -0600 Subject: [PATCH 097/118] fix extra line --- saltproc/simulation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saltproc/simulation.py b/saltproc/simulation.py index 64998e222..3e5dfa84f 100644 --- a/saltproc/simulation.py +++ b/saltproc/simulation.py @@ -78,6 +78,7 @@ def check_restart(self): ---------- restart_flag : bool Is the current simulation restarted? + """ if not self.restart_flag: try: @@ -108,7 +109,6 @@ def store_after_repr(self, after_mats, waste_dict, dep_step): dep_step : int Current depletion time step. - """ streams_gr = 'in_out_streams' db = tb.open_file( From a6eb03beb122c1c866c814e50d65129b3dd20d14 Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 28 Jan 2022 15:48:29 -0600 Subject: [PATCH 098/118] remove cruft from depcode.py --- saltproc/depcode.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/saltproc/depcode.py b/saltproc/depcode.py index 10639e221..607556893 100644 --- a/saltproc/depcode.py +++ b/saltproc/depcode.py @@ -17,18 +17,6 @@ class Depcode(ABC): and output files, and write new input files for the depletion code. """ - # class Step_info(tb.IsDescription): - # keff_bds = tb.Float32Col((2,)) - # keff_eds = tb.Float32Col((2,)) - # breeding_ratio = tb.Float32Col((2,)) - # step_execution_time = tb.Float32Col() - # cumulative_time_at_eds = tb.Float32Col() - # power_level = tb.Float32Col() - # memory_usage = tb.Float32Col() - # beta_eff_eds = tb.Float32Col((b_g, 2)) - # delayed_neutrons_lambda_eds = tb.Float32Col((b_g, 2)) - # fission_mass_bds = tb.Float32Col() - # fission_mass_eds = tb.Float32Col() def __init__(self, codename, From 849f186f72b9ad203401602ef9003cafc3c6ee9a Mon Sep 17 00:00:00 2001 From: yardasol Date: Wed, 2 Feb 2022 15:36:34 -0600 Subject: [PATCH 099/118] remove reference to serpent in App.parse_arguments --- saltproc/app.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/saltproc/app.py b/saltproc/app.py index fbe18349a..30a84ae28 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -29,9 +29,9 @@ def parse_arguments(): Returns -------- n: int - Number of nodes for use in Serpent simulation. + Number of nodes for use in depletion code simulation. d: int - Number of cores for use in Serpent simulation. + Number of cores for use in depletion code simulation. i: str Path and name of main SaltProc input file (json format). @@ -40,11 +40,13 @@ def parse_arguments(): parser.add_argument('-n', # Number of nodes to use type=int, default=1, - help='number of cluster nodes to use in Serpent') + help='number of cluster nodes to use in \ + depletion code simulation') parser.add_argument('-d', # Number of nodes to use type=int, default=1, - help='number of threads to use in Serpent') + help='number of threads to use in \ + depletion code simulation') parser.add_argument('-i', # main input file type=str, default=None, From 83a8e17624cc1de74dd8b3c91a2c13d1bbace558 Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 4 Feb 2022 11:05:23 -0600 Subject: [PATCH 100/118] typo fix in docstring of test_check_switch_geo_trigger --- saltproc/tests/test_simulation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saltproc/tests/test_simulation.py b/saltproc/tests/test_simulation.py index 538d59e33..07f82219f 100644 --- a/saltproc/tests/test_simulation.py +++ b/saltproc/tests/test_simulation.py @@ -33,7 +33,7 @@ def test_check_switch_geo_trigger(): """ This unit test checks that ``check_switch_geo_trigger`` functions - consistent with its docstring. + consistently with its docstring. """ switch_times = [1.0, 3, -31, 86.23333, 1e-16, 2e-18, "two o clock"] From ad86976af162427f5c17e47673b27fbdc5f50889 Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 4 Feb 2022 11:27:24 -0600 Subject: [PATCH 101/118] make nsteps in runsim_no_reproc match its docstring definition --- .../tests/integration_tests/no_repro/test_no_reproc_run.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py b/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py index e49d788fc..57008e80a 100644 --- a/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py +++ b/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py @@ -60,7 +60,7 @@ def runsim_no_reproc(simulation, reactor, nsteps): ###################################################################### # Start sequence - for dep_step in range(nsteps): + for dep_step in range(nsteps-1): print("\nStep #%i has been started" % (dep_step + 1)) if dep_step == 0: # First step simulation.sim_depcode.write_depcode_input( @@ -94,7 +94,7 @@ def runsim_no_reproc(simulation, reactor, nsteps): @pytest.mark.slow # @pytest.mark.skip def test_integration_3step_saltproc_no_reproc_heavy(): - runsim_no_reproc(simulation, tap, 2) + runsim_no_reproc(simulation, tap, 3) saltproc_out = sss_file + '_dep.m' dep_ser = serpent.parse_dep( directory + '/serpent_9d_dep.m', From cb2c556566df9a8c1efb8584022f801861a37dbd Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 4 Feb 2022 11:57:21 -0600 Subject: [PATCH 102/118] remove requirement for depsteps to match implied behavior in app.py --- saltproc/input_schema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saltproc/input_schema.json b/saltproc/input_schema.json index 152744fa4..4843d43db 100644 --- a/saltproc/input_schema.json +++ b/saltproc/input_schema.json @@ -117,5 +117,5 @@ "required": ["volume", "mass_flowrate", "power_levels", "depl_hist"] } }, - "required": ["proc_input_file", "dot_input_file", "output_path", "depsteps", "depcode", "simulation", "reactor"] + "required": ["proc_input_file", "dot_input_file", "output_path", "depcode", "simulation", "reactor"] } From 2d83302193dbd6c5127806535bf7a93319bf2fcd Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 4 Feb 2022 12:00:02 -0600 Subject: [PATCH 103/118] fix comment referring to cores as nodes --- saltproc/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saltproc/app.py b/saltproc/app.py index 30a84ae28..0255598e6 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -42,7 +42,7 @@ def parse_arguments(): default=1, help='number of cluster nodes to use in \ depletion code simulation') - parser.add_argument('-d', # Number of nodes to use + parser.add_argument('-d', # Number of cores to use type=int, default=1, help='number of threads to use in \ From ca5a8c41b3030ec23525b016305e766c293ce46e Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 4 Feb 2022 12:12:46 -0600 Subject: [PATCH 104/118] docstring format fixes --- saltproc/app.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/saltproc/app.py b/saltproc/app.py index 0255598e6..adbd1166c 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -24,10 +24,10 @@ def parse_arguments(): """Parses arguments from command line. Parameters - ----------- + ---------- Returns - -------- + ------- n: int Number of nodes for use in depletion code simulation. d: int @@ -59,7 +59,7 @@ def read_main_input(main_inp_file): """Reads main SaltProc input file (json format). Parameters - ----------- + ---------- main_inp_file : str Path to SaltProc main input file and name of this file. """ @@ -214,7 +214,7 @@ def read_dot(dot_file): Path to `.dot` file with reprocessing system structure. Returns - -------- + ------- mat_name : str Name of burnable material which reprocessing scheme described in `.dot` file. @@ -240,7 +240,7 @@ def reprocessing(mats): """Applies reprocessing scheme to burnable materials. Parameters - ----------- + ---------- mats : dict of str to Materialflow Dictionary that contains `Materialflow` objects with burnable material data right after irradiation in the core. @@ -251,7 +251,7 @@ def reprocessing(mats): `Materialflow` object holding composition and properties. Returns - -------- + ------- waste : dict of str to Materialflow ``key`` @@ -323,16 +323,14 @@ def refill(mats, extracted_mass, waste_dict): """Makes up material loss in removal processes by adding fresh fuel. Parameters - ----------- + ---------- mats : dict of str to Materialflow ``key`` Name of burnable material. ``value`` `Materialflow` object after performing all removals. - extracted_mass: dict of str to float - - ``key`` + extracted_mass : dict of str to float Name of burnable material. ``value`` Mass removed as waste in reprocessing function for each material. @@ -344,7 +342,7 @@ def refill(mats, extracted_mass, waste_dict): `Materialflow` object containing waste streams data. Returns - -------- + ------- refilled_mats: dict of str to Materialflow Dictionary that contains `Materialflow` objects. From ae7e20adbcc70f835d7e3aa485ba0de74794957c Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 4 Feb 2022 12:15:35 -0600 Subject: [PATCH 105/118] print 'database' instead of 'DB' --- saltproc/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saltproc/app.py b/saltproc/app.py index adbd1166c..88d0fa92b 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -388,7 +388,7 @@ def run(): '\tMaterial File Path = ' + os.path.abspath(depcode_inp['iter_matfile']) + '\n' - '\tOutput HDF5 DB Path = ' + + '\tOutput HDF5 database Path = ' + os.path.abspath(simulation_inp['db_name']) + '\n') # Intializing objects From 781f76ff9c07bbea31b7f8a77d1724f9ced4eb75 Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 4 Feb 2022 12:46:00 -0600 Subject: [PATCH 106/118] fix typo in input_schema.json --- saltproc/input_schema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saltproc/input_schema.json b/saltproc/input_schema.json index 4843d43db..a97fd686a 100644 --- a/saltproc/input_schema.json +++ b/saltproc/input_schema.json @@ -41,7 +41,7 @@ "description": "Name of depletion code input file for depletion code rerunning", "type": "string" }, "iter_matfile": { - "description": "Name of iteratvie, rewritable material file for depletion code rerunning", + "description": "Name of iterable, rewritable material file for depletion code rerunning", "type": "string" }, "npop": { "description": "Number of neutrons per generation", From fdc48420f9fa1aa0fb1247b08bc6a67a0fed629c Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 4 Feb 2022 13:03:42 -0600 Subject: [PATCH 107/118] input params: depsteps->num_depstes, depl_hist -> dep_step_length_cumulative --- examples/msbr/msbr_main.json | 4 +-- examples/tap/tap_main.json | 4 +-- saltproc/app.py | 30 +++++++++---------- saltproc/depcode.py | 6 ++-- saltproc/input_schema.json | 10 +++---- saltproc/reactor.py | 6 ++-- .../const_repr/tap_main_test.json | 4 +-- .../no_repro/test_no_reproc_run.py | 2 +- saltproc/tests/test_app.py | 2 +- saltproc/tests/test_depcode.py | 4 +-- 10 files changed, 36 insertions(+), 36 deletions(-) diff --git a/examples/msbr/msbr_main.json b/examples/msbr/msbr_main.json index 4ac5f64af..7355f9be2 100644 --- a/examples/msbr/msbr_main.json +++ b/examples/msbr/msbr_main.json @@ -2,7 +2,7 @@ "proc_input_file": "msbr_objects.json", "dot_input_file": "msbr.dot", "output_path": "./data", - "depsteps": 12, + "num_depsteps": 12, "depcode": { "codename": "serpent", "exec_path": "sss2", @@ -24,6 +24,6 @@ "volume": 1.0, "mass_flowrate": 9920000, "power_levels": [ 2250000000 ], - "depl_hist": [ 3 ] + "dep_step_length_cumulative": [ 3 ] } } diff --git a/examples/tap/tap_main.json b/examples/tap/tap_main.json index 754f10923..08cb8e0d6 100644 --- a/examples/tap/tap_main.json +++ b/examples/tap/tap_main.json @@ -2,7 +2,7 @@ "proc_input_file": "tap_objects.json", "dot_input_file": "tap.dot", "output_path": "./data", - "depsteps": 3, + "num_depsteps": 3, "depcode": { "codename": "serpent", "exec_path": "sss2", @@ -40,6 +40,6 @@ "volume": 1.0, "mass_flowrate": 9920000, "power_levels": [ 1250000000 ], - "depl_hist": [ 2 ] + "dep_step_length_cumulative": [ 2 ] } } diff --git a/saltproc/app.py b/saltproc/app.py index 88d0fa92b..6492d508f 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -81,7 +81,7 @@ def read_main_input(main_inp_file): input_path = os.path.join(path_prefix, os.path.dirname(f.name)) # Saltproc settings - global spc_inp_file, dot_inp_file, output_path, depsteps + global spc_inp_file, dot_inp_file, output_path, num_depsteps spc_inp_file = os.path.join( os.path.dirname(f.name), j['proc_input_file']) @@ -89,7 +89,7 @@ def read_main_input(main_inp_file): os.path.dirname(f.name), j['dot_input_file']) output_path = j['output_path'] - depsteps = j['depsteps'] + num_depsteps = j['num_depsteps'] # Global output path output_path = os.path.join(input_path, output_path) @@ -120,20 +120,20 @@ def read_main_input(main_inp_file): output_path, simulation_inp['db_name']) simulation_inp['db_name'] = db_name - depl_hist = reactor_inp['depl_hist'] + dep_step_length_cumulative = reactor_inp['dep_step_length_cumulative'] power_levels = reactor_inp['power_levels'] - if depsteps is not None and len(depl_hist) == 1: - if depsteps < 0.0 or not int: + if num_depsteps is not None and len(dep_step_length_cumulative) == 1: + if num_depsteps < 0.0 or not int: raise ValueError('Depletion step interval cannot be negative') else: - step = int(depsteps) - deptot = float(depl_hist[0]) * step - depl_hist = np.linspace(float(depl_hist[0]), deptot, num=step) - power_levels = float(power_levels[0]) * np.ones_like(depl_hist) - reactor_inp['depl_hist'] = depl_hist + step = int(num_depsteps) + deptot = float(dep_step_length_cumulative[0]) * step + dep_step_length_cumulative = np.linspace(float(dep_step_length_cumulative[0]), deptot, num=step) + power_levels = float(power_levels[0]) * np.ones_like(dep_step_length_cumulative) + reactor_inp['dep_step_length_cumulative'] = dep_step_length_cumulative reactor_inp['power_levels'] = power_levels - elif depsteps is None and isinstance(depl_hist, (np.ndarray, list)): - if len(depl_hist) != len(power_levels): + elif num_depsteps is None and isinstance(dep_step_length_cumulative, (np.ndarray, list)): + if len(dep_step_length_cumulative) != len(power_levels): raise ValueError( 'Depletion step list and power list shape mismatch') @@ -419,12 +419,12 @@ def run(): volume=reactor_inp['volume'], mass_flowrate=reactor_inp['mass_flowrate'], power_levels=reactor_inp['power_levels'], - depl_hist=reactor_inp['depl_hist']) + dep_step_length_cumulative=reactor_inp['dep_step_length_cumulative']) # Check: Restarting previous simulation or starting new? simulation.check_restart() # Run sequence # Start sequence - for dep_step in range(len(msr.depl_hist)): + for dep_step in range(len(msr.dep_step_length_cumulative)): print("\n\n\nStep #%i has been started" % (dep_step + 1)) simulation.sim_depcode.write_depcode_input(msr, dep_step, @@ -477,4 +477,4 @@ def run(): '''print("Reactor object data.\n", msr.mass_flowrate, msr.power_levels, - msr.depl_hist)''' + msr.dep_step_length_cumulative)''' diff --git a/saltproc/depcode.py b/saltproc/depcode.py index 607556893..c5e492157 100644 --- a/saltproc/depcode.py +++ b/saltproc/depcode.py @@ -538,10 +538,10 @@ def replace_burnup_parameters( line_idx = 8 # burnup setting line index by default current_depstep_power = reactor.power_levels[current_depstep_idx] if current_depstep_idx == 0: - current_depstep = reactor.depl_hist[0] + current_depstep = reactor.dep_step_length_cumulative[0] else: - current_depstep = reactor.depl_hist[current_depstep_idx] - \ - reactor.depl_hist[current_depstep_idx - 1] + current_depstep = reactor.dep_step_length_cumulative[current_depstep_idx] - \ + reactor.dep_step_length_cumulative[current_depstep_idx - 1] for line in template_data: if line.startswith('set power '): line_idx = template_data.index(line) diff --git a/saltproc/input_schema.json b/saltproc/input_schema.json index a97fd686a..a7f4840b0 100644 --- a/saltproc/input_schema.json +++ b/saltproc/input_schema.json @@ -1,4 +1,4 @@ -{ + "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://github.com/arfc/saltproc", "title": "SaltProc input file schema", @@ -19,7 +19,7 @@ "type": "string", "pattern": "^\\.\\/(.*)$" }, - "depsteps": { + "num_depsteps": { "description": "Number of steps for constant power and depletion interval case", "type": "number" }, @@ -105,8 +105,8 @@ "minItems": 1, "uniqueItems": false }, - "depl_hist": { - "description": "Depletion step interval or cumulative time (end of step) [d]", + "dep_step_length_cumulative": { + "description": "Depletion step length(s) (cumulative) [d]", "type": "array", "items": { "type": "number", "minimum": 0}, @@ -114,7 +114,7 @@ "uniqueItems": false } }, - "required": ["volume", "mass_flowrate", "power_levels", "depl_hist"] + "required": ["volume", "mass_flowrate", "power_levels", "dep_step_length_cumulative"] } }, "required": ["proc_input_file", "dot_input_file", "output_path", "depcode", "simulation", "reactor"] diff --git a/saltproc/reactor.py b/saltproc/reactor.py index 80404ad88..2d8dbcce2 100644 --- a/saltproc/reactor.py +++ b/saltproc/reactor.py @@ -7,7 +7,7 @@ def __init__(self, volume=1.0, mass_flowrate=0.0, power_levels=[0.0], - depl_hist=[1]): + dep_step_length_cumulative=[1]): """Initializes the class. Parameters @@ -18,7 +18,7 @@ def __init__(self, Total mass flowrate through reactor core (g/s). power_levels : array [:math:`N_{steps}` x1] Normalized power level for each depletion step (W). - depl_hist : array [:math:`N_{steps}` x1] + dep_step_length_cumulative : array [:math:`N_{steps}` x1] Cumulative depletion time (d). """ @@ -26,4 +26,4 @@ def __init__(self, self.volume = volume self.mass_flowrate = mass_flowrate self.power_levels = power_levels - self.depl_hist = depl_hist + self.dep_step_length_cumulative = dep_step_length_cumulative diff --git a/saltproc/tests/integration_tests/const_repr/tap_main_test.json b/saltproc/tests/integration_tests/const_repr/tap_main_test.json index a67571f3c..86d50f528 100644 --- a/saltproc/tests/integration_tests/const_repr/tap_main_test.json +++ b/saltproc/tests/integration_tests/const_repr/tap_main_test.json @@ -2,7 +2,7 @@ "proc_input_file": "input_5leu.json", "dot_input_file": "tap.dot", "output_path": "./data", - "depsteps": 2, + "num_depsteps": 2, "depcode": { "codename": "serpent", "exec_path": "sss2", @@ -24,6 +24,6 @@ "volume": 1.0, "mass_flowrate": 9.92E+6, "power_levels": [ 1.250E+9 ], - "depl_hist": [ 5 ] + "dep_step_length_cumulative": [ 5 ] } } diff --git a/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py b/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py index 57008e80a..5dd0a6cff 100644 --- a/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py +++ b/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py @@ -40,7 +40,7 @@ tap = Reactor(volume=1.0, power_levels=[1.250E+09], - depl_hist=[3]) + dep_step_length_cumulative=[3]) def runsim_no_reproc(simulation, reactor, nsteps): diff --git a/saltproc/tests/test_app.py b/saltproc/tests/test_app.py index 3888337cd..fa9c4d9b0 100644 --- a/saltproc/tests/test_app.py +++ b/saltproc/tests/test_app.py @@ -32,7 +32,7 @@ def test_read_main_input(): np.testing.assert_equal( app.reactor_inp['power_levels'], [ 1.250E+9, 1.250E+9]) - np.testing.assert_equal(app.reactor_inp['depl_hist'], [5, 10]) + np.testing.assert_equal(app.reactor_inp['dep_step_length_cumulative'], [5, 10]) def test_read_processes_from_input(): diff --git a/saltproc/tests/test_depcode.py b/saltproc/tests/test_depcode.py index 166b2018d..51872c07c 100644 --- a/saltproc/tests/test_depcode.py +++ b/saltproc/tests/test_depcode.py @@ -27,7 +27,7 @@ msr = Reactor(volume=1.0, power_levels=[1.250E+09, 1.250E+09, 5.550E+09], - depl_hist=[111.111, 2101.9, 3987.5]) + dep_step_length_cumulative=[111.111, 2101.9, 3987.5]) geo_test_input = directory + '/test_geometry_switch.inp' @@ -160,7 +160,7 @@ def test_insert_path_to_geometry(): def test_replace_burnup_parameters(): - time = msr.depl_hist.copy() + time = msr.dep_step_length_cumulative.copy() time.insert(0, 0.0) depsteps = np.diff(time) d = serpent.read_depcode_template(serpent.template_inputfile_path) From 1fafe3481e0bbb0ee2aca834c6f72c6be7b9ed8c Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 4 Feb 2022 13:05:57 -0600 Subject: [PATCH 108/118] fix typo in test_app.py --- saltproc/tests/test_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saltproc/tests/test_app.py b/saltproc/tests/test_app.py index fa9c4d9b0..8426e45e9 100644 --- a/saltproc/tests/test_app.py +++ b/saltproc/tests/test_app.py @@ -24,7 +24,7 @@ def test_read_main_input(): assert app.depcode_inp['codename'] == "serpent" assert app.depcode_inp['npop'] == 50 assert app.depcode_inp['active_cycles'] == 20 - assert app.depcode_inp['active_cycles'] == 20 + assert app.depcode_inp['inactive_cycles'] == 20 assert app.simulation_inp['db_name'] == directory + \ '/./data/db_saltproc.h5' assert app.depcode_inp['geo_file_paths'] == [directory + '/./347_base.ini'] From a272b5613c9a23b5e4eb820394173d11b10ac2ef Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 4 Feb 2022 13:07:02 -0600 Subject: [PATCH 109/118] apply changes from fdc4842 to test.json --- saltproc/tests/test.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/saltproc/tests/test.json b/saltproc/tests/test.json index 45e84f03b..207f0efa9 100644 --- a/saltproc/tests/test.json +++ b/saltproc/tests/test.json @@ -2,7 +2,7 @@ "proc_input_file": "processes.json", "dot_input_file": "test.dot", "output_path": "./data", - "depsteps": 2, + "num_depsteps": 2, "depcode": { "codename": "serpent", "exec_path": "sss2", @@ -24,6 +24,6 @@ "volume": 1.0, "mass_flowrate": 9.92E+6, "power_levels": [ 1.250E+9 ], - "depl_hist": [ 5 ] + "dep_step_length_cumulative": [ 5 ] } } From 46768804e7cbabc8e4cd65b8fda680d5fde6f988 Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 4 Feb 2022 13:15:09 -0600 Subject: [PATCH 110/118] sss_meta_zzz -> convert_nuclide_name_serpent_to_zam --- saltproc/depcode.py | 4 ++-- saltproc/tests/test_depcode.py | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/saltproc/depcode.py b/saltproc/depcode.py index c5e492157..0335e58ec 100644 --- a/saltproc/depcode.py +++ b/saltproc/depcode.py @@ -332,7 +332,7 @@ def get_nuc_name(self, nuc_code): nuc_name = pyname.name(nuc_code)[:-1] + 'm' + str(meta_flag) else: nuc_name = pyname.name(nuc_code) - nuc_zzaaam = self.sss_meta_zzz(pyname.zzaaam(nuc_code)) + nuc_zzaaam = self.convert_nuclide_name_serpent_to_zam(pyname.zzaaam(nuc_code)) return nuc_name, nuc_zzaaam def get_tra_or_dec(self, input_file): @@ -596,7 +596,7 @@ def run_depcode(self, cores, nodes): % (self.codename)) print('Finished Serpent2 Run') - def sss_meta_zzz(self, nuc_code): + def convert_nuclide_name_serpent_to_zam(self, nuc_code): """Checks Serpent2-specific meta stable-flag for zzaaam. For instance, 47310 instead of 471101 for `Ag-110m1`. Metastable isotopes represented with `aaa` started with ``3``. diff --git a/saltproc/tests/test_depcode.py b/saltproc/tests/test_depcode.py index 51872c07c..f0164c6c9 100644 --- a/saltproc/tests/test_depcode.py +++ b/saltproc/tests/test_depcode.py @@ -44,14 +44,14 @@ def test_get_tra_or_dec(): assert serpent.iso_map[410911] == '410911' -def test_sss_meta_zzz(): - assert serpent.sss_meta_zzz(47310) == 471101 - assert serpent.sss_meta_zzz(95342) == 952421 - assert serpent.sss_meta_zzz(61348) == 611481 - assert serpent.sss_meta_zzz(52327) == 521271 - assert serpent.sss_meta_zzz(1001) == 1001 - assert serpent.sss_meta_zzz(1002) == 1002 - assert serpent.sss_meta_zzz(48315) == 481151 +def test_convert_nuclide_name_serpent_to_zam(): + assert serpent.convert_nuclide_name_serpent_to_zam(47310) == 471101 + assert serpent.convert_nuclide_name_serpent_to_zam(95342) == 952421 + assert serpent.convert_nuclide_name_serpent_to_zam(61348) == 611481 + assert serpent.convert_nuclide_name_serpent_to_zam(52327) == 521271 + assert serpent.convert_nuclide_name_serpent_to_zam(1001) == 1001 + assert serpent.convert_nuclide_name_serpent_to_zam(1002) == 1002 + assert serpent.convert_nuclide_name_serpent_to_zam(48315) == 481151 def test_read_depcode_template(): From 3527e7d941481ac27a3e34745de1f6ff1cbd29fa Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 4 Feb 2022 13:17:28 -0600 Subject: [PATCH 111/118] get_tra_or_dec -> create_nuclide_name_map_zam_to_serpent --- saltproc/depcode.py | 4 ++-- saltproc/tests/test_depcode.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/saltproc/depcode.py b/saltproc/depcode.py index 0335e58ec..120e6ee33 100644 --- a/saltproc/depcode.py +++ b/saltproc/depcode.py @@ -335,7 +335,7 @@ def get_nuc_name(self, nuc_code): nuc_zzaaam = self.convert_nuclide_name_serpent_to_zam(pyname.zzaaam(nuc_code)) return nuc_name, nuc_zzaaam - def get_tra_or_dec(self, input_file): + def create_nuclide_name_map_zam_to_serpent(self, input_file): """Returns the isotopes map to transform isotope `zzaaam` code to Serpent2. Uses Serpent2 `*.out` file with list of all isotopes in simulation. @@ -446,7 +446,7 @@ def read_dep_comp(self, read_at_end=False): mats[m].mass = mats[m].density * volume mats[m].vol = volume mats[m].burnup = dep['MAT_' + m + '_BURNUP'][moment] - self.get_tra_or_dec(self.iter_inputfile) + self.create_nuclide_name_map_zam_to_serpent(self.iter_inputfile) return mats def read_depcode_info(self): diff --git a/saltproc/tests/test_depcode.py b/saltproc/tests/test_depcode.py index f0164c6c9..3d8696e5d 100644 --- a/saltproc/tests/test_depcode.py +++ b/saltproc/tests/test_depcode.py @@ -32,8 +32,8 @@ geo_test_input = directory + '/test_geometry_switch.inp' -def test_get_tra_or_dec(): - serpent.get_tra_or_dec(serpent.iter_inputfile) +def test_create_nuclide_name_map_zam_to_serpent(): + serpent.create_nuclide_name_map_zam_to_serpent(serpent.iter_inputfile) assert serpent.iso_map[380880] == '38088.09c' assert serpent.iso_map[962400] == '96240.09c' assert serpent.iso_map[952421] == '95342.09c' From a285361b1970ac4b4444b60fe8bf06a7e9979521 Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 4 Feb 2022 13:21:25 -0600 Subject: [PATCH 112/118] fix missing '{' in input_schema.json --- saltproc/input_schema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saltproc/input_schema.json b/saltproc/input_schema.json index a7f4840b0..9446f0e1b 100644 --- a/saltproc/input_schema.json +++ b/saltproc/input_schema.json @@ -1,4 +1,4 @@ - +{ "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://github.com/arfc/saltproc", "title": "SaltProc input file schema", From 0774592c77b377facc73849e2ffce33a24d4a3ac Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 4 Feb 2022 14:06:06 -0600 Subject: [PATCH 113/118] read_depcode_template -> read_plaintext_file --- saltproc/depcode.py | 33 ++++++++++++++------------------- saltproc/tests/test_depcode.py | 22 +++++++++++----------- 2 files changed, 25 insertions(+), 30 deletions(-) diff --git a/saltproc/depcode.py b/saltproc/depcode.py index 120e6ee33..7526b8c4e 100644 --- a/saltproc/depcode.py +++ b/saltproc/depcode.py @@ -335,16 +335,11 @@ def get_nuc_name(self, nuc_code): nuc_zzaaam = self.convert_nuclide_name_serpent_to_zam(pyname.zzaaam(nuc_code)) return nuc_name, nuc_zzaaam - def create_nuclide_name_map_zam_to_serpent(self, input_file): + def create_nuclide_name_map_zam_to_serpent(self): """Returns the isotopes map to transform isotope `zzaaam` code to Serpent2. Uses Serpent2 `*.out` file with list of all isotopes in simulation. - Parameters - ---------- - input_file : str - Serpent2 input file name and path. - Returns ------- isotope_map : dict of str to str @@ -361,7 +356,7 @@ def create_nuclide_name_map_zam_to_serpent(self, input_file): """ map_dict = {} # Construct path to the *.out File - out_file = os.path.join('%s.out' % input_file) + out_file = os.path.join('%s.out' % self.iter_inputfile) file = open(out_file, 'r') str_list = file.read().split('\n') # Stop-line @@ -446,7 +441,7 @@ def read_dep_comp(self, read_at_end=False): mats[m].mass = mats[m].density * volume mats[m].vol = volume mats[m].burnup = dep['MAT_' + m + '_BURNUP'][moment] - self.create_nuclide_name_map_zam_to_serpent(self.iter_inputfile) + self.create_nuclide_name_map_zam_to_serpent() return mats def read_depcode_info(self): @@ -489,23 +484,23 @@ def read_depcode_step_param(self): self.param['fission_mass_bds'] = res['INI_FMASS'][1] self.param['fission_mass_eds'] = res['TOT_FMASS'][1] - def read_depcode_template(self, template_inputfile_path): - """Reads prepared Serpent2 template (input) file for use in - other class functions that prepare the input file for multiple runs. + def read_plaintext_file(self, file_path): + """Reads the content of a plaintext file for use by other methods. Parameters ---------- - template_inputfile_path : str - Path to user template file for depletion code. + file_path : str + Path to file. Returns ------- - tempalate_data : list - List of strings containing user template file. + file_data : list + List of strings containing file lines. """ - file = open(template_inputfile_path, 'r') - template_data = file.readlines() + template_data = [] + with open(file_path, 'r') as file: + template_data = file.readlines() return template_data def replace_burnup_parameters( @@ -669,12 +664,12 @@ def write_depcode_input( """ if dep_step == 0 and not restart: - data = self.read_depcode_template(self.template_inputfile_path) + data = self.read_plaintext_file(self.template_inputfile_path) data = self.insert_path_to_geometry(data) data = self.change_sim_par(data) data = self.create_iter_matfile(data) else: - data = self.read_depcode_template(self.iter_inputfile) + data = self.read_plaintext_file(self.iter_inputfile) data = self.replace_burnup_parameters(data, reactor, dep_step) if data: diff --git a/saltproc/tests/test_depcode.py b/saltproc/tests/test_depcode.py index 3d8696e5d..de85a4fa8 100644 --- a/saltproc/tests/test_depcode.py +++ b/saltproc/tests/test_depcode.py @@ -33,7 +33,7 @@ def test_create_nuclide_name_map_zam_to_serpent(): - serpent.create_nuclide_name_map_zam_to_serpent(serpent.iter_inputfile) + serpent.create_nuclide_name_map_zam_to_serpent() assert serpent.iso_map[380880] == '38088.09c' assert serpent.iso_map[962400] == '96240.09c' assert serpent.iso_map[952421] == '95342.09c' @@ -54,8 +54,8 @@ def test_convert_nuclide_name_serpent_to_zam(): assert serpent.convert_nuclide_name_serpent_to_zam(48315) == 481151 -def test_read_depcode_template(): - template_str = serpent.read_depcode_template( +def test_read_plaintext_file(): + template_str = serpent.read_plaintext_file( serpent.template_inputfile_path) assert template_str[6] == '%therm zrh_h 900 hzr05.32t hzr06.32t\n' assert template_str[18] == 'set pop 30 20 10\n' @@ -68,7 +68,7 @@ def test_change_sim_par(): serpent.active_cycles = 101 serpent.inactive_cycles = 33 out = serpent.change_sim_par( - serpent.read_depcode_template(serpent.template_inputfile_path) + serpent.read_plaintext_file(serpent.template_inputfile_path) ) assert out[18] == 'set pop %i %i %i\n' % ( serpent.npop, @@ -139,7 +139,7 @@ def test_write_mat_file(): iter_matfile_old = serpent.iter_matfile serpent.iter_inputfile = serpent.iter_inputfile + '.mat' serpent.write_mat_file(mats, 12.0) - mat_str = serpent.read_depcode_template(serpent.iter_matfile) + mat_str = serpent.read_plaintext_file(serpent.iter_matfile) assert mat_str[0] == '% Material compositions (after 12.000000 days)\n' if 'fuel' in mat_str[3]: assert mat_str[3].split()[-1] == '2.27175E+07' @@ -154,7 +154,7 @@ def test_write_mat_file(): def test_insert_path_to_geometry(): - d = serpent.read_depcode_template(serpent.template_inputfile_path) + d = serpent.read_plaintext_file(serpent.template_inputfile_path) d_new = serpent.insert_path_to_geometry(d) assert d_new[5].split('/')[-1] == 'test_geo.inp"\n' @@ -163,7 +163,7 @@ def test_replace_burnup_parameters(): time = msr.dep_step_length_cumulative.copy() time.insert(0, 0.0) depsteps = np.diff(time) - d = serpent.read_depcode_template(serpent.template_inputfile_path) + d = serpent.read_plaintext_file(serpent.template_inputfile_path) for idx in range(len(msr.power_levels)): d = serpent.replace_burnup_parameters(d, msr, @@ -171,7 +171,7 @@ def test_replace_burnup_parameters(): out_file = open(serpent.template_inputfile_path + str(idx), 'w') out_file.writelines(d) out_file.close() - d_new = serpent.read_depcode_template( + d_new = serpent.read_plaintext_file( serpent.template_inputfile_path + str(idx)) assert d_new[8].split()[4] == 'daystep' assert d_new[8].split()[2] == str("%5.9E" % msr.power_levels[idx]) @@ -180,7 +180,7 @@ def test_replace_burnup_parameters(): def test_create_iter_matfile(): - d = serpent.read_depcode_template(serpent.template_inputfile_path) + d = serpent.read_plaintext_file(serpent.template_inputfile_path) out = serpent.create_iter_matfile(d) assert out[0].split()[-1] == '\"' + serpent.iter_matfile + '\"' os.remove(serpent.iter_matfile) @@ -192,7 +192,7 @@ def test_write_depcode_input(): serpent.write_depcode_input(msr, 0, False) - d = serpent.read_depcode_template(serpent.iter_inputfile) + d = serpent.read_plaintext_file(serpent.iter_inputfile) print(d[0]) assert d[0].split('/')[-2] == 'tests' assert d[0].split('/')[-1] == 'material"\n' @@ -212,7 +212,7 @@ def test_switch_to_next_geometry(): serpent.iter_inputfile = serpent.iter_inputfile + '_test' serpent.geo_files += ['../../examples/406.inp', '../../examples/988.inp'] serpent.switch_to_next_geometry() - d = serpent.read_depcode_template(serpent.iter_inputfile) + d = serpent.read_plaintext_file(serpent.iter_inputfile) assert d[5].split('/')[-1] == '988.inp"\n' os.remove(serpent.iter_inputfile) serpent.iter_inputfile = iter_inputfile_old From 4c8fce114703640302c48fb5297d8e769f268660 Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 4 Feb 2022 14:13:19 -0600 Subject: [PATCH 114/118] pep8 fixes --- saltproc/app.py | 14 ++++++++++---- saltproc/depcode.py | 6 ++++-- saltproc/tests/test_app.py | 3 ++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/saltproc/app.py b/saltproc/app.py index 6492d508f..cc66a244b 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -128,11 +128,17 @@ def read_main_input(main_inp_file): else: step = int(num_depsteps) deptot = float(dep_step_length_cumulative[0]) * step - dep_step_length_cumulative = np.linspace(float(dep_step_length_cumulative[0]), deptot, num=step) - power_levels = float(power_levels[0]) * np.ones_like(dep_step_length_cumulative) - reactor_inp['dep_step_length_cumulative'] = dep_step_length_cumulative + dep_step_length_cumulative = \ + np.linspace(float(dep_step_length_cumulative[0]), \ + deptot, \ + num=step) + power_levels = float(power_levels[0]) * \ + np.ones_like(dep_step_length_cumulative) + reactor_inp['dep_step_length_cumulative'] = \ + dep_step_length_cumulative reactor_inp['power_levels'] = power_levels - elif num_depsteps is None and isinstance(dep_step_length_cumulative, (np.ndarray, list)): + elif num_depsteps is None and isinstance(dep_step_length_cumulative, \ + (np.ndarray, list)): if len(dep_step_length_cumulative) != len(power_levels): raise ValueError( 'Depletion step list and power list shape mismatch') diff --git a/saltproc/depcode.py b/saltproc/depcode.py index 7526b8c4e..043e8b115 100644 --- a/saltproc/depcode.py +++ b/saltproc/depcode.py @@ -332,7 +332,8 @@ def get_nuc_name(self, nuc_code): nuc_name = pyname.name(nuc_code)[:-1] + 'm' + str(meta_flag) else: nuc_name = pyname.name(nuc_code) - nuc_zzaaam = self.convert_nuclide_name_serpent_to_zam(pyname.zzaaam(nuc_code)) + nuc_zzaaam = \ + self.convert_nuclide_name_serpent_to_zam(pyname.zzaaam(nuc_code)) return nuc_name, nuc_zzaaam def create_nuclide_name_map_zam_to_serpent(self): @@ -535,7 +536,8 @@ def replace_burnup_parameters( if current_depstep_idx == 0: current_depstep = reactor.dep_step_length_cumulative[0] else: - current_depstep = reactor.dep_step_length_cumulative[current_depstep_idx] - \ + current_depstep = \ + reactor.dep_step_length_cumulative[current_depstep_idx] - \ reactor.dep_step_length_cumulative[current_depstep_idx - 1] for line in template_data: if line.startswith('set power '): diff --git a/saltproc/tests/test_app.py b/saltproc/tests/test_app.py index 8426e45e9..250cd1093 100644 --- a/saltproc/tests/test_app.py +++ b/saltproc/tests/test_app.py @@ -32,7 +32,8 @@ def test_read_main_input(): np.testing.assert_equal( app.reactor_inp['power_levels'], [ 1.250E+9, 1.250E+9]) - np.testing.assert_equal(app.reactor_inp['dep_step_length_cumulative'], [5, 10]) + np.testing.assert_equal(app.reactor_inp['dep_step_length_cumulative'], \ + [5, 10]) def test_read_processes_from_input(): From 30824966bc0e91e46e766117da8de6f25c67efda Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 4 Feb 2022 14:14:22 -0600 Subject: [PATCH 115/118] more pep8 fixes --- saltproc/app.py | 6 +++--- saltproc/tests/test_app.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/saltproc/app.py b/saltproc/app.py index cc66a244b..033aa0c1b 100644 --- a/saltproc/app.py +++ b/saltproc/app.py @@ -129,15 +129,15 @@ def read_main_input(main_inp_file): step = int(num_depsteps) deptot = float(dep_step_length_cumulative[0]) * step dep_step_length_cumulative = \ - np.linspace(float(dep_step_length_cumulative[0]), \ - deptot, \ + np.linspace(float(dep_step_length_cumulative[0]), + deptot, num=step) power_levels = float(power_levels[0]) * \ np.ones_like(dep_step_length_cumulative) reactor_inp['dep_step_length_cumulative'] = \ dep_step_length_cumulative reactor_inp['power_levels'] = power_levels - elif num_depsteps is None and isinstance(dep_step_length_cumulative, \ + elif num_depsteps is None and isinstance(dep_step_length_cumulative, (np.ndarray, list)): if len(dep_step_length_cumulative) != len(power_levels): raise ValueError( diff --git a/saltproc/tests/test_app.py b/saltproc/tests/test_app.py index 250cd1093..6ed47dadb 100644 --- a/saltproc/tests/test_app.py +++ b/saltproc/tests/test_app.py @@ -32,7 +32,7 @@ def test_read_main_input(): np.testing.assert_equal( app.reactor_inp['power_levels'], [ 1.250E+9, 1.250E+9]) - np.testing.assert_equal(app.reactor_inp['dep_step_length_cumulative'], \ + np.testing.assert_equal(app.reactor_inp['dep_step_length_cumulative'], [5, 10]) From a44d419041dd5c8f47b234b788d763939248d137 Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 4 Feb 2022 15:56:32 -0600 Subject: [PATCH 116/118] update docstring for create_nuclide_name_map_zam_to_serpent --- saltproc/depcode.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/saltproc/depcode.py b/saltproc/depcode.py index 043e8b115..16cf83776 100644 --- a/saltproc/depcode.py +++ b/saltproc/depcode.py @@ -337,15 +337,15 @@ def get_nuc_name(self, nuc_code): return nuc_name, nuc_zzaaam def create_nuclide_name_map_zam_to_serpent(self): - """Returns the isotopes map to transform isotope `zzaaam` code to - Serpent2. Uses Serpent2 `*.out` file with list of all isotopes in - simulation. + """ Create a map that accepts nuclide names in `zzaaam` format and + returns the Serpent2 nuclide code format. Uses Serpent2 `*.out` file + with list of all nuclides in simulation. Returns ------- - isotope_map : dict of str to str - Contains mapping for isotopes names from `zzaaam` to Serpent2 name - imported from Serpent2 ouput file: + nuclide_map : dict of str to str + Contains mapping for nuclide names from `zzaaam` to Serpent2 + format imported from Serpent2 ouput file: ``key`` The key is nuclide name in `zzaaam` format. For example, From 7d75b047df7510ff6f6b433bcd9b510f87f56608 Mon Sep 17 00:00:00 2001 From: yardasol Date: Mon, 7 Feb 2022 14:50:07 -0600 Subject: [PATCH 117/118] Revert "make nsteps in runsim_no_reproc match its docstring definition" This reverts commit ad86976af162427f5c17e47673b27fbdc5f50889. --- .../tests/integration_tests/no_repro/test_no_reproc_run.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py b/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py index 5dd0a6cff..0682c5749 100644 --- a/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py +++ b/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py @@ -60,7 +60,7 @@ def runsim_no_reproc(simulation, reactor, nsteps): ###################################################################### # Start sequence - for dep_step in range(nsteps-1): + for dep_step in range(nsteps): print("\nStep #%i has been started" % (dep_step + 1)) if dep_step == 0: # First step simulation.sim_depcode.write_depcode_input( @@ -94,7 +94,7 @@ def runsim_no_reproc(simulation, reactor, nsteps): @pytest.mark.slow # @pytest.mark.skip def test_integration_3step_saltproc_no_reproc_heavy(): - runsim_no_reproc(simulation, tap, 3) + runsim_no_reproc(simulation, tap, 2) saltproc_out = sss_file + '_dep.m' dep_ser = serpent.parse_dep( directory + '/serpent_9d_dep.m', From 98e90c68b7b2a03564ae3b0a076045341a044b54 Mon Sep 17 00:00:00 2001 From: yardasol Date: Mon, 7 Feb 2022 15:06:07 -0600 Subject: [PATCH 118/118] 3step -> 2step --- saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py b/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py index 0682c5749..301b2a9cf 100644 --- a/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py +++ b/saltproc/tests/integration_tests/no_repro/test_no_reproc_run.py @@ -93,7 +93,7 @@ def runsim_no_reproc(simulation, reactor, nsteps): @pytest.mark.slow # @pytest.mark.skip -def test_integration_3step_saltproc_no_reproc_heavy(): +def test_integration_2step_saltproc_no_reproc_heavy(): runsim_no_reproc(simulation, tap, 2) saltproc_out = sss_file + '_dep.m' dep_ser = serpent.parse_dep(