def angularPointwiseEnergy2ENDF6(self, targetInfo, EinFactor=1): interpolation = gndToENDFInterpolationFlag(self.interpolation) if len(self) > 201: accuracy, angularData = self.thinToNumberOfPoints(201) assert len(angularData) <= 201 angularData = angularData.normalize() print( " WARNING: ENDF limited to 201 mu values. %d points removed for incident energy %g %s" % (len(self) - len(angularData), self.value, self.axes[-1].unit)) else: angularData = self if (targetInfo['doMF4AsMF6']): interpolation += 10 ENDFDataList = [ endfFormatsModule.endfContLine(0, self.value * EinFactor, interpolation, 0, 2 * len(angularData), len(angularData)) ] ENDFDataList += endfFormatsModule.endfNdDataList(angularData) else: ENDFDataList = [ endfFormatsModule.endfContLine(0, self.value * EinFactor, 0, 0, 1, len(angularData)) ] ENDFDataList += endfFormatsModule.endfInterpolationList( [len(angularData), interpolation]) ENDFDataList += endfFormatsModule.endfNdDataList(angularData) return (ENDFDataList)
def toENDF6(self, baseMT, endfMFList, flags, targetInfo): MF, MT, LP = 12, baseMT + int(self.label), 0 nGammas, gammaData, levelEnergy_eV = len( self.gammas), [], self.energy.getValueAs('eV') for gamma in self.gammas: gammaData.append(gamma.toENDF6List()) LGp = len(gammaData[0]) for gamma in gammaData: gamma[0] = levelEnergy_eV - gamma[0] endfMFList[MF][MT] = [ endfFormatsModule.endfHeadLine(targetInfo['ZA'], targetInfo['mass'], 2, LGp - 1, MT - baseMT, 0), endfFormatsModule.endfHeadLine(levelEnergy_eV, 0., LP, 0, LGp * nGammas, nGammas) ] gammaData.sort(reverse=True) endfMFList[MF][MT] += endfFormatsModule.endfNdDataList(gammaData) endfMFList[MF][MT].append(endfFormatsModule.endfSENDLineNumber()) # Currently, assume all distributions are isotropic endfMFList[14][MT] = [ endfFormatsModule.endfHeadLine(targetInfo['ZA'], targetInfo['mass'], 1, 0, nGammas, 0) ] endfMFList[14][MT].append(endfFormatsModule.endfSENDLineNumber())
def angularPointwiseEnergy2ENDF6(self, targetInfo): interpolation = gndToENDFInterpolationFlag(self.interpolation) if (targetInfo['doMF4AsMF6']): interpolation += 10 ENDFDataList = [ endfFormatsModule.endfContLine(0, self.value, interpolation, 0, 2 * len(self), len(self)) ] ENDFDataList += endfFormatsModule.endfNdDataList(self) else: ENDFDataList = [ endfFormatsModule.endfContLine(0, self.value, 0, 0, 1, len(self)) ] ENDFDataList += endfFormatsModule.endfInterpolationList( [len(self), interpolation]) ENDFDataList += endfFormatsModule.endfNdDataList(self) return (ENDFDataList)
def angularLegendreEnergy2ENDF6(self, targetInfo): data = self if ('doProductionGamma' in targetInfo): data = data.coefficients[1:] ENDFDataList = [ endfFormatsModule.endfContLine(0, self.value, 0, 0, len(data), 0) ] ENDFDataList += endfFormatsModule.endfNdDataList(data) return (ENDFDataList)
def toENDF6(self, flags, targetInfo, verbosityIndent=''): endf = [] AP = self.scatteringRadius if AP.isEnergyDependent(): scatRadius = AP.form NR, NP = 1, len(scatRadius) endf.append(endfFormatsModule.endfHeadLine(0, 0, 0, 0, NR, NP)) endf += endfFormatsModule.endfInterpolationList( (NP, gndToENDF6.gndToENDFInterpolationFlag(scatRadius.interpolation))) endf += endfFormatsModule.endfNdDataList( scatRadius.convertAxisToUnit(0, '10*fm')) AP = 0 else: AP = AP.getValueAs('10*fm') NLS = len(self.L_values) LFW = targetInfo['unresolved_LFW'] LRF = targetInfo['unresolved_LRF'] def v(val): # get value back from PhysicalQuantityWithUncertainty if type(val) == type(None): return return val.getValueAs('eV') if LFW == 0 and LRF == 1: # 'Case A' from ENDF 2010 manual pg 70 endf.append( endfFormatsModule.endfHeadLine(targetInfo['spin'], AP, self.forSelfShieldingOnly, 0, NLS, 0)) for Lval in self.L_values: NJS = len(Lval.J_values) endf.append( endfFormatsModule.endfHeadLine(targetInfo['mass'], 0, Lval.L, 0, 6 * NJS, NJS)) for Jval in Lval.J_values: # here we only have one width per J: ave = Jval.constantWidths endf.append( endfFormatsModule.endfDataLine([ v(ave.levelSpacing), Jval.J.value, Jval.neutronDOF, v(ave.neutronWidth), v(ave.captureWidth), 0 ])) elif LFW == 1 and LRF == 1: # 'Case B' energies = self.L_values[0].J_values[ 0].energyDependentWidths.getColumn('energy', units='eV') NE = len(energies) endf.append( endfFormatsModule.endfHeadLine(targetInfo['spin'], AP, self.forSelfShieldingOnly, 0, NE, NLS)) nlines = int(math.ceil(NE / 6.0)) for line in range(nlines): endf.append( endfFormatsModule.endfDataLine(energies[line * 6:line * 6 + 6])) for Lval in self.L_values: NJS = len(Lval.J_values) endf.append( endfFormatsModule.endfHeadLine(targetInfo['mass'], 0, Lval.L, 0, NJS, 0)) for Jval in Lval.J_values: cw = Jval.constantWidths endf.append( endfFormatsModule.endfHeadLine(0, 0, Lval.L, Jval.fissionDOF, NE + 6, 0)) endf.append( endfFormatsModule.endfDataLine([ v(cw.levelSpacing), Jval.J.value, Jval.neutronDOF, v(cw.neutronWidth), v(cw.captureWidth), 0 ])) fissWidths = Jval.energyDependentWidths.getColumn( 'fissionWidthA', units='eV') for line in range(nlines): endf.append( endfFormatsModule.endfDataLine( fissWidths[line * 6:line * 6 + 6])) elif LRF == 2: # 'Case C', most common in ENDF endf.append( endfFormatsModule.endfHeadLine(targetInfo['spin'], AP, self.forSelfShieldingOnly, 0, NLS, 0)) INT = gndToENDF6.gndToENDFInterpolationFlag(self.interpolation) for Lval in self.L_values: NJS = len(Lval.J_values) endf.append( endfFormatsModule.endfHeadLine(targetInfo['mass'], 0, Lval.L, 0, NJS, 0)) for Jval in Lval.J_values: NE = len(Jval.energyDependentWidths) useConstant = not NE if useConstant: NE = 2 endf.append( endfFormatsModule.endfHeadLine(Jval.J.value, 0, INT, 0, 6 * NE + 6, NE)) endf.append( endfFormatsModule.endfDataLine([ 0, 0, Jval.competitiveDOF, Jval.neutronDOF, Jval.gammaDOF, Jval.fissionDOF ])) cws = Jval.constantWidths if useConstant: # widths are all stored in 'constantWidths' instead. get energies from parent class NE = 2 useConstant = True eLow, eHigh = targetInfo['regionEnergyBounds'] for e in (eLow, eHigh): endf.append( endfFormatsModule.endfDataLine([ v(e), v(cws.levelSpacing), v(cws.competitiveWidth), v(cws.neutronWidth), v(cws.captureWidth), v(cws.fissionWidthA) ])) else: table = [ Jval.energyDependentWidths.getColumn('energy', units='eV') ] for attr in ('levelSpacing', 'competitiveWidth', 'neutronWidth', 'captureWidth', 'fissionWidthA'): # find each attribute, in energy-dependent or constant width section column = (Jval.energyDependentWidths.getColumn( attr, units='eV') or [v(getattr(cws, attr))] * NE) if not any(column): column = [0] * NE table.append(column) for row in zip(*table): endf.append(endfFormatsModule.endfDataLine(row)) return endf
def toENDF6(self, flags, targetInfo, verbosityIndent=''): endf = [] AP = getattr(self, 'scatteringRadius') if AP.isEnergyDependent(): scatRadius = AP.form NR, NP = 1, len(scatRadius) endf.append(endfFormatsModule.endfHeadLine(0, 0, 0, 0, NR, NP)) endf += endfFormatsModule.endfInterpolationList( (NP, gndToENDF6.gndToENDFInterpolationFlag(scatRadius.interpolation))) endf += endfFormatsModule.endfNdDataList( scatRadius.convertAxisToUnit(0, '10*fm')) AP = 0 else: AP = self.scatteringRadius.getValueAs('10*fm') L_list = self.resonanceParameters.table.getColumn('L') NLS = len(set(L_list)) LAD = getattr(self, 'computeAngularDistribution') or 0 NLSC = getattr(self, 'LvaluesNeededForConvergence') or 0 endf += [ endfFormatsModule.endfHeadLine(targetInfo['spin'], AP, LAD, 0, NLS, NLSC) ] table = [ self.resonanceParameters.table.getColumn('energy', units='eV'), self.resonanceParameters.table.getColumn('J') ] NE = len(table[0]) if isinstance(self, (resonancesModule.SLBW, resonancesModule.MLBW)): attrList = ('totalWidth', 'neutronWidth', 'captureWidth', 'fissionWidthA') elif isinstance(self, resonancesModule.RM): attrList = ('neutronWidth', 'captureWidth', 'fissionWidthA', 'fissionWidthB') for attr in attrList: column = self.resonanceParameters.table.getColumn(attr, units='eV') if not column: column = [0] * NE table.append(column) CS = self.resonanceParameters.table.getColumn('channelSpin') if CS is not None: # ENDF hack: J<0 -> use lower available channel spin targetSpin = targetInfo['spin'] CS = [2 * (cs - targetSpin) for cs in CS] Js = [v[0] * v[1] for v in zip(table[1], CS)] table[1] = Js table = zip(*table) for L in set(L_list): APL = 0 if self.scatteringRadius.isLdependent( ) and L in self.scatteringRadius.form.lvals: APL = self.scatteringRadius.getValueAs('10*fm', L=L) resonances = [table[i] for i in range(NE) if L_list[i] == L] NRS = len(resonances) endf.append( endfFormatsModule.endfHeadLine(targetInfo['mass'], APL, L, 0, 6 * NRS, NRS)) for row in resonances: endf.append(endfFormatsModule.endfDataLine(row)) return endf
def gammasToENDF6_MF12_13(MT, MF, endfMFList, flags, targetInfo, gammas): """ MF=12 stores the multiplicity for gamma products, can be converted directly to/from GND. MF=13 stores 'gamma production cross section', equal to cross section * multiplicity. ENDF-to-GND translator converts to multiplicity (dividing by reaction cross section). When writing back to ENDF-6 MF=13, need to convert back using adjustMF13Multiplicity. """ doMF4AsMF6 = targetInfo['doMF4AsMF6'] targetInfo['doMF4AsMF6'] = False ZA, mass, MFGammas, NI, continuum, NK, NKp = targetInfo['ZA'], targetInfo[ 'mass'], [], 0, None, len(gammas), 0 total, piecewise, recomputeTotal = None, None, False crossSection = None if (MF == 13): crossSection = targetInfo['crossSection'] crossSection = crossSection.toPointwise_withLinearXYs(accuracy=1e-3, upperEps=1e-8) if (NK > 1): # If more than one gamma is present, both MF=12 and MF=13 start with the sum over all gammas. # Search for the correct multiplicitySum in reactionSuite/sums section total = [ tmp for tmp in targetInfo['reactionSuite'].sums.multiplicities if tmp.ENDF_MT == MT ] if len(total) > 1: raise Exception( "Cannot find unique gamma multiplicity sum for MT%d" % MT) elif not total: # total multiplicity is missing from sums section, need to recompute from parts recomputeTotal = True else: total = total[0].multiplicity.evaluated for gammaIndex, gamma in enumerate(gammas): distribution = gamma.distribution component = distribution[targetInfo['style']] if (isinstance(component, unspecifiedModule.form)): continue NKp += 1 originationLevel = 0 if ('originationLevel' in gamma.attributes): originationLevel = PQUModule.PQU( gamma.getAttribute('originationLevel')).getValueAs('eV') isPrimary, isDiscrete = False, False if (isinstance(component, uncorrelatedModule.form)): energySubform = component.energySubform.data if (isinstance(energySubform, energyModule.primaryGamma)): isPrimary = True elif (isinstance(energySubform, energyModule.discreteGamma)): isDiscrete = True angularSubform = component.angularSubform.data else: raise 'hell - fix me' LP, LF, levelEnergy = 0, 2, 0. if (isPrimary): gammaEnergy = PQUModule.PQU( energySubform.value, energySubform.axes[1].unit).getValueAs('eV') LP = 2 elif (isDiscrete): gammaEnergy = PQUModule.PQU( energySubform.value, energySubform.axes[1].unit).getValueAs('eV') if (originationLevel != 0): LP = 1 else: if (continuum is not None): raise Exception( 'Multiple continuum gammas detected for MT=%s' % (MT)) continuum = gamma energySubform = component.energySubform.data gammaEnergy, LP, LF = 0, 0, 1 NC, MF15 = energySubform.toENDF6(flags, targetInfo) endfMFList[15][MT] = [ endfFormatsModule.endfContLine(ZA, mass, 0, 0, NC, 0) ] endfMFList[15][MT] += MF15 endfMFList[15][MT].append(endfFormatsModule.endfSENDLineNumber()) isNotIsotropic = 0 if (isinstance(angularSubform, angularModule.isotropic)): MF14 = None LI, LTT = 1, 0 elif (isinstance(angularSubform, angularModule.XYs2d)): isNotIsotropic = 1 targetInfo['doProductionGamma'] = True dummy, dummy, MF14 = angularSubform.toENDF6(flags, targetInfo) del targetInfo['doProductionGamma'] del MF14[-1] MF14[0] = endfFormatsModule.floatToFunky( gammaEnergy) + endfFormatsModule.floatToFunky( originationLevel) + MF14[0][22:] LI, LTT = 0, 1 else: raise 'hell - fix me' multiplicity = gamma.multiplicity.evaluated if recomputeTotal: if (isinstance(multiplicity, multiplicityModule.regions1d)): if (piecewise is not None): if (len(piecewise) != len(multiplicity)): raise Exception( 'MF=12/13 piecewise multiplicities must all have same number of regions' ) for i1, region in enumerate(piecewise): region.setData( (region + multiplicity[i1]).copyDataToXYs()) else: piecewise = multiplicity total = piecewise[ 0] # BRB, FIXME, this is a kludge until total is put into sums. elif (total is None): total = multiplicity else: total = total + multiplicity if (MF == 12): LO = 1 NR, NP, MF12or13Data = multiplicity.toENDF6List(targetInfo) if (type(NR) == type([])): for index, NRsub in enumerate( endfFormatsModule.endfInterpolationList(NR)): MF12or13Data.insert(index, NRsub) NR = len(NR) / 2 MF12 = [ endfFormatsModule.endfContLine(gammaEnergy, originationLevel, LP, LF, NR, NP) ] + MF12or13Data MFGammas.append( [isNotIsotropic, gammaEnergy, originationLevel, MF12, MF14]) elif (MF == 13): LO = 0 interpolationInfo = [] xsec_mult = [] if (isinstance(multiplicity, multiplicityModule.XYs1d)): adjustMF13Multiplicity(interpolationInfo, xsec_mult, multiplicity, crossSection) elif (isinstance(multiplicity, multiplicityModule.regions1d)): for region in multiplicity: adjustMF13Multiplicity(interpolationInfo, xsec_mult, region, crossSection) else: raise Exception('Unsupport multiplicity "%s" for MF=13' % multiplicity.moniker) NR = len(interpolationInfo) / 2 NP = len(xsec_mult) / 2 MF13 = [ endfFormatsModule.endfContLine(gammaEnergy, originationLevel, LP, LF, NR, NP) ] MF13 += [ endfFormatsModule.endfInterpolationLine(interpolationInfo) ] MF13 += endfFormatsModule.endfNdDataList(xsec_mult) MFGammas.append( [isNotIsotropic, gammaEnergy, originationLevel, MF13, MF14]) else: pass if (NKp == 0): return endfMFList[MF][MT] = [ endfFormatsModule.endfContLine(ZA, mass, LO, 0, NK, 0) ] if ( NK > 1 ): # If more than one gamma is present, both MF=12 and MF=13 start with the sum over all gammas. totalInterpolationInfo = [] xsec_mult = [] if (isinstance(total, multiplicityModule.XYs1d)): adjustMF13Multiplicity(totalInterpolationInfo, xsec_mult, total, crossSection) elif (isinstance(total, multiplicityModule.regions1d)): for region in total: adjustMF13Multiplicity(totalInterpolationInfo, xsec_mult, region, crossSection) else: raise Exception( 'Unsupported total multiplicity type "%s" for MF=13' % total.moniker) NR = len(totalInterpolationInfo) / 2 NP = len(xsec_mult) / 2 endfMFList[MF][MT].append( endfFormatsModule.endfContLine(0, 0, 0, 0, NR, NP)) endfMFList[MF][MT] += [ endfFormatsModule.endfInterpolationLine(totalInterpolationInfo) ] endfMFList[MF][MT] += endfFormatsModule.endfNdDataList(xsec_mult) MFGammas12_13 = [[gammaEnergy, originationLevel, MF12_13] for isNotIsotropic, gammaEnergy, originationLevel, MF12_13, MF14 in MFGammas] MFGammas12_13.sort(reverse=True) for gammaEnergy, originationLevel, MF12_13 in MFGammas12_13: endfMFList[MF][MT] += MF12_13 # Store MF 12 or 13 before sorting. MFGammas.sort(reverse=True) for isNotIsotropic, gammaEnergy, originationLevel, MF12_13, MF14 in MFGammas: if (isNotIsotropic): break NI += 1 if (LI == 1): NI = 0 endfMFList[MF][MT].append(endfFormatsModule.endfSENDLineNumber()) # if any gammas are anisotropic, MF14 data must be supplied for all gammas: isotropic = [gamma for gamma in MFGammas if not gamma[0]] anisotropic = [gamma for gamma in MFGammas if gamma[0]] if anisotropic: LI, LTT, NI = 0, 1, len(isotropic) endfMFList[14][MT] = [ endfFormatsModule.endfContLine(ZA, mass, LI, LTT, NK, NI) ] for gamma in isotropic: endfMFList[14][MT].append( endfFormatsModule.endfContLine(gamma[1], gamma[2], 0, 0, 0, 0)) for gamma in anisotropic: endfMFList[14][MT] += gamma[-1] endfMFList[14][MT].append(endfFormatsModule.endfSENDLineNumber()) else: endfMFList[14][MT] = [ endfFormatsModule.endfContLine(ZA, mass, LI, LTT, NK, NI), endfFormatsModule.endfSENDLineNumber() ] targetInfo['doMF4AsMF6'] = doMF4AsMF6