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, MT, endfMFList, flags, targetInfo): subform = self.angularEnergySubform if (hasattr(subform, 'toENDF6')): LAW, frame, MF6 = subform.toENDF6(flags, targetInfo) gndToENDF6Module.toENDF6_MF6(MT, endfMFList, flags, targetInfo, LAW, frame, MF6) else: print 'WARNING: angularEnergy subform "%s" has no toENDF6 method' % subform.moniker
def toENDF6(self, MT, endfMFList, flags, targetInfo): mass = self.numberOfProductsMasses.getValueAs( 'eV/c**2') / targetInfo['neutronMass'] ENDFDataList = [ endfFormatsModule.endfContLine(mass, 0, 0, 0, 0, self.numberOfProducts) ] gndToENDF6Module.toENDF6_MF6(MT, endfMFList, flags, targetInfo, 6, standardsModule.frames.centerOfMassToken, ENDFDataList)
def toENDF6(self, MT, endfMFList, flags, targetInfo): LI, LTT, MF6 = self.angularSubform.toENDF6(flags, {'doMF4AsMF6': True}) target, projectile = targetInfo['reactionSuite'].target, targetInfo[ 'reactionSuite'].projectile spin = projectile.getSpin().value LIDP = target == projectile NR, NE = [int(a) for a in MF6[0].split()[-2:]] MF6[0] = endfFormatsModule.endfContLine(spin, 0, LIDP, 0, NR, NE) LAW = 5 gndToENDF6Module.toENDF6_MF6(MT, endfMFList, flags, targetInfo, LAW, self.productFrame, MF6)
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 toENDF6(self, MT, endfMFList, flags, targetInfo): gndToENDF6Module.toENDF6_MF6(MT, endfMFList, flags, targetInfo, 0, self.productFrame, [])
def toENDF6(self, MT, endfMFList, flags, targetInfo): angularForm = self.angularForm angularEnergyForm = self.angularEnergyForm energy_inInterpolation, energy_inFunctionInterpolation, energy_inInterpolationQualifier = angularEnergyForm.axes[ 0].interpolation.getInterpolationTokens() muInterpolation, muFunctionInterpolation, muQualifier = angularEnergyForm.axes[ 1].interpolation.getInterpolationTokens() energy_outInterpolation, probabilityInterpolation, energy_outQualifier = angularEnergyForm.axes[ 2].interpolation.getInterpolationTokens() frame = angularEnergyForm.getProductFrame() axes = pointwise.defaultAxes( energyInterpolation=energy_inInterpolation, energyFunctionInterpolation=energy_inFunctionInterpolation, energyInterpolationQualifier=energy_inInterpolationQualifier, muInterpolation=muInterpolation, energy_outInterpolation=energy_outInterpolation, probabilityInterpolation=probabilityInterpolation) E_inRatio = PQUModule.PQU( 1, angularEnergyForm.axes[0].getUnit()).getValueAs('eV') E_outRatio = PQUModule.PQU( 1, angularEnergyForm.axes[2].getUnit()).getValueAs('eV') LAW7 = pointwise(axes, self.getProductFrame()) if (len(angularForm) != len(angularEnergyForm)): raise Exception( "len( angularForm ) = %s != len( angularEnergyForm ) = %s" % (len(angularForm), len(angularEnergyForm))) for indexE, EMuP in enumerate(angularForm): EMuEpP = angularEnergyForm[indexE] if (EMuP.value != EMuEpP.value): raise Exception( "At indexE = %d, EMuP.value %s != EMuEpP.value = %s" % (indexE, EMuP.value, EMuEpP.value)) if (len(EMuP) != len(EMuEpP)): raise Exception( "At indexE = %d (E_in = %s), len( EMuP ) %s != len( EMuEpP ) = %s" % (indexE, EMuP.value, len(EMuP), len(EMuEpP))) w_xys = W_XYs.W_XYs(axesW_XY, index=indexE, value=EMuP.value) for indexMu, muP in enumerate(EMuP): muEpP = EMuEpP[indexMu] if (muP[0] != muEpP.value): raise Exception("At indexE = %d, mu = %s != muEpP.value = %s" % (indexE, muP[0], muEpP.value)) xys = [[E_outRatio * Ep, muP[1] * P / E_outRatio] for Ep, P in muEpP] xys = XYs.XYs(axesXY, xys, accuracy=muEpP.getAccuracy(), value=muP[0], index=indexMu, parent=w_xys) w_xys.append( XYs.XYs(axesXY, muEpP * muP[1], accuracy=muEpP.getAccuracy(), value=muP[0], index=indexMu, parent=w_xys)) LAW7.append(w_xys) LAW, frame, MF6 = LAW7.toENDF6(flags, targetInfo) gndToENDF6Module.toENDF6_MF6(MT, endfMFList, flags, targetInfo, LAW, frame, MF6)
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]
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, MT, endfMFList, flags, targetInfo): 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) counts, interpolationFlagsList, lineData = 0, [], [] LTP = 1 # indicates this is a nuclear + interference section target, projectile = targetInfo['reactionSuite'].target, targetInfo[ 'reactionSuite'].projectile LIDP = target == projectile if (isinstance(self.nuclear_term, angularModule.XYs2d)): for ridx in xrange(len(self.nuclear_term)): counts += 1 nuclear, interferenceReal, interferenceImaginary = self.nuclear_term[ ridx], self.interferenceReal_term[ ridx], self.interferenceImaginary_term[ridx] LTP_oneSubParsing(LTP, LIDP, nuclear, interferenceReal, interferenceImaginary, lineData) interpolationFlagsList += [ counts, gndToENDF6Module.gndToENDFInterpolationFlag( self.nuclear_term.interpolation) ] elif (isinstance(self.nuclear_term, angularModule.regions2d)): for regionIndex, region in enumerate(self.nuclear_term): interferenceReal, interferenceImaginary = self.interferenceReal_term[ regionIndex], self.interferenceImaginary_term[regionIndex] for energyIndex, nuclear in enumerate(region): if ((regionIndex != 0) and (energyIndex == 0)): continue counts += 1 LTP_oneSubParsing(LTP, LIDP, nuclear, interferenceReal[energyIndex], interferenceImaginary[energyIndex], lineData) interpolationFlagsList += [ counts, gndToENDF6Module.gndToENDFInterpolationFlag( region.interpolation) ] else: raise NotImplementedError( "Unknown data storage inside CoulombExpansion: %s" % type(self.nuclear_term)) interpolationFlags = endfFormatsModule.endfInterpolationList( interpolationFlagsList) ENDFDataList = [ endfFormatsModule.endfContLine(projectile.getSpin().value, 0, LIDP, 0, len(interpolationFlagsList) / 2, counts) ] + interpolationFlags + lineData if (not (targetInfo['doMF4AsMF6'])): ENDFDataList.append(endfFormatsModule.endfSENDLineNumber()) LAW = 5 gndToENDF6Module.toENDF6_MF6(MT, endfMFList, flags, targetInfo, LAW, self.productFrame, ENDFDataList)