Skip to content

Commit

Permalink
Create VARSRC reading test
Browse files Browse the repository at this point in the history
The test using the VARIANT NHFLUX file from the existing tests. I strip out
the datasets that are not present in the VARSRC file and build the test
based on that, rather than having to create a reference VARSRC file.
  • Loading branch information
Nebbychadnezzar committed Feb 6, 2024
1 parent 2d859a3 commit 5476dfd
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion armi/nuclearDataIO/cccc/tests/test_nhflux.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ def test_fluxMoments(self):
)

def test_write(self):
"""Verify binary equivalence of written binary file."""
"""
Verify binary equivalence of written binary file.
"""
with TemporaryDirectoryChanger():
nhflux.NhfluxStreamVariant.writeBinary(self.nhf, "NHFLUX2")
with open(SIMPLE_HEXZ_NHFLUX_VARIANT, "rb") as f1, open(
Expand All @@ -191,3 +193,57 @@ def test_write(self):
actualData = f2.read()
for expected, actual in zip(expectedData, actualData):
self.assertEqual(expected, actual)


class TestNhfluxVariantVarsrc(unittest.TestCase):
@classmethod
def setUpClass(cls):
"""
Load NHFLUX data from binary file. This file was produced using VARIANT v11.0
and is identical to the file used in TestNhfluxVariant.
"""
cls.nhf = nhflux.NhfluxStreamVariant.readBinary(SIMPLE_HEXZ_NHFLUX_VARIANT)

# Make the data structure match the format for VARSRC
cls.nhf.metadata["nSurf"] = 1
cls.nhf.metadata["iwnhfl"] = 1
cls.emptyDatasets = [
"incomingPointersToAllAssemblies",
"externalCurrentPointers",
"geodstCoordMap",
"outgoingPCSymSecPointers",
"ingoingPCSymSecPointers",
"partialCurrentsHexAll",
"partialCurrentsHex_extAll",
"partialCurrentsZAll",
]
for zeroDataset in cls.emptyDatasets:
setattr(cls.nhf, zeroDataset, np.array([]))

def test_writeRead(self):
"""
Write out the data structure to file. Then read it back in and make sure it matches
the data currently in memory.
"""
filename = "VARSRC"
with TemporaryDirectoryChanger():
nhflux.NhfluxStreamVariant.writeBinary(self.nhf, filename)
writtenVarsrc = nhflux.NhfluxStreamVariant.readBinary(filename)

# Make sure the metadata matches
self.assertEqual(len(writtenVarsrc.metadata), len(self.nhf.metadata))
for key in writtenVarsrc.metadata:
self.assertEqual(writtenVarsrc.metadata[key], self.nhf.metadata[key])

# Make sure that the flux moments match identically
self.assertTrue(
np.isclose(
writtenVarsrc.fluxMoments, self.nhf.fluxMoments, rtol=0.0, atol=0.0
).all()
)

# Make sure all other datasets are empty, since the reader should not be trying
# to populate them.
for zeroDataset in self.emptyDatasets:
dataset = getattr(self.nhf, zeroDataset)
self.assertEqual(dataset.shape, (0,))

0 comments on commit 5476dfd

Please sign in to comment.