Skip to content

Commit

Permalink
Update material modifications to use consistent keyword for theoretic…
Browse files Browse the repository at this point in the history
…al density
  • Loading branch information
keckler committed Oct 4, 2021
1 parent 07a06e6 commit 11c5dc5
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 5 deletions.
24 changes: 21 additions & 3 deletions armi/materials/b4c.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,33 @@ class B4C(material.Material):
enrichedNuclide = "B10"

def applyInputParams(
self, B10_wt_frac=None, theoretical_density=None, *args, **kwargs
self,
B10_wt_frac=None,
theoretical_density=None,
TD_frac=None,
*args, **kwargs,
):
if B10_wt_frac is not None:
# we can't just use the generic enrichment adjustment here because the
# carbon has to change with enrich.
self.adjustMassEnrichment(B10_wt_frac)
if theoretical_density is not None:
self.p.theoreticalDensityFrac = theoretical_density
self.clearCache()
runLog.warning(
"The 'threoretical_density' material modification for B4C will be "
"deprecated. Update your inputs to use 'TD_frac' instead.",
single=True)
if TD_frac is not None:
runLog.warning(
f"Both 'theoretical_density' and 'TD_frac' are specified "
f"for {self}. 'TD_frac' will be used.")
else:
self.updateTD(theoretical_density)
if TD_frac is not None:
self.updateTD(TD_frac)

def updateTD(self, TD):
self.p.theoreticalDensityFrac = TD
self.clearCache()

def setNewMassFracsFromMassEnrich(self, massEnrichment):
r"""
Expand Down
19 changes: 17 additions & 2 deletions armi/materials/sulfur.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
Sulfur
"""

from armi import runLog
from armi import utils
from armi.utils.units import getTk
from armi.materials import material
Expand All @@ -24,9 +25,23 @@
class Sulfur(material.Fluid):
name = "Sulfur"

def applyInputParams(self, sulfur_density_frac=None):
def applyInputParams(self, sulfur_density_frac=None, TD_frac=None):
if sulfur_density_frac is not None:
self.fullDensFrac = float(sulfur_density_frac)
runLog.warning(
"The 'sulfur_density_frac' material modification for Sulfur "
"will be deprecated. Update your inputs to use 'TD_frac' instead.",
single=True)
if TD_frac is not None:
runLog.warning(
f"Both 'sulfur_density_frac' and 'TD_frac' are specified "
f"for {self}. 'TD_frac' will be used.")
else:
self.updateTD(sulfur_density_frac)
if TD_frac is not None:
self.updateTD(TD_frac)

def updateTD(self, TD):
self.fullDensFrac = float(TD)

def setDefaultMassFracs(self):
"""Mass fractions"""
Expand Down
51 changes: 51 additions & 0 deletions armi/materials/tests/test_b4c.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""
Tests for boron carbide.
"""

import unittest

from armi.materials.tests.test_materials import _Material_Test
from armi.materials.b4c import B4C
from armi.materials.b4c import DEFAULT_THEORETICAL_DENSITY_FRAC


class B4C_TestCase(_Material_Test, unittest.TestCase):
MAT_CLASS = B4C

def setUp(self):
_Material_Test.setUp(self)
self.mat = B4C()

self.B4C_theoretical_density = B4C()
self.B4C_theoretical_density.applyInputParams(theoretical_density=0.5)

self.B4C_TD_frac = B4C()
self.B4C_TD_frac.applyInputParams(TD_frac=0.4)

self.B4C_both = B4C()
self.B4C_both.applyInputParams(theoretical_density=0.5, TD_frac=0.4)

def test_theoretical_density(self):
ref = self.mat.density(500)

reduced = self.B4C_theoretical_density.density(500)
self.assertAlmostEqual(
ref * 0.5 / DEFAULT_THEORETICAL_DENSITY_FRAC,
reduced
)

reduced = self.B4C_TD_frac.density(500)
self.assertAlmostEqual(
ref * 0.4 / DEFAULT_THEORETICAL_DENSITY_FRAC,
reduced
)

reduced = self.B4C_both.density(500)
self.assertAlmostEqual(
ref * 0.4 / DEFAULT_THEORETICAL_DENSITY_FRAC,
reduced
)


if __name__ == "__main__":
unittest.main()
41 changes: 41 additions & 0 deletions armi/materials/tests/test_sulfur.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
Tests for sulfur.
"""

import unittest

from armi.materials.tests.test_materials import _Material_Test
from armi.materials.sulfur import Sulfur


class Sulfur_TestCase(_Material_Test, unittest.TestCase):
MAT_CLASS = Sulfur

def setUp(self):
_Material_Test.setUp(self)
self.mat = Sulfur()

self.Sulfur_sulfur_density_frac = Sulfur()
self.Sulfur_sulfur_density_frac.applyInputParams(sulfur_density_frac=0.5)

self.Sulfur_TD_frac = Sulfur()
self.Sulfur_TD_frac.applyInputParams(TD_frac=0.4)

self.Sulfur_both = Sulfur()
self.Sulfur_both.applyInputParams(sulfur_density_frac=0.5, TD_frac=0.4)

def test_sulfur_density_frac(self):
ref = self.mat.density(500)

reduced = self.Sulfur_sulfur_density_frac.density(500)
self.assertAlmostEqual(ref * 0.5, reduced)

reduced = self.Sulfur_TD_frac.density(500)
self.assertAlmostEqual(ref * 0.4, reduced)

reduced = self.Sulfur_both.density(500)
self.assertAlmostEqual(ref * 0.4, reduced)


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

0 comments on commit 11c5dc5

Please sign in to comment.