Exemplo n.º 1
0
    def calculateAverageProductData(self, style, indent='', **kwargs):

        raise 'FIXME, when am I called'

        energyUnit = kwargs['incidentEnergyUnit']
        momentumDepositionUnit = energyUnit + '/c'
        massUnit = energyUnit + '/c**2'
        energyAccuracy = kwargs['energyAccuracy']
        momentumAccuracy = kwargs['momentumAccuracy']
        product = kwargs['product']
        reactionSuite = kwargs['reactionSuite']

        if (product.name != 'gamma'):
            raise Exception(
                'For form %s, calculateAverageProductData is only for gammas, not %s'
                % (self.moniker, product.name))

        depData = []
        angularSubform = self.angularSubform

        Es = angularSubform.getEnergyArray(kwargs['EMin'], kwargs['EMax'])
        if (('discrete' in product.attributes)
                or ('primary' in product.attributes)):
            massRatio = 0.
            if ('discrete' in product.attributes):
                Eg = product.attributes['discrete'].getValueAs(energyUnit)
            else:
                Eg = product.attributes['primary'].getValueAs(energyUnit)
                mass1 = reactionSuite.projectile.getMass(massUnit)
                mass2 = reactionSuite.target.getMass(massUnit)
                massRatio = mass2 / (mass1 + mass2)
            depEnergy = [[E, Eg + massRatio * E] for E in Es]
            depMomentum = [[
                E, (Eg + massRatio * E) *
                angularSubform.averageMu(E, accuracy=0.1 * momentumAccuracy)
            ] for E in Es]
        else:
            raise Exception(
                'Unsupported gamma; gamma must be "discrete" or "primary"')

        axes = energyDepositionModule.XYs1d.defaultAxes(
            energyUnit=energyUnit, energyDepositionUnit=energyUnit)
        depData.append(
            energyDepositionModule.XYs1d(data=depEnergy,
                                         axes=axes,
                                         label=style.label,
                                         accuracy=energyAccuracy))
        axes = momentumDepositionModule.XYs1d.defaultAxes(
            energyUnit=energyUnit,
            momentumDepositionUnit=momentumDepositionUnit)
        depData.append(
            momentumDepositionModule.XYs1d(data=depMomentum,
                                           axes=axes,
                                           label=style.label,
                                           accuracy=momentumAccuracy))

        return (depData)
Exemplo n.º 2
0
    def calculateAverageProductData( self, style, indent = '', **kwargs ) :

        from fudge.core.math import fudgemath

        def calculateDepositionMomentumAtMu( mu, parameters ) :

            f = ( mu - parameters.mu1 ) / ( parameters.mu2 - parameters.mu1 )
            P_mu = ( 1 - f ) * parameters.P1 + f * parameters.P2
            EpP = parameters.muEpPs.interpolateAtValue( mu, unitBase = True, extrapolation = standardsModule.flatExtrapolationToken )
            Ep = EpP.integrateWithWeight_sqrt_x( )
            return( mu * P_mu * Ep )

        def calculateDepositionMomentum( muPs, muEpPs ) :

            class LLNLAngular_angularEnergy_MomentumParameters :

                def __init__( self, mu1, P1, mu2, P2, muEpPs ) :

                    self.mu1, self.P1, self.mu2, self.P2, self.muEpPs = mu1, P1, mu2, P2, muEpPs

                def nextMu( self, m2, P2 ) :

                    self.mu1, self.P1 = self.mu2, self.P2
                    self.mu2, self.P2 = mu2, P2

            parameters = LLNLAngular_angularEnergy_MomentumParameters( 0, 0, 0, 0, muEpPs )
            mu1, p = None, 0
            for mu2, P2 in muPs :
                parameters.nextMu( mu2, P2 )
                if( mu1 is not None ) :
                    p += miscellaneousModule.GnG_adaptiveQuadrature( calculateDepositionMomentumAtMu, mu1, mu2, parameters, 
                            miscellaneousModule.GaussQuadrature2, tolerance = 1e-4 )[0]
                mu1 = mu2
            return( p )

        class calculateDepositionMomentumThicken :

            def __init__( self, angularSubform, angularEnergySubform, relativeTolerance, absoluteTolerance ) :

                self.angularSubform = angularSubform
                self.angularEnergySubform = angularEnergySubform
                self.relativeTolerance = relativeTolerance
                self.absoluteTolerance = absoluteTolerance

            def evaluateAtX( self, E ) :

                muPs = self.angularSubform.getAtEnergy( E )
                muEpPs = self.angularEnergySubform.interpolateAtV( E, unitBase = True )
                return( calculateDepositionMomentum( muPs, muEpPs ) )

        energyUnit = kwargs['incidentEnergyUnit']
        momentumDepositionUnit = kwargs['momentumDepositionUnit']
        multiplicity = kwargs['multiplicity']
        energyAccuracy = kwargs['energyAccuracy']
        momentumAccuracy = kwargs['momentumAccuracy']
        product = kwargs['product']
        productMass = kwargs['productMass']

        angularSubform = self.angularSubform.data
        angularEnergySubform = self.angularEnergySubform.data

        depEnergy = miscellaneousModule.calculateDepositionEnergyFromAngular_angularEnergy( style, 
                angularSubform, angularEnergySubform, multiplicity, accuracy = energyAccuracy )

        if( product.id == IDsPoPsModule.photon ) :
            depMomentum = miscellaneousModule.calculateDepositionEnergyFromAngular_angularEnergy( style, 
                    angularSubform, angularEnergySubform, multiplicity, True, accuracy = momentumAccuracy )
        else :
            relativeTolerance, absoluteTolerance = momentumAccuracy, momentumAccuracy
            depMomentum = []
            for indexE, muPs in enumerate( angularSubform ) :
                depMomentum.append( [ muPs.value, calculateDepositionMomentum( muPs, angularEnergySubform[indexE] ) ] )
#            depMomentum = fudgemath.thickenXYList( depMomentum, calculateDepositionMomentumThicken( angularSubform, angularEnergySubform, relativeTolerance, absoluteTolerance ) )
            const = math.sqrt( 2. * productMass )
            for EMomenutem in depMomentum : EMomenutem[1] *= const * multiplicity.evaluate( EMomenutem[0] )

        axes = momentumDepositionModule.defaultAxes( energyUnit = energyUnit, momentumDepositionUnit = momentumDepositionUnit )
        depMomentum = momentumDepositionModule.XYs1d( data = depMomentum, axes = axes,
                        label = style.label )

        return( [ depEnergy ], [ depMomentum ] )
Exemplo n.º 3
0
    def calculateAverageProductData(self, style, indent='', **kwargs):

        verbosity = kwargs.get('verbosity', 0)
        indent2 = indent + kwargs.get('incrementalIndent', '  ')

        energyUnit = kwargs['incidentEnergyUnit']
        momentumDepositionUnit = kwargs['momentumDepositionUnit']
        multiplicity = kwargs['multiplicity']
        productMass = kwargs['productMass']
        energyAccuracy = kwargs['energyAccuracy']
        momentumAccuracy = kwargs['momentumAccuracy']
        EMin = kwargs['EMin']

        Legendre_l0, Legendre_l1 = self[0], None
        if (len(self) > 1): Legendre_l1 = self[1]

        if (isinstance(multiplicity, multiplicityModule.XYs1d)
            ):  # If multiplicity as points not in Legendre_l0 add them.
            Es = set([EpP.value for EpP in Legendre_l0])
            for E, m in multiplicity:
                Es.add(E)
            if (len(Es) > len(Legendre_l0)):
                Es = sorted(Es)

                Legendre_l0p = multiD_XYsModule.XYs2d()
                for energy in Es:
                    Legendre_l0p.append(
                        Legendre_l0.interpolateAtValue(
                            energy,
                            unitBase=True,
                            extrapolation=standardsModule.
                            flatExtrapolationToken))
                Legendre_l0 = Legendre_l0p

                if (Legendre_l1 is not None):
                    Legendre_l1p = multiD_XYsModule.XYs2d()
                    for energy in Es:
                        Legendre_l1p.append(
                            Legendre_l1.interpolateAtValue(
                                energy,
                                unitBase=True,
                                extrapolation=standardsModule.
                                flatExtrapolationToken))
                    Legendre_l1 = Legendre_l1p

        calculateDepositionEnergyFromEpP = miscellaneousModule.calculateDepositionEnergyFromEpP
        depEnergy = [[
            EpP.value,
            multiplicity.evaluate(EpP.value) *
            calculateDepositionEnergyFromEpP(EpP.value, EpP)
        ] for EpP in Legendre_l0]
        if (depEnergy[0][0] > EMin):
            depEnergy.insert(0, [EMin, 0.])  # Special case for bad data
        axes = energyDepositionModule.defaultAxes(energyUnit)
        energyDep = energyDepositionModule.XYs1d(data=depEnergy,
                                                 axes=axes,
                                                 label=style.label)

        if (Legendre_l1 is not None):
            depMomentum = []
            const = math.sqrt(2. * productMass)
            for EpP in Legendre_l1:
                if (const == 0):  # For gammas.
                    depMomentum.append([
                        EpP.value,
                        multiplicity.evaluate(EpP.value) *
                        EpP.integrateWithWeight_x()
                    ])
                else:
                    depMomentum.append([
                        EpP.value, const * multiplicity.evaluate(EpP.value) *
                        EpP.integrateWithWeight_sqrt_x()
                    ])
        else:
            depMomentum = [[Legendre_l0[0].value, 0.],
                           [Legendre_l0[-1].value, 0.]]
        axes = momentumDepositionModule.defaultAxes(energyUnit,
                                                    momentumDepositionUnit)
        if (depMomentum[0][0] > EMin):
            depMomentum.insert(0, [EMin, 0.])  # Special case for bad data
        momentumDep = momentumDepositionModule.XYs1d(data=depMomentum,
                                                     axes=axes,
                                                     label=style.label)

        return ([energyDep], [momentumDep])
Exemplo n.º 4
0
    def calculateDepositionData(self, style, indent='', **kwargs):

        verbosity = kwargs.get('verbosity', 0)
        indent2 = indent + kwargs.get('incrementalIndent', '  ')
        energyUnit = kwargs['incidentEnergyUnit']
        momentumDepositionUnit = energyUnit + '/c'
        massUnit = energyUnit + '/c**2'
        multiplicity = kwargs['multiplicity']
        productMass = kwargs['product'].getMass(massUnit)
        energyAccuracy = kwargs['energyAccuracy']
        momentumAccuracy = kwargs['momentumAccuracy']
        EMin = kwargs['EMin']

        depData = []

        Legendre_l0, Legendre_l1 = self[0], None
        if (len(self) > 1): Legendre_l1 = self[1]

        if (isinstance(multiplicity, multiplicityModule.XYs1d)):
            Es = [EpP.value for EpP in Legendre_l0]
            doIt = False
            for E, m in multiplicity.getFormByToken(
                    tokensModule.pointwiseFormToken):
                if (E < Es[0]): continue
                if (E not in Es):
                    doIt = True
                    Es.append(E)
            if (doIt):
                Es.sort()
                Legendre_l0p, Legendre_l1p = LLNLPointwiseEEpP(
                    0), LLNLPointwiseEEpP(1)
                indexE, EpP1 = 0, None
                for EpP2 in Legendre_l0:
                    while ((indexE < len(Es)) and (EpP2.value > Es[indexE])):
                        if (EpP1.value != Es[indexE]):
                            EpP = XYs.pointwiseXY_C.unitbaseInterpolate(
                                Es[indexE], EpP1.value, EpP1, EpP2.value, EpP2)
                            axes = EpP1.axes.copy()
                            Legendre_l0p.append(
                                XYs.XYs(axes,
                                        EpP,
                                        EpP1.getAccuracy(),
                                        value=Es[indexE]))
                        indexE += 1
                    Legendre_l0p.append(EpP2)
                    EpP1 = EpP2
                Legendre_l0 = Legendre_l0p
                if (Legendre_l1 is not None):
                    for EpP2 in Legendre_l1:
                        while ((indexE < len(Es))
                               and (EpP2.value > Es[indexE])):
                            if (EpP1 is None):
                                raise Exception(
                                    'multiplicity energy = %s before Legendre l = 0 distribution energy = %s'
                                    % (Es[indexE], EpP2.value))
                            if (EpP1.value != Es[indexE]):
                                EpP = XYs.pointwiseXY_C.unitbaseInterpolate(
                                    Es[indexE], EpP1.value, EpP1, EpP2.value,
                                    EpP2)
                                axes = EpP1.axes.copy()
                                Legendre_l1p.append(
                                    XYs.XYs(axes,
                                            EpP,
                                            EpP1.getAccuracy(),
                                            value=Es[indexE]))
                            indexE += 1
                        Legendre_l1p.append(EpP2)
                        EpP1 = EpP2
                    Legendre_l1 = Legendre_l1p

        depEnergy = [[
            EpP.value,
            multiplicity.getValue(EpP.value) *
            miscellaneous.calculateDepositionEnergyFromEpP(EpP.value, EpP)
        ] for EpP in Legendre_l0]
        if (depEnergy[0][0] > EMin):
            depEnergy.insert(0, ['EMin', 0.])  # Special case for bad data

        axes = energyDepositionModule.XYs1d.defaultAxes(
            energyUnit=energyUnit, energyDepositionUnit=energyUnit)
        depData.append(
            energyDepositionModule.XYs1d(data=depEnergy,
                                         axes=axes,
                                         label=style.label,
                                         accuracy=energyAccuracy))

        if (Legendre_l1 is not None):
            const = math.sqrt(2. * productMass)
            if (const == 0.): const = 1  # For gammas.
            depMomentum = []
            EpP = Legendre_l1[0]
            for EpP in Legendre_l1:
                if (const == 0.):  # For gammas.
                    depMomentum.append([
                        EpP.value, const * multiplicity.getValue(EpP.value) *
                        EpP.integrateWithWeight_x()
                    ])
                else:
                    depMomentum.append([
                        EpP.value, const * multiplicity.getValue(EpP.value) *
                        EpP.integrateWithWeight_sqrt_x()
                    ])
        else:
            depMomentum = [[Legendre_l0[0].value, 0.],
                           [Legendre_l0[-1].value, 0.]]
        axes = momentumDepositionModule.XYs1d.defaultAxes(
            energyUnit=energyUnit,
            momentumDepositionUnit=momentumDepositionUnit)
        if (depMomentum[0][0] > EMin):
            depMomentum.insert(0, [EMin, 0.])  # Special case for bad data
        depData.append(
            momentumDepositionModule.XYs1d(data=depMomentum,
                                           axes=axes,
                                           label=style.label,
                                           accuracy=momentumAccuracy))
        return (depData)