Skip to content

Commit

Permalink
read_depcode_info -> read_depcode_metadata; associated consistency ch…
Browse files Browse the repository at this point in the history
…anges
  • Loading branch information
yardasol committed Nov 7, 2022
1 parent 5edaf3a commit b2a849b
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 63 deletions.
4 changes: 3 additions & 1 deletion doc/releasenotes/v0.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,17 @@ Python API Changes

- ``template_inputfile_path`` → ``template_input_file_path``
- Changed `iter_inputfile` and `iter_matfile` to be attributes instead of parameters
- ``read_depcode_info`` → ``read_depcode_metadata``

- ``DepcodeSerpent`` → ``SerpentDepcode``

- ``template_inputfile_path`` → ``template_input_file_path``
- Changed `iter_inputfile` and `iter_matfile` to be attributes instead of parameters
- ``read_depcode_info`` → ``read_depcode_metadata``


- ``OpenMCDepcode`` is a ``Depcode`` subclass that interfaces with ``openmc``. This class implements the following functions

- ``read_depcode_info`` → ``read_depcode_metadata``
- ``run_depcode()``
- ``switch_to_next_geometry()``
- ``write_depcode_input()``
Expand Down
15 changes: 8 additions & 7 deletions saltproc/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class Depcode(ABC):
param : dict of str to type
Holds depletion step parameter information. Parameter names are keys
and parameter values are values.
sim_info : dict of str to type
Holds simulation settings information. Setting names are keys
and setting values are values.
depletion_metadata : dict of str to type
Holds depletion code depletion metadata. Metadata labels are keys
and metadata values are values.
iter_inputfile : str
Path to depletion code input file for depletion code rerunning.
iter_matfile : str
Expand Down Expand Up @@ -64,14 +64,15 @@ def __init__(self,
self.active_cycles = active_cycles
self.inactive_cycles = inactive_cycles
self.param = {}
self.sim_info = {}
self.depletion_metadata = {}
self.iter_inputfile = './iter_input'
self.iter_matfile = './iter_mat'

@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.
def read_depcode_metadata(self):
"""Reads depletion simulation metadata from depletion code output file
and stores it in the :class:`Depcode` object's
:attr:`depletion_metadata` attribute.
"""

@abstractmethod
Expand Down
13 changes: 7 additions & 6 deletions saltproc/openmc_depcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class OpenMCDepcode(Depcode):
param : dict of str to type
Holds depletion step parameter information. Parameter names are keys
and parameter values are values.
sim_info : dict of str to type
Holds simulation settings information. Setting names are keys
and setting values are values.
depletion_metadata : dict of str to type
Holds OpenMC depltetion metadata. Metadata labels are keys
and metadata values are values.
iter_inputfile : dict of str to str
Paths to OpenMC input files for OpenMC rerunning.
iter_matfile : str
Expand Down Expand Up @@ -79,9 +79,10 @@ def __init__(self,
'settings': './settings.xml'},
self.iter_matfile = './materials.xml'

def read_depcode_info(self):
"""Parses initial OpenMC simulation info from the OpenMC output files
and stores it in the `Depcode` object's ``sim_info`` attribute.
def read_depcode_metadata(self):
"""Reads depletion simulation metadata from OpenMC's output files
and stores it in the :class:`OpenMCDepcode` object's
:attr:`depletion_metadata` attribute.
"""

def read_depcode_step_param(self):
Expand Down
35 changes: 18 additions & 17 deletions saltproc/serpent_depcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class SerpentDepcode(Depcode):
param : dict of str to type
Holds Serpent depletion step parameter information. Parameter names are
keys and parameter values are values.
sim_info : dict of str to type
Holds Serpent simulation settings information. Setting names are keys
and setting values are values.
depletion_metadata : dict of str to type
Holds Serpent2 depletion metadata. Metadata labels are keys
and metadata values are values.
iter_inputfile : str
Path to Serpent2 input file for Serpent2 rerunning.
iter_matfile : str
Expand Down Expand Up @@ -302,26 +302,27 @@ def read_dep_comp(self, read_at_end=False):
self.create_nuclide_name_map_zam_to_serpent()
return mats

def read_depcode_info(self):
"""Parses initial simulation info data from Serpent2 output and stores
it in the `SerpentDepcode` object's ``sim_info`` attributes.
def read_depcode_metadata(self):
"""Reads depletion simulation metadata from Serpent2 output file and
stores it in the :class:`SerpentDepcode` object's
:attr:`depletion_metadata` attribute.
"""
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_ver
self.sim_info['title'] = res['TITLE'][0].decode('utf-8')
self.sim_info['depcode_input_filename'] = \
self.depletion_metadata['depcode_name'] = depcode_name
self.depletion_metadata['depcode_version'] = depcode_ver
self.depletion_metadata['title'] = res['TITLE'][0].decode('utf-8')
self.depletion_metadata['depcode_input_filename'] = \
res['INPUT_FILE_NAME'][0].decode('utf-8')
self.sim_info['depcode_working_dir'] = \
self.depletion_metadata['depcode_working_dir'] = \
res['WORKING_DIRECTORY'][0].decode('utf-8')
self.sim_info['xs_data_path'] = \
self.depletion_metadata['xs_data_path'] = \
res['XS_DATA_FILE_PATH'][0].decode('utf-8')
self.sim_info['OMP_threads'] = res['OMP_THREADS'][0]
self.sim_info['MPI_tasks'] = res['MPI_TASKS'][0]
self.sim_info['memory_optimization_mode'] = res['OPTIMIZATION_MODE'][0]
self.sim_info['depletion_timestep'] = res['BURN_DAYS'][1][0]
self.sim_info['depletion_timestep'] = res['BURN_DAYS'][1][0]
self.depletion_metadata['OMP_threads'] = res['OMP_THREADS'][0]
self.depletion_metadata['MPI_tasks'] = res['MPI_TASKS'][0]
self.depletion_metadata['memory_optimization_mode'] = res['OPTIMIZATION_MODE'][0]
self.depletion_metadata['depletion_timestep'] = res['BURN_DAYS'][1][0]
self.depletion_metadata['depletion_timestep'] = res['BURN_DAYS'][1][0]

def read_depcode_step_param(self):
"""Parses data from Serpent2 output for each step and stores it in
Expand Down
36 changes: 18 additions & 18 deletions saltproc/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def store_run_init_info(self):
# numpy arraw row storage for run info
# delete and make this datatype specific
# to Depcode subclasses
sim_info_dtype = np.dtype([
depletion_metadata_dtype = np.dtype([
('neutron_population', int),
('active_cycles', int),
('inactive_cycles', int),
Expand All @@ -383,39 +383,39 @@ def store_run_init_info(self):
('depletion_timestep', float)
])
# Read info from depcode _res.m File
self.sim_depcode.read_depcode_info()
self.sim_depcode.read_depcode_metadata()
# Store information about material properties in new array row
sim_info_row = (
depletion_metadata_row = (
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_version'],
self.sim_depcode.sim_info['title'],
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'],
self.sim_depcode.sim_info['memory_optimization_mode'],
self.sim_depcode.sim_info['depletion_timestep']
self.sim_depcode.depletion_metadata['depcode_name'],
self.sim_depcode.depletion_metadata['depcode_version'],
self.sim_depcode.depletion_metadata['title'],
self.sim_depcode.depletion_metadata['depcode_input_filename'],
self.sim_depcode.depletion_metadata['depcode_working_dir'],
self.sim_depcode.depletion_metadata['xs_data_path'],
self.sim_depcode.depletion_metadata['OMP_threads'],
self.sim_depcode.depletion_metadata['MPI_tasks'],
self.sim_depcode.depletion_metadata['memory_optimization_mode'],
self.sim_depcode.depletion_metadata['depletion_timestep']
)
sim_info_array = np.array([sim_info_row], dtype=sim_info_dtype)
depletion_metadata_array = np.array([depletion_metadata_row], dtype=depletion_metadata_dtype)

# Open or restore db and append datat to it
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')
depletion_metadata_table = db.get_node(db.root, 'initial_depcode_siminfo')
except Exception:
sim_info_table = db.create_table(
depletion_metadata_table = db.create_table(
db.root,
'initial_depcode_siminfo',
sim_info_array,
depletion_metadata_array,
"Initial depletion code simulation parameters")
sim_info_table.flush()
depletion_metadata_table.flush()
db.close()

def read_k_eds_delta(self, current_timestep):
Expand Down
4 changes: 2 additions & 2 deletions tests/integration_tests/database_storage/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ def test_store_run_init_info(simulation):
"""

# read data
simulation.sim_depcode.read_depcode_info()
init_info = simulation.sim_depcode.sim_info
simulation.sim_depcode.read_depcode_metadata()
init_info = simulation.sim_depcode.depletion_metadata

# we want to keep the old path for other sims, but for this
# test we'll want a fresh db
Expand Down
24 changes: 12 additions & 12 deletions tests/unit_tests/test_depcode_serpent.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,22 @@ def test_get_nuc_name(serpent_depcode):
assert serpent_depcode.get_nuc_name('491142')[0] == 'In114m2'


def test_read_depcode_info(serpent_depcode):
serpent_depcode.read_depcode_info()
assert serpent_depcode.sim_info['depcode_name'] == 'Serpent'
assert serpent_depcode.sim_info['depcode_version'] == '2.1.31'
assert serpent_depcode.sim_info['title'] == 'Untitled'
assert serpent_depcode.sim_info['depcode_input_filename'] == \
def test_read_depcode_metadata(serpent_depcode):
serpent_depcode.read_depcode_metadata()
assert serpent_depcode.depletion_metadata['depcode_name'] == 'Serpent'
assert serpent_depcode.depletion_metadata['depcode_version'] == '2.1.31'
assert serpent_depcode.depletion_metadata['title'] == 'Untitled'
assert serpent_depcode.depletion_metadata['depcode_input_filename'] == \
'/home/andrei2/Desktop/git/saltproc/develop/saltproc/data/saltproc_tap'
assert serpent_depcode.sim_info['depcode_working_dir'] == \
assert serpent_depcode.depletion_metadata['depcode_working_dir'] == \
'/home/andrei2/Desktop/git/saltproc/develop/saltproc'
assert serpent_depcode.sim_info['xs_data_path'] == \
assert serpent_depcode.depletion_metadata['xs_data_path'] == \
'/home/andrei2/serpent/xsdata/jeff312/sss_jeff312.xsdata'

assert serpent_depcode.sim_info['MPI_tasks'] == 1
assert serpent_depcode.sim_info['OMP_threads'] == 4
assert serpent_depcode.sim_info['memory_optimization_mode'] == 4
assert serpent_depcode.sim_info['depletion_timestep'] == 3.0
assert serpent_depcode.depletion_metadata['MPI_tasks'] == 1
assert serpent_depcode.depletion_metadata['OMP_threads'] == 4
assert serpent_depcode.depletion_metadata['memory_optimization_mode'] == 4
assert serpent_depcode.depletion_metadata['depletion_timestep'] == 3.0


def test_read_depcode_step_param(serpent_depcode):
Expand Down

0 comments on commit b2a849b

Please sign in to comment.