Skip to content

Commit

Permalink
add test for detailedNDensity with detailed axial expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
HunterPSmith committed Oct 28, 2024
1 parent 59a0d75 commit c358aa4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion armi/reactor/composites.py
Original file line number Diff line number Diff line change
Expand Up @@ -1576,7 +1576,7 @@ def changeNDensByFactor(self, factor):
}
self.setNumberDensities(densitiesScaled)
# Update detailedNDens
if self.p.detailedNDens:
if self.p.detailedNDens is not None:
self.p.detailedNDens *= factor

def clearNumberDensities(self):
Expand Down
32 changes: 31 additions & 1 deletion armi/reactor/converters/tests/test_axialExpansionChanger.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import collections
import os
import unittest
import copy
from statistics import mean

from numpy import array, linspace, zeros
Expand Down Expand Up @@ -267,6 +268,8 @@ def test_thermalExpansionContractionConservation_simple(self):
a = buildTestAssemblyWithFakeMaterial(name="HT9")
origMesh = a.getAxialMesh()[:-1]
origMasses, origNDens = self._getComponentMassAndNDens(a)
# set component detailedNDens
origDetailedNDens = self._setComponentDetailedNDens(a, origNDens)
axialExpChngr = AxialExpansionChanger(detailedAxialExpansion=True)

tempGrid = linspace(0.0, a.getHeight())
Expand All @@ -281,16 +284,20 @@ def test_thermalExpansionContractionConservation_simple(self):
# Set new isothermal temp and expand
tempField = array([temp] * len(tempGrid))
oldMasses, oldNDens = self._getComponentMassAndNDens(a)
oldDetailedNDens = self._getComponentDetailedNDens(a)
axialExpChngr.performThermalAxialExpansion(a, tempGrid, tempField)
newMasses, newNDens = self._getComponentMassAndNDens(a)
newDetailedNDens = self._getComponentDetailedNDens(a)
self._checkMass(oldMasses, newMasses)
self._checkNDens(oldNDens, newNDens, totGrowthFrac)
self._checkDetailedNDens(oldDetailedNDens, newDetailedNDens, totGrowthFrac)

# make sure that the assembly returned to the original state
for orig, new in zip(origMesh, a.getAxialMesh()):
self.assertAlmostEqual(orig, new, places=12)
self._checkMass(origMasses, newMasses)
self._checkNDens(origNDens, newNDens, 1.0)
self._checkDetailedNDens(origDetailedNDens, newDetailedNDens, 1.0)

def test_thermalExpansionContractionConservation_complex(self):
"""Thermally expand and then contract to ensure original state is recovered.
Expand Down Expand Up @@ -412,7 +419,13 @@ def _checkNDens(self, prevNDen, newNDens, ratio):
for prev, new in zip(prevComp.values(), newComp.values()):
if prev:
self.assertAlmostEqual(prev / new, ratio, msg=f"{prev} / {new}")


def _checkDetailedNDens(self, prevDetailedNDen, newDetailedNDens, ratio):
for prevComp, newComp in zip(prevDetailedNDen.values(), newDetailedNDens.values()):
for prev, new in zip(prevComp, newComp):
if prev:
self.assertAlmostEqual(prev / new, ratio, msg=f"{prev} / {new}")

@staticmethod
def _getComponentMassAndNDens(a):
masses = {}
Expand All @@ -422,6 +435,23 @@ def _getComponentMassAndNDens(a):
masses[c] = c.getMass()
nDens[c] = c.getNumberDensities()
return masses, nDens

@staticmethod
def _setComponentDetailedNDens(a, nDens):
detailedNDens = {}
for b in a:
for c in getSolidComponents(b):
c.p.detailedNDens = copy.deepcopy([val for val in nDens[c].values()])
detailedNDens[c] = c.p.detailedNDens
return detailedNDens

@staticmethod
def _getComponentDetailedNDens(a):
detailedNDens = {}
for b in a:
for c in getSolidComponents(b):
detailedNDens[c] = copy.deepcopy(c.p.detailedNDens)
return detailedNDens

def test_targetComponentMassConservation(self):
"""Tests mass conservation for target components."""
Expand Down

0 comments on commit c358aa4

Please sign in to comment.