Skip to content

Commit

Permalink
Parse through applyInputParams in the MRO (#1151)
Browse files Browse the repository at this point in the history
* Parse through applyInputParams in the MRO

* Fix the by-component checks and add tests

* Change |= to .update()
  • Loading branch information
keckler committed Feb 7, 2023
1 parent d31a6da commit e3fa30e
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 6 deletions.
26 changes: 20 additions & 6 deletions armi/reactor/blueprints/blockBlueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import yamlize

from armi import getPluginManagerOrFail, runLog
from armi.materials.material import Material
from armi.reactor import blocks
from armi.reactor import parameters
from armi.reactor.flags import Flags
Expand Down Expand Up @@ -128,9 +129,16 @@ def construct(
if isinstance(c, Component):
# there are other things like composite groups that don't get
# material modifications -- skip those
validMatModOptions = signature(
c.material.applyInputParams
).parameters.keys()
validMatModOptions = set()
for materialParentClass in c.material.__class__.__mro__:
# we must loop over parents as well, since applyInputParams
# could call to Parent.applyInputParams()
if issubclass(materialParentClass, Material):
validMatModOptions.update(
signature(
materialParentClass.applyInputParams
).parameters.keys()
)
for key in byComponentMatModKeys:
if key not in validMatModOptions:
raise ValueError(
Expand Down Expand Up @@ -165,9 +173,15 @@ def construct(
if isinstance(c, Component):
# there are other things like composite groups that don't get
# material modifications -- skip those
validMatModOptions |= signature(
c.material.applyInputParams
).parameters.keys()
for materialParentClass in c.material.__class__.__mro__:
# we must loop over parents as well, since applyInputParams
# could call to Parent.applyInputParams()
if issubclass(materialParentClass, Material):
validMatModOptions.update(
signature(
materialParentClass.applyInputParams
).parameters.keys()
)

if "byBlock" in materialInput:
for key in materialInput["byBlock"]:
Expand Down
48 changes: 48 additions & 0 deletions armi/reactor/blueprints/tests/test_materialModifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,54 @@ def test_invalidMatModName(self):
"""
)

def test_matModsUpTheMRO(self):
"""
Make sure that valid/invalid material modifications are searched up
the MRO for a material class.
"""
a = self.loadUZrAssembly(
"""
material modifications:
ZR_wt_frac: [1]
class1_wt_frac: [1]
class1_custom_isotopics: [dummy]
class2_custom_isotopics: [dummy]
by component:
fuel2:
ZR_wt_frac: [0]
class1_wt_frac: [1]
class1_custom_isotopics: [dummy]
class2_custom_isotopics: [dummy]
custom isotopics:
dummy:
input format: mass fractions
density: 1
U: 1
"""
)

with self.assertRaises(ValueError):
a = self.loadUZrAssembly(
"""
material modifications:
ZR_wt_frac: [1]
klass1_wt_frac: [1]
klass1_custom_isotopics: [dummy]
klass2_custom_isotopics: [dummy]
by component:
fuel2:
ZR_wt_frac: [0]
klass1_wt_frac: [1]
klass1_custom_isotopics: [dummy]
klass2_custom_isotopics: [dummy]
custom isotopics:
dummy:
input format: mass fractions
density: 1
U: 1
"""
)


if __name__ == "__main__":
unittest.main()

0 comments on commit e3fa30e

Please sign in to comment.