from dust import setup_dust if not os.path.exists("models"): os.mkdir("models") if not os.path.exists("models/indiv"): os.mkdir("models/indiv") seed = -69102 for model_name in ["sky_updarm_gaussian_hole_morepah"]: for spectral_type in spectral_types: print "Processing %s..." % spectral_type m = Model("models/indiv/energy_%s_%s" % (model_name, spectral_type.replace(" ", "_"))) seed += 1 m.set_seed(seed) m = setup_sources(m, model_name, sky_model[model_name][0], spectral_type=spectral_type) m = setup_dust(m, **sky_model[model_name][1]) m.set_n_initial_iterations(3) m.set_n_photons(initial=100000000, imaging=0) m.set_enforce_energy_range(False) m.write()
def sph_m_gen(fname,field_add): refined,dustdens,fc1,fw1,pf,ad = yt_octree_generate(fname,field_add) xmin = (fc1[:,0]-fw1[:,0]/2.).convert_to_units('cm') #in proper cm xmax = (fc1[:,0]+fw1[:,0]/2.).convert_to_units('cm') ymin = (fc1[:,1]-fw1[:,1]/2.).convert_to_units('cm') ymax = (fc1[:,1]+fw1[:,1]/2.).convert_to_units('cm') zmin = (fc1[:,2]-fw1[:,2]/2.).convert_to_units('cm') zmax = (fc1[:,2]+fw1[:,2]/2.).convert_to_units('cm') #dx,dy,dz are the edges of the parent grid dx = (np.max(xmax)-np.min(xmin)).value dy = (np.max(ymax)-np.min(ymin)).value dz = (np.max(zmax)-np.min(zmin)).value xcent = np.mean([np.min(xmin),np.max(xmax)]) #kpc ycent = np.mean([np.min(ymin),np.max(ymax)]) zcent = np.mean([np.min(zmin),np.max(zmax)]) boost = np.array([xcent,ycent,zcent]) print ('[pd_front end] boost = ',boost) #Tom Robitaille's conversion from z-first ordering (yt's default) to #x-first ordering (the script should work both ways) refined_array = np.array(refined) refined_array = np.squeeze(refined_array) order = find_order(refined_array) refined_reordered = [] dustdens_reordered = np.zeros(len(order)) for i in range(len(order)): refined_reordered.append(refined[order[i]]) dustdens_reordered[i] = dustdens[order[i]] refined = refined_reordered dustdens=dustdens_reordered #hyperion octree stats max_level = hos.hyperion_octree_stats(refined) pto.test_octree(refined,max_level) dump_cell_info(refined,fc1,fw1,xmin,xmax,ymin,ymax,zmin,zmax) np.save('refined.npy',refined) np.save('density.npy',dustdens) #======================================================================== #Initialize Hyperion Model #======================================================================== m = Model() if cfg.par.FORCE_RANDOM_SEED == True: m.set_seed(cfg.par.seed) print ('Setting Octree Grid with Parameters: ') #m.set_octree_grid(xcent,ycent,zcent, # dx,dy,dz,refined) m.set_octree_grid(0,0,0,dx/2,dy/2,dz/2,refined) #get CMB: energy_density_absorbed=energy_density_absorbed_by_CMB() specific_energy = np.repeat(energy_density_absorbed.value,dustdens.shape) if cfg.par.PAH == True: # load PAH fractions for usg, vsg, and big (grain sizes) frac = cfg.par.PAH_frac # Normalize to 1 total = np.sum(list(frac.values())) frac = {k: v / total for k, v in frac.items()} for size in frac.keys(): d = SphericalDust(cfg.par.dustdir+'%s.hdf5'%size) if cfg.par.SUBLIMATION == True: d.set_sublimation_temperature('fast',temperature=cfg.par.SUBLIMATION_TEMPERATURE) #m.add_density_grid(dustdens * frac[size], cfg.par.dustdir+'%s.hdf5' % size) m.add_density_grid(dustdens*frac[size],d,specific_energy=specific_energy) m.set_enforce_energy_range(cfg.par.enforce_energy_range) else: d = SphericalDust(cfg.par.dustdir+cfg.par.dustfile) if cfg.par.SUBLIMATION == True: d.set_sublimation_temperature('fast',temperature=cfg.par.SUBLIMATION_TEMPERATURE) m.add_density_grid(dustdens,d,specific_energy=specific_energy) #m.add_density_grid(dustdens,cfg.par.dustdir+cfg.par.dustfile) m.set_specific_energy_type('additional') return m,xcent,ycent,zcent,dx,dy,dz,pf,boost
def arepo_m_gen(fname, field_add): reg, ds, dustdens = arepo_vornoi_grid_generate(fname, field_add) xcent = ds.quan(cfg.model.x_cent, 'code_length').to('cm') #proper cm ycent = ds.quan(cfg.model.y_cent, 'code_length').to('cm') zcent = ds.quan(cfg.model.z_cent, 'code_length').to('cm') boost = np.array([xcent, ycent, zcent]) print('[arepo_tributary/vornoi_m_gen]: boost = ', boost) #======================================================================== #Initialize Hyperion Model #======================================================================== m = Model() if cfg.par.FORCE_RANDOM_SEED == True: m.set_seed(cfg.par.seed) #because we boost the stars to a [0,0,0] coordinate center, we #want to make sure our vornoi tesslation is created in the same manner. particle_x = reg["gascoordinates"][:, 0].to('cm') particle_y = reg["gascoordinates"][:, 1].to('cm') particle_z = reg["gascoordinates"][:, 2].to('cm') #just for the sake of symmetry, pass on a dx,dy,dz since it can be #used optionally downstream in other functions. dx = 2. * ds.quan(cfg.par.zoom_box_len, 'kpc').to('cm') dy = 2. * ds.quan(cfg.par.zoom_box_len, 'kpc').to('cm') dz = 2. * ds.quan(cfg.par.zoom_box_len, 'kpc').to('cm') print('[arepo_tributary] boost = ', boost) print('[arepo_tributary] xmin (pc)= ', (xcent - dx / 2.).to('pc')) print('[arepo_tributary] xmax (pc)= ', (xcent + dx / 2.).to('pc')) print('[arepo_tributary] ymin (pc)= ', (ycent - dy / 2.).to('pc')) print('[arepo_tributary] ymax (pc)= ', (ycent + dy / 2.).to('pc')) print('[arepo_tributary] zmin (pc)= ', (zcent - dz / 2.).to('pc')) print('[arepo_tributary] zmax (pc)= ', (zcent + dz / 2.).to('pc')) x_pos_boost = (particle_x - xcent).to('cm') y_pos_boost = (particle_y - ycent).to('cm') z_pos_boost = (particle_z - zcent).to('cm') m.set_voronoi_grid(x_pos_boost.value, y_pos_boost.value, z_pos_boost.value) #get CMB: energy_density_absorbed = energy_density_absorbed_by_CMB() specific_energy = np.repeat(energy_density_absorbed.value, dustdens.shape) if cfg.par.PAH == True: # load PAH fractions for usg, vsg, and big (grain sizes) frac = cfg.par.PAH_frac # Normalize to 1 total = np.sum(list(frac.values())) frac = {k: v / total for k, v in frac.items()} for size in frac.keys(): d = SphericalDust(cfg.par.dustdir + '%s.hdf5' % size) if cfg.par.SUBLIMATION == True: d.set_sublimation_temperature( 'fast', temperature=cfg.par.SUBLIMATION_TEMPERATURE) #m.add_density_grid(dustdens * frac[size], cfg.par.dustdir+'%s.hdf5' % size) m.add_density_grid(dustdens * frac[size], d, specific_energy=specific_energy) m.set_enforce_energy_range(cfg.par.enforce_energy_range) else: d = SphericalDust(cfg.par.dustdir + cfg.par.dustfile) if cfg.par.SUBLIMATION == True: d.set_sublimation_temperature( 'fast', temperature=cfg.par.SUBLIMATION_TEMPERATURE) m.add_density_grid(dustdens, d, specific_energy=specific_energy) #m.add_density_grid(dustdens,cfg.par.dustdir+cfg.par.dustfile) m.set_specific_energy_type('additional') return m, xcent, ycent, zcent, dx.value, dy.value, dz.value, reg, ds, boost