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

Update material modifications to use consistent keyword for theoretical density #430

Merged
merged 3 commits into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions armi/materials/b4c.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,31 @@ 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(
"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
21 changes: 19 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,25 @@
class Sulfur(material.Fluid):
name = "Sulfur"

def applyInputParams(self, sulfur_density_frac=None):
def applyInputParams(self, sulfur_density_frac=None, TD_frac=None):
john-science marked this conversation as resolved.
Show resolved Hide resolved
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(
"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
42 changes: 42 additions & 0 deletions armi/materials/tests/test_b4c.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""
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):
john-science marked this conversation as resolved.
Show resolved Hide resolved
_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()