Beispiel #1
0
    def toPointwise_withLinearXYs(self,
                                  accuracy=None,
                                  lowerEps=0,
                                  upperEps=0,
                                  invert=False):

        eps = 1e-6
        ptw = XYs2d(XYs2d.defaultAxes(energyUnit=self.domainUnit()))
        if (invert):
            ptw.append(
                XYsModule.XYs1d([[-1, 2 / eps], [eps - 1, 0.]],
                                value=self.domainMin(),
                                accuracy=1e-6))
            ptw.append(
                XYsModule.XYs1d([[-1, 2 / eps], [eps - 1, 0.]],
                                value=self.domainMax(),
                                accuracy=1e-6))
        else:
            ptw.append(
                XYsModule.XYs1d([[1 - eps, 0.], [1, 2 / eps]],
                                value=self.domainMin(),
                                accuracy=1e-6))
            ptw.append(
                XYsModule.XYs1d([[1 - eps, 0.], [1, 2 / eps]],
                                value=self.domainMax(),
                                accuracy=1e-6))
        return (ptw)
Beispiel #2
0
def KalbachMannDataToString( KalbachMannData, energy_in_unit ) :

    nForm = 4
    if( KalbachMannData.aSubform.data is None ) : nForm = 3
    if( nForm == 4 ) : raise Exception( 'This is currently not implemented' )

    fSubform = KalbachMannData.fSubform.data
    rSubform = KalbachMannData.rSubform.data

    factor = fSubform.domainUnitConversionFactor( energy_in_unit ) # Energies passed to get_transfer must be in energy_in_unit, traditionally MeV.
    _fSubform = multiD_XYsModule.XYs2d( )
    for xys in fSubform :
        _xys = XYsModule.XYs1d( data = xys.scaleOffsetXAndY( xScale = factor, yScale = 1 / factor ), value = factor * xys.value )
        _fSubform.append( _xys )

    _rSubform = multiD_XYsModule.XYs2d( )
    for xys in rSubform :
        _xys = XYsModule.XYs1d( data = xys.scaleOffsetXAndY( xScale = factor ), value = factor * xys.value )
        _rSubform.append( _xys )

    s  = startOfNewData
    s += "Kalbach probabilities: n = %s\n" % len( _fSubform )
    s += "Incident energy interpolation: %s %s\n" % ( linlin,
            GND2ProcessingInterpolationQualifiers[standardsModule.interpolation.unitBaseToken] )
    s += "Outgoing energy interpolation: %s\n" % fSubform[0].interpolation
    s += threeDListToString( _fSubform )

    s += "Kalbach r parameter: n = %s\n" % len( rSubform )
    s += "Incident energy interpolation: %s %s\n" % ( rSubform.interpolation, 
            GND2ProcessingInterpolationQualifiers[standardsModule.interpolation.unitBaseUnscaledToken] )
    s += "Outgoing energy interpolation: %s\n" % rSubform[0].interpolation
    s += threeDListToString( _rSubform )

    return( s )
Beispiel #3
0
def gammaDeltaDistribution(energy):

    deltaEnergy = float("1e%s" % ("%.0e" % (energy * energyEps)).split('e')[1])
    eMin, eMax = energy - deltaEnergy, energy + deltaEnergy
    if (eMin < 0):
        return (XYsModule.XYs1d([[energy, 1.], [eMax, 0.]]).normalize())
    return (XYsModule.XYs1d([[eMin, 0.], [energy, 1], [eMax, 0.]]).normalize())
Beispiel #4
0
    def toPointwise_withLinearXYs(self, **kwargs):

        accuracy = xDataBaseModule.getArguments(kwargs,
                                                {'accuracy': 1e-6})['accuracy']

        ptw = XYs2d(defaultAxes(self.domainUnit))
        ptw.append(
            XYsModule.XYs1d([[1 - accuracy, 0.], [1, 2 / accuracy]],
                            value=self.domainMin))
        ptw.append(
            XYsModule.XYs1d([[1 - accuracy, 0.], [1, 2 / accuracy]],
                            value=self.domainMax))
        return (ptw)
Beispiel #5
0
    def averageForwardMomentum(self, sqrt_2_ProductMass):

        averageMu = [[pdfOfMuAtEp.value,
                      pdfOfMuAtEp.averageMu()] for pdfOfMuAtEp in self]
        return (sqrt_2_ProductMass * float(
            XYsModule.XYs1d(averageMu, interpolation=self.interpolation).
            integrateWithWeight_sqrt_x()))
Beispiel #6
0
    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')
Beispiel #7
0
def calculateMomentumPoints( massInE, EMin, EMax, energyUnit, accuracy = 1e-4 ) :
    """
    This is a temporary function (hopefully) to calculate momentum vs E.
    What is really needed is a function like rriint in mcfgen.
    """

    import math

    momentum = []

    def insertPointIfNeeded( Ep1, Ep2 ) :

        E1, p1 = Ep1
        E2, p2 = Ep2
        s = ( p2 - p1 ) / ( E2 - E1 )
        Em = massInE / ( 2. * s * s )
        pc = math.sqrt( 2 * massInE * Em )
        pi = s * ( Em - E1 ) + p1
        if( abs( pi / pc  - 1 ) > accuracy ) :
            m = [ Em, pc ]
            momentum.append( m )
            insertPointIfNeeded( Ep1, m )
            insertPointIfNeeded( m, Ep2 )

    if( massInE == 0 ) :            # gammas
        momentum.append( [ EMin, EMin ] )
        momentum.append( [ EMax, EMax ] )
    else :
        momentum.append( [ EMin, math.sqrt( 2 * massInE * EMin ) ] )
        momentum.append( [ EMax, math.sqrt( 2 * massInE * EMax ) ] )
        insertPointIfNeeded( momentum[0], momentum[1] )
    momentum.sort( )
    axes = axesModule.axes( labelsUnits = { 0 : [ 'energy_in', energyUnit ], 1 : [ 'momentum', energyUnit + '/c' ] } )
    return( XYsModule.XYs1d( data = momentum, axes = axes, accuracy = accuracy ) )
Beispiel #8
0
    def averageEnergy(self):

        integralOfMu = [[pdfOfMuAtEp.value,
                         pdfOfMuAtEp.integrate()] for pdfOfMuAtEp in self]
        return (float(
            XYsModule.XYs1d(
                integralOfMu,
                interpolation=self.interpolation).integrateWithWeight_x()))
Beispiel #9
0
    def getFluxAtLegendreOrder(self, order):

        axes = axesModule.axes()
        axes[1] = self.axes[2].copy([])
        axes[0] = self.axes[0].copy([])
        for LS in self:
            if (len(LS) > 1): raise Exception('FIXME -- next line is wrong.')
        return (XYsModule.XYs1d([[LS.value, LS[0]] for LS in self], axes=axes))
Beispiel #10
0
def energyFunctionToString( energyData, weight = None ) :

    def getParameter( data, label ) :

        _linlin = data.toPointwise_withLinearXYs( lowerEps = lowerEps, upperEps = upperEps )
        sData = [ startOfNewData, "%s: n = %d" % ( label, len( _linlin ) ) ]
        sData.append( 'Interpolation: %s' % linlin )
        for x, y in _linlin : sData.append( '%s %s' % ( x, y ) )
        return( sData )

    sData = []
    if( isinstance( energyData, ( energyModule.simpleMaxwellianFissionSpectrum, energyModule.evaporationSpectrum, energyModule.WattSpectrum ) ) ) :
        sData.append( 'U: %s' % energyData.U.getValueAs( energyData.parameter1.data.axes[-1].unit ) )

    parameter1 = energyData.parameter1.data.toPointwise_withLinearXYs( accuracy = 1e-5, lowerEps = lowerEps, upperEps = upperEps )

    if( energyData.parameter2 is not None ) :
        parameter2 = energyData.parameter2.data.toPointwise_withLinearXYs( accuracy = 1e-5, lowerEps = lowerEps, upperEps = upperEps )

    if( weight is None ) :
        axes = axesModule.axes( )
        weight = XYsModule.XYs1d( data = [ [ parameter1.domainMin, 1. ], [ parameter1.domainMax, 1. ] ], axes = axes )
    else :
        weight = weight.weight
    sData += twoDToString( "weight", weight, addExtraBlankLine = False )

    if( isinstance( energyData, energyModule.generalEvaporationSpectrum ) ) :
        sProcess = 'Process: general evaporation\n'
        sSpecific = ''
        sData += getParameter( parameter1, 'Theta' )
        sData += getParameter( parameter2, 'g' )
    elif( isinstance( energyData, energyModule.simpleMaxwellianFissionSpectrum ) ) :
        sProcess = 'Process: Maxwell spectrum\n'
        sSpecific = ''
        sData += getParameter( parameter1, 'Theta' )
    elif( isinstance( energyData, energyModule.evaporationSpectrum ) ) :
        sProcess = 'Process: Evaporation spectrum\n'
        sSpecific = 'Interpolate Eout integrals: false\n'
        sSpecific += 'Quadrature method: Gauss6\n'
        sData += getParameter( parameter1, 'Theta' )
    elif( isinstance( energyData, energyModule.WattSpectrum ) ) :
        sProcess = 'Process: Watt spectrum\n'
        sSpecific = 'Interpolate Eout integrals: false\n'
        sSpecific += 'Conserve: number\n'
        sData += getParameter( parameter1, 'a' )
        sData += getParameter( parameter2, 'b' )
    elif( isinstance( energyData, energyModule.MadlandNix ) ) :
        sProcess = 'Process: Madland-Nix spectrum\n'
        sSpecific  = 'Quadrature method: adaptive\n'
        sSpecific += 'Interpolate Eout integrals: false\n'
        sSpecific += 'Conserve: number\n'
        sSpecific += 'EFL: %s\n' % energyData.EFL.getValueAs( energyData.parameter1.data.axes[-1].unit )
        sSpecific += 'EFH: %s\n' % energyData.EFH.getValueAs( energyData.parameter1.data.axes[-1].unit )
        sData += getParameter( parameter1, 'TM' )
    else :
        raise Exception( 'Unsupport energy functional = %s' % energyData.moniker )
    sData.append( '' )
    return( sProcess, sSpecific, startOfNewData + '\n'.join( sData ) )
Beispiel #11
0
def calculateDepositionEnergyFromEpP(E, EpP):
    "EpP is a list of [ E', P(E') ]"

    axes = axesModule.axes()
    axes[0] = axesModule.axis('a', 0, EpP.axes[0].unit)
    axes[1] = axesModule.axis('b', 1, EpP.axes[1].unit)
    Ep = XYsModule.XYs1d(data=[[EpP[0][0], EpP[0][0]],
                               [EpP[-1][0], EpP[-1][0]]],
                         axes=axes)
    return (float(EpP.integrateTwoFunctions(Ep)))
Beispiel #12
0
def grouped_values_to_XYs( groupBdries, valueList, \
                           domainUnit='eV', domainName='energy_in', rangeUnit='b', rangeName='crossSection', \
                           accuracy=upperEps, domainMin=1e-5, domainMax=20.0):
    if len(groupBdries) != len(valueList)+1:
        raise ValueError("Group boundries and value lists have incompatable lengths: len(bdries)=%i, len(vals)=%i"%(len(groupBdries),len(valueList)))
    return XYs.XYs1d(\
        data=[groupBdries, [valueList[0]]+valueList], \
        dataForm="xsandys", \
        interpolation=standards.interpolation.flatToken, \
        axes=XYs1d.defaultAxes(labelsUnits={ \
                XYs.yAxisIndex : ( rangeName, rangeUnit ), \
                XYs.xAxisIndex : ( domainName, domainUnit ) }) )
Beispiel #13
0
def addData( endlZA, X1, temperature, energyMin_MeV, energyMax_MeV, I0Data, I1Data, I3Data, halflife = None ) :

    endlFile = getEndlFile( endlZA, 0, 11, 0, 1 )
    data = [ [ energy, xSec ] for energy, xSec in I0Data ]
    if( data[0][0] > energyMin_MeV ) :
        if( data[0][1] != 0 ) : data.insert( 0, [ data[0][0], 0 ] )
        data.insert( 0, [ energyMin_MeV, 0 ] )
    if( data[-1][0] < energyMax_MeV ) :
        if( data[-1][1] != 0 ) : data.append( [ data[-1][0], 0 ] )
        data.append( [ energyMax_MeV, 0 ] )
    endlData = endlFile.addData( data, Q = 0, X1 = X1, temperature = temperature, halflife = halflife )
    endlData.setFormat( 15 )

    if( I1Data[0][0] > energyMin_MeV ) : I1Data.insert( 0, [ energyMin_MeV, copy.copy( I1Data[0][1] ) ] )
    if( I1Data[-1][0] < energyMax_MeV ) : I1Data.append( [ energyMax_MeV, copy.copy( I1Data[-1][1] ) ] )
    _I1Data = []
    for energy, PofMu in I1Data :
        PofMu = XYsModule.XYs1d( PofMu ).normalize( )
        _I1Data.append( [ energy, [ [ P, Mu ] for P, Mu in PofMu ] ] )

    endlFile = getEndlFile( endlZA, 1, 11, 1, 1 )
    endlData = endlFile.addData( _I1Data, Q = 0, X1 = X1, temperature = temperature, halflife = halflife )
    endlData.setFormat( 15 )

    if I3Data is not None:
        if( I3Data[0][0] > energyMin_MeV ) : I3Data.insert( 0, [ energyMin_MeV, copy.copy( I3Data[0][1] ) ] )
        if( I3Data[-1][0] < energyMax_MeV ) : I3Data.append( [ energyMax_MeV, copy.copy( I3Data[-1][1] ) ] )

        _I3Data = []
        for energy, PofEprimeMu in I3Data:
            tmp = []
            for mu, PofEprime in PofEprimeMu:
                PofEprime = XYsModule.XYs1d( PofEprime ).normalize( )
                tmp.append( [ mu, [ [ Ep, P ] for Ep, P in PofEprime ] ] )
            _I3Data.append( [ energy, tmp ] )

        endlFile = getEndlFile( endlZA, 1, 11, 3, 1 )
        endlData = endlFile.addData( _I3Data, Q = 0, X1 = X1, temperature = temperature, halflife = halflife )
        endlData.setFormat( 15 )
Beispiel #14
0
def uncorrelated_EMuP_EEpP_TransferMatrix( style, tempInfo, crossSection, productFrame, angularData, energyData, 
        multiplicity, comment = None, weight = None ) :

    logFile = tempInfo['logFile']
    workDir = tempInfo['workDir']

    sSpecific = ''
    if( isinstance( energyData, energyModule.functionalBase ) ) :
        sProcess, sSpecific, sData = energyFunctionToString( energyData, weight = weight )
        weight = None
    elif( isinstance( energyData, energyModule.weightedFunctionals ) ) :
        TM1s, TMEs = [], []
        for weight in energyData :
            TM1, TME = uncorrelated_EMuP_EEpP_TransferMatrix( style, tempInfo, crossSection, productFrame, angularData, 
                    weight.functional, multiplicity, comment = comment, weight = weight )
            TM1s.append( TM1 )
            TMEs.append( TME )
        TM1 = addTMs( TM1s )
        TME = addTMs( TMEs )
        return( TM1, TME )
    elif( isinstance( energyData, energyModule.regions2d ) ) :
        TM1s, TMEs = [], []
        axes = axesModule.axes( )
        for i1, region in enumerate( energyData ) :
            weight = XYsModule.XYs1d( data = [ [ region.domainMin, 1. ], [ region.domainMax, 1. ] ], axes = axes )
            tempInfo['workFile'].append( 'r%s' % i1 )
            try :
                TM1, TME = uncorrelated_EMuP_EEpP_TransferMatrix( style, tempInfo, crossSection, productFrame, angularData,
                        region, multiplicity, comment = comment, weight = weight )
            except :
                del tempInfo['workFile'][-1]
                raise
            del tempInfo['workFile'][-1]
            TM1s.append( TM1 )
            TMEs.append( TME )
        TM1 = addTMs( TM1s )
        TME = addTMs( TMEs )
        return( TM1, TME )
    elif( isinstance( energyData, energyModule.primaryGamma ) ) :
        return( primaryGammaAngularData( style, tempInfo, crossSection, energyData, angularData, multiplicity = multiplicity, comment = comment ) )
    else :
        if( angularData.isIsotropic() ) :
            sProcess = "Process: isotropic table\n"
            sData = EEpPDataToString( energyData )
        else:
            sProcess = "Process: 'Uncorrelated energy-angle data transfer matrix'\n"
            sData = angularToString( angularData, crossSection )
            sData += EEpPDataToString( energyData )
    sCommon = commonDataToString( comment, style, tempInfo, crossSection, productFrame, multiplicity = multiplicity, weight = weight )
    s = versionStr + '\n' + sProcess + sSpecific + sCommon + sData
    return( executeCommand( logFile, transferMatrixExecute, s, workDir, tempInfo['workFile'] ) )
Beispiel #15
0
    def getUncertaintyVector( self, theData=None, relative=True ):
        """ 
        Get an XYs1d object containing uncertainty for this matrix.
        Convert relative/absolute if requested (if so, must also pass central values as theData)

        Examples:

            - if the covariance matrix is relative and we want relative uncertainty vector, just do:
            
                > matrix.getUncertaintyVector()
                
            - if we want the absolute matrix instead:
            
                > matrix.getUncertaintyVector( theData=<XYs1d instance>, relative=False )
                
        """
        if not self.isSymmetric():
            raise ValueError("getUncertaintyVector only applies to symmetric matrices!")
        energies = list( self.matrix.axes[-1].values )
        diag = numpy.diagonal( self.matrix.array.constructArray() ).copy()
        diag[ diag < 0.0 ] = 0.0
        diag = list( numpy.sqrt( diag ) )
        diag.append( diag[-1] )                             # point corresponding to final energy bin
        yunit = self.matrix.axes[0].unit
        if yunit != '': # get square root of the unit
            yunit = PQU.PQU(1,yunit).sqrt().getUnitSymbol()
        axes_ = axesModule.axes(
                                 labelsUnits={1:('energy_in',self.matrix.axes[2].unit),
                                              0:('uncertainty',yunit)} )
        uncert = XYsModule.XYs1d( zip(energies,copy.deepcopy(diag)), axes=axes_, interpolation='flat',
                                accuracy=0.0001, )    # what should accuracy be set to?
        uncert = uncert.changeInterpolation('lin-lin',None,1e-8,1e-8)

        # do we need to convert absolute->relative or vice versa?
        if (relative and self.type==tokens.absoluteToken) or (not relative and self.type==tokens.relativeToken):
            if theData is None:
                theData = self.ancestor.rowData.link.toPointwise_withLinearXYs(1e-8,1e-8)
            try:
                theData = theData.toPointwise_withLinearXYs(1e-8,1e-8)
                uncert, theData = uncert.mutualify(1e-8, 1e-8, False, theData, 1e-8, 1e-8, False)
                if relative: #convert absolute to relative
                    uncert /= theData
                else: #relative to absolute
                    uncert *= theData
            except Exception as err:
                print len( uncert ), uncert.copyDataToXYs()[0], uncert.copyDataToXYs()[-1]
                print len( theData ), theData.copyDataToXYs()[0], theData.copyDataToXYs()[-1]
                raise Exception( err.message )
        return uncert
Beispiel #16
0
    def __init__( self, angularEnergy ) :

        self.__productFrame = angularEnergy.productFrame
        axes = axesModule.defaultAxes( 3 )
        axes2d[2] = angularEnergy.axes[2]
        axes2d[1] = angularEnergy.axes[1]
        axes2d[0] = axesModule.axis( "P(mu|energy_in)", 0, "" )
        axes1d = XYsModule.XYs1d.defaultAxes( )
        axes1d[0] = axes2d[0]
        axes1d[1] = axes2d[1]
        multiD_XYsModule.XYs2d.__init__( self, axes = axes2d )

        for P_EpGivenMu in angularEnergy :
            P_mu = [ [ xys.value, xys.integrate( ) ] for xys in P_EpGivenMu ]
            self.append( XYsModule.XYs1d( data = P_mu, axes = axes1d, accuracy = 1e-3, value = P_EpGivenMu.value ) )
Beispiel #17
0
    def makeGrouped(self, processInfo, tempInfo):

        projectile, target = processInfo.getProjectileName(
        ), processInfo.getTargetName()
        groups = processInfo.getParticleGroups(projectile)
        energyUnit = tempInfo['crossSection'].domainUnit()
        axes = axesModule.axes(labelsUnits={
            0: ['energy_in', energyUnit],
            1: ['energy', energyUnit]
        })
        domainMin, domainMax = tempInfo['crossSection'].domain()
        energy = XYsModule.XYs1d(data=[[domainMin, domainMin],
                                       [domainMax, domainMax]],
                                 axes=axes,
                                 accuracy=1e-8)
        axes, grouped_ = miscellaneousModule.makeGrouped(
            self, processInfo, tempInfo, energy)
        self.addForm(grouped(axes, grouped_))
        axes, grouped_ = miscellaneousModule.makeGrouped(
            self, processInfo, tempInfo, energy, normType='groupedFlux')
        self.addForm(groupedWithCrossSection(axes, grouped_))
Beispiel #18
0
def twoBodyTransferMatrix( style, tempInfo, productFrame, crossSection, angularData, Q, weight = None, comment = None ) :
    """
    Generate input and call processing code to generate a transfer matrix for two-body angular distribution.
    If the distribution is actually made up of two different forms in different energy regions, this function
    calls itself in the two regions and sums the result.
    """

    if( isinstance( angularData, angularModule.isotropic ) ) : angularData = angularData.toPointwise_withLinearXYs( )

    if( isinstance( angularData, angularModule.XYs2d ) ) :
        TM1, TME = twoBodyTransferMatrix2( style, tempInfo, crossSection, angularData, Q, productFrame, comment = comment )
    elif( isinstance( angularData, angularModule.regions2d ) ) :
        TM1s, TMEs = [], []
        lowestBound, highestBound = angularData[0].domainMin, angularData[-1].domainMax
        weightAxes = axesModule.axes( )
        for iRegion, region in enumerate( angularData ) :
                if( iRegion == 0 ) :
                    weightData = [ [ lowestBound, 1 ], [ region.domainMax, 0 ], [ highestBound, 0 ] ]
                elif( iRegion == len( angularData ) - 1 ) :
                    weightData = [ [ lowestBound, 0 ], [ region.domainMin, 1 ], [ highestBound, 1 ] ]
                else :
                    weightData = [ [ lowestBound, 0 ], [ region.domainMin, 1 ], [ region.domainMax, 0 ], [ highestBound, 0 ] ]
                _weight = XYsModule.XYs1d( data = weightData, axes = weightAxes )

                tempInfo['workFile'].append( 'r%s' % iRegion )
                try :
                    TM1, TME = twoBodyTransferMatrix2( style, tempInfo, crossSection, region, Q,
                            productFrame, weight = _weight, comment = comment )
                except :
                    del tempInfo['workFile'][-1]
                    raise
                del tempInfo['workFile'][-1]
                TM1s.append( TM1 )
                TMEs.append( TME )
        TM1 = addTMs( TM1s )
        TME = addTMs( TMEs )
    else :
        raise Exception( 'Unsupported P(mu|E) = %s' % angularData.moniker )

    return( TM1, TME )
Beispiel #19
0
    def check(self, info):
        from fudge.gnd import warning
        from pqu import PQU
        warnings = []
        axes = axesModule.axes()
        axes[0] = self.axes[-2]
        axes[1] = self.axes[-1]

        for index, energy_in in enumerate(self):
            integral = float(
                XYsModule.XYs1d([(eout.value, eout.coefficients[0])
                                 for eout in energy_in],
                                axes=axes,
                                accuracy=0.001).integrate())
            if abs(integral - 1.0) > info['normTolerance']:
                warnings.append(
                    warning.unnormalizedDistribution(
                        PQU.PQU(energy_in.value, axes[0].unit), index,
                        integral, self.toXLink()))
            minProb = min([
                xy.toPointwise_withLinearXYs(0.001).rangeMin()
                for xy in energy_in
            ])
            if minProb < 0:
                warnings.append(
                    warning.negativeProbability(PQU.PQU(
                        energy_in.value, axes[0].unit),
                                                value=minProb,
                                                obj=energy_in))
            if self.interpolationQualifier is standardsModule.interpolation.unitBaseToken:
                # check for more than one outgoing distribution integrating to 0 at high end of incident energies
                integrals = [eout.integrate() for eout in energy_in]
                for idx, integral in enumerate(integrals[::-1]):
                    if integral != 0: break
                if idx > 1:
                    warnings.append(
                        warning.extraOutgoingEnergy(PQU.PQU(
                            energy_in.value, axes[-1].unit),
                                                    obj=energy_in))
        return warnings
Beispiel #20
0
def addContinuumSpectrum(decayModes, RTYP_key, decayParticleIndex, regions,
                         covariance):

    decayParticleID = decayParticles[decayParticleIndex]
    if (decayParticleID is None):
        raise Exception('decayParticleID is None, what is to be done?')

    decayParticleLabel = STYPProduct[decayParticleIndex]
    spectra = decayModes[RTYP_key].spectra
    if (decayParticleLabel not in spectra):
        spectrum = spectrumModule.spectrum(decayParticleLabel, decayParticleID)
        spectra.add(spectrum)
    else:
        spectrum = spectra[decayParticleLabel]

    if (len(regions) == 1):
        data = XYsModule.XYs1d(
            regions[0], axes=spectrumModule.continuum.defaultAxes(energyUnit))
    else:
        print("len( regions ) > 1")
        return
    continuum = spectrumModule.continuum(data)
    spectrum.append(continuum)
Beispiel #21
0
def get_ENDF_flux(file, mat, mf, mt):
    import fudge.legacy.converting.ENDFToGND.endfFileToGNDMisc as endfFileToGNDMiscModule
    import xData.axes as axesModule
    import xData.XYs as XYsModule
    # Grab the data corresponding to the spectrum
    MF3Data = [
        line.strip('\r\n') for line in open(file).readlines()
        if int(line[67:70]) == int(mat) and int(line[70:72]) == int(mf)
        and int(line[72:75]) == int(mt)
    ]
    # Define the axes
    spectrumAxes = axesModule.axes(rank=2)
    spectrumAxes[0] = axesModule.axis('spectrum', 0, '1/eV')
    spectrumAxes[1] = axesModule.axis('energy_in', 1, 'eV')
    # Now make the spectrum as an XYs1d
    dataLine, TAB1, spectrumRegions = endfFileToGNDMiscModule.getTAB1Regions(
        1,
        MF3Data,
        allowInterpolation6=True,
        logFile=None,  #info.logs,
        axes=spectrumAxes,
        cls=XYsModule.XYs1d)
    if (len(spectrumRegions) == 1):  # Store as XYs1d.
        spectrumForm = XYsModule.XYs1d(
            data=spectrumRegions[0],
            label=None,
            axes=spectrumAxes,
            interpolation=spectrumRegions[0].interpolation)
    else:
        raise NotImplementedError(
            "Fluxes with multiple regions for %s/%s/%s/%s" %
            (file, mat, mf, mt))
        spectrumForm = crossSectionModule.regions1d(label=None,
                                                    axes=spectrumAxes)
        for region in spectrumRegions:
            if (len(region) > 1): spectrumForm.append(region)
    return (spectrumForm)
Beispiel #22
0
def toENDL(coherentElastic,
           energyMin_MeV,
           energyMax_MeV,
           temperature_MeV,
           accuracy=0.001,
           epsilon=1e-6):

    S_table = coherentElastic.S_table
    gridded2d = S_table.gridded2d

    array = gridded2d.array.constructArray()

    energyGrid = gridded2d.axes[1].copy([])

    temperatureGrid = gridded2d.axes[2].copy([])
    temperatureGrid.convertToUnit('MeV/k')
    for index2, temperature2 in enumerate(temperatureGrid.values):
        if (temperature2 >= temperature_MeV): break
    if (temperature_MeV > temperature2):
        SofE = XYsModule.XYs1d((energyGrid.values, array[-1]),
                               dataForm='XsAndYs',
                               interpolation=energyGrid.interpolation)
    elif ((index2 == 0) or (temperature2 == temperature_MeV)):
        SofE = XYsModule.XYs1d((energyGrid.values, array[index2]),
                               dataForm='XsAndYs',
                               interpolation=energyGrid.interpolation)
    else:
        index1 = index2 - 1
        temperature1 = temperatureGrid.values[index1]
        fraction = (temperature_MeV - temperature1) / (temperature2 -
                                                       temperature1)

        SofE1 = XYsModule.XYs1d((energyGrid.values, array[index1]),
                                dataForm='XsAndYs',
                                interpolation=energyGrid.interpolation)
        SofE2 = XYsModule.XYs1d((energyGrid.values, array[index2]),
                                dataForm='XsAndYs',
                                interpolation=energyGrid.interpolation)
        SofE = (1 - fraction) * SofE1 + fraction * SofE2

    axes = axesModule.axes()
    axes[0].label = gridded2d.axes[0].label
    axes[0].unit = gridded2d.axes[0].unit
    axes[1].label = energyGrid.label
    axes[1].unit = energyGrid.unit
    SofE.axes = axes
    SofE.convertUnits({"eV": "MeV"})

    _SofE = SofE
    SofE = []
    for energy, S2 in _SofE:
        if (energy > energyMax_MeV): break
        SofE.append([energy, S2])
    if ((SofE[-1][0] < energyMax_MeV) and (SofE[-1][0] < _SofE[-1][0])):
        eMax = _SofE[-1][0]
        if (energyMax_MeV < eMax): eMax = energyMax_MeV
        SofE.append([eMax, SofE[-1][1]])

    S1 = 0
    I0 = []
    I1 = []
    n_minus1 = len(SofE) - 1
    for index, energyS in enumerate(SofE):
        energy, S2 = energyS

        energy1 = (1 - epsilon) * energy
        if (index == 0):
            S1 = S2
            energy1 = energy

        energy2 = (1 + epsilon) * energy
        if (index == n_minus1): energy2 = energy

        if (energy >= energyMax_MeV):
            energy = energyMax_MeV
            energy2 = energyMax_MeV
        if (energy2 > energyMax_MeV):
            energy2 = energyMax_MeV

        I0.append([energy1, S1 / energy])
        if (energy != energy1): I0.append([energy2, S2 / energy])

        PofMu = calculatePofMu(energy1, index, SofE, epsilon)
        if (len(PofMu) > 0): I1.append([energy1, PofMu])
        if (energy != energy1):
            PofMu = calculatePofMu(energy2, index + 1, SofE, epsilon)
            if (len(PofMu) > 0): I1.append([energy2, PofMu])

        S1 = S2
        if (energy == energyMax_MeV): break

    accuracy = min(0.1, max(1e-5, accuracy))
    I0Fine = [I0.pop(0)]
    x1, y1 = I0Fine[0]
    for x2, y2 in I0:
        if ((x2 - x1) > (2 * epsilon * x1)):
            bisectionTest(I0Fine, x1, y1, x2, y2, accuracy)
        I0Fine.append([x2, y2])
        x1, y1 = x2, y2

    return (I0Fine, I1, None)
Beispiel #23
0
    def calculate_a( self, energy_in, energy_out_cmMin, energy_out_cmMax, accuracy = 1e-6 ) :

        from fudge.core.math import fudgemath
        from fudge.particles import nuclear

        def getParticleData( particle ) :

            Z, A, suffix, ZA = particle.getZ_A_SuffixAndZA( )
            return( particle.name, Z, max( 0, A - Z ), A, particle.getMass( 'MeV/c**2' ) )

        energyFactor = PQU.PQU( 1, 'MeV' ).getValueAs( self.fSubform.data.axes[-1].unit )
        projectile = self.findAttributeInAncestry( 'projectile' )
        target = self.findAttributeInAncestry( 'target' )
        product = self.findClassInAncestry( fudge.gnd.product.product ).particle
        name_a, Z_a, N_a, A_a, AWRa = getParticleData( projectile )
        name_A, Z_A, N_A, A_A, AWRA = getParticleData( target )
        name_b, Z_b, N_b, A_b, AWRb = getParticleData( product )
        Z_C, N_C = Z_a + Z_A, N_a + N_A
        if( N_A == 0 ) : N_C = 0
        Z_B, N_B = Z_C - Z_b, max( 0, N_C - N_b )
        A_B = Z_B + N_B
        if( N_B == 0 ) : A_B = 0
        particles = self.findClassInAncestry( fudge.gnd.reactionSuite.reactionSuite ).particles
        residual = particles.getParticle( nuclear.nucleusNameFromZA( 1000 * Z_B + A_B ) )
        AWRB = residual.getMass( 'MeV/c**2' )
        Ma, Ia = self.KalbachMann_a_parameters[name_a]['M'], self.KalbachMann_a_parameters[name_a]['I']
        mb, Ib = self.KalbachMann_a_parameters[name_b]['m'], self.KalbachMann_a_parameters[name_b]['I']
        Sa, Sb = energyFactor * self.calculate_S_ab_MeV( Z_A, N_A, Z_C, N_C, Ia ), energyFactor * self.calculate_S_ab_MeV( Z_B, N_B, Z_C, N_C, Ib )

        C1, C2, C3 = 0.04 / energyFactor, 1.8e-6 / energyFactor**3, 6.7e-7 / energyFactor**4

        ea = energy_in * AWRA / ( AWRa + AWRA ) + Sa

        R1, R3 = 130 * energyFactor, 41 * energyFactor                        # MeV to self's energy units.
        if( ea < R1 ) : R1 = ea
        if( ea < R3 ) : R3 = ea

        def calculate_a2( energy_out_cm ) :

            eb = energy_out_cm * ( AWRb + AWRB ) / AWRB + Sb
            X1, X3 = R1 * eb / ea, R3 * eb / ea
            return( X1 * ( C1 + C2 * X1 * X1 ) + C3 * Ma * mb * X3**4 )

        class thicken_a :

            def __init__( self, calculate_a2, relativeTolerance, absoluteTolerance ) :

                self.calculate_a2 = calculate_a2
                self.relativeTolerance = relativeTolerance
                self.absoluteTolerance = absoluteTolerance

            def evaluateAtX( self, x ) :

                return( self.calculate_a2( x ) )

        a = [ [ energy_out_cmMin, calculate_a2( energy_out_cmMin ) ], [ energy_out_cmMax, calculate_a2( energy_out_cmMax ) ] ]
        a = fudgemath.thickenXYList( a, thicken_a( calculate_a2, accuracy, 1e-10 ) )

        axes = axesModule.axes( )
        axes[0] = axesModule.axis( 'a', 0, '' )
        axes[1] = self.fSubform.data.axes[1].copy( )
        return( XYsModule.XYs1d( data = a, axes = axes, accuracy = accuracy ) )
Beispiel #24
0
def primaryGammaAngularData( style, tempInfo, crossSection, energyData, angularData, multiplicity = 1, comment = None ) :
    """
    Currently, only isotropic (i.e., l = 0) data are returned. That is, lMax and angularData are ignored. massRatio is the
    target mass divide by the sum of the projectile and target masses.

    This function perform the integration 

        TM = \int_g dE \int_h dE' S(E) M(E) f(E) P(E -> E') / \int_g dE f(E)

    where \int_g is the integral of E from E_i to E_{i+1}, \int_g is the integral of E' from E'_j to E'_{j+1}, S(E) is the cross section,
    M(E) is the products multiplicity, f(E) is the flux weighting and P(E -> E') is the probability for a projectile of energy E producing
    a primary gamma of energy E' for binding energy bindingEnergy. This function assumes that M(E) is a constant. For primary gamma's captured
    into binding energy bindingEnergy P(E -> E') = deltaFunction( E' - ( bindingEnergy + massRatio E ) ) where massRatio = mt / ( mp + mt ),
    mp is the projectile's mass and mt is the target's mass. Note, this formula is from the ENDF manual which ignores the recoil of the residual
    nucleus.
    """

    reactionSuite = tempInfo['reactionSuite']
    projectileName = reactionSuite.projectile
    projectileGroupBoundaries = style.transportables[projectileName].group.boundaries
    productName = tempInfo['productName']
    productGroupBoundaries = style.transportables[productName].group.boundaries
    flux0 = style.flux.getFluxAtLegendreOrder( 0 )
    groupedFlux = tempInfo['groupedFlux']

    bindingEnergy = energyData.value * energyData.axes[1].unitConversionFactor( tempInfo['incidentEnergyUnit'] )
    massRatio = energyData.massRatio

    nProj = len( projectileGroupBoundaries.values ) - 1
    nProd = len( productGroupBoundaries.values ) - 1
    TM_1, TM_E = {}, {}
    for i1 in range( nProj ) :
        TM_1[i1] = {}
        TM_E[i1] = {}
        for i2 in range( nProd ) :
            TM_1[i1][i2] = [ 0. ]
            TM_E[i1][i2] = [ 0. ]
    Eg2 = bindingEnergy + massRatio * projectileGroupBoundaries.values[0]
    for indexEo, Eo in enumerate( productGroupBoundaries.values ) :
        if( Eg2 <= Eo ) : break
    indexEo = min( max( indexEo - 1, 0 ), nProd - 1 )

    EMin, EMax = crossSection.domainMin, crossSection.domainMax
    axes = axesModule.axes( labelsUnits = { 0 : ( 'energy_out', tempInfo['incidentEnergyUnit'] ), 
                                            1 : ( crossSection.axes[1].label, crossSection.axes[1].unit ) } )
    Egp = XYsModule.XYs1d( data = [ [ EMin, bindingEnergy + massRatio * EMin ], [ EMax, bindingEnergy + massRatio * EMax ] ], axes = axes )

    for indexEi in range( nProj ) :
        Ei2 = projectileGroupBoundaries.values[indexEi + 1]
        Eg2 = bindingEnergy + massRatio * Ei2
        EiMin = projectileGroupBoundaries.values[indexEi]
        while( True ) :
            incrementIndexEo, EiMax = 0, Ei2
            if( indexEo < ( nProd - 1 ) ) :
                if( Eg2 > productGroupBoundaries.values[indexEo + 1] ) :
                    incrementIndexEo = 1
                    EiMax = ( productGroupBoundaries.values[indexEo + 1] - bindingEnergy ) / massRatio
            TM_1[indexEi][indexEo][0] = float( crossSection.integrateTwoFunctions( flux0, 
                    domainMin = EiMin, domainMax = EiMax ) / groupedFlux[indexEi] )
            TM_E[indexEi][indexEo][0] = float( crossSection.integrateThreeFunctions( flux0, Egp, 
                    domainMin = EiMin, domainMax = EiMax ) / groupedFlux[indexEi] )
            if( incrementIndexEo == 0 ) : break
            EiMin = EiMax
            if( indexEo < ( nProd - 1 ) ) : indexEo += 1
    return( TM_1, TM_E )
Beispiel #25
0
                         Q=Q,
                         X1=X1,
                         temperature=args.temperature)


branchingGammas = {}
for chemicalElement in reactionSuite.PoPs.chemicalElements:
    for isotope in chemicalElement:
        for nuclearLevel in isotope:
            gammas = getGammaEmission([], 1, nuclearLevel, reactionSuite.PoPs)
            multiplicity = 0
            spectra = None
            for product, probability, gammaEnergy in gammas:
                spectrum = probability * gammaDeltaDistribution(gammaEnergy)
                data = [[float("%.14e" % x), y] for x, y in spectrum]
                spectrum = XYsModule.XYs1d(data, axes=spectrum.axes)
                multiplicity += probability
                if (spectra is None):
                    spectra = spectrum
                else:
                    spectra = spectra + spectrum
            if (spectra is not None):
                spectra = spectra.normalize()
                branchingGammas[nuclearLevel.id] = (multiplicity, spectra)

if (args.verbose):
    print '%s ->' % reactionSuite.inputParticlesToReactionString()

multiplicitySums = {}
for _sum in reactionSuite.sums.multiplicities:
    multiplicity = _sum.multiplicity.toPointwise_withLinearXYs(
Beispiel #26
0
    def getDistribution(self, energy, energies, numberOfGammas, zeroTotal):

        if (self.multiplicity.domainMin <= energy <=
                self.multiplicity.domainMax):
            domainMin, domainMax = self.energyForm.domainMin, self.energyForm.domainMax
            dE = energy - domainMin
            if (dE < 0):
                if (abs(dE) < 1e-15 * energy):
                    energy = domainMin
                else:
                    return (None)
            dE = domainMax - energy
            if (dE < 0):
                if (abs(dE) < 1e-15 * energy):
                    energy = domainMin
                else:
                    return (None)

            energyForm = self.energyForm
            if (isinstance(energyForm, (energyModule.regions2d, ))):
                for region in energyForm:
                    if (energy < region.domainMax): break
                energyForm = region

            PofEp1 = PofEp2 = energyForm[0]
            for PofEp2 in energyForm:
                if (PofEp2.value >= energy * (1 - 1e-15)): break
                PofEp1 = PofEp2
            if (abs(energy - PofEp1.value) <
                (energy *
                 1e-3)):  # If energy is close to PofEp1.value use PofEp1
                energyForm = PofEp1.toPointwise_withLinearXYs(
                    accuracy=1e-4, lowerEps=energyEps, upperEps=energyEps)
            elif (abs(energy - PofEp2.value) <
                  (energy *
                   1e-3)):  # If energy is close to PofEp2.value use PofEp2
                energyForm = PofEp2.toPointwise_withLinearXYs(
                    accuracy=1e-4, lowerEps=energyEps, upperEps=energyEps)
            else:
                fraction2 = (energy - PofEp1.value) / (PofEp2.value -
                                                       PofEp1.value)
                fraction2 = min(1.0, max(0.0, fraction2))
                energyForm1 = PofEp1.toPointwise_withLinearXYs(
                    accuracy=1e-4, lowerEps=energyEps, upperEps=energyEps)
                energyForm2 = PofEp2.toPointwise_withLinearXYs(
                    accuracy=1e-4, lowerEps=energyEps, upperEps=energyEps)
                try:
                    energyForm = XYsModule.pointwiseXY_C.unitbaseInterpolate(
                        energy, PofEp1.value, energyForm1, PofEp2.value,
                        energyForm2, 1)
                except:
                    if (fraction2 > 0.5):
                        energyForm = energyForm2
                    else:
                        energyForm = energyForm1
            lowerEps = energyEps
            if (energyForm.domainMin == 0): lowerEps = 0
            energyForm = energyForm.dullEdges(lowerEps=lowerEps,
                                              upperEps=energyEps)
            energyForm = XYsModule.XYs1d(energyForm)
            multiplicity = getMultiplicityForDistributionSum(
                self, energy, energies, numberOfGammas, zeroTotal)
            distribution = multiplicity * energyForm

            return (distribution)
        else:
            return (None)
Beispiel #27
0
    def group( self, groupBoundaries = ( None, None ), groupUnit = ( None, None ) ):
        '''
        Group the matrix in self

        :param groupBoundaries: a 2 element list containing the group boundaries for the rows 
                                and columns (respectively) of the covariance to be regrouped
                                rows go in the first element, columns in the second
        :param groupUnit: a 2 element list containing the units in which group boundaries are 
                          specified for the rows and columns (respectively) of the covariance 
                          to be regrouped

        :returns: the regrouped matrix (an xData.array.full as the array in a gridded2d.matrix)
            
        .. note::  We still need to do flux weighting
            
            
        .. rubric:: Regrouping Theory
        
        Given a function :math:`f(E)`, we write the grouped data using fudge's ``flat`` interpolation 
        scheme.  We note that we could write this scheme as an expansion over basis functions:
        
        .. math::    
            f(E) = \sum_{i=0}^{N+1} w_i(E) * f_i
        
        where the weight functions :math:`w_i(E)` are
        
        .. math::
            w_i(E) = 1  \;\\text{for}\; E_i <= E <= E_{i+1}; \;\; 0 \;\\textrm{otherwise}
            
        These weights are an orthogonal (bot not orthonormal) basis, with 
        
        .. math::
            (E_{i+1}-E_i) \delta_{ij} = \int dE w_i(E) * w_j(E)
        
        So, to transform from basis :math:`w_i(E)` to :math:`v_i(E)` (which has group boundaries 
        :math:`[ E'_0, ... ]`), do: 
        
        .. math::
            f'_j = \sum_i m_{ji} f_i
            
        where :math:`f'` is the regrouped function coefficients and :math:`m_{ji}` is the matrix
        
        .. math::
            m_{ij} = (E'_{i+1}-E'_i)^{-1} \int dE v_i(E) w_j(E) 

            
        .. rubric:: Applying regrouping theory to covariance matrices   
        
        When we are given a covariance matrix :math:`c_{ij}` in ENDF, it is meant to be interpreted
        as a grouped covariance in both the direction of the matrix rows and the matrix 
        columns.  Therefore, we must regroup in both the row direction and the column 
        direction.  The ENDF format gives both the group boundaries for the rows and columns.
        In other words, ENDF gives us the following rule for evaluating the continuous row-
        column covariance:
        
        .. math::
            c( E1, E2 ) = \sum_{ij} w_i(E1) w_j(E2) c_{ij}
            
        Computing :math:`m_{ij}` as before, 
            
        .. math::
            cc_{ij} = \sum_{i',j'} m_{ii'} c_{i'j'} m_{j'j}
            
        It is straightforward to generalize to the case where the row and column bases are 
        different.
        
        In the routine below, we abuse :py:class:`xData.XYs1d` to specify the functions 
        :math:`w_i(E)` and use the :py:func:`XYs1d.groupOneFunction()` method to perform the integrals to get
        the regrouping matrix.  We do this separately for the rows and the columns.
        The matrix multiplication that converts a covariance from one pair of bases (group 
        structures) to another is accomplished using numpy.

        
        .. rubric:: An explanation of fudge's 'flat' interpolation
        
        Suppose we have a function :math:`f(E)` specified using fudge's `'flat'` interpolation.  
        Then we have :math:`N` entries :math:`[f_0, f_1, ..., f_{N-1}]` and a set of group 
        boundaries :math:`[E_0, E_1, ..., E_N]` and the following rule for interpolation:
        
            * Below :math:`E_0`, :math:`f(E)` evaluates to :math:`0.0`
            * From :math:`E_0 \\rightarrow E_1`, :math:`f(E)` evaluates to :math:`f_0`
            * From :math:`E_1 \\rightarrow E_2`, :math:`f(E)` evaluates to :math:`f_1`
            * ...
            * From :math:`E_{i} \\rightarrow E_{i+1}`, :math:`f(E)` evaluates to :math:`f_i`
            * ...
            * From :math:`E_{N-1} \\rightarrow E_N`, :math:`f(E)` evaluates to :math:`f_{N-1}`
            * Above :math:`E_N`, :math:`f(E)` evaluates to :math:`0.0`
        '''
        # determine where to get the settings for the potentially mirrored second axis
        if self.matrix.axes[1].style == 'link': axis1index = 2
        else:                                   axis1index = 1
        
        # setup the old axes in a form we can (ab)use in the XYs1d class
        axes2_ = axesModule.axes( labelsUnits={1:( self.matrix.axes[2].label, self.matrix.axes[2].unit ),0:( 'dummy', '' )} )
        axes1_ = axesModule.axes( labelsUnits={1:( self.matrix.axes[axis1index].label, self.matrix.axes[axis1index].unit ),0:( 'dummy', '' )} )
        
        # define basis functions for the rows and columns
        basis2 = XYsModule.XYs1d( axes=axes2_, data=[ ( x, 0.0 ) for x in self.matrix.axes[2].values ], interpolation='flat' )
        basis1 = XYsModule.XYs1d( axes=axes1_, data=[ ( x, 0.0 ) for x in self.matrix.axes[axis1index].values ], interpolation='flat' )
        basis2 = basis2.convertAxisToUnit( 1, groupUnit[0] )
        basis1 = basis1.convertAxisToUnit( 1, groupUnit[1] )

        # build the regrouping matrices for the two bases
        w0 = []
        for idx in range( self.matrix.array.shape[0] ):
            basis2[idx] = ( basis2[idx][0], 1.0 )
            w0.append( basis2.groupOneFunction( groupBoundaries[0], norm = 'dx' ) )
            basis2[idx] = ( basis2[idx][0], 0.0 )
        w0 = numpy.mat( w0 )
        w1 = []
        for j in range( self.matrix.array.shape[1] ):
            basis1[j] = ( basis1[j][0], 1.0 )
            w1.append( basis1.groupOneFunction( groupBoundaries[1], norm = 'dx' ) )
            basis1[j] = ( basis1[j][0], 0.0 )
        w1 = numpy.mat( w1 )
                
        # set up the regrouped covariance matrix
        grouped = copy.copy( self )
        grouped.matrix.axes[2].data = groupBoundaries[0]
        grouped.matrix.axes[1].data = groupBoundaries[1]
        grouped.matrix.axes[2].unit = groupUnit[0]
        grouped.matrix.axes[1].unit = groupUnit[1]
        odata = numpy.mat( self.matrix.array.constructArray() )
        gdata = w0.T * odata * w1
        trigdata = gdata[numpy.tri(gdata.shape[0])==1.0].tolist()[0]
        grouped.matrix.array = arrayModule.full(shape=gdata.shape,data=trigdata,symmetry=arrayModule.symmetryLowerToken)
        return grouped
Beispiel #28
0
def processGamma(gamma, gammas, crossSection):

    distribution = gamma.distribution[style]
    if (isinstance(distribution, unspecifiedModule.form)):
        if (args.verbose > 1): print '            No distribution data'
        return

    MF13 = False
    if ('ENDFconversionFlag' in gamma.attributes):
        MF13 = gamma.attributes['ENDFconversionFlag'] == 'MF13'
    multiplicity = gamma.multiplicity[style]
    if (isinstance(multiplicity, (multiplicityModule.constant1d))):
        domainMin, domainMax = multiplicity.domainMin, multiplicity.domainMax
        multiplicity = XYsModule.XYs1d(
            [[float(domainMin), multiplicity.constant],
             [float(domainMax), multiplicity.constant]],
            axes=XYsModule.XYs1d.defaultAxes(
                labelsUnits={1: ('energy_in', 'MeV')}))
    elif (isinstance(
            multiplicity,
        (multiplicityModule.XYs1d, multiplicityModule.regions1d))):
        if (isinstance(multiplicity, multiplicityModule.regions1d) and MF13):
            for region in multiplicity:
                if (region.interpolation ==
                        standardsModule.interpolation.flatToken):
                    print '    WARNING: This may need to be fixed.'
        if (MF13 and isinstance(multiplicity, multiplicityModule.XYs1d)):
            pass
        else:
            multiplicity = multiplicity.toPointwise_withLinearXYs(
                lowerEps=energyEps, upperEps=energyEps)
    else:
        raise Exception('Unsupported multiplicity form "%s"' %
                        multiplicity.moniker)
    multiplicity = multiplicity.domainSlice(domainMax=args.EMax)
    if ((len(multiplicity) < 2) or (multiplicity.rangeMax == 0)):
        if (args.verbose):
            print '''INFO: 1) not writing reaction's gamma data as gamma multiplicity is 0. below EMax = %s''' % args.EMax
        return

    if (crossSection is not None):
        if (MF13):
            values = [[E1, m1 * crossSection.evaluate(E1)]
                      for E1, m1 in multiplicity]
            multiplicity = XYsModule.XYs1d(
                values,
                axes=multiplicity.axes,
                interpolation=multiplicity.interpolation)
            multiplicity = multiplicity.toPointwise_withLinearXYs(
                lowerEps=energyEps, upperEps=energyEps)
            multiplicity.axes[0].unit = "b"
        else:
            crossSection = crossSection.domainSlice(domainMax=args.EMax)
            crossSection.setInfill(False)
            multiplicity.setInfill(False)
            try:
                multiplicity = multiplicity * crossSection
            except:
                print 'multiplicity'
                print multiplicity.toString()
                print 'crossSection'
                print crossSection.toString()
                print multiplicity.domainMin, multiplicity.domainMax, crossSection.domainMin, crossSection.domainMax
                raise
            multiplicity = multiplicity.trim()

    if (isinstance(distribution, uncorrelatedModule.form)):
        angularForm = distribution.angularSubform.data
        energyForm = distribution.energySubform.data
        if (isinstance(angularForm, angularModule.XYs2d)):
            if (not (angularForm.isIsotropic())):
                print 'WARNING: treating angular XYs2d as isotropic'
            isIsotropic = True
        else:
            isIsotropic = angularForm.isIsotropic()
            if (not (isIsotropic)):
                raise Exception('unsupported angular distribution')
        if (isIsotropic):
            if (isinstance(energyForm, energyModule.primaryGamma)):
                gammas['primaries'].append(
                    primaryGamma(multiplicity, energyForm.value,
                                 float(energyForm.massRatio), angularForm))
            elif (isinstance(energyForm, energyModule.discreteGamma)):
                gammas['discretes'].append(
                    discreteGamma(multiplicity, energyForm.value, angularForm))
            else:
                if (isinstance(energyForm,
                               (energyModule.XYs2d, energyModule.regions2d))):
                    pass
                else:
                    raise Exception('Unsupported energy form "%s"' %
                                    energyForm.moniker)
                gammas['continuum'].append(
                    continuumGammaIsotropic(multiplicity, energyForm))
        else:
            raise Exception('Unsupported angular form "%s"' %
                            angularForm.moniker)
    else:
        raise Exception('Unsupported distribution type "%s"' %
                        distribution.moniker)
Beispiel #29
0
    def averageMomentum( self ) :

        MpOfMu = [ [ pdfOfMpAtMu.value, pdfOfMpAtMu.averageMomentum( ) ] for pdfOfMpAtMu in self ]
        return( float( XYsModule.XYs1d( MpOfMu ).integrate( ) ) )
Beispiel #30
0
    def averageEnergy( self ) :

        EpOfMu = [ [ pdfOfEpAtMu.value, pdfOfEpAtMu.averageEnergy( ) ] for pdfOfEpAtMu in self ]
        return( float( XYsModule.XYs1d( EpOfMu ).integrate( ) ) )