Esempio n. 1
0
def toENDF6(self, MT, endfMFList, flags, targetInfo):

    weight = targetInfo['delayedNubarWeight']
    energySubform = self.energySubform
    if (hasattr(energySubform, 'toENDF6')):
        if (isinstance(energySubform, energyModule.constant)):
            energySubform.toENDF6(flags, targetInfo)
            return
        if (MT in [527, 528]):
            NK, MF5 = energySubform.toENDF6(flags,
                                            targetInfo,
                                            weight=weight,
                                            MT=MT)
        else:
            NK, MF5 = energySubform.toENDF6(flags, targetInfo, weight=weight)

        if (MT == 455):
            endfMFList[5][MT].append(MF5)
        elif (MT == 528):
            endfMFList[26][MT] = [ endfFormatsModule.endfHeadLine( targetInfo['ZA'], targetInfo['mass'], 0, 0, NK, 0 ) ] + \
                    MF5 + [ endfFormatsModule.endfSENDLineNumber( ) ]
        else:
            endfMFList[5][MT]  = [ endfFormatsModule.endfHeadLine( targetInfo['ZA'], targetInfo['mass'], 0, 0, NK, 0 ) ] + \
                    MF5 + [ endfFormatsModule.endfSENDLineNumber( ) ]
    else:
        print 'WARNING: energy subform "%s" does not have method toENDF6' % energySubform.moniker
Esempio n. 2
0
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()]
Esempio n. 3
0
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( ) ]
Esempio n. 4
0
def fissionNeutronsToENDF6(MT, multiplicity, endfMFList, flags, targetInfo):

    if (isinstance(multiplicity, multiplicityModule.polynomial)):
        multiplicity.toENDF6(MT, endfMFList, flags, targetInfo)
    else:
        interpolation, n1, data = multiplicity.toENDF6List(targetInfo)
        if (MT not in endfMFList[1]):
            endfMFList[1][MT] = [
                endfFormatsModule.endfHeadLine(targetInfo['ZA'],
                                               targetInfo['mass'], 0, 2, 0, 0)
            ]
        endfMFList[1][MT] += [
            endfFormatsModule.endfHeadLine(0, 0, 0, 0,
                                           len(interpolation) / 2, n1)
        ]
        endfMFList[1][MT] += endfFormatsModule.endfInterpolationList(
            interpolation)
        endfMFList[1][MT] += data + [endfFormatsModule.endfSENDLineNumber()]
Esempio n. 5
0
def toENDF6(self, flags, targetInfo):

    ENDFDataList = [endfFormatsModule.endfContLine(0, 0, 0, 0, 1, len(self))]
    interpolation = gndToENDF6Module.gndToENDF2PlusDInterpolationFlag(
        self.interpolation, self.interpolationQualifier)
    ENDFDataList += endfFormatsModule.endfInterpolationList(
        [len(self), interpolation])
    for energy_in in self:
        if (isinstance(energy_in, XYsModule.XYs1d)):
            ENDFDataList += gndToENDF6Module.angularPointwiseEnergy2ENDF6(
                energy_in, targetInfo)
        elif (isinstance(energy_in, series1dModule.LegendreSeries)):
            ENDFDataList += gndToENDF6Module.angularLegendreEnergy2ENDF6(
                energy_in, targetInfo)
        else:
            raise 'hell - fix me'
    if (not (targetInfo['doMF4AsMF6'])):
        ENDFDataList.append(endfFormatsModule.endfSENDLineNumber())
    return (0, 2, ENDFDataList)
Esempio n. 6
0
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())
Esempio n. 7
0
def toAngularPointwise(angularSubform, targetInfo, insertSENDL):

    energyConversionFactor = PQUModule.PQU(
        1, angularSubform.axes[-1].unit).getValueAs('eV')

    def angularPointwiseEnergy2ENDF6(self, targetInfo):

        interpolation = gndToENDF6Module.gndToENDFInterpolationFlag(
            self.interpolation)
        energy_in_eV = self.value * energyConversionFactor
        if (targetInfo['doMF4AsMF6']):
            ENDFDataList = [
                endfFormatsModule.endfContLine(0, energy_in_eV,
                                               interpolation + 10, 0,
                                               2 * len(self), len(self))
            ]
        else:
            ENDFDataList = [
                endfFormatsModule.endfContLine(0, energy_in_eV, 0, 0, 1,
                                               len(self))
            ]
            ENDFDataList += endfFormatsModule.endfInterpolationList(
                [len(self), interpolation])
        ENDFDataList += endfFormatsModule.endfNdDataList(self)
        return (ENDFDataList)

    ENDFDataList = [
        endfFormatsModule.endfContLine(0, 0, 0, 0, 1, len(angularSubform))
    ]
    interpolation = (gndToENDF6Module.gndToENDFInterpolationFlag(
        angularSubform.interpolation))
    ENDFDataList += endfFormatsModule.endfInterpolationList(
        [len(angularSubform), interpolation])
    start = 0
    if targetInfo.get('skipFirstEnergy'): start = 1
    for energy_in in angularSubform[start:]:
        ENDFDataList += angularPointwiseEnergy2ENDF6(energy_in, targetInfo)
    if (insertSENDL):
        ENDFDataList.append(endfFormatsModule.endfSENDLineNumber())
    return (0, 2, ENDFDataList)
Esempio n. 8
0
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)
Esempio n. 9
0
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())
Esempio n. 10
0
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( ) ]
Esempio n. 11
0
def toENDF6(self, flags, targetInfo):

    ENDFDataList = []
    if (not (targetInfo['doMF4AsMF6'])):
        ENDFDataList.append(endfFormatsModule.endfSENDLineNumber())
    return (1, 0, ENDFDataList)
Esempio n. 12
0
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)
Esempio n. 13
0
def toENDF6(self, endfMFList, flags, targetInfo, verbosityIndent=''):
    def addDecayProducts(parent, products):

        if (parent.outputChannel is None): return (False)
        doMF4AsMF6 = False
        for product in parent.outputChannel:
            if (len(product.distribution) and (product.name != 'gamma')):
                if (product.attributes.get('ENDFconversionFlag') == 'MF6'):
                    doMF4AsMF6 = True
                products.append(product)
        return (doMF4AsMF6)

    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')

    def thinWeights(weights):

        i, n, thinnedWeights = 1, len(weights), [weights[0]]
        if (n == 2):
            thinnedWeights.append(weights[-1])
        else:
            while (i < n):
                y = thinnedWeights[-1][1]
                while (True):
                    i += 1
                    if (i == n): break
                    if (abs(y - weights[i][1]) > 1e-8 * y): break
                    if (abs(y - weights[i - 1][1]) > 1e-8 * y): break
                thinnedWeights.append(weights[i - 1])
        return (thinnedWeights)

    outputChannel = self.outputChannel
    if isinstance(outputChannel, channelsModule.productionChannel):
        print '        toENDF6 does not support writing of "%s" channel' % outputChannel.genre
        return
    MT = self.ENDF_MT
    if (flags['verbosity'] >= 10):
        print '%s%s' % (verbosityIndent,
                        outputChannel.toString(simpleString=True))
    targetInfo['Q'] = self.getQ('eV', groundStateQ=True)
    targetInfo['QM'] = None

    LR, tryLR = 0, False
    if isinstance(outputChannel, channelsModule.twoBodyOutputChannel):
        tryLR = True
    elif isinstance(outputChannel, channelsModule.NBodyOutputChannel):
        if (MT == 91): tryLR = True
    if (tryLR and (len(outputChannel) > 1)):
        secondProduct = outputChannel[1]
        primaryResidualName, decayProducts, decayChannel, = secondProduct.name.split(
            '_')[0], [], secondProduct.outputChannel
        if (not (decayChannel is None)):
            for decayProduct in decayChannel:
                decayProductName = decayProduct.name
                if (decayProductName not in [primaryResidualName, 'gamma']):
                    decayProducts.append(decayProductName)
        if (len(decayProducts) == 1
            ):  # Kludge for Carbon breakup into 3 alphas.
            if ((primaryResidualName == 'C') and (decayProducts == ['He4'])):
                LR = 23
        elif (len(decayProducts) > 1):  # This must be a breakup reaction.
            MTProducts = endf_endlModule.endfMTtoC_ProductList(0, '')
            MTProducts.productCounts[outputChannel[0].name] += 1
            for decayProduct in decayProducts[:-1]:
                MTProducts.productCounts[decayProduct] += 1
            for MT_LR in [22, 23, 24, 25, 28, 29, 30, 32, 33, 34, 35,
                          36]:  # 39 and 40 not allowed in ENDF6
                if (endf_endlModule.endfMTtoC_ProductLists[MT_LR].productCounts
                        == MTProducts.productCounts):
                    LR = MT_LR
                    break
            if ((LR == 32) and (primaryResidualName == 'B10')
                    and (decayProducts[-1] == 'He4')):
                LR = 35  # Kludge for bad data.
        if (LR != 0):
            QM = outputChannel.Q[targetInfo['style']].getValue(
                0, 'eV') + decayChannel.Q[targetInfo['style']].getValue(
                    0, 'eV')
            targetInfo['QM'] = QM
    targetInfo['LRs'][MT] = LR

    level = 0.
    for product in outputChannel:
        tmp = None
        if (hasattr(product, 'getLevelAsFloat')):
            tmp = product.getLevelAsFloat('eV')
        if (tmp is not None): level = tmp

    targetInfo['EMin'], targetInfo['EMax'] = self.crossSection.domain(
        unitTo="eV")
    if (self.EFL is not None): targetInfo['EFL'] = self.EFL.getValueAs("eV")
    self.crossSection.toENDF6(MT, endfMFList, targetInfo, level, LR)
    if ('EFL' in targetInfo): del targetInfo['EFL']

    products = []
    doMF4AsMF6 = False
    for product in outputChannel:
        if (len(product.distribution)): products.append(product)
        doMF4AsMF6 = doMF4AsMF6 or addDecayProducts(product, products)
    if (outputChannel.isFission()):
        doMF4AsMF6 = False
        if (not (outputChannel.fissionEnergyReleased is None)):
            outputChannel.fissionEnergyReleased.toENDF6(
                1, endfMFList, flags, targetInfo)
        delayedNubar = None  # Special work to get delayed nubar weights.
        for product in outputChannel:
            if ('emissionMode' in product.attributes):
                if (product.getAttribute('emissionMode') ==
                        tokensModule.delayedToken):
                    if (delayedNubar is None):
                        delayedNubar = product.multiplicity[
                            targetInfo['style']]
                    else:
                        delayedNubar = delayedNubar + product.multiplicity[
                            targetInfo['style']]
                    targetInfo['delayedRates'].append(
                        product.getAttribute('decayRate').getValueAs('1/s'))
        if (delayedNubar is not None):
            targetInfo['totalDelayedNubar'] = delayedNubar
            for product in outputChannel:
                if ('emissionMode' in product.attributes):
                    if (product.getAttribute('emissionMode') ==
                            tokensModule.delayedToken):
                        weight = divideIgnoring0DividedBy0(
                            product.multiplicity[targetInfo['style']],
                            delayedNubar)
                        product.ENDF6_delayedNubarWeights = thinWeights(weight)
    if (MT in [526, 527]): doMF4AsMF6 = True
    targetInfo['doMF4AsMF6'] = doMF4AsMF6
    targetInfo['MF6LCTs'], targetInfo['gammas'] = [], []
    for productIndex, product in enumerate(outputChannel):
        if ((product.name == 'gamma') and not isinstance(
                outputChannel, channelsModule.twoBodyOutputChannel)
                and (MT != 527)):
            targetInfo['gammas'].append(product)
            continue
        targetInfo['productIndex'] = str(productIndex)
        targetInfo['productToken'] = product.name
        targetInfo['productLabel'] = product.label
        product.toENDF6(MT,
                        endfMFList,
                        flags,
                        targetInfo,
                        verbosityIndent=verbosityIndent + '    ')
    gammas = targetInfo['gammas']
    if (len(gammas)):
        gamma = gammas[0]
        targetInfo['zapID'] = gamma.name
        targetInfo['particleMass'] = gamma.getMass('eV/c**2')
        multiplicity = gamma.multiplicity
        if (gamma.getAttribute('ENDFconversionFlag') == 'MF6'):
            targetInfo['multiplicity'] = gamma.multiplicity
            gndToENDF6Module.gammasToENDF6_MF6(MT, endfMFList, flags,
                                               targetInfo, gammas)
        elif (gamma.getAttribute('ENDFconversionFlag') == 'MF13'):
            targetInfo['crossSection'] = self.crossSection[targetInfo['style']]
            gndToENDF6Module.gammasToENDF6_MF12_13(MT, 13, endfMFList, flags,
                                                   targetInfo, gammas)
        elif (
                isinstance(multiplicity, multiplicityModule.constant)
        ):  # This should probably be changed to unknown in some cases?????
            pass
        elif (
                isinstance(multiplicity, multiplicityModule.unknown)
        ):  # This should probably be changed to unknown in some cases?????
            pass
        else:
            gndToENDF6Module.gammasToENDF6_MF12_13(MT, 12, endfMFList, flags,
                                                   targetInfo, gammas)
    if (len(targetInfo['MF6LCTs']) > 0):
        LCT = targetInfo['MF6LCTs'][0]
        for i in targetInfo['MF6LCTs']:
            if (not (LCT is None)): break
        if (LCT is None): LCT = 2
        for i in targetInfo['MF6LCTs']:
            if (i is None): continue
            if (i != LCT): LCT = 3
        if (500 <= MT <= 572): LCT = 0
        MF6or26 = {3: 6, 23: 26}[targetInfo['crossSectionMF']]
        endfMFList[MF6or26][MT].insert(
            0,
            endfFormatsModule.endfHeadLine(targetInfo['ZA'],
                                           targetInfo['mass'], 0, LCT,
                                           len(targetInfo['MF6LCTs']), 0))
        endfMFList[MF6or26][MT].append(endfFormatsModule.endfSENDLineNumber())