Source code for armi.nuclearDataIO.cccc.tests.test_dif3d

# Copyright 2023 TerraPower, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Test reading/writing of DIF3D binary input."""
import os
import unittest

from armi.nuclearDataIO.cccc import dif3d
from armi.utils.directoryChangers import TemporaryDirectoryChanger

THIS_DIR = os.path.dirname(__file__)

SIMPLE_HEXZ_INP = os.path.join(THIS_DIR, "../../tests", "simple_hexz.inp")
SIMPLE_HEXZ_DIF3D = os.path.join(THIS_DIR, "fixtures", "simple_hexz.dif3d")


[docs]class TestDif3dSimpleHexz(unittest.TestCase): @classmethod def setUpClass(cls): """ Load DIF3D data from binary file. This binary file was generated by running dif3d.exe v11.0r3284 on the SIMPLE_HEXZ_INP file above (and renaming the DIF3D binary file to simple_hexz.dif3d). """ cls.df = dif3d.Dif3dStream.readBinary(SIMPLE_HEXZ_DIF3D)
[docs] def test__rwFileID(self): """Verify the file identification info. .. test:: Test reading DIF3D files. :id: T_ARMI_NUCDATA_DIF3D0 :tests: R_ARMI_NUCDATA_DIF3D """ self.assertEqual(self.df.metadata["HNAME"], "DIF3D") self.assertEqual(self.df.metadata["HUSE1"], "") self.assertEqual(self.df.metadata["HUSE2"], "") self.assertEqual(self.df.metadata["VERSION"], 1)
[docs] def test__rwFile1DRecord(self): """Verify the rest of the metadata. .. test:: Test reading DIF3D files. :id: T_ARMI_NUCDATA_DIF3D1 :tests: R_ARMI_NUCDATA_DIF3D """ TITLE_A6 = ["3D Hex", "-Z to", "genera", "te NHF", "LUX fi", "le"] EXPECTED_TITLE = TITLE_A6 + [""] * 5 for i in range(dif3d.TITLE_RANGE): self.assertEqual(self.df.metadata[f"TITLE{i}"], EXPECTED_TITLE[i]) self.assertEqual(self.df.metadata["MAXSIZ"], 10000) self.assertEqual(self.df.metadata["MAXBLK"], 1800000) self.assertEqual(self.df.metadata["IPRINT"], 0)
[docs] def test__rw2DRecord(self): """Verify the control parameters.""" EXPECTED_2D = [ 0, 0, 0, 10000, 30, 0, 1000000000, 5, 0, 0, 50, 0, 1, 1, 0, 0, 0, 110, 10, 100, 1, 0, 0, 0, 0, 0, 0, 0, 0, 10, 40, 32, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ] for i, param in enumerate(dif3d.FILE_SPEC_2D_PARAMS): self.assertEqual(self.df.twoD[param], EXPECTED_2D[i])
[docs] def test__rw3DRecord(self): """Verify the convergence criteria and other floating point data.""" EXPECTED_3D = [ 1e-7, 1e-5, 1e-5, 3.823807613470224e-01, 1e-3, 4e-2, 1e0, 0e0, 0e0, 9.999999747378752e-05, ] + [0.0 for i in range(1, 21)] for i, param in enumerate(dif3d.FILE_SPEC_3D_PARAMS): self.assertEqual(self.df.threeD[param], EXPECTED_3D[i])
[docs] def test__rw4DRecord(self): """Verify the optimum overrelaxation factors.""" self.assertEqual(self.df.fourD, None)
[docs] def test__rw5DRecord(self): """Verify the axial coarse-mesh rebalance boundaries.""" self.assertEqual(self.df.fiveD, None)
[docs] def test_writeBinary(self): """Verify binary equivalence of written DIF3D file. .. test:: Test writing DIF3D files. :id: T_ARMI_NUCDATA_DIF3D2 :tests: R_ARMI_NUCDATA_DIF3D """ with TemporaryDirectoryChanger(): dif3d.Dif3dStream.writeBinary(self.df, "DIF3D2") with open(SIMPLE_HEXZ_DIF3D, "rb") as f1, open("DIF3D2", "rb") as f2: expectedData = f1.read() actualData = f2.read() for expected, actual in zip(expectedData, actualData): self.assertEqual(expected, actual)
[docs]class TestDif3dEmptyRecords(unittest.TestCase):
[docs] def test_empty4and5Records(self): """Since the inputs results in these being None, get test coverage another way.""" df = dif3d.Dif3dStream.readBinary(SIMPLE_HEXZ_DIF3D) # Hack some values that allow 4 and 5 records to be populated \ # and then populate them df.twoD["NUMORP"] = 1 df.twoD["NCMRZS"] = 1 df.fourD = {"OMEGA1": 1.0} df.fiveD = {"ZCMRC1": 1.0, "NZINTS1": 10} with TemporaryDirectoryChanger(): # Write then read a new one dif3d.Dif3dStream.writeBinary(df, "DIF3D2") df2 = dif3d.Dif3dStream.readBinary("DIF3D2") # Kinda a null test, but this coverage caught some code mistakes! self.assertEqual(df2.fourD, df.fourD) self.assertEqual(df2.fiveD, df.fiveD)