From 2d859a3e51ee63f1218ced46d9a58a7970af1361 Mon Sep 17 00:00:00 2001 From: Virinder Sandhu Date: Tue, 6 Feb 2024 13:28:16 -0800 Subject: [PATCH 1/3] Update reader to ignore the 2D record when nSurf is less than 2 --- armi/nuclearDataIO/cccc/nhflux.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/armi/nuclearDataIO/cccc/nhflux.py b/armi/nuclearDataIO/cccc/nhflux.py index 87a5ae64d..c4a210d8f 100644 --- a/armi/nuclearDataIO/cccc/nhflux.py +++ b/armi/nuclearDataIO/cccc/nhflux.py @@ -253,8 +253,10 @@ 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 one for VARSRC files, which are a subset of NHFLUX files). + if self._metadata["nSurf"] > 1: + self._rwGeodstCoordMap2D() # Number of energy groups ng = self._metadata["ngroup"] @@ -320,7 +322,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): From 5476dfdc4d0d3e24cc9e2a9afef76734bd7729e5 Mon Sep 17 00:00:00 2001 From: Virinder Sandhu Date: Tue, 6 Feb 2024 13:30:10 -0800 Subject: [PATCH 2/3] Create VARSRC reading test 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. --- armi/nuclearDataIO/cccc/tests/test_nhflux.py | 58 +++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/armi/nuclearDataIO/cccc/tests/test_nhflux.py b/armi/nuclearDataIO/cccc/tests/test_nhflux.py index 7bd39bef7..94e8eecab 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 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,)) From 24daf154527e2384b4d49bb35edfaf4fe5baceba Mon Sep 17 00:00:00 2001 From: Virinder Sandhu Date: Tue, 6 Feb 2024 15:11:45 -0800 Subject: [PATCH 3/3] Update comments --- armi/nuclearDataIO/cccc/nhflux.py | 5 +++-- armi/nuclearDataIO/cccc/tests/test_nhflux.py | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/armi/nuclearDataIO/cccc/nhflux.py b/armi/nuclearDataIO/cccc/nhflux.py index c4a210d8f..f8efbeff5 100644 --- a/armi/nuclearDataIO/cccc/nhflux.py +++ b/armi/nuclearDataIO/cccc/nhflux.py @@ -253,8 +253,9 @@ 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. This record is only required when nSurf is greater than 1 (it - # is equal to one for VARSRC files, which are a subset of NHFLUX files). + # 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() diff --git a/armi/nuclearDataIO/cccc/tests/test_nhflux.py b/armi/nuclearDataIO/cccc/tests/test_nhflux.py index 94e8eecab..d791c33fb 100644 --- a/armi/nuclearDataIO/cccc/tests/test_nhflux.py +++ b/armi/nuclearDataIO/cccc/tests/test_nhflux.py @@ -222,8 +222,8 @@ def setUpClass(cls): 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. + 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():