Ejemplo n.º 1
0
    def __init__(self,
                 designerFile,
                 name,
                 path,
                 ZA,
                 yi,
                 halflife=None,
                 bdflsFile=None):
        """In general, this routine should be used indirectly via endlZA.read( ) or endlZA.addFile( ) and not called directly, 
        unless you know what you are doing."""

        if (bdflsFile == None): bdflsFile = bdfls.getDefaultBdfls()
        self.bdflsFile = bdflsFile
        self.designerFile = designerFile
        self.name = name
        self.path = path
        self.ZA = ZA
        self.yiTags = endlmisc.incidentParticleTags(yi)
        self.yi = self.yiTags[0]
        self.yo = int(name[2:4])
        self.C = int(name[5:7])
        self.I = int(name[8:11])
        self.S = int(name[12:15])
        self.mode = endlmisc.getmodestring_(self.I, "endlFile.__init__")
        self.halflife = halflife  # Added so uses can input for natural ZA because the halflife is not in the bdfls file.
        self.levels = []
Ejemplo n.º 2
0
def possibleReactions( projectile, target, energy_MeV, maxProducts = 4, bdflsFile = None ) :
    """This function returns a list of all reactions for the projectile with kinetic energy energy_MeV 
    hitting the stationary target that are allowed by the amount of energy_MeV available in the 
    center-of-mass and a reaction's Q.  Reactions considered will only contain products of n_1, 
    H_1, H_2, H_3, He_3, He_4 and a residual. The reactions considered are also limited to the 
    number of outgoing products, not including the residual, being no greater than maxProducts."""

    if( bdflsFile is None ) :
        import bdfls
        bdflsFile = bdfls.getDefaultBdfls( )
    import endlmisc

    projectile_ = endlmisc.incidentParticleTags( projectile )
    projectiles = [ [ 1, 0 ], [ 1001, 0 ], [ 1002, 0 ], [ 1003, 0 ], [ 2003, 0 ], [ 2004, 0 ] ]
    nProjectiles = len( projectiles )
    if( not ( 0 < projectile_[0] <= nProjectiles ) and projectile != 7 ) : raise Exception( '%s is an unsupported projectile' % projectile )
    projectileZA = yoToZA( projectile_[0] )
    incidentZA = projectileZA + target

    if projectile != 7:
        for p in projectiles :
            p[1] = bdflsFile.mass( p[0] )
            if( p[0] == projectileZA ) : projectileMass = p[1]
    else: projectileMass = 0.0
    targetMass = bdflsFile.mass( target )
    incidentMass = projectileMass + targetMass
    kineticMass = energy_MeV / bdflsFile.constant( 4 )
    if( kineticMass < 1e-6 * projectileMass ) :                         # Use non-relativity
        incidentMass += targetMass * kineticMass / incidentMass
    else :                                                              # Need relativity
        incidentMass = math.sqrt( incidentMass * incidentMass + 2. * kineticMass * targetMass )

    reactions = []

    def possibleReactions2( currentZA, products, productMass, level ) :

        if( level > maxProducts ) : return
        for ZA, mass in projectiles :
            residualZA = currentZA - ZA
            if( residualZA < ZA ) : break
            Z, A = ZandAFromZA( residualZA )
            if( A < Z ) : continue
            newProducts = products + [ ZA ]
            newProductMass = productMass + mass
            if( not( 1 < residualZA < 1001 ) ) : 
                residualMass = bdflsFile.mass( residualZA )
                if( residualMass is not None ) : 
                    if( incidentMass >= ( residualMass + newProductMass ) ) : reactions.append(  newProducts + [ residualZA ] )
            possibleReactions2( residualZA, newProducts, newProductMass, level + 1 )

    possibleReactions2( incidentZA, [], 0., 1 )
    return( reactions )
Ejemplo n.º 3
0
def reactionThreshold( yi, ZA, C, targetELevel = 0., residualELevel = 0., Q = None, specialCases = 0, S = None, bdflsFile = None ) :
    """Returns the threshold for this reaction. targetELevel is the excited state of the target
    and residualELevel is the excited state of the residual."""

    if( bdflsFile is None ) :
        import bdfls
        bdflsFile = bdfls.getDefaultBdfls( )
    QRequired = False
    if( AFromZA( ZA ) == 0 ) :        # User must enter Q
        QRequired = True
    elif( 99120 <= ZA <= 99200 ) :          # User must enter Q
        QRequired = True
    elif( C == 1 ) :
        raise Exception( 'Error from reactionThreshold: cannot calculate threshold for C = 1 reaction' )
    elif( C == 5 ) :
        raise Exception( 'Error from reactionThreshold: cannot calculate threshold for C = 5 reaction' )
    elif( C == 15 ) :                       # User must enter Q
        QRequired = True
    elif( C >= 50 ) :                  # User must enter Q
        QRequired = True
    else :
        C_ = C
        if( S == 1 ) :
            yos = endl_C.endl_C_yoInfo( C )
            if( len( yos ) > 1 ) :              # Attempt to handle breakup of residual properly (e.g., n + C12 --> n + (C12' -> 3a )).
                yo = yos[:1]
                CList = endl_C.endl_C_CList( )
                for Cp in CList :
                    if( yo == endl_C.endl_C_yoInfo( Cp ) ) :
                        C_ = Cp
                        break
        Q = reactionQ( yi, ZA, C_, specialCases = specialCases, bdflsFile = bdflsFile )
    if( QRequired and ( Q is None ) ) : raise Exception( 'Error from reactionThreshold: user must supply Q for requested ZA = %s or C = %d' % ( `ZA`, C ) )
    Threshold = -Q  - targetELevel + residualELevel
    if( Threshold < 0. ) : Threshold = 0.
    r = 1. + bdflsFile.mass( yi ) / bdflsFile.mass( ZA )
    Threshold *= r
    return( Threshold )
Ejemplo n.º 4
0
def reactionQByZAs( incomingZAs, outgoingZAs, bdflsFile = None ) :
    """Returns the Q in MeV for the reaction, that is, the (sum of incoming masses) - (sum of outgoing mass) in MeV.
    Returns None if at least one of the masses is unknown."""

    if( bdflsFile is None ) :
        import bdfls
        bdflsFile = bdfls.getDefaultBdfls( )
    ZAMultiplicities = {}
    for ZA in incomingZAs :
        if( ZA < 1000 ) : ZA = yoToZA_forNuclei( ZA )
        if( ZA not in ZAMultiplicities ) : ZAMultiplicities[ZA] = 0
        ZAMultiplicities[ZA] += 1
    for ZA in outgoingZAs :
        if( ZA < 1000 ) : ZA = yoToZA_forNuclei( ZA )
        if( ZA not in ZAMultiplicities ) : ZAMultiplicities[ZA] = 0
        ZAMultiplicities[ZA] -= 1
    mass = 0.
    ZAs = ZAMultiplicities.keys( )
    ZAs.sort( )
    for ZA in ZAs :
        m = bdflsFile.mass( ZA )
        if( m is None ) : return( None )
        mass += m * ZAMultiplicities[ZA]
    return( mass * bdflsFile.constant( 4 ) )
Ejemplo n.º 5
0
def residualZA_yos_Q( yi_, ZA_, C, targetELevel = 0., X4 = 0, specialCases = 1, printQWarning = True, bdflsFile = None ) :
    """Returns a tuple containing the residual ZA', yos and Q for reaction of type 
    C involving incident particle yi and target ZA.  yos is a list.  For example,
    the reation, ZA + yi -> ZA' + yo_1 + yo_2 + ... + yo_n + Q,
    would return ( ZA', [ yo_1, yo_2, ..., yo_n ], Q )."""

    if( bdflsFile is None ) :
        import bdfls
        bdflsFile = bdfls.getDefaultBdfls( )
    import endlmisc
    ZA, Suffix = endlmisc.intZASuffix( ZA_ )
    if( ( ( ZA % 1000 ) / 100 ) > 7 ) : ZA = ZA % 100 + 1000 * ( ZA / 1000 )
    yi = endlmisc.incidentParticleTags( yi_ )[0]
    if( ( ( yi == 3 ) and ( ZA == 1003 ) and ( C == 30 ) ) or       # Added kludge to handle t(d,g n)He reaction.
        ( ( yi == 4 ) and ( ZA == 1002 ) and ( C == 30 ) ) ) :
        yos = [ 7, 1 ]
    else :
        yos = endl_C.endl_C_yoInfo( C )
    if ( yos is None ) or ( yos == () ) : return (None, ( ), None) # No such C-value or C-value does is not a reaction (e.g., C=1).
    if ( yos[0] == -1 ) : return ( ZA, ( yi, ), None )            # yo unknown.
    if ( yos[0] == -2 ) : return ( ZA, ( yi, ), 0. )              # yo = yi.
    if ( yos[0] == -3 ) : return ( None, ( -3, ), None )          # Fission
    if ( yos[0] == -4 ) : return ( None, ( -4, yos[1] ), None )  # Xyo
    if ( ZA >= 99000 ) and ( ZA <= 99200 ) : return( None, yos, None )
    Zr, Ar = ZandAFromZA( ZA )
    Z_A = ZandAFromZA( yoToZA_forNuclei( ZAToYo( yi ) ) )             # yi's Z and A.
    Zr += Z_A[0]
    if( Ar != 0 ) : Ar += Z_A[1]
    ZAr = ZA + yoToZA_forNuclei( ZAToYo( yi ) )                   # Add yi's ZA to ZAr.
    for yo in yos :                                         # Subtract yos' Z, A and ZA from ZAr.
        if( yo in [ 7, 8, 9 ] ) : continue
        yo_ = yo
        if ( yo < 1001 ) : yo_ = yoToZA_forNuclei( yo )
        Z_A = ZandAFromZA( yo_ )
        Zr -= Z_A[0]
        if( Ar != 0 ) :
            Ar -= Z_A[1]
            ZAr -= yo_
    if( Zr < 0 ) :                                          # Check all ok.
        raise Exception( "\nError in residualZA_yos_Q: bad C-value = %d for ZA = %d and yi = %d" % ( C, ZA, yi ) )
    if( specialCases and ( ZAr == 4008 ) ) :        # Special case for Be8 ->  2 He (e.g., n + Be9  -> 2 n + (Be8 ->  2 He)).
        yos = yos + ( 2004, )
        Zr, Ar, ZAr = 2, 4, 2004
    if( Ar < 0 ) : Ar = 0
    if( Ar == 0 ) : return( 1000 * Zr, yos, None )
    Remove_yi = True
    yos_ = []
    for yo in yos :                                         # To make math better, do not add and then subtract when yo = yi.
        try :
            yo_ = ZAToYo( yo )
        except :
            yo_ = yo
        if( Remove_yi and ( yo_ == yi ) ) :
            Remove_yi = False
        else :
            if ( yo != 0 ) : yos_.append( yo )
    if ( ZAr == ZA ) :
        ZAyos = 0
        for yo in yos :
            if( yo < 1000 ) :
                ZAyos += yoToZA_forNuclei( yo )
            else :
                ZAyos += yo
        q = bdflsFile.mass( yi )
        for yo in yos : q -= bdflsFile.mass( yo )
        if ( len( yos_ ) == 0 ) or ( ZAyos == yoToZA_forNuclei( yi ) ) :
            q = ( bdflsFile.constant( 4 ) * q )
            q += targetELevel - X4
            return ( ZAr, yos, q )
        endlmisc.printWarning( "Printing yo list")
        for yo in yos_ : endlmisc.printWarning( `yo` )
        endlmisc.printWarning( "\n" )
        raise Exception( "Error in residualZA_yos_Q: ZAr == ZA, but yo list not empty" )
    q = 0.
    if( Remove_yi ) : q += bdflsFile.mass( yi )
    for yo in yos_ : q -= bdflsFile.mass( yo )
    ZAm = bdflsFile.mass( ZA )
    if ( ZAm is None ) :
        if( printQWarning ) : endlmisc.printWarning( "Warning in residualZA_yos_Q: target ZA = %d not in bdfls file (yi = %d, ZA = %d, C = %d)" % \
            ( ZA, yi, ZA, C ) )
        q = None
    else :
        m = bdflsFile.mass( ZAr )                              # Mass of residual.
        if ( m is None ) : 
            if( printQWarning ) : endlmisc.printWarning( "Warning in residualZA_yos_Q: could not calculate Q as residual ZA = %d" % ZAr + 
                " not in bdfls file (yi = %d, ZA = %d, C = %d)" % ( yi, ZA, C ) )
            q = None
        else :
            q += bdflsFile.mass( ZA ) - m
            q *= bdflsFile.constant( 4 )                       # Convert AMU to MeVs.
    if q is not None : q += targetELevel - X4
    return ( ZAr, yos, q )
Ejemplo n.º 6
0
def processTDF_Reaction(target,
                        C,
                        S=None,
                        X1=None,
                        X2=None,
                        X3=None,
                        X4=None,
                        Q=None,
                        outputFile='tdfgen.out',
                        workDir=None,
                        bdflsFile=None):

    if (bdflsFile is None): bdflsFile = bdfls.getDefaultBdfls()
    AMUToMeV = bdflsFile.constant(4)
    xsec = target.findData(C=C, I=0, S=S, X1=X1, X2=X2, X3=X3, X4=X4, Q=Q)

    residualZA, yos, Q = endl2.residualZA_yos_Q(target.yi,
                                                target.ZA,
                                                C,
                                                bdflsFile=bdflsFile)
    projectileMass = bdflsFile.mass(target.yi)
    targetMass = bdflsFile.mass(target.ZA)

    yi = endl2.ZAToYo(target.yi)
    yiZA = endl2.yoToZA(yi)
    yiZ, yiA = endl2.ZandAFromZA(yiZA)

    ZA = target.ZA
    #    ZAZA = endl2.yoToZA( ZA )
    ZAZA = ZA
    ZAZ, ZAA = endl2.ZandAFromZA(ZAZA)

    if (projectileMass > targetMass):
        reaction = '%s%d__%s%d_' % (endl_Z.endl_ZSymbol(yiZ), yiA,
                                    endl_Z.endl_ZSymbol(ZAZ), ZAA)
    else:
        reaction = '%s%d__%s%d_' % (endl_Z.endl_ZSymbol(ZAZ), ZAA,
                                    endl_Z.endl_ZSymbol(yiZ), yiA)

    outGoing = []
    print yos
    for yo in yos:
        if (yo < 1000):
            outGoing.append([endl2.yoToZA(yo)])
        else:
            outGoing.append([yo])
    outGoing.append([residualZA])

    for i in outGoing:
        iZA = i[0]
        i.insert(0, bdflsFile.mass(iZA))
        Z, A = endl2.ZandAFromZA(iZA)
        i.append(Z)
        i.append(A)
    outGoing.sort()
    s = ''
    for mass, iZA, Z, A in outGoing:
        reaction += '%s%s%d' % (s, endl_Z.endl_ZSymbol(Z), A)
        s = '__'

    outputStr = ['## Fudge generated data for tdfgen version:0.9.9']
    outputStr.append('## Data generated from:fudge')
    outputStr.append('')
    outputStr.append('## Reaction:%s' % reaction)
    outputStr.append('')
    outputStr.append('# Masses of particles in MeV.')
    outputStr.append('## Mass of projectile:%.12e' %
                     (projectileMass * AMUToMeV))
    outputStr.append('## Mass of target:%.12e' % (targetMass * AMUToMeV))

    outputStr.append('')
    outputStr.append('## Number of final particles:%d' % len(outGoing))
    for mass, iZA, Z, A in outGoing:
        outputStr.append('## %.12e' % (mass * AMUToMeV))

    outputStr.append('')
    outputStr.append('## Lab of CM frame:Lab')
    outputStr.append('## Number of data points:%d' % len(xsec))
    outputStr.append('# E(MeV)    Sigma( barn )')
    outputStr.append('#------------------------')
    outputStr.append(xsec.toString())

    outputStr = '\n'.join(outputStr)

    inputFile = fudgeFileMisc.fudgeTempFile(dir=workDir)
    inputFile.write(outputStr)

    inputName = inputFile.getName()
    print inputName
    os.system('./tdfgen -i %s -o %s' % (inputFile.getName(), outputFile))
Ejemplo n.º 7
0
    def __init__(self,
                 f,
                 I_,
                 yo,
                 C,
                 I,
                 S,
                 h,
                 points,
                 i0=0,
                 i1=1,
                 i2=None,
                 i3=None,
                 bdflsFile=None):
        """For internal use only."""

        if (I != I_):
            raise Exception("\nError in endlI%d.__init__: I = %d != %d" %
                            (I_, I, I_))
        if (bdflsFile == None): bdflsFile = bdfls.getDefaultBdfls()
        self.bdflsFile = bdflsFile
        self.columns = endlmisc.getNumberOfColumns_(I, "endlNd.__init__")
        self.yo = yo
        self.C = C
        self.I = I
        self.S = S
        self.format = 12
        if (f == None):  # Designer data.
            self.h = copy.deepcopy(h)
            data = points
            self.designerData = 1
        elif (type(f) == file
              ):  # Otherwise, data must be in an endl formatted file.
            self.h = [f.readline(), ""]
            if (self.h[0] == ""): return
            self.h[1] = f.readline()
            if (self.h[1] == ""):
                raise Exception(
                    "\nError in endlNd.__init__: end-of-file while reading from %s"
                    % f.name)
            data = readNdEndlData(f, i0, i1, i2, i3)  # File data.
            self.designerData = 0
        else:
            raise Exception(
                "\nError from endlNd.__init__: invalid type = %s for f" %
                type(f))
        if (not ((self.h[0] == "\n") and (C == 1) and (I == 0))):
            if (self.yo != int(self.h[0][9:12])):
                raise Exception(
                    "\nError in endlNd.__init__: yo in header differs from requested yo\n"
                    + ` self.h `)
            if (self.C != int(self.h[1][:2])):
                raise Exception(
                    "\nError in endlNd.__init__: C in header differs from requested C\n"
                    + ` self.h `)
            if (self.I != int(self.h[1][2:5])):
                raise Exception(
                    "\nError in endlNd.__init__: I in header differs from requested I\n"
                    + ` self.h `)
            if (self.S != int(self.h[1][5:8])):
                raise Exception(
                    "\nError in endlNd.__init__: S in header differs from requested S\n"
                    + ` self.h `)
            try:
                self.ZA = int(self.h[0][:6])
                self.yi = int(self.h[0][6:9])
                self.Mass = endlmisc.headerString2FunkyDouble(
                    self.h[0], 13, "endlNd.__init__")
                if (self.h[0][31] == ' '):
                    self.ENDLInterpolation = 0
                else:
                    self.ENDLInterpolation = int(self.h[0][31])
                self.format = int(self.h[0][32:34])
                self.ELevel = endlmisc.headerString2FunkyDouble(
                    self.h[0], 35, "endlNd.__init__")
                self.Halflife = endlmisc.headerString2FunkyDouble(
                    self.h[0], 47, "endlNd.__init__")
                self.Temperature = endlmisc.headerString2FunkyDouble(
                    self.h[0], 59, "endlNd.__init__")
                self.Q = 0.
            except:
                endlmisc.printWarning(self.h[0])
                endlmisc.printWarning(self.h[1])
                raise
            if (len(self.h[1]) >= 20):
                self.Q = endlmisc.headerString2FunkyDouble(
                    self.h[1], 9, "endlNd.__init__")
            self.X1 = 0.
            if (len(self.h[1]) >= 32):
                self.X1 = endlmisc.headerString2FunkyDouble(
                    self.h[1], 21, "endlNd.__init__")
            self.X2 = 0.
            if (len(self.h[1]) >= 44):
                self.X2 = endlmisc.headerString2FunkyDouble(
                    self.h[1], 33, "endlNd.__init__")
            self.X3 = 0.
            if (len(self.h[1]) >= 56):
                self.X3 = endlmisc.headerString2FunkyDouble(
                    self.h[1], 45, "endlNd.__init__")
            self.X4 = 0.
            if (len(self.h[1]) >= 68):
                self.X4 = endlmisc.headerString2FunkyDouble(
                    self.h[1], 57, "endlNd.__init__")
        else:
            if (not (self.designerData)):
                endlmisc.printWarning(
                    "Warning: using old style C = 1, I = 0 header file")
            self.ZA = None
            self.yi = None
            self.yo = 0
            self.C = 1
            self.I = 0
            self.S = 0
            self.Mass = None
            self.ENDLInterpolation = 0
            self.ELevel = None
            self.Halflife = None
            self.Temperature = None
            self.Q = 0.
            self.X1 = 0.
            self.X2 = 0.
            self.X3 = 0.
            self.X4 = 0.
        self.set(data,
                 checkDataType=0,
                 interpolation=endlmisc.endlToFudgeInterpolation(
                     self.ENDLInterpolation))