def toENDF6(self, MT, endfMFList, flags, targetInfo): weight = targetInfo['delayedNubarWeight'] energySubform = self.energySubform if (hasattr(energySubform, 'toENDF6')): if (isinstance(energySubform, energyModule.constant)): energySubform.toENDF6(flags, targetInfo) return if (MT in [527, 528]): NK, MF5 = energySubform.toENDF6(flags, targetInfo, weight=weight, MT=MT) else: NK, MF5 = energySubform.toENDF6(flags, targetInfo, weight=weight) if (MT == 455): endfMFList[5][MT].append(MF5) elif (MT == 528): endfMFList[26][MT] = [ endfFormatsModule.endfHeadLine( targetInfo['ZA'], targetInfo['mass'], 0, 0, NK, 0 ) ] + \ MF5 + [ endfFormatsModule.endfSENDLineNumber( ) ] else: endfMFList[5][MT] = [ endfFormatsModule.endfHeadLine( targetInfo['ZA'], targetInfo['mass'], 0, 0, NK, 0 ) ] + \ MF5 + [ endfFormatsModule.endfSENDLineNumber( ) ] else: print 'WARNING: energy subform "%s" does not have method toENDF6' % energySubform.moniker
def toENDF6(self, MT, endfMFList, flags, targetInfo): endfMFList[1][MT] = [ endfFormatsModule.endfHeadLine(targetInfo['ZA'], targetInfo['mass'], 0, 1, 0, 0) ] endfMFList[1][MT] += [ endfFormatsModule.endfHeadLine(0, 0, 0, 0, len(self), 0) ] endfMFList[1][MT] += endfFormatsModule.endfDataList( self.coefficients) + [endfFormatsModule.endfSENDLineNumber()]
def fissionNeutronsToENDF6(MT, multiplicity, endfMFList, flags, targetInfo): if (isinstance(multiplicity, multiplicityModule.polynomial)): multiplicity.toENDF6(MT, endfMFList, flags, targetInfo) else: interpolation, n1, data = multiplicity.toENDF6List(targetInfo) if (MT not in endfMFList[1]): endfMFList[1][MT] = [ endfFormatsModule.endfHeadLine(targetInfo['ZA'], targetInfo['mass'], 0, 2, 0, 0) ] endfMFList[1][MT] += [ endfFormatsModule.endfHeadLine(0, 0, 0, 0, len(interpolation) / 2, n1) ] endfMFList[1][MT] += endfFormatsModule.endfInterpolationList( interpolation) endfMFList[1][MT] += data + [endfFormatsModule.endfSENDLineNumber()]
def toENDF6(self, MT, endfMFList, flags, targetInfo): if (MT == 502): MT = self.ancestor.ENDFMT Z = targetInfo['ZA'] / 1000 endfInterpolation = gndToENDF6Module.gndToENDFInterpolationFlag( self.interpolation) data = [] for xy in self.copyDataToXYs(xUnitTo='eV', yUnitTo=''): data += xy endfMFList[27][MT] = [ endfFormatsModule.endfHeadLine( targetInfo['ZA'], targetInfo['mass'], 0, 0, 0, 0 ), endfFormatsModule.endfContLine( 0, Z, 0, 0, 1, len( data ) / 2 ) ] + \ endfFormatsModule.endfInterpolationList( ( len( data ) / 2, endfInterpolation ) ) + \ endfFormatsModule.endfDataList( data ) + [ endfFormatsModule.endfSENDLineNumber( ) ]
def toENDF6(self, MT, endfMFList, targetInfo, level, LR): """ Convert self into ENDF format :param int MT: The ENDF reaction designator, MT :param endfMFList: :param targetInfo: :param level: :param LR: """ ZA, mass, QI, QM = targetInfo['ZA'], targetInfo['mass'], targetInfo[ 'Q'], targetInfo['QM'] if ('EFL' in targetInfo): QM = QI QI = targetInfo['EFL'] else: if (QM is None): if (MT in (2, 5)): QM = QI elif (MT == 4): # Q should be 0 except for excited-state targets: QM = 0 if (hasattr(targetInfo['reactionSuite'].target, 'getLevelIndex')): if (targetInfo['reactionSuite'].target.getLevelIndex() > 0): QM = QI else: QM = QI + level interpolationFlatData, crossSectionFlatData = self[ targetInfo['style']].toENDF6Data(MT, endfMFList, targetInfo, level) MF = targetInfo['crossSectionMF'] endfMFList[MF][MT] = [endfFormatsModule.endfHeadLine(ZA, mass, 0, 0, 0, 0)] endfMFList[MF][MT].append( endfFormatsModule.endfContLine(QM, QI, 0, LR, len(interpolationFlatData) / 2, len(crossSectionFlatData) / 2)) endfMFList[MF][MT] += endfFormatsModule.endfInterpolationList( interpolationFlatData) endfMFList[MF][MT] += endfFormatsModule.endfDataList(crossSectionFlatData) endfMFList[MF][MT].append(endfFormatsModule.endfSENDLineNumber())
def toENDF6(self, MT, endfMFList, flags, targetInfo, energyUnit='eV'): if (MT == 502): MT = self.ancestor.ENDFMT Z = targetInfo['ZA'] / 1000 endfInterpolation, data = [], [] counter, lastX, lastY = 0, None, None for region in self: ENDFInterpolation = gndToENDF6Module.gndToENDFInterpolationFlag( region.interpolation) regionData = region.copyDataToXYs(xUnitTo=energyUnit, yUnitTo='') if (lastX is not None): if (lastY == regionData[0][1]): del regionData[0] counter += len(regionData) endfInterpolation.append(counter) endfInterpolation.append(ENDFInterpolation) for xy in regionData: data += xy lastX, lastY = regionData[-1] endfMFList[27][MT] = [ endfFormatsModule.endfHeadLine( targetInfo['ZA'], targetInfo['mass'], 0, 0, 0, 0 ), endfFormatsModule.endfContLine( 0, Z, 0, 0, len( endfInterpolation ) / 2, len( data ) / 2 ) ] + \ endfFormatsModule.endfInterpolationList( endfInterpolation ) + \ endfFormatsModule.endfDataList( data ) + [ endfFormatsModule.endfSENDLineNumber( ) ]
def toENDF6(self, MT, endfMFList, flags, targetInfo): if (MT == 455) and (MT in endfMFList[4]): return # only write one 'isotropic' section for all delayed neutron groups angularSubform = self.angularSubform if (hasattr(angularSubform, 'toENDF6')): doMF4AsMF6 = targetInfo['doMF4AsMF6'] MF = 4 NM = 0 frame = self.productFrame if (frame is None): frame = self.ancestor.productFrame # Happens for uncorrelated distribution. if (isinstance(angularSubform, multiD_XYsModule.XYs2d)): if (isinstance(angularSubform[0], XYsModule.XYs1d)): LI, LTT, MF4 = toAngularPointwise(angularSubform, targetInfo, not (doMF4AsMF6)) elif (isinstance(angularSubform[0], series1dModule.LegendreSeries)): interpolation, numberOfPoints, LI, LTT, NM, MF4Sub = toAngularLegendre( angularSubform, targetInfo, not (doMF4AsMF6)) MF4 = [ endfFormatsModule.endfContLine( 0, 0, 0, 0, 1, numberOfPoints ) ] + \ endfFormatsModule.endfInterpolationList( [ len( angularSubform ), interpolation ] ) MF4 += MF4Sub else: raise 'hell - fix me' elif (isinstance(angularSubform, regionsModule.regions2d)): LTT, MF4, numberOfPoints, LegendreInterpolations, LegendreData = None, [], 0, [], [] for ridx, region in enumerate(angularSubform): targetInfo['skipFirstEnergy'] = False if ridx > 0 and type(angularSubform[ridx][0]) == type( angularSubform[ridx - 1][-1]): # FIXME: following should work once __eq__ fixed for xData. Shows up in ENDF-VII.1 Cu evaluations #if angularSubform[ridx-1][-1] == angularSubform[ridx][0]: targetInfo['skipFirstEnergy'] = True if isinstance(angularSubform[ridx][0], series1dModule.LegendreSeries): if angularSubform[ridx][ 0].coefficients == angularSubform[ ridx - 1][-1].coefficients: targetInfo['skipFirstEnergy'] = True else: raise NotImplementedError if (isinstance(region, angularModule.XYs2d)): if (isinstance(region[0], series1dModule.LegendreSeries)): interpolation, numberOfPointsSub, LI, LTTSub, NMtmp, MF4Sub = toAngularLegendre( region, targetInfo, not (doMF4AsMF6)) numberOfPoints += numberOfPointsSub NM = max(NM, NMtmp) LegendreInterpolations += [ numberOfPoints, interpolation ] elif (isinstance(region[0], XYsModule.XYs1d)): LI, LTTSub, MF4Sub = toAngularPointwise( region, targetInfo, not (doMF4AsMF6)) else: raise 'hell - fix me' if (len(MF4) > 0): MF4.pop(-1) MF4 += MF4Sub if (LTT is None): LTT = LTTSub if (LTT != LTTSub): if ((LTT == 1) and (LTTSub == 2)): LTT = 3 else: raise 'hell - fix me' else: raise 'hell - fix me' del targetInfo['skipFirstEnergy'] if (len(LegendreInterpolations) > 0): MF4 = [ endfFormatsModule.endfContLine( 0, 0, 0, 0, len( LegendreInterpolations ) / 2, LegendreInterpolations[-2] ) ] + \ endfFormatsModule.endfInterpolationList( LegendreInterpolations ) + MF4 ENDFDataList = [ endfFormatsModule.endfContLine(0, 0, 0, 0, 1, len(angularSubform)) ] ENDFDataList += endfFormatsModule.endfInterpolationList( [len(angularSubform), interpolation]) LI = 0 elif (isinstance(angularSubform, angularModule.recoil)): if not targetInfo['doMF4AsMF6']: return # recoil partners only get written to file 6 LI, LTT, MF4 = angularSubform.toENDF6(flags, targetInfo) MF = 6 elif (isinstance(angularSubform, angularModule.isotropic)): LI, LTT, MF4 = angularSubform.toENDF6(flags, targetInfo) MF = 4 if (doMF4AsMF6): MF = 6 else: brb.objectoutline(angularSubform) raise 'hell - fix me' if (doMF4AsMF6): if (LTT in [0]): LAW = 3 elif (LTT in [1, 2]): LAW = 2 elif (LTT in [4]): LAW = 4 else: raise Exception('LTT = %s needs a LAW' % LTT) gndToENDF6Module.toENDF6_MF6(MT, endfMFList, flags, targetInfo, LAW, frame, MF4) else: LCT = { standardsModule.frames.labToken: 1, standardsModule.frames.centerOfMassToken: 2 }[frame] if (MT not in endfMFList[MF]): endfMFList[MF][MT] = [] if LTT != 3: NM = 0 endfMFList[MF][MT] += [ endfFormatsModule.endfHeadLine( targetInfo['ZA'], targetInfo['mass'], 0, LTT, 0, 0), endfFormatsModule.endfHeadLine(0, targetInfo['mass'], LI, LCT, 0, NM) ] + MF4 else: print 'WARNING: subform %s does not have method toENDF6 for form %s' % ( targetInfo['style'], self.moniker)
def toENDF6(self, endfMFList, flags, targetInfo, verbosityIndent=''): def addDecayProducts(parent, products): if (parent.outputChannel is None): return (False) doMF4AsMF6 = False for product in parent.outputChannel: if (len(product.distribution) and (product.name != 'gamma')): if (product.attributes.get('ENDFconversionFlag') == 'MF6'): doMF4AsMF6 = True products.append(product) return (doMF4AsMF6) def divideIgnoring0DividedBy0(self, other): if (isinstance(self, XYsModule.XYs1d) and isinstance(other, XYsModule.XYs1d)): d = self.union( other.domainSlice(domainMin=self.domainMin(), domainMax=self.domainMax())) result = [] for p in d: vp = other.evaluate(p[0]) if (vp == 0): if (p[1] != 0): raise Exception( 'Divide non-zero number by zero at %e' % p[0]) else: p[1] = p[1] / vp result.append([p[0], p[1]]) return (XYsModule.pointwiseXY(data=result)) elif (isinstance(self, regionsModule.regions1d) and isinstance(other, regionsModule.regions1d) and len(self) == len(other)): regions = regionsModule.regions1d() for idx in range(len(self)): regions.append( XYsModule.XYs1d( data=divideIgnoring0DividedBy0(self[idx], other[idx]))) return regions else: raise NotImplementedError('Divide XYs1d by regions or vice-versa') def thinWeights(weights): i, n, thinnedWeights = 1, len(weights), [weights[0]] if (n == 2): thinnedWeights.append(weights[-1]) else: while (i < n): y = thinnedWeights[-1][1] while (True): i += 1 if (i == n): break if (abs(y - weights[i][1]) > 1e-8 * y): break if (abs(y - weights[i - 1][1]) > 1e-8 * y): break thinnedWeights.append(weights[i - 1]) return (thinnedWeights) outputChannel = self.outputChannel if isinstance(outputChannel, channelsModule.productionChannel): print ' toENDF6 does not support writing of "%s" channel' % outputChannel.genre return MT = self.ENDF_MT if (flags['verbosity'] >= 10): print '%s%s' % (verbosityIndent, outputChannel.toString(simpleString=True)) targetInfo['Q'] = self.getQ('eV', groundStateQ=True) targetInfo['QM'] = None LR, tryLR = 0, False if isinstance(outputChannel, channelsModule.twoBodyOutputChannel): tryLR = True elif isinstance(outputChannel, channelsModule.NBodyOutputChannel): if (MT == 91): tryLR = True if (tryLR and (len(outputChannel) > 1)): secondProduct = outputChannel[1] primaryResidualName, decayProducts, decayChannel, = secondProduct.name.split( '_')[0], [], secondProduct.outputChannel if (not (decayChannel is None)): for decayProduct in decayChannel: decayProductName = decayProduct.name if (decayProductName not in [primaryResidualName, 'gamma']): decayProducts.append(decayProductName) if (len(decayProducts) == 1 ): # Kludge for Carbon breakup into 3 alphas. if ((primaryResidualName == 'C') and (decayProducts == ['He4'])): LR = 23 elif (len(decayProducts) > 1): # This must be a breakup reaction. MTProducts = endf_endlModule.endfMTtoC_ProductList(0, '') MTProducts.productCounts[outputChannel[0].name] += 1 for decayProduct in decayProducts[:-1]: MTProducts.productCounts[decayProduct] += 1 for MT_LR in [22, 23, 24, 25, 28, 29, 30, 32, 33, 34, 35, 36]: # 39 and 40 not allowed in ENDF6 if (endf_endlModule.endfMTtoC_ProductLists[MT_LR].productCounts == MTProducts.productCounts): LR = MT_LR break if ((LR == 32) and (primaryResidualName == 'B10') and (decayProducts[-1] == 'He4')): LR = 35 # Kludge for bad data. if (LR != 0): QM = outputChannel.Q[targetInfo['style']].getValue( 0, 'eV') + decayChannel.Q[targetInfo['style']].getValue( 0, 'eV') targetInfo['QM'] = QM targetInfo['LRs'][MT] = LR level = 0. for product in outputChannel: tmp = None if (hasattr(product, 'getLevelAsFloat')): tmp = product.getLevelAsFloat('eV') if (tmp is not None): level = tmp targetInfo['EMin'], targetInfo['EMax'] = self.crossSection.domain( unitTo="eV") if (self.EFL is not None): targetInfo['EFL'] = self.EFL.getValueAs("eV") self.crossSection.toENDF6(MT, endfMFList, targetInfo, level, LR) if ('EFL' in targetInfo): del targetInfo['EFL'] products = [] doMF4AsMF6 = False for product in outputChannel: if (len(product.distribution)): products.append(product) doMF4AsMF6 = doMF4AsMF6 or addDecayProducts(product, products) if (outputChannel.isFission()): doMF4AsMF6 = False if (not (outputChannel.fissionEnergyReleased is None)): outputChannel.fissionEnergyReleased.toENDF6( 1, endfMFList, flags, targetInfo) delayedNubar = None # Special work to get delayed nubar weights. for product in outputChannel: if ('emissionMode' in product.attributes): if (product.getAttribute('emissionMode') == tokensModule.delayedToken): if (delayedNubar is None): delayedNubar = product.multiplicity[ targetInfo['style']] else: delayedNubar = delayedNubar + product.multiplicity[ targetInfo['style']] targetInfo['delayedRates'].append( product.getAttribute('decayRate').getValueAs('1/s')) if (delayedNubar is not None): targetInfo['totalDelayedNubar'] = delayedNubar for product in outputChannel: if ('emissionMode' in product.attributes): if (product.getAttribute('emissionMode') == tokensModule.delayedToken): weight = divideIgnoring0DividedBy0( product.multiplicity[targetInfo['style']], delayedNubar) product.ENDF6_delayedNubarWeights = thinWeights(weight) if (MT in [526, 527]): doMF4AsMF6 = True targetInfo['doMF4AsMF6'] = doMF4AsMF6 targetInfo['MF6LCTs'], targetInfo['gammas'] = [], [] for productIndex, product in enumerate(outputChannel): if ((product.name == 'gamma') and not isinstance( outputChannel, channelsModule.twoBodyOutputChannel) and (MT != 527)): targetInfo['gammas'].append(product) continue targetInfo['productIndex'] = str(productIndex) targetInfo['productToken'] = product.name targetInfo['productLabel'] = product.label product.toENDF6(MT, endfMFList, flags, targetInfo, verbosityIndent=verbosityIndent + ' ') gammas = targetInfo['gammas'] if (len(gammas)): gamma = gammas[0] targetInfo['zapID'] = gamma.name targetInfo['particleMass'] = gamma.getMass('eV/c**2') multiplicity = gamma.multiplicity if (gamma.getAttribute('ENDFconversionFlag') == 'MF6'): targetInfo['multiplicity'] = gamma.multiplicity gndToENDF6Module.gammasToENDF6_MF6(MT, endfMFList, flags, targetInfo, gammas) elif (gamma.getAttribute('ENDFconversionFlag') == 'MF13'): targetInfo['crossSection'] = self.crossSection[targetInfo['style']] gndToENDF6Module.gammasToENDF6_MF12_13(MT, 13, endfMFList, flags, targetInfo, gammas) elif ( isinstance(multiplicity, multiplicityModule.constant) ): # This should probably be changed to unknown in some cases????? pass elif ( isinstance(multiplicity, multiplicityModule.unknown) ): # This should probably be changed to unknown in some cases????? pass else: gndToENDF6Module.gammasToENDF6_MF12_13(MT, 12, endfMFList, flags, targetInfo, gammas) if (len(targetInfo['MF6LCTs']) > 0): LCT = targetInfo['MF6LCTs'][0] for i in targetInfo['MF6LCTs']: if (not (LCT is None)): break if (LCT is None): LCT = 2 for i in targetInfo['MF6LCTs']: if (i is None): continue if (i != LCT): LCT = 3 if (500 <= MT <= 572): LCT = 0 MF6or26 = {3: 6, 23: 26}[targetInfo['crossSectionMF']] endfMFList[MF6or26][MT].insert( 0, endfFormatsModule.endfHeadLine(targetInfo['ZA'], targetInfo['mass'], 0, LCT, len(targetInfo['MF6LCTs']), 0)) endfMFList[MF6or26][MT].append(endfFormatsModule.endfSENDLineNumber())