Skip to content

Commit

Permalink
Remove circular function calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
mgjarrett committed Feb 6, 2025
1 parent 57abab5 commit e0a8297
Showing 1 changed file with 20 additions and 49 deletions.
69 changes: 20 additions & 49 deletions armi/reactor/components/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,43 +669,19 @@ def setTemperature(self, temperatureInC):
self.changeNDensByFactor(f)
self.clearLinkedCache()

def setPuFrac(self, prevPuFrac):
r"""
Adjust puFrac of this component.
This will cause effective expansion or contraction of solid components similar to thermal
expansion but at a constant temperature. If the thermal expansion coefficient is dependent
on composition (like puFrac), then changing the puFrac at a constant temperature will
effectively expand/contract the material. When this happens, number densities need to be
adjusted to conserve mass.
Since some composites have multiple materials in them that thermally expand differently,
the axial dimension is generally left unchanged. Hence, this a 2-D thermal expansion.
Number density change is proportional to mass density change :math:`\frac{d\rho}{\rho}`.
A multiplicative factor :math:`f_N` to apply to number densities when going from T to T'
is as follows:
.. math::
N^{\prime} = N \cdot f_N \\
\frac{dN}{N} = f_N - 1
Since :math:`\frac{dN}{N} \sim\frac{d\rho}{\rho}`, we have:
.. math::
f_N = \frac{d\rho}{\rho} + 1 = \frac{\rho^{\prime}}{\rho}
def changeNDensByFactor(self, factor):
"""
prevMaterial = self.material.__class__()
prevMaterial.puFrac = prevPuFrac
dLLprev = prevMaterial.linearExpansionPercent(Tc=self.temperatureInC) / 100.0
dLLnew = self.material.linearExpansionPercent(Tc=self.temperatureInC) / 100.0
expansionRatio = (1.0 + dLLnew) / (1.0 + dLLprev)
f = 1.0 / expansionRatio**2
self.changeNDensByFactor(f)
self.clearLinkedCache()
Change the number density of all nuclides within the object by a multiplicative factor.
Don't call `updateNumberDensities` to avoid a circular call stack.
"""
for nuc, val in self.getNumberDensities().items():
self.p.numberDensities[nuc] = val * factor

if self.p.detailedNDens is not None:
self.p.detailedNDens *= factor
# Update pinNDens
if self.p.pinNDens is not None:
self.p.pinNDens *= factor

def getNuclides(self):
"""
Expand Down Expand Up @@ -817,14 +793,12 @@ def updateNumberDensities(self, numberDensities):
"""
# prepare to change the densities with knowledge that dims could change due to
# material thermal expansion dependence on composition
dLLprev = self.material.linearExpansionPercent(Tc=self.temperatureInC) / 100.0
try:
vol = self.getVolume()
except:
# either no parent to get height or parent's height is None
# which would be AttributeError and TypeError respectively, but other errors could be possible
vol = None
area = self.getArea()
if len(self.p.numberDensities) > 0:
dLLprev = (
self.material.linearExpansionPercent(Tc=self.temperatureInC) / 100.0
)
else:
dLLprev = 0.0

# change the densities
self.p.numberDensities.update(numberDensities)
Expand All @@ -837,12 +811,9 @@ def updateNumberDensities(self, numberDensities):
# (since the density change was for the old volume and otherwise mass wouldn't be conserved)

# enable recalculation of volume, otherwise it uses stored.
self.clearLinkedCache()
if vol is not None:
factor = vol / self.getVolume()
else:
factor = area / self.getArea()
factor = (1.0 + dLLprev) ** 2 / (1.0 + dLLnew) ** 2
self.changeNDensByFactor(factor)
self.clearLinkedCache()

# since we're calling update on the object the param points to, but not the param itself, we have to inform
# the param system to flag it as modified so it properly syncs during ``syncMpiState``.
Expand Down

0 comments on commit e0a8297

Please sign in to comment.