Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Support passing depletion reader settings at construction #516

Merged
Prev Previous commit
Next Next commit
enh: support passing materials to DepletionReader init
drewejohnson committed Jun 3, 2024
commit e889d833e2cdad6e85e689ba8c0a914c470e3be9
11 changes: 10 additions & 1 deletion src/serpentTools/parsers/depletion.py
Original file line number Diff line number Diff line change
@@ -147,6 +147,13 @@ class DepletionReader(DepPlotMixin, MaterialReader):
----------
filePath: str
path to the depletion file
materials : list of string, optional
Names and patterns to use when determining if a material found
in the file should be processed or not. ``["fuel"]`` will
result in only the material exactly named ``fuel`` to be processed.
But ``["fuel.*"]`` is a pattern that will match and collect any
material that begins with ``fuel``. If not provided,
pulls from ``depletion.materials`` setting.
metadataKeys : list of string, optional
Metadata fields to pull from the file. List can contain
zero or more of the following strings: ``"ZAI"``, ``"NAMES"``,
@@ -184,10 +191,12 @@ class DepletionReader(DepPlotMixin, MaterialReader):
Dictionary with file-wide data names as keys and the
corresponding data, e.g. ``'zai'``: [list of zai numbers]"""

def __init__(self, filePath, metadataKeys=None):
def __init__(self, filePath, materials=None, metadataKeys=None):
MaterialReader.__init__(self, filePath, "depletion")
if metadataKeys is not None:
self.settings["metadataKeys"] = metadataKeys
if materials is not None:
self.settings["materials"] = materials
patterns = self.settings["materials"] or [".*"]
# match all materials if nothing given
self._matPatterns = [re.compile(mat) for mat in patterns]
9 changes: 7 additions & 2 deletions tests/test_depletion.py
Original file line number Diff line number Diff line change
@@ -441,19 +441,24 @@ def test_defaultSettings():
"""Test behavior of settings if no additional arguments given"""
r = DepletionReader(DEP_FILE_PATH)
assert r.settings["metadataKeys"] == ["ZAI", "NAMES", "DAYS", "BU"]
assert r.settings["materials"] == []


def test_simpleOverloadSettings():
"""Test overwritting some settings and the behavior"""
base = DepletionReader(DEP_FILE_PATH)
base.read()
alt = DepletionReader(DEP_FILE_PATH, metadataKeys=["ZAI"])
alt = DepletionReader(
DEP_FILE_PATH,
materials=["f.*"],
metadataKeys=["ZAI"],
)
alt.read()
assert set(alt.metadata) == {
"zai",
}
assert alt.zais == base.zais
assert set(alt.materials) == set(base.materials)
assert set(alt.materials) == {"fuel", "total"}
assert alt.days is None
assert alt.burnup is None
assert alt.names is None