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

Expose tight coupling to OperatorSnapshots #1113

Merged
merged 5 commits into from
Jan 24, 2023
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
17 changes: 13 additions & 4 deletions armi/operators/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,17 +378,26 @@ def _timeNodeLoop(self, cycle, timeNode):
"""Run the portion of the main loop that happens each subcycle."""
self.r.p.timeNode = timeNode
self.interactAllEveryNode(cycle, timeNode)
# perform tight coupling if requested
self._performTightCoupling(cycle, timeNode)

def _performTightCoupling(self, cycle: int, timeNode: int, writeDB: bool = True):
"""if requested, perform tight coupling and write out database

Notes
-----
writeDB is False for OperatorSnapshots as the DB gets written at EOL.
"""
if self.couplingIsActive():
self._convergenceSummary = collections.defaultdict(list)
for coupledIteration in range(self.cs["tightCouplingMaxNumIters"]):
self.r.core.p.coupledIteration = coupledIteration + 1
converged = self.interactAllCoupled(coupledIteration)
if converged:
break
# database has not yet been written, so we need to write it.
dbi = self.getInterface("database")
dbi.writeDBEveryNode(cycle, timeNode)
if writeDB:
# database has not yet been written, so we need to write it.
dbi = self.getInterface("database")
dbi.writeDBEveryNode(cycle, timeNode)

def _interactAll(self, interactionName, activeInterfaces, *args):
"""
Expand Down
1 change: 1 addition & 0 deletions armi/operators/snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def _mainOperate(self):
self.interactAllEveryNode(
ssCycle, ssNode, excludedInterfaceNames=("database",)
)
self._performTightCoupling(ssCycle, ssNode, writeDB=False)

# database is excluded at last snapshot since it writes at EOL
exclude = ("database",) if (ssCycle, ssNode) == lastTimeStep else ()
Expand Down
21 changes: 21 additions & 0 deletions armi/operators/tests/test_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
from armi.physics.neutronics.globalFlux.globalFluxInterface import (
GlobalFluxInterfaceUsingExecuters,
)
from armi.utils import directoryChangers
from armi.bookkeeping.db.databaseInterface import DatabaseInterface


class InterfaceA(Interface):
Expand Down Expand Up @@ -107,6 +109,25 @@ def test_couplingIsActive(self):
self.o.cs["tightCoupling"] = True
self.assertTrue(self.o.couplingIsActive())

def test_dbWriteForCoupling(self):
with directoryChangers.TemporaryDirectoryChanger():
self.o.cs["tightCoupling"] = True
self.dbWriteForCoupling(writeDB=True)
self.dbWriteForCoupling(writeDB=False)

def dbWriteForCoupling(self, writeDB: bool):
self.o.removeAllInterfaces()
dbi = DatabaseInterface(self.r, self.o.cs)
dbi.initDB(fName=self._testMethodName + ".h5")
self.o.addInterface(dbi)
self.o._performTightCoupling(0, 0, writeDB=writeDB)
h5Contents = list(dbi.database.getH5Group(dbi.r).items())
if writeDB:
self.assertTrue(h5Contents)
else:
self.assertFalse(h5Contents)
dbi.database.close()

def test_computeTightCouplingConvergence(self):
"""ensure that tight coupling convergence can be computed and checked

Expand Down
1 change: 1 addition & 0 deletions doc/release/0.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ What's new in ARMI
#. Allow MCNP material card number to be defined after the card is written. (`PR#1086 <https://github.com/terrapower/armi/pull/1086>`_)
#. Refine logic for Block.getNumPins() to only count components that are actually pins. (`PR#1098 <https://github.com/terrapower/armi/pull/1098>`_)
#. Improve handling of peak/max parameters by the UniformMeshConverter parameter mapper. (`PR#1108 <https://github.com/terrapower/armi/pull/1108>`_)
#. Bug fix to expose new tight coupling functionality to ``OperatorSnapshots``. (`PR#1113 https://github.com/terrapower/armi/pull/1113`_)

Bug fixes
---------
Expand Down