Exemple #1
0
    def setUp(self):
        """provide the base case"""
        _o, r = loadTestReactor(
            os.path.join(TEST_ROOT, "detailedAxialExpansion"),
            {"inputHeightsConsideredHot": True},
        )
        self.stdAssems = [a for a in r.core.getAssemblies()]

        _oCold, rCold = loadTestReactor(
            os.path.join(TEST_ROOT, "detailedAxialExpansion"),
            {"inputHeightsConsideredHot": False},
        )
        self.testAssems = [a for a in rCold.core.getAssemblies()]
Exemple #2
0
    def test_interactBOC(self):
        o, r = loadTestReactor()
        repInt = reportInterface.ReportInterface(r, o.cs)

        self.assertEqual(repInt.fuelCycleSummary["bocFissile"], 0.0)
        repInt.interactBOC(1)
        self.assertEqual(repInt.fuelCycleSummary["bocFissile"], 0.0)
Exemple #3
0
    def test_createRepresentativeBlocksUsingExistingBlocks(self):
        """
        Demonstrates that a new representative block can be generated from an existing representative block.

        Notes
        -----
        This tests that the XS ID of the new representative block is correct and that the compositions are identical
        between the original and the new representative blocks.
        """
        _o, r = test_reactors.loadTestReactor(TEST_ROOT)
        self.csm.createRepresentativeBlocks()
        unperturbedReprBlocks = copy.deepcopy(self.csm.representativeBlocks)
        self.assertNotIn("BA", unperturbedReprBlocks)
        block = r.core.getFirstBlock()
        blockXSID = block.getMicroSuffix()
        blockList = [block]
        (
            _bCollect,
            newRepresentativeBlocks,
        ) = self.csm.createRepresentativeBlocksUsingExistingBlocks(
            blockList, unperturbedReprBlocks)
        self.assertIn("BA", newRepresentativeBlocks)
        oldReprBlock = unperturbedReprBlocks[blockXSID]
        newReprBlock = newRepresentativeBlocks["BA"]
        self.assertEqual(newReprBlock.getMicroSuffix(), "BA")
        self.assertEqual(newReprBlock.getNumberDensities(),
                         oldReprBlock.getNumberDensities())
Exemple #4
0
    def test_compareDatabaseDuplicate(self):
        """end-to-end test of compareDatabases() on a photocopy database"""
        # build two super-simple H5 files for testing
        o, r = test_reactors.loadTestReactor(TEST_ROOT)

        # create two DBs, identical but for file names
        dbs = []
        for i in range(2):
            # create the tests DB
            dbi = database3.DatabaseInterface(r, o.cs)
            dbi.initDB(fName=self._testMethodName + str(i) + ".h5")
            db = dbi.database

            # validate the file exists, and force it to be readable again
            b = h5py.File(db._fullPath, "r")
            self.assertEqual(list(b.keys()), ["inputs"])
            self.assertEqual(sorted(b["inputs"].keys()),
                             ["blueprints", "geomFile", "settings"])
            b.close()

            # append to lists
            dbs.append(db)

        # end-to-end validation that comparing a photocopy database works
        diffs = compareDatabases(dbs[0]._fullPath, dbs[1]._fullPath)
        self.assertEqual(len(diffs.diffs), 0)
        self.assertEqual(diffs.nDiffs(), 0)
Exemple #5
0
    def test_addInterfaceSubclassCollision(self):

        self.cs = settings.Settings()
        o, r = test_reactors.loadTestReactor()

        interfaceA = InterfaceA(r, self.cs)

        interfaceB = InterfaceB(r, self.cs)
        o.addInterface(interfaceA)

        # 1) Adds B and gets rid of A
        o.addInterface(interfaceB)
        self.assertEqual(o.getInterface("Second"), interfaceB)
        self.assertEqual(o.getInterface("First"), None)

        # 2) Now we have B which is a subclass of A,
        #    we want to not add A (but also not have an error)

        o.addInterface(interfaceA)
        self.assertEqual(o.getInterface("Second"), interfaceB)
        self.assertEqual(o.getInterface("First"), None)

        # 3) Also if another class not a subclass has the same function,
        #    raise an error
        interfaceC = InterfaceC(r, self.cs)

        self.assertRaises(RuntimeError, o.addInterface, interfaceC)

        # 4) Check adding a different function Interface

        interfaceC.function = "C"

        o.addInterface(interfaceC)
        self.assertEqual(o.getInterface("Second"), interfaceB)
        self.assertEqual(o.getInterface("Third"), interfaceC)
Exemple #6
0
    def test_convert(self):
        """Test conversion with no fuel driver."""
        block = (
            loadTestReactor(TEST_ROOT)[1]
            .core.getAssemblies(Flags.FUEL)[2]
            .getFirstBlock(Flags.FUEL)
        )
        area = block.getArea()
        converter = blockConverters.HexComponentsToCylConverter(block)
        converter.convert()
        self.assertAlmostEqual(area, converter.convertedBlock.getArea())
        self.assertAlmostEqual(area, block.getArea())

        for compType in [Flags.FUEL, Flags.CLAD, Flags.DUCT]:
            self.assertAlmostEqual(
                block.getComponent(compType).getArea(),
                sum(
                    [
                        component.getArea()
                        for component in converter.convertedBlock
                        if component.hasFlags(compType)
                    ]
                ),
            )

        self._checkAreaAndComposition(block, converter.convertedBlock)
        self._checkCiclesAreInContact(converter.convertedBlock)
Exemple #7
0
 def setUp(self):
     self.o, self.r = test_reactors.loadTestReactor(
         TEST_ROOT, customSettings={"xsKernel": "MC2v2"}
     )
     self.r.core.lib = isotxs.readBinary(ISOAA_PATH)
     self.r.core.p.keff = 1.0
     self.converter = uniformMesh.NeutronicsUniformMeshConverter()
Exemple #8
0
    def test_mapper(self):
        # Switch to MC2v2 setting to make sure the isotopic/elemental expansions are compatible
        # with actually doing some math using the ISOAA test microscopic library
        _o, r = test_reactors.loadTestReactor(customSettings={"xsKernel": "MC2v2"})
        applyDummyFlux(r)
        r.core.lib = isotxs.readBinary(ISOAA_PATH)
        mapper = globalFluxInterface.GlobalFluxResultMapper()
        mapper.r = r
        mapper._renormalizeNeutronFluxByBlock(100)
        self.assertAlmostEqual(r.core.calcTotalParam("power", generationNum=2), 100)

        mapper._updateDerivedParams()
        self.assertGreater(r.core.p.maxPD, 0.0)
        self.assertGreater(r.core.p.maxFlux, 0.0)

        mapper.updateDpaRate()
        block = r.core.getFirstBlock()
        self.assertGreater(block.p.detailedDpaRate, 0)
        self.assertEqual(block.p.detailedDpa, 0)

        # Test DoseResultsMapper. Pass in full list of blocks to apply() in order
        # to exercise blockList option (does not change behavior, since this is what
        # apply() does anyway)
        opts = globalFluxInterface.GlobalFluxOptions("test")
        dosemapper = globalFluxInterface.DoseResultsMapper(1000, opts)
        dosemapper.apply(r, blockList=r.core.getBlocks())
        self.assertGreater(block.p.detailedDpa, 0)

        mapper.clearFlux()
        self.assertEqual(len(block.p.mgFlux), 0)
Exemple #9
0
    def test_classesInHierarchy(self):
        """Tests the classesInHierarchy utility

        .. test:: Tests that the Reactor is stored heirarchically
           :id: TEST_REACTOR_HIERARCHY_0
           :links: REQ_REACTOR_HIERARCHY

           This test shows that the Blocks and Assemblies are stored
           heirarchically inside the Core, which is inside the Reactor object.
        """
        # load the test reactor
        o, r = loadTestReactor()

        # call the `classesInHierarchy` function
        classCounts = defaultdict(lambda: 0)
        utils.classesInHierarchy(r, classCounts, None)

        # validate the `classesInHierarchy` function
        self.assertGreater(len(classCounts), 30)
        self.assertEqual(classCounts[type(r)], 1)
        self.assertEqual(classCounts[type(r.core)], 1)

        # further validate the Reactor heirarchy is in place
        self.assertGreater(len(r.core.getAssemblies()), 50)
        self.assertGreater(len(r.core.getBlocks()), 200)
Exemple #10
0
    def setUpClass(cls):
        cls.td = directoryChangers.TemporaryDirectoryChanger()
        cls.td.__enter__()

        # The database writes the settings object to the DB rather
        # than the original input file. This allows settings to be
        # changed in memory like this and survive for testing.
        newSettings = {"verbosity": "extra"}
        newSettings["nCycles"] = 2
        newSettings["burnSteps"] = 3
        o, _r = test_reactors.loadTestReactor(customSettings=newSettings)

        settings.setMasterCs(o.cs)

        o.interfaces = [i for i in o.interfaces if isinstance(i, (DatabaseInterface))]
        dbi = o.getInterface("database")
        dbi.enabled(True)
        dbi.initDB()  # Main Interface normally does this

        # update a few parameters
        def writeFlux(cycle, node):
            for bi, b in enumerate(o.r.core.getBlocks()):
                b.p.flux = 1e6 * bi + cycle * 100 + node
                b.p.mgFlux = numpy.repeat(b.p.flux / 33, 33)

        o.interfaces.insert(0, MockInterface(o.r, o.cs, writeFlux))
        with o:
            o.operate()

        cls.cs = o.cs
        cls.bp = o.r.blueprints
        cls.dbName = o.cs.caseTitle + ".h5"

        # needed for test_readWritten
        cls.r = o.r
Exemple #11
0
    def test_splitZones(self):
        # Test to make sure that we can split a zone containing control and fuel assemblies.
        # Also test that we can separate out assemblies with differing numbers of blocks.

        o, r = test_reactors.loadTestReactor(inputFileName="partisnTestReactor.yaml")
        cs = o.cs
        cs["splitZones"] = False
        cs[globalSettings.CONF_ZONING_STRATEGY] = "byRingZone"
        cs["ringZones"] = [1, 2, 3, 4, 5, 6, 7, 8, 9]
        diverseZone = "ring-4"
        r.core.buildZones(cs)
        daZones = r.core.zones
        # lets make one of the assemblies have an extra block
        zoneLocations = daZones.getZoneLocations(diverseZone)
        originalAssemblies = r.core.getLocationContents(
            zoneLocations, assemblyLevel=True
        )
        fuel = [a for a in originalAssemblies if a.hasFlags(Flags.FUEL)][0]
        newBlock = copy.deepcopy(fuel[-1])
        fuel.add(newBlock)

        # should contain a zone for every ring zone
        # we only want one ring zone for this test, containing assemblies of different types.
        zoneTup = tuple(daZones.names)
        for zoneName in zoneTup:
            if zoneName != diverseZone:
                daZones.removeZone(zoneName)
        # this should split diverseZone into multiple zones by nodalization type.
        cs["splitZones"] = True
        zones.splitZones(r.core, cs, daZones)
        # test to make sure that we split the ring zone correctly
        self.assertEqual(len(daZones["ring-4-primary-control-5"]), 2)
        self.assertEqual(len(daZones["ring-4-middle-fuel-5"]), 3)
        self.assertEqual(len(daZones["ring-4-middle-fuel-6"]), 1)
    def test_macroXSGenerationInterface(self):
        cs = Settings()
        o, r = loadTestReactor()
        i = MacroXSGenerationInterface(r, cs)

        self.assertIsNone(i.macrosLastBuiltAt)
        self.assertEqual(i.name, "macroXsGen")
Exemple #13
0
    def setUpClass(cls):
        caseSetting = settings.Settings()
        _, cls.r = test_reactors.loadTestReactor()

        cls.hexBlock = cls.r.core.getBlocks()[0]

        cls.cartesianBlock = blocks.CartesianBlock("TestCartesianBlock",
                                                   caseSetting)
        cartesianComponent = components.HoledSquare(
            "duct",
            "UZr",
            Tinput=273.0,
            Thot=273.0,
            holeOD=68.0,
            widthOuter=12.5,
            mult=1.0,
        )
        cls.cartesianBlock.add(cartesianComponent)
        cls.cartesianBlock.add(
            components.Circle("clad",
                              "HT9",
                              Tinput=273.0,
                              Thot=273.0,
                              od=68.0,
                              mult=169.0))
Exemple #14
0
 def test_convertHexWithFuelDriver(self):
     """Test conversion with fuel driver."""
     driverBlock = (loadTestReactor(TEST_ROOT)[1].core.getAssemblies(
         Flags.FUEL)[2].getFirstBlock(Flags.FUEL))
     block = loadTestReactor(TEST_ROOT)[1].core.getFirstBlock(Flags.CONTROL)
     self._testConvertWithDriverRings(
         block,
         driverBlock,
         blockConverters.HexComponentsToCylConverter,
         hexagon.numPositionsInRing,
     )
     self._testConvertWithDriverRings(
         block,
         driverBlock,
         blockConverters.BlockAvgToCylConverter,
         hexagon.numPositionsInRing,
     )
 def setUpClass(cls):
     random.seed(987324987234)  # so it's always the same
     cls.o, cls.r = test_reactors.loadTestReactor(
         TEST_ROOT, customSettings={"xsKernel": "MC2v2"})
     cls.r.core.lib = isotxs.readBinary(ISOAA_PATH)
     # make the mesh a little non-uniform
     a = cls.r.core[4]
     a[2].setHeight(a[2].getHeight() * 1.05)
Exemple #16
0
    def test_interactEOL(self):
        o, r = loadTestReactor()
        repInt = reportInterface.ReportInterface(r, o.cs)

        with mockRunLogs.BufferLog() as mock:
            repInt.interactEOL()
            self.assertIn("Comprehensive Core Report", mock._outputStream)
            self.assertIn("Assembly Area Fractions", mock._outputStream)
Exemple #17
0
    def test_interactEOC(self):
        o, r = loadTestReactor()
        repInt = reportInterface.ReportInterface(r, o.cs)

        with mockRunLogs.BufferLog() as mock:
            repInt.interactEOC(0)
            self.assertIn("Cycle 0", mock._outputStream)
            self.assertIn("TIMER REPORTS", mock._outputStream)
 def setUp(self):
     self.o, self.r = loadTestReactor(TEST_ROOT)
     self.cs = settings.getMasterCs()
     runLog.setVerbosity("extra")
     self._expandReactor = False
     self._massScaleFactor = 1.0
     if not self._expandReactor:
         self._massScaleFactor = 3.0
Exemple #19
0
 def setUp(self):
     self.o, self.r = loadTestReactor(TEST_ROOT, {"circularRingMode": True})
     self.cs = settings.getMasterCs()
     runLog.setVerbosity("info")
     self._expandReactor = False
     self._massScaleFactor = 1.0
     if not self._expandReactor:
         self._massScaleFactor = 3.0
Exemple #20
0
    def setUp(self):
        self.td = directoryChangers.TemporaryDirectoryChanger()
        self.td.__enter__()
        self.o, self.r = test_reactors.loadTestReactor(TEST_ROOT)

        self.dbi = DatabaseInterface(self.r, self.o.cs)
        self.dbi.initDB(fName=self._testMethodName + ".h5")
        self.db: db.Database3 = self.dbi.database
        self.stateRetainer = self.r.retainState().__enter__()
Exemple #21
0
    def test_interactEveryNode(self):
        o, r = loadTestReactor()
        repInt = reportInterface.ReportInterface(r, o.cs)

        with mockRunLogs.BufferLog() as mock:
            repInt.interactEveryNode(0, 0)
            self.assertIn("Cycle 0", mock._outputStream)
            self.assertIn("node 0", mock._outputStream)
            self.assertIn("keff=", mock._outputStream)
Exemple #22
0
 def test_convertCartesianLatticeWithFuelDriver(self):
     """Test conversion with fuel driver."""
     r = loadTestReactor(TEST_ROOT, inputFileName="zpprTest.yaml")[1]
     driverBlock = r.core.getAssemblies(Flags.FUEL)[2].getFirstBlock(Flags.FUEL)
     block = r.core.getAssemblies(Flags.FUEL)[2].getFirstBlock(Flags.BLANKET)
     converter = blockConverters.BlockAvgToCylConverter
     self._testConvertWithDriverRings(
         block, driverBlock, converter, lambda n: (n - 1) * 8
     )
Exemple #23
0
 def setUpClass(cls):
     # random seed to support random mesh in unit tests below
     random.seed(987324987234)
     cls.o, cls.r = test_reactors.loadTestReactor(
         TEST_ROOT, customSettings={"xsKernel": "MC2v2"})
     cls.r.core.lib = isotxs.readBinary(ISOAA_PATH)
     # make the mesh a little non-uniform
     a = cls.r.core[4]
     a[2].setHeight(a[2].getHeight() * 1.05)
Exemple #24
0
 def setUp(self):
     self.o, self.r = loadTestReactor(TEST_ROOT)
     self._converterSettings = {
         "uniformThetaMesh": True,
         "thetaBins": 1,
         "thetaMesh": [2 * math.pi],
         "axialMesh": [25.0, 50.0, 174.0],
         "axialSegsPerBin": 1,
     }
Exemple #25
0
    def setUp(self):
        r"""
        Build a dummy reactor without using input files. There are some igniters and feeds
        but none of these have any number densities.
        """
        self.o, self.r = test_reactors.loadTestReactor(
            self.directoryChanger.destination
        )
        blockList = self.r.core.getBlocks()
        for bi, b in enumerate(blockList):
            b.p.flux = 5e10
            if b.isFuel():
                b.p.percentBu = 30.0 * bi / len(blockList)
        self.nfeed = len(self.r.core.getAssemblies(Flags.FEED))
        self.nigniter = len(self.r.core.getAssemblies(Flags.IGNITER))
        self.nSfp = len(self.r.core.sfp)

        # generate a reactor with assemblies
        # generate components with materials
        nPins = 271

        fuelDims = {"Tinput": 273.0, "Thot": 273.0, "od": 1.0, "id": 0.0, "mult": nPins}
        fuel = components.Circle("fuel", "UZr", **fuelDims)

        cladDims = {"Tinput": 273.0, "Thot": 273.0, "od": 1.1, "id": 1.0, "mult": nPins}
        clad = components.Circle("clad", "HT9", **cladDims)

        interDims = {
            "Tinput": 273.0,
            "Thot": 273.0,
            "op": 16.8,
            "ip": 16.0,
            "mult": 1.0,
        }
        interSodium = components.Hexagon("interCoolant", "Sodium", **interDims)

        # generate a block
        self.block = blocks.HexBlock("TestHexBlock", self.o.cs)
        self.block.setType("fuel")
        self.block.setHeight(10.0)
        self.block.add(fuel)
        self.block.add(clad)
        self.block.add(interSodium)

        # generate an assembly
        self.assembly = assemblies.HexAssembly("TestAssemblyType")
        self.assembly.spatialGrid = grids.axialUnitGrid(1)
        for _ in range(1):
            self.assembly.add(copy.deepcopy(self.block))

        # copy the assembly to make a list of assemblies and have a reference assembly
        self.aList = []
        for _ in range(6):
            self.aList.append(copy.deepcopy(self.assembly))

        self.refAssembly = copy.deepcopy(self.assembly)
        self.directoryChanger.open()
Exemple #26
0
    def test_interactBOLReportInt(self):
        o, r = loadTestReactor()
        repInt = reportInterface.ReportInterface(r, o.cs)

        with mockRunLogs.BufferLog() as mock:
            repInt.interactBOL()
            self.assertIn("Writing assem layout", mock._outputStream)
            self.assertIn("BOL Assembly", mock._outputStream)
            self.assertIn("wetMass", mock._outputStream)
            self.assertIn("moveable plenum", mock._outputStream)
    def test_isotopicDepletionInterface(self):
        o, r = loadTestReactor()
        cs = Settings()

        aid = idi.AbstractIsotopicDepleter(r, cs)
        self.assertIsNone(aid.efpdToBurn)
        self.assertEqual(len(aid._depleteByName), 0)

        self.assertEqual(len(aid.getToDeplete()), 0)
        self.assertEqual(ORDER, 5.0)
    def setUpClass(cls):
        o, r = test_reactors.loadTestReactor()
        opts = executionOptions.Dif3dOptions("test-output-file")
        opts.fromUserSettings(o.cs)
        opts.resolveDerivedOptions()
        opts.fromReactor(r)
        with directoryChangers.DirectoryChanger(FIXTURE_DIR):
            outputReader = outputReaders.Dif3dReader(opts)
            outputReader.apply(r)

        cls.r = r
Exemple #29
0
    def test_convertHexWithFuelDriver(self):
        """Test conversion with fuel driver."""
        driverBlock = (loadTestReactor(TEST_ROOT)[1].core.getAssemblies(
            Flags.FUEL)[2].getFirstBlock(Flags.FUEL))

        block = loadTestReactor(TEST_ROOT)[1].core.getFirstBlock(Flags.CONTROL)

        driverBlock.spatialGrid = None
        block.spatialGrid = grids.HexGrid.fromPitch(1.0)

        self._testConvertWithDriverRings(
            block,
            driverBlock,
            blockConverters.HexComponentsToCylConverter,
            hexagon.numPositionsInRing,
        )

        # This should fail because a spatial grid is required
        # on the block.
        driverBlock.spatialGrid = None
        block.spatialGrid = None
        with self.assertRaises(ValueError):
            self._testConvertWithDriverRings(
                block,
                driverBlock,
                blockConverters.HexComponentsToCylConverter,
                hexagon.numPositionsInRing,
            )

        # The ``BlockAvgToCylConverter`` should work
        # without any spatial grid defined because it
        # assumes the grid based on the block type.
        driverBlock.spatialGrid = None
        block.spatialGrid = None

        self._testConvertWithDriverRings(
            block,
            driverBlock,
            blockConverters.BlockAvgToCylConverter,
            hexagon.numPositionsInRing,
        )
Exemple #30
0
    def setUp(self):
        self.o, self.r = test_reactors.loadTestReactor(TEST_ROOT)
        cs = self.o.cs

        self.dbi = database3.DatabaseInterface(self.r, cs)
        self.dbi.initDB(fName=self._testMethodName + ".h5")
        self.db: db.Database3 = self.dbi.database
        self.stateRetainer = self.r.retainState().__enter__()

        # used to test location-based history. see details below
        self.centralAssemSerialNums = []
        self.centralTopBlockSerialNums = []