Skip to content

Commit

Permalink
Adding tests/impl tags for Utils (#1471)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdlafleur authored Nov 13, 2023
1 parent 63c9264 commit 18d71cf
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 1 deletion.
16 changes: 16 additions & 0 deletions armi/utils/densityTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ def getNDensFromMasses(rho, massFracs, normalize=False):
"""
Convert density (g/cc) and massFracs vector into a number densities vector (#/bn-cm).
.. impl:: Get number densities
:id: I_ARMI_UTIL_MASS2N_DENS
:implements: R_ARMI_UTIL_MASS2N_DENS
Parameters
----------
rho : float
Expand Down Expand Up @@ -168,6 +172,10 @@ def formatMaterialCard(
"""
Formats nuclides and densities into a MCNP material card.
.. impl:: Create MCNP material card
:id: I_ARMI_UTIL_MCNP_MAT_CARD
:implements: R_ARMI_UTIL_MCNP_MAT_CARD
Parameters
----------
densities : dict
Expand Down Expand Up @@ -254,6 +262,10 @@ def normalizeNuclideList(nuclideVector, normalization=1.0):
"""
Normalize the nuclide vector.
.. impl:: Normalize nuclide vector
:id: I_ARMI_UTIL_DENS_TOOLS
:implements: R_ARMI_UTIL_DENS_TOOLS
Parameters
----------
nuclideVector : dict
Expand Down Expand Up @@ -287,6 +299,10 @@ def expandElementalMassFracsToNuclides(
-----
This indirectly updates number densities through mass fractions.
.. impl:: Expand mass fractions to nuclides
:id: I_ARMI_UTIL_EXP_MASS_FRACS
:implements: R_ARMI_UTIL_EXP_MASS_FRACS
Parameters
----------
massFracs : dict(str, float)
Expand Down
11 changes: 10 additions & 1 deletion armi/utils/hexagon.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def area(pitch):
"""
Area of a hex given the flat-to-flat pitch.
.. impl:: Compute hexagonal area
:id: I_ARMI_UTIL_HEXAGON0
:implements: R_ARMI_UTIL_HEXAGON
Notes
-----
The pitch is the distance between the center of the hexagons in the lattice.
Expand Down Expand Up @@ -129,5 +133,10 @@ def numRingsToHoldNumCells(numCells):


def numPositionsInRing(ring):
"""Number of positions in ring (starting at 1) of a hex lattice."""
"""Number of positions in ring (starting at 1) of a hex lattice.
.. impl:: Compute hexagonal area
:id: I_ARMI_UTIL_HEXAGON1
:implements: R_ARMI_UTIL_HEXAGON
"""
return (ring - 1) * 6 if ring != 1 else 1
35 changes: 35 additions & 0 deletions armi/utils/tests/test_densityTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@

class Test_densityTools(unittest.TestCase):
def test_expandElementalMassFracsToNuclides(self):
"""
Expand mass fraction to nuclides.
.. test:: Expand mass fractions to nuclides
:id: T_ARMI_UTIL_EXP_MASS_FRACS
:tests: R_ARMI_UTIL_EXP_MASS_FRACS
"""
element = elements.bySymbol["N"]
mass = {"N": 1.0}
densityTools.expandElementalMassFracsToNuclides(mass, [(element, None)])
Expand Down Expand Up @@ -99,7 +106,21 @@ def test_applyIsotopicsMix(self):
) # HM blended
self.assertAlmostEqual(uo2.massFrac["O"], massFracO) # non-HM stays unchanged

def test_getNDensFromMasses(self):
"""
Number densities from masses.
.. test:: Get number densities
:id: T_ARMI_UTIL_MASS2N_DENS
:tests: R_ARMI_UTIL_MASS2N_DENS
"""
nDens = densityTools.getNDensFromMasses(1, {"O": 1, "H": 2})

self.assertAlmostEqual(nDens["O"], 0.03764, 5)
self.assertAlmostEqual(nDens["H"], 1.19490, 5)

def test_getMassFractions(self):
"""Number densities to mass fraction."""
numDens = {"O17": 0.1512, "PU239": 1.5223, "U234": 0.135}
massFracs = densityTools.getMassFractions(numDens)

Expand All @@ -108,6 +129,7 @@ def test_getMassFractions(self):
self.assertAlmostEqual(massFracs["U234"], 0.07937081219437897)

def test_calculateNumberDensity(self):
"""Mass fraction to number density."""
nDens = densityTools.calculateNumberDensity("U235", 1, 1)
self.assertAlmostEqual(nDens, 0.0025621344549254283)

Expand All @@ -128,6 +150,13 @@ def test_getMassInGrams(self):
self.assertAlmostEqual(m, 843.5790671316283)

def test_normalizeNuclideList(self):
"""
Normalize a nuclide list.
.. test:: Normalize nuclide vector
:id: T_ARMI_UTIL_DENS_TOOLS
:tests: R_ARMI_UTIL_DENS_TOOLS
"""
nList = {"PU239": 23.2342, "U234": 0.001234, "U235": 34.152}
norm = densityTools.normalizeNuclideList(nList)

Expand All @@ -136,6 +165,12 @@ def test_normalizeNuclideList(self):
self.assertAlmostEqual(norm["U235"], 0.5951128604216736)

def test_formatMaterialCard(self):
"""Formatting material information into an MCNP input card.
.. test:: Create MCNP material card
:id: T_ARMI_UTIL_MCNP_MAT_CARD
:tests: R_ARMI_UTIL_MCNP_MAT_CARD
"""
u235 = nuclideBases.byName["U235"]
pu239 = nuclideBases.byName["PU239"]
o16 = nuclideBases.byName["O16"]
Expand Down
45 changes: 45 additions & 0 deletions armi/utils/tests/test_hexagon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2023 TerraPower, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Test hexagon tools."""
import math
import unittest

from armi.utils import hexagon


class Test_hexagon(unittest.TestCase):
def test_hexagon_area(self):
"""
Area of a hexagon.
.. test:: Compute hexagonal area
:id: T_ARMI_UTIL_HEXAGON0
:test: R_ARMI_UTIL_HEXAGON
"""
# Calculate area given a pitch
self.assertEqual(hexagon.area(1), math.sqrt(3.0) / 2)
self.assertEqual(hexagon.area(2), 4 * math.sqrt(3.0) / 2)

def test_numPositionsInRing(self):
"""
Calculate number of positions in a ring of hexagons.
.. test:: Compute number of positions in ring
:id: T_ARMI_UTIL_HEXAGON1
:tests: R_ARMI_UTIL_HEXAGON
"""
self.assertEqual(hexagon.numPositionsInRing(1), 1)
self.assertEqual(hexagon.numPositionsInRing(2), 6)
self.assertEqual(hexagon.numPositionsInRing(3), 12)
self.assertEqual(hexagon.numPositionsInRing(4), 18)

0 comments on commit 18d71cf

Please sign in to comment.