diff --git a/armi/nuclearDataIO/cccc/nhflux.py b/armi/nuclearDataIO/cccc/nhflux.py index 7d740cf95..63057549b 100644 --- a/armi/nuclearDataIO/cccc/nhflux.py +++ b/armi/nuclearDataIO/cccc/nhflux.py @@ -251,8 +251,11 @@ def readWrite(self): # Read the hex ordering map between DIF3D nodal and DIF3D GEODST. Also read index # pointers to incoming partial currents on outer reactor surface (these don't # belong to any assembly). Incoming partial currents are non-zero due to flux - # extrapolation - self._rwGeodstCoordMap2D() + # extrapolation. This record is only required when nSurf is greater than 1. It + # is equal to 1 for VARSRC files, which are a subset of NHFLUX files; VARSRC files + # do not have a 2D record (or 4D or 5D records). + if self._metadata["nSurf"] > 1: + self._rwGeodstCoordMap2D() # Number of energy groups ng = self._metadata["ngroup"] @@ -318,7 +321,7 @@ def readWrite(self): self._data.fluxMomentsAll[:, z, :, gEff] ) - # Process currents + # Process currents, but only if iwnhfl is not equal to 1. if self._metadata["iwnhfl"] != 1: # Loop through axial nodes for z in range(nz): diff --git a/armi/nuclearDataIO/cccc/tests/test_nhflux.py b/armi/nuclearDataIO/cccc/tests/test_nhflux.py index 7bd39bef7..d791c33fb 100644 --- a/armi/nuclearDataIO/cccc/tests/test_nhflux.py +++ b/armi/nuclearDataIO/cccc/tests/test_nhflux.py @@ -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( @@ -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 modified data structure to file. Then, we 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,))