示例#1
0
def BH_source_add(m,reg,df_nu,boost):

    print("--------------------------------\n")
    print("Adding Black Holes to Source List in source_creation\n")
    print("--------------------------------\n")
 
    try:
        nholes = reg["bh","sed"].shape[0]

    except: 
        print('BH source creation failed. No BH found')
        nholes = 0


    if nholes == 0:
        print('BH source creation failed. No BH found')
    
    else:
        #temporary wavelength compress just to get the length of the
        #compressed nu for a master array
        dumnu,dumfnu = wavelength_compress(reg["bh","nu"].value,reg["bh","sed"][0,:].value,df_nu)
        master_bh_fnu = np.zeros([nholes,len(dumnu)])
         
        width = reg.right_edge-reg.left_edge

        agn_ids = []

        for i in range(nholes):  
            #since the BH was added in a front end, we don't know
            #if the hole is in the actual cut out region of the yt
            #dataset.  so we need to filter out any holes that
            #might not be in the simulation domain or have no luminosity.

            if ((reg["bh","coordinates"][i,0].in_units('kpc') <  (reg.center[0].in_units('kpc')+(0.5*width[0].in_units('kpc'))))
            and
            (reg["bh","coordinates"][i,0].in_units('kpc') >  (reg.center[0].in_units('kpc')-(0.5*width[0].in_units('kpc'))))
            and
            (reg["bh","coordinates"][i,1].in_units('kpc') <  (reg.center[1].in_units('kpc')+(0.5*width[1].in_units('kpc'))))
            and
            (reg["bh","coordinates"][i,1].in_units('kpc') >  (reg.center[1].in_units('kpc')-(0.5*width[1].in_units('kpc'))))
            and
            (reg["bh","coordinates"][i,2].in_units('kpc') <  (reg.center[2].in_units('kpc')+(0.5*width[2].in_units('kpc'))))
            and
            (reg["bh","coordinates"][i,2].in_units('kpc') >  (reg.center[2].in_units('kpc')-(0.5*width[2].in_units('kpc'))))
            and 
            (reg["bh","luminosity"][i].value > 0)):

                agn_ids.append(i)


        print ('Number AGNs in the cutout with non zero luminositites: ', len(agn_ids))

        fnu_arr = sg.get_agn_seds(agn_ids, reg)
        nu = reg["bh","nu"].value

        for j in range(len(agn_ids)):
                i = agn_ids[j]
                fnu = fnu_arr[j,:]
                nu, fnu = wavelength_compress(nu,fnu,df_nu)

                master_bh_fnu[i,:] = fnu

                print('Boosting BH Coordinates and adding BH #%d to the source list now'%i)
                #the tolist gets rid of the array brackets
                bh = m.add_point_source(luminosity = reg["bh","luminosity"][i].value.tolist(), 
                                        spectrum = (nu,fnu),
                                        position = (reg["bh","coordinates"][i,:].in_units('cm').value-boost).tolist())

        dump_AGN_SEDs(nu,master_bh_fnu,reg["bh","luminosity"].value)
示例#2
0
def BH_source_add(m, reg, df_nu, boost):

    print("--------------------------------\n")
    print("Adding Black Holes to Source List in source_creation\n")
    print("--------------------------------\n")

    try:
        nholes = reg["bhsed"].shape[0]

        #temporary wavelength compress just to get the length of the
        #compressed nu for a master array
        dumnu, dumfnu = wavelength_compress(reg["bhnu"].value,
                                            reg["bhsed"][0, :].value, df_nu)
        master_bh_fnu = np.zeros([nholes, len(dumnu)])

        holecounter = 0
        for i in range(nholes):

            #don't create a BH luminsoity source if there's no luminosity since the SED will be nans/infs
            if reg["bhluminosity"][i].value > 0:

                nu = reg["bhnu"].value
                fnu = reg["bhsed"][i, :].value  #.tolist()
                nu, fnu = wavelength_compress(nu, fnu, df_nu)

                master_bh_fnu[i, :] = fnu

                if holecounter == 0:
                    fnu_compressed = np.zeros([nholes, len(nu)])
                fnu_compressed[i, :] = fnu

                #since the BH was added in a front end, we don't know
                #if the hole is in the actual cut out region of the yt
                #dataset.  so we need to filter out any holes that
                #might not be in the simulation domain.

                if ((reg["bhcoordinates"][i, 0].in_units('kpc') <
                     (reg.domain_center[0].in_units('kpc') +
                      (0.5 * reg.domain_width[0].in_units('kpc'))))
                        and (reg["bhcoordinates"][i, 0].in_units('kpc') >
                             (reg.domain_center[0].in_units('kpc') -
                              (0.5 * reg.domain_width[0].in_units('kpc'))))
                        and (reg["bhcoordinates"][i, 1].in_units('kpc') <
                             (reg.domain_center[1].in_units('kpc') +
                              (0.5 * reg.domain_width[1].in_units('kpc'))))
                        and (reg["bhcoordinates"][i, 1].in_units('kpc') >
                             (reg.domain_center[1].in_units('kpc') -
                              (0.5 * reg.domain_width[1].in_units('kpc'))))
                        and (reg["bhcoordinates"][i, 2].in_units('kpc') <
                             (reg.domain_center[2].in_units('kpc') +
                              (0.5 * reg.domain_width[2].in_units('kpc'))))
                        and (reg["bhcoordinates"][i, 2].in_units('kpc') >
                             (reg.domain_center[2].in_units('kpc') -
                              (0.5 * reg.domain_width[2].in_units('kpc'))))):

                    print(
                        'Boosting BH Coordinates and adding BH #%d to the source list now'
                        % i)
                    #the tolist gets rid of the array brackets
                    bh = m.add_point_source(
                        luminosity=reg["bhluminosity"][i].value.tolist(),
                        spectrum=(nu, fnu),
                        position=(
                            reg["bhcoordinates"][i, :].in_units('cm').value -
                            boost).tolist())
                else:
                    print(
                        'black hole #%d is not in the domain: rejecting adding it to the source list'
                        % i)

                holecounter += 1

        dump_AGN_SEDs(nu, master_bh_fnu, reg["bhluminosity"].value)
    except:
        print('BH source creation failed.')