def writeToDB(self, reactor, statePointName=None): """ Puts self.r in the database. Parameters ---------- statePointName: str, optional explicit name of the state point to be written. A state point is not necessarily a cycle or time node, it may make the most sense to simply think of it as a label for the current state. """ if self._initDatabaseContact: self._createDBSchema(reactor) self._initDatabaseContact = False if statePointName: statePointName = statePointName else: # check for None instead of truth since these may be 0 cycle = reactor.p.cycle node = reactor.p.timeNode statePointName = utils.getTimeStepNum(cycle, node, settings.getMasterCs()) self._writeReactorParams(reactor, statePointName) self._writeAssemblyParams(reactor, statePointName) self._writeBlockParams(reactor, statePointName) self._writeComponentParams(reactor, statePointName) self._numTimeSteps = -1 # update numTimeSteps attribute
def genAuxiliaryData(self, ts: Tuple[int, int]) -> Generator[str, None, None]: cycle, node = ts cs = self.loadCS() tn = utils.getTimeStepNum(cycle, node, cs) specialKeys = {"reactors", "blocks", "assemblies"} return (str(tn) + "/" + key for key in self._hdf_file[str(tn)].keys() if key not in specialKeys)
def getTimeIndices(self, a=None, boc=False, moc=False, eoc=False): r""" Generate a list of timestep indices where valid history data exist for the given criteria. Parameters ---------- a : Assembly, optional If given, only generate time indices where the assembly `a` is in the core. Default: All assemblies. boc, moc, eoc : bool, optional Will return boc/moc/eoc timenodes in every cycle. If any of these are true, allNodes becomes False Returns ------- timeIndices : list A list of integers where history data exists. Examples -------- If there are 5 nodes per cycle (burnSteps = 4), 0 1 2 3 4 | 5 6 7 8 9 | 10 11 12 13 14 | ...: >>> getTimeIndices(moc=True): [2, 7, 12, ...] See Also -------- getTimeSteps : gets time in years where the assembly is in the core """ timeIndices = [] for globalNode in range( utils.getTimeStepNum(self.r.p.cycle, self.r.p.timeNode, self.cs) + 1): if a is None: timeIndices.append(globalNode) else: fBlock = a.getFirstBlock(Flags.FUEL) if fBlock is None: blockLocationLabel = None else: blockLocationLabel = self._blockLocationAtTimenode( fBlock, globalNode) runLog.info( "Location label of {} at timestep {} is {}".format( fBlock, globalNode, blockLocationLabel)) # only add this timestep if it's around for this assembly. if blockLocationLabel is not None: bLoc = locations.Location(label=blockLocationLabel) if bLoc.isInCore(): timeIndices.append(globalNode) return self.filterTimeIndices(timeIndices, boc, moc, eoc)
def load(self, cycle, node, cs=None, bp=None, geom=None): cs = cs or self.loadCS() settings.setMasterCs(cs) bp = bp or self.loadBlueprints() geom = geom or self.loadGeometry() if self._reactor is None: self._reactor = reactors.factory(cs, bp, geom) dbTimeStep = utils.getTimeStepNum(cycle, node, cs) self.updateFromDB(self._reactor, dbTimeStep) return self._reactor
def test_calcMGFluence(self): """ This test confirms that mg flux has many groups when loaded with the history tracker. armi.bookeeping.db.hdf.hdfDB.readBlocksHistory requires historical_values[historical_indices] to be cast as a list to read more than the first energy group. This test shows that this behavior is preserved. """ o = self.o b = o.r.core.childrenByLocator[o.r.core.spatialGrid[0, 0, 0]].getFirstBlock( Flags.FUEL) bVolume = b.getVolume() bName = b.name hti = o.getInterface("history") timesInYears = [duration or 1.0 for duration in hti.getTimeSteps() ] # duration is None in this DB timeStepsToRead = [ utils.getCycleNode(i, self.o.cs) for i in range(len(timesInYears)) ] hti.preloadBlockHistoryVals([bName], ["mgFlux"], timeStepsToRead) mgFluence = None for ts, years in enumerate(timesInYears): cycle, node = utils.getCycleNode(ts, self.o.cs) # get coverage for getTimeStepNum by checking against getcycleNode testTS = utils.getTimeStepNum(cycle, node, self.o.cs) self.assertEqual(ts, testTS) mgFlux = (hti.getBlockHistoryVal(bName, "mgFlux", (cycle, node)) / bVolume ) # b.p.mgFlux is vol integrated timeInSec = years * 365 * 24 * 3600 if mgFluence is None: mgFluence = timeInSec * mgFlux else: mgFluence += timeInSec * mgFlux self.assertTrue( len(mgFluence) > 1, "mgFluence should have more than 1 group")
def getAuxiliaryDataPath(self, ts: Tuple[int, int], name: str) -> str: cycle, node = ts cs = self.loadCS() tn = utils.getTimeStepNum(cycle, node, cs) return str(tn) + "/" + name
def getTimeIndices(self, a=None, boc=False, moc=False, eoc=False): r""" Generate a list of timestep indices where valid history data exist for the given criteria. Parameters ---------- a : Assembly, optional If given, only generate time indices where the assembly `a` is in the core. Default: All assemblies. boc, moc, eoc : bool, optional Will return boc/moc/eoc timenodes in every cycle. If any of these are true, allNodes becomes False Returns ------- timeIndices : list A list of integers where history data exists. Examples -------- If there are 5 nodes per cycle (burnSteps = 4), 0 1 2 3 4 | 5 6 7 8 9 | 10 11 12 13 14 | ...: >>> getTimeIndices(moc=True): [2, 7, 12, ...] Warning ------- This is no longer functional, as much of the old history tracking was based on implementation details of the Database, version 2. We now directly support history tracking through the Database, version 3. At some point this code should be removed. See Also -------- getTimeSteps : gets time in years where the assembly is in the core """ timeIndices = [] coreGrid = self.r.core.spatialGrid for globalNode in range( utils.getTimeStepNum(self.r.p.cycle, self.r.p.timeNode, self.cs) + 1): if a is None: timeIndices.append(globalNode) else: fBlock = a.getFirstBlock(Flags.FUEL) if fBlock is None: blockLocationLabel = None else: blockLocationLabel = self._blockLocationAtTimenode( fBlock, globalNode) runLog.info( "Location label of {} at timestep {} is {}".format( fBlock, globalNode, blockLocationLabel)) # only add this timestep if it's around for this assembly. if blockLocationLabel is not None: # this label doesn't actually properly correspond to the block # location label determined by _blockLocationAtTimenode. # blockLocationLabel is supposed to be coming from a previous time # state in the database. if a.spatialLocator.grid is coreGrid: timeIndices.append(globalNode) return self.filterTimeIndices(timeIndices, boc, moc, eoc)