Skip to content

Commit

Permalink
read_dep_comp() -> read_depleted_materials(); variable name adjustments
Browse files Browse the repository at this point in the history
associated changes to relevant files
  • Loading branch information
yardasol committed Nov 7, 2022
1 parent 4947cd7 commit 94b2647
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 63 deletions.
4 changes: 2 additions & 2 deletions doc/releasenotes/v0.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ Python API Changes
- ``sim_info`` → ``step_metadata``
- ``read_depcode_step_param()`` → ``read_neutronics_parameters()``
- ``param`` → ``neutronics_parameters``
- ``read_dep_comp()`` → ``read_depleted_materials()``

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

Expand All @@ -127,10 +128,9 @@ Python API Changes
- ``sim_info`` → ``step_metadata``
- ``read_depcode_step_param()`` → ``read_neutronics_parameters()``
- ``param`` → ``neutronics_parameters``

- ``read_dep_comp()`` → ``read_depleted_materials()``

- ``OpenMCDepcode`` is a ``Depcode`` subclass that interfaces with ``openmc``. This class implements the following functions
- ``read_depletion_step_metadata()``
- ``run_depcode()``
- ``switch_to_next_geometry()``
- ``write_depcode_input()``
Expand Down
14 changes: 6 additions & 8 deletions saltproc/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,28 +82,26 @@ def read_neutronics_parameters(self):
"""

@abstractmethod
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.
def read_depleted_materials(self, read_at_end=False):
"""Reads depleted materials from the depletion step results
and returns a dictionary containing them.
Parameters
----------
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.
Returns
-------
mats : dict of str to Materialflow
Dictionary that contains `Materialflow` objects.
depleted_materials : dict of str to Materialflow
Dictionary containing depleted materials.
``key``
Name of burnable material.
``value``
`Materialflow` object holding composition and properties.
:class:`Materialflow` object holding material composition and properties.
"""

Expand Down
4 changes: 2 additions & 2 deletions saltproc/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ def run():
# 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(False)
mats = depcode.read_depleted_materials(False)
simulation.store_mat_data(mats, dep_step - 1, False)
# Finish of First step
# Main sequence
mats = depcode.read_dep_comp(True)
mats = depcode.read_depleted_materials(True)
simulation.store_mat_data(mats, dep_step, False)
simulation.store_run_step_info()
# Reprocessing here
Expand Down
15 changes: 7 additions & 8 deletions saltproc/openmc_depcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,28 +90,27 @@ def read_neutronics_parameters(self):
attribute.
"""

def read_dep_comp(self, read_at_end=False):
"""Reads the depleted material data from the OpenMC depletion
simulation and returns a dictionary with a `Materialflow` object for
each burnable material.
def read_depleted_materials(self, read_at_end=False):
"""Reads depleted materials from OpenMC's `depletion_results.h5` file
and returns a dictionary with a :class:`Materialflow` object for each
depleted material.
Parameters
----------
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.
Returns
-------
mats : dict of str to Materialflow
Dictionary that contains `Materialflow` objects.
depleted_materials : dict of str to Materialflow
Dictionary containing depleted materials.
``key``
Name of burnable material.
``value``
`Materialflow` object holding composition and properties.
:class:`Materialflow` object holding composition and properties.
"""

Expand Down
56 changes: 28 additions & 28 deletions saltproc/serpent_depcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,27 +250,26 @@ def insert_path_to_geometry(self, template_data):
'include \"' + str(self.geo_files[0]) + '\"\n')
return template_data

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.
def read_depleted_materials(self, read_at_end=False):
"""Reads depleted materials from Serpent2's `*_dep.m`
file and returns a dictionary containing them.
Parameters
----------
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.
Returns
-------
mats : dict of str to Materialflow
Dictionary that contains `Materialflow` objects.
depleted_materials : dict of str to Materialflow
Dictionary containing depleted materials.
``key``
Name of burnable material.
``value``
`Materialflow` object holding composition and properties.
:class:`Materialflow` object holding material composition and properties.
"""
# Determine moment in depletion step to read data from
Expand All @@ -279,28 +278,29 @@ def read_dep_comp(self, read_at_end=False):
else:
moment = 0

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
mat_name = []
mats = {}
for key in dep.keys():
m = re.search('MAT_(.+?)_VOLUME', key)
if m:
mat_name.append(m.group(1))
zai = list(map(int, dep['ZAI'][:-2])) # zzaaam codes of isotopes

for m in mat_name:
volume = dep['MAT_' + m + '_VOLUME'][moment]
nucvec = dict(zip(zai, dep['MAT_' + m + '_MDENS'][:, moment]))
mats[m] = Materialflow(nucvec)
mats[m].density = dep['MAT_' + m + '_MDENS'][-1, moment]
mats[m].mass = mats[m].density * volume
mats[m].vol = volume
mats[m].burnup = dep['MAT_' + m + '_BURNUP'][moment]
results_file = os.path.join('%s_dep.m' % self.iter_inputfile)
results = serpent.parse_dep(results_file, make_mats=False)
self.days = results['DAYS'][moment]

# Get material names
mat_names = []
depleted_materials = {}
for key in results.keys():
name_match = re.search('MAT_(.+?)_VOLUME', key)
if name_match:
mat_names.append(name_match.group(1))
zai = list(map(int, results['ZAI'][:-2])) # zzaaam codes of isotopes

for name in mat_names:
volume = results[f'MAT_{name}_VOLUME'][moment]
nucvec = dict(zip(zai, results[f'MAT_{name}_MDENS'][:, moment]))
depleted_materials[name] = Materialflow(nucvec)
depleted_materials[name].density = results[f'MAT_{name}_MDENS'][-1, moment]
depleted_materials[name].mass = depleted_materials[name].density * volume
depleted_materials[name].vol = volume
depleted_materials[name].burnup = results[f'MAT_{name}_BURNUP'][moment]
self.create_nuclide_name_map_zam_to_serpent()
return mats
return depleted_materials

def read_step_metadata(self):
"""Reads Serpent2 depletion step metadata and stores it in the
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests/basic_reprocessing/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def test_reprocessing_and_refill(
serpent_depcode,
proc_test_file,
path_test_file):
mats = serpent_depcode.read_dep_comp(True)
mats = serpent_depcode.read_depleted_materials(True)
waste_streams, extracted_mass = reprocess_materials(mats,
proc_test_file,
path_test_file)
Expand Down
6 changes: 3 additions & 3 deletions tests/integration_tests/database_storage/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_store_after_reprocessing(
"""
# read data
mats = simulation.sim_depcode.read_dep_comp(
mats = simulation.sim_depcode.read_depleted_materials(
True)
waste_streams, extracted_mass = reprocess_materials(
mats, proc_test_file, path_test_file)
Expand Down Expand Up @@ -139,9 +139,9 @@ def test_store_mat_data(simulation):
explicity in value and implicitly in type.
"""
# read data
mats_before = simulation.sim_depcode.read_dep_comp(
mats_before = simulation.sim_depcode.read_depleted_materials(
False)
mats_after = simulation.sim_depcode.read_dep_comp(
mats_after = simulation.sim_depcode.read_depleted_materials(
True)

fuel_before = mats_before['fuel']
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests/file_interface_serpent/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_iter_input_from_template(serpent_depcode, msr):


def test_write_iter_files(serpent_depcode, msr):
mats = serpent_depcode.read_dep_comp(True)
mats = serpent_depcode.read_depleted_materials(True)

# write_mat_file
serpent_depcode.write_mat_file(mats, 12.0)
Expand Down
4 changes: 2 additions & 2 deletions tests/integration_tests/run_no_reprocessing/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def runsim_no_reproc(simulation, reactor, nsteps):
# 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(
mats = simulation.sim_depcode.read_depleted_materials(
False)
simulation.store_mat_data(mats, dep_step, False)
# Finish of First step
Expand All @@ -97,7 +97,7 @@ def runsim_no_reproc(simulation, reactor, nsteps):
simulation.sim_depcode.run_depcode(
simulation.core_number,
simulation.node_number)
mats = simulation.sim_depcode.read_dep_comp(
mats = simulation.sim_depcode.read_depleted_materials(
True)
simulation.store_mat_data(mats, dep_step, False)
simulation.store_run_step_info()
Expand Down
6 changes: 3 additions & 3 deletions tests/unit_tests/test_materialflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@


def test_get_mass(serpent_depcode):
mats = serpent_depcode.read_dep_comp(True)
mats = serpent_depcode.read_depleted_materials(True)
assert mats['fuel'].get_mass() == 112683343.50000001
assert mats['ctrlPois'].get_mass() == 65563.2355


def test_scale_matflow(serpent_depcode):
mats = serpent_depcode.read_dep_comp(True)
mats = serpent_depcode.read_depleted_materials(True)
scale_factor = 0.7
scaled_matflow = mats['fuel'].scale_matflow(scale_factor)
assert scaled_matflow[922350000] == scale_factor * 3499538.3359278883
Expand All @@ -18,7 +18,7 @@ def test_scale_matflow(serpent_depcode):


def test_copy_pymat_attrs(serpent_depcode):
mats = serpent_depcode.read_dep_comp(True)
mats = serpent_depcode.read_depleted_materials(True)
target_mat = mats['fuel']
target_mat.copy_pymat_attrs(mats['ctrlPois'])
assert target_mat.density == 5.873
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def process():


def test_process_material(serpent_depcode, process):
mats = serpent_depcode.read_dep_comp(True)
mats = serpent_depcode.read_depleted_materials(True)
thru, waste = process.process_material(mats['fuel'])
np.testing.assert_almost_equal(waste[541350000], 19.79776930513891)
np.testing.assert_almost_equal(waste[541360000], 176.44741987005173)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/test_separator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def separator():


def test_rem_elements(serpent_depcode, separator):
mats = serpent_depcode.read_dep_comp(True)
mats = serpent_depcode.read_depleted_materials(True)
thru, waste = separator.process_material(mats['fuel'])
np.testing.assert_almost_equal(waste[541350000], 19.5320018359295)
np.testing.assert_almost_equal(waste[541360000], 174.0787699729534)
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/test_serpent_depcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ def test_read_neutronics_parameters(serpent_depcode):
assert serpent_depcode.neutronics_parameters['breeding_ratio'][1] == 5.20000e-04


def test_read_dep_comp(serpent_depcode):
mats = serpent_depcode.read_dep_comp(True)
def test_read_depleted_materials(serpent_depcode):
mats = serpent_depcode.read_depleted_materials(True)
assert mats['fuel']['U235'] == 3499538.3359278883
assert mats['fuel']['U238'] == 66580417.24509208
assert mats['fuel']['F19'] == 37145139.35897285
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/test_sparger.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def sparger():


def test_rem_elements(serpent_depcode, sparger):
mats = serpent_depcode.read_dep_comp(True)
mats = serpent_depcode.read_depleted_materials(True)
thru, waste = sparger.process_material(mats['fuel'])
np.testing.assert_almost_equal(waste[541350000], 8.061014535231715)
np.testing.assert_almost_equal(waste[541360000], 71.8437109936129)
Expand Down

0 comments on commit 94b2647

Please sign in to comment.