def toENDF6( self, MT, endfMFList, flags, targetInfo ) : LAW, LEP = 1, 2 EInInterpolation = gndToENDF6Module.axisToEndfInterpolationFlag( self.axes[1] ) E_ins = [ [ EpCl.value, {} ] for EpCl in self[0].EpP ] for l_EEpCl in self : for indexE, EpCl in enumerate( l_EEpCl ) : if( EpCl.value != E_ins[indexE][0] ) : raise Exception( "E_in = %s not in list E_ins" % EpCl.value ) for Ep, Cl in EpCl : if( Ep not in E_ins[indexE][1] ) : E_ins[indexE][1][Ep] = [] for l in xrange( l_EEpCl.l ) : E_ins[indexE][1][Ep].append( 0. ) E_ins[indexE][1][Ep].append( Cl ) ENDFDataList = [ endfFormatsModule.endfContLine( 0, 0, 1, LEP, 1, len( E_ins ) ) ] ENDFDataList += endfFormatsModule.endfInterpolationList( [ len( E_ins ), EInInterpolation ] ) for Es in E_ins : NA, data = 0, [] for key in sorted( Es[1] ) : LegendreSeries = Es[1][key] NA = max( len( LegendreSeries ) , NA ) data += [ key ] + LegendreSeries ENDFDataList.append( endfFormatsModule.endfContLine( 0, Es[0], 0, NA - 1, len( data ), len( data ) / ( NA + 1 ) ) ) ENDFDataList += endfFormatsModule.endfDataList( data ) gndToENDF6Module.toENDF6_MF6( MT, endfMFList, flags, targetInfo, LAW, self.productFrame, ENDFDataList )
def toENDF6( self, flags, targetInfo ) : MT = 5 EInInterpolation = gndToENDF6Module.gndToENDF2PlusDInterpolationFlag( self.interpolation, self.interpolationQualifier ) EpInterpolation0 = gndToENDF6Module.gndToENDF2PlusDInterpolationFlag( self[0].interpolation, self[0].interpolationQualifier ) if( EpInterpolation0 == 1 ) : # flat interpolation LEP = 1 elif( EpInterpolation0 == 2 ) : # lin-lin interpolation LEP = 2 else : raise 'hell - fix me' ENDFDataList = [ endfFormatsModule.endfContLine( 0, 0, 1, LEP, 1, len( self ) ) ] ENDFDataList += endfFormatsModule.endfInterpolationList( [ len( self ), EInInterpolation ] ) energyInFactor = PQUModule.PQU( 1, self.axes[3].unit ).getValueAs( 'eV' ) energyPFactor = PQUModule.PQU( 1, self.axes[2].unit ).getValueAs( 'eV' ) for energyIn in self : if( not( isinstance( energyIn, multiD_XYsModule.XYs2d ) ) ) : raise 'hell - fix me' EpInterpolation = gndToENDF6Module.gndToENDF2PlusDInterpolationFlag( energyIn.interpolation, energyIn.interpolationQualifier ) if( EpInterpolation != EpInterpolation0 ) : raise 'hell - fix me' NA, data = 0, [] for energy_p in energyIn : if( not( isinstance( energy_p, series1dModule.LegendreSeries ) ) ) : raise 'hell - fix me' NA = max( len( energy_p ) , NA ) coefficients = [ coefficient / energyPFactor for coefficient in energy_p ] data += [ energy_p.value * energyPFactor ] + coefficients ENDFDataList.append( endfFormatsModule.endfContLine( 0, energyIn.value * energyInFactor, 0, NA - 1, len( data ), len( data ) / ( NA + 1 ) ) ) ENDFDataList += endfFormatsModule.endfDataList( data ) LAW = 1 return( LAW, ENDFDataList )
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 toENDF6(self, MT, endfMFList, flags, targetInfo): data = [] for xy in self.copyDataToXYs(xUnitTo='eV', yUnitTo='eV'): data += xy NE = len(self) EInInterpolation = gndToENDF6Module.gndToENDFInterpolationFlag( self.interpolation) ENDFDataList = [ endfFormatsModule.endfContLine( 0, 0, 0, 0, 1, NE ) ] + \ endfFormatsModule.endfInterpolationList( [ NE, EInInterpolation ] ) ENDFDataList += endfFormatsModule.endfDataList(data) return (standardsModule.frames.labToken, ENDFDataList)
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 LTP_oneSubParsing(LTP, LIDP, nuclear, interferenceReal, interferenceImaginary, lineData): if LIDP: NL = len(nuclear) - 1 NW = 3 * NL + 3 else: NL = (len(nuclear) - 1) // 2 NW = 4 * NL + 3 lineData.append( endfFormatsModule.endfContLine(0, nuclear.value, LTP, 0, NW, NL)) legendreDat = nuclear.coefficients for j, r in enumerate(interferenceReal.coefficients): legendreDat.append(r) legendreDat.append(interferenceImaginary[j]) lineData += endfFormatsModule.endfDataList(legendreDat)
def toENDF6(self, MT, endfMFList, flags, targetInfo): fSubform = self.fSubform.data rSubform = self.rSubform.data aSubform = self.aSubform if (not (aSubform.isEmptyASubform())): raise 'hell - FIXME' outgoingInterpolation = set([val.interpolation for val in fSubform] + [val.interpolation for val in rSubform]) if len(outgoingInterpolation) != 1: raise NotImplementedError( "Only one outgoing interpolation supported when writing Kalbach-Mann to ENDF-6" ) LEP = {'flat': 1, 'lin-lin': 2}[outgoingInterpolation.pop()] ENDFDataList = [ endfFormatsModule.endfContLine(0, 0, 2, LEP, 1, len(fSubform)) ] ENDFDataList += endfFormatsModule.endfInterpolationList([len(fSubform), 2]) EInUnit = fSubform.axes[2].unit EpUnit = fSubform.axes[1].unit fUnit = fSubform.axes[0].unit EInFactor = PQUModule.PQU(1, EInUnit).getValueAs('eV') EpFactor = PQUModule.PQU(1, EpUnit).getValueAs('eV') fFactor = PQUModule.PQU(1, fUnit).getValueAs('1/eV') for i1, fAtEnergy in enumerate(fSubform): rAtEnergy = rSubform[i1] if (not (isinstance(fAtEnergy, XYsModule.XYs1d))): raise 'hell - FIXME' if (not (isinstance(rAtEnergy, XYsModule.XYs1d))): raise 'hell - FIXME' value = fAtEnergy.value if (value != rAtEnergy.value): raise 'hell - FIXME' value *= EInFactor coefficients = [] for i1, (Ep1, f1) in enumerate(fAtEnergy): Ep2, r1 = rAtEnergy[i1] if (Ep1 != Ep2): raise 'hell - FIXME' coefficients += [EpFactor * Ep1, fFactor * f1, r1] length = len(coefficients) ENDFDataList += [ endfFormatsModule.endfContLine(0, value, 0, 1, length, length / 3) ] ENDFDataList += endfFormatsModule.endfDataList(coefficients) gndToENDF6Module.toENDF6_MF6(MT, endfMFList, flags, targetInfo, 1, self.productFrame, ENDFDataList)
def toENDF6( self, MT, endfMFList, flags, targetInfo ) : EInInterpolation = gndToENDF6Module.axisToEndfInterpolationFlag( self.axes[0] ) independent, dependent, qualifier = self.axes[1].interpolation.getInterpolationTokens( ) if( dependent == standardsModule.interpolation.flatToken ) : LEP = 1 # interpolation for Eout else : LEP = 2 ENDFDataList = [ endfFormatsModule.endfContLine( 0, 0, 1, LEP, 1, len( self ) ) ] ENDFDataList += endfFormatsModule.endfInterpolationList( [ len( self ), EInInterpolation ] ) for energy_in in self : NA, data = 0, [] for w_xys_LegendreSeries in energy_in : NA = max( len( w_xys_LegendreSeries) , NA ) data += [ w_xys_LegendreSeries.value ] + w_xys_LegendreSeries.coefficients ENDFDataList.append( endfFormatsModule.endfContLine( 0, energy_in.value, 0, NA - 1, len( data ), len( data ) / ( NA + 1 ) ) ) ENDFDataList += endfFormatsModule.endfDataList( data ) LAW = 1 gndToENDF6Module.toENDF6_MF6( MT, endfMFList, flags, targetInfo, LAW, self.productFrame, ENDFDataList )
def toENDF6List(self, targetInfo): interpolationFlatData, multiplicityFlatData = [], [] counter = 0 lastX, lastY = None, None for region in self: ENDFInterpolation = gndToENDF6Module.gndToENDFInterpolationFlag( region.interpolation) data = region.copyDataToXYs(xUnitTo='eV') if (lastX is not None): if (lastY == data[0][1]): data = data[1:] counter += len(data) interpolationFlatData.append(counter) interpolationFlatData.append(ENDFInterpolation) for xy in data: multiplicityFlatData += xy lastX, lastY = data[-1] return (interpolationFlatData, counter, endfFormatsModule.endfDataList(multiplicityFlatData))
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 toAngularLegendre(angularSubform, targetInfo, insertSENDL): """This should only be called from this module.""" NM = 0 interpolation = gndToENDF6Module.gndToENDFInterpolationFlag( angularSubform.interpolation) energyConversionFactor = PQUModule.PQU( 1, angularSubform.axes[-1].unit).getValueAs('eV') ENDFDataList = [] start = 0 if targetInfo.get('skipFirstEnergy'): start = 1 for energy in angularSubform[start:]: NW, NL = len(energy) - 1, 0 if (targetInfo['doMF4AsMF6']): NL = NW ENDFDataList.append( endfFormatsModule.endfContLine( 0, energy.value * energyConversionFactor, 0, 0, NW, NL)) ENDFDataList += endfFormatsModule.endfDataList(energy.coefficients[1:]) NM = max(NM, len(energy.coefficients[1:])) if (insertSENDL): ENDFDataList.append(endfFormatsModule.endfSENDLineNumber()) return (interpolation, len(angularSubform[start:]), 0, 1, NM, ENDFDataList)
def toENDF6(self, MT, endfMFList, flags, targetInfo): n, data = self.order + 1, {} for i in xrange(n): data[i] = [] for index, label in enumerate(self.labels): d = self.data[label][i][0] u = 0 if (self.hasUncertainties): u = self.data[label][i][1] data[i].append(d) data[i].append(u) list = [] for i in xrange(n): list += data[i] endfMFList[MT][458] = [ endfFormatsModule.endfContLine(targetInfo['ZA'], targetInfo['mass'], 0, 0, 0, 0) ] endfMFList[MT][458].append( endfFormatsModule.endfContLine(0, 0, 0, self.order, 18 * n, 9 * n)) endfMFList[MT][458] += endfFormatsModule.endfDataList(list) endfMFList[MT][458].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 ) : """ In ENDF MF=6, some distributions should really be treated as uncorrelated: NBodyPhaseSpace, and also Legendre expansions when only L=0 is listed. For GND we split these into uncorrelated angular (isotropic) and energy distributions. Must put back in original format when writing back to ENDF. """ frame = self.productFrame energySubform = self.energySubform.data angularSubform = self.angularSubform.data if( isinstance( energySubform, energyModule.NBodyPhaseSpace ) ) : energySubform.toENDF6( MT, endfMFList, flags, targetInfo ) elif( isinstance( energySubform, energyModule.energyLoss ) ) : frame, ENDFDataList = energySubform.toENDF6( MT, endfMFList, flags, targetInfo ) gndToENDF6Module.toENDF6_MF6( MT, endfMFList, flags, targetInfo, 8, frame, ENDFDataList ) elif( targetInfo['product'].getAttribute( 'ENDFconversionFlag' ) in [ 'MF6', 'MF26' ] ) : if( isinstance( energySubform, energyModule.constant ) ) : # BRB - this needs to be checked. if( targetInfo['product'].name != 'gamma' ) : raise ValueError( 'This logic is only for discete gammas' ) energyForm = energyModule.form( self.label, frame, energySubform ) angularForm = angularModule.form( self.label, frame, angularSubform ) energyForm.toENDF6( MT, endfMFList, flags, targetInfo ) angularForm.toENDF6( MT, endfMFList, flags, targetInfo ) elif( isinstance( angularSubform, angularModule.isotropic ) ) : # Change to energyAngular with Legendre if( not( isinstance( energySubform, energyModule.XYs2d ) ) ) : raise 'hell - fix me' axes = axesModule.axes( rank = 4 ) axes[3] = axesModule.axis( 'energy_in', 3, 'eV' ) axes[2] = axesModule.axis( 'energy_out', 2, 'eV' ) axes[1] = axesModule.axis( 'l', 1, '' ) axes[0] = axesModule.axis( 'C_l(energy_out|energy_in)', 0, '1/eV' ) energyAngularSubform = energyAngularModule.XYs3d( axes = axes, interpolation = energySubform.interpolation, interpolationQualifier = energySubform.interpolationQualifier ) EInFactor = PQUModule.PQU( 1, energySubform.axes[2].unit ).getValueAs( 'eV' ) for EIn in energySubform : if isinstance( EIn, regionsModule.regions1d ): # writing to MF6 LAW=1, LANG=1 doesn't support multiple regions, must recombine. if( len( set( [ ein.interpolation for ein in EIn ] ) ) != 1 ) : raise NotImplemented, "ENDF MF6 LAW=1 LANG=1 doesn't support multiple E' interpolations!" xyvals = EIn[0].copyDataToXYs() for region in EIn[1:]: xynew = region.copyDataToXYs() xynew[0][0] *= 1.00000001 xyvals.extend( xynew ) EIn_copy = EIn[0].copy( value=EIn.value, axes=EIn.axes ) EIn_copy.setData( xyvals ) EIn = EIn_copy multiD_2d = energyAngularModule.XYs2d( value = EIn.value * EInFactor, interpolation = EIn.interpolation ) EpCls = EIn.copyDataToXYs( xUnitTo = 'eV', yUnitTo = '1/eV' ) for e_out, Cls in EpCls : multiD_2d.append( energyAngularModule.Legendre( [ Cls ], value = e_out ) ) energyAngularSubform.append( multiD_2d ) form = energyAngularModule.form( '', self.productFrame, energyAngularSubform ) if( targetInfo.dict.get( "gammaToENDF6" ) ) : return( form ) form.toENDF6( MT, endfMFList, flags, targetInfo ) elif( isinstance( energySubform, energyModule.XYs2d ) and isinstance( angularSubform, angularModule.XYs2d ) ) : LANG, LEP = 12, 2 if( energySubform.interpolation == standardsModule.interpolation.flatToken ) : LEP = 1 # interpolation for E_out LANG = 11 elif( energySubform.interpolation in (standardsModule.interpolation.loglinToken, standardsModule.interpolation.loglogToken ) ) : LANG = 14 MF6 = [ endfFormatsModule.endfContLine( 0, 0, LANG, LEP, 1, len( energySubform ) ) ] EInInterpolation = gndToENDF6Module.gndToENDFInterpolationFlag( energySubform.interpolation ) MF6 += endfFormatsModule.endfInterpolationList( [ len( energySubform ), EInInterpolation ] ) for indexE, EEpP in enumerate( energySubform ) : EMuP = angularSubform[indexE] if( EEpP.value != EMuP.value ) : raise Exception( "EEpP.value = %s != EMuP.value = %s" % ( EEpP.value, EMuP.value ) ) NA, NEP = 2 * len( EMuP ), len( EEpP ) MF6.append( endfFormatsModule.endfContLine( 0, EEpP.value, 0, NA, NEP * ( NA + 2 ), NEP ) ) data = [] for EpP in EEpP : data = [ EpP[0], EpP[1] ] for muP in EMuP : data += muP MF6 += endfFormatsModule.endfDataList( data ) LAW = 1 gndToENDF6Module.toENDF6_MF6( MT, endfMFList, flags, targetInfo, LAW, frame, MF6 ) else : raise Exception( 'uncorrelated.toENDF6 not supported for energy subform = %s and angular subform = %s' % ( energySubform.label, angularSubform.label ) ) else : # original data is in uncorrelated form if( MT not in [ 527, 528 ] ) : angularForm = angularModule.form( "", frame, self.angularSubform.data ) angularForm.toENDF6( MT, endfMFList, flags, targetInfo ) energyForm = energyModule.form( "", frame, self.energySubform.data ) energyForm.toENDF6( MT, endfMFList, flags, targetInfo ) if( MT == 527 ) : endfMFList[26][MT][0]