MStar = 34 * u.MSun r_max = 2530 * u.au #H II sphere size r_min = r_max / 200 #Minimum distance (!= 0 to avoid indeterminations) r_s = r_max #Normalization distance rho_s = 1.4e5 * 1e6 #from cgs to SI. Density at r_s q = 1.3 #Density powerlaw t_e = 1.e4 #K #--------------- #GRID Definition #--------------- sizex = sizey = sizez = 2600 * u.au Nx = Ny = Nz = 63 #Number of divisions for each axis GRID = Model.grid([sizex, sizey, sizez], [Nx, Ny, Nz], rt_code='radmc3d') NPoints = GRID.NPoints #Final number of nodes in the grid #------------------- #PHYSICAL PROPERTIES #------------------- density = Model.density_Powerlaw_HII(r_min, r_max, r_s, rho_s, q, GRID) temperature = Model.temperature_Constant(density, GRID, envTemp=t_e, backTemp=2.725) Model.PrintProperties(density, temperature, GRID) #------- #TIMING
dx_grid = 40*u.au #rho = lambda R: dens0 #T = lambda R: 10000. T0 = 10000. qT = 0. temp = [T0, qT] dens0 = 0.14*2.6e13 qn = -0.15 #-0.4 dens = [dens0, qn] a = 2.05*np.sqrt(300*u.au) b = 2.05*np.sqrt(300*u.au) GRID, props = make_paraboloid(z_min, z_max, dx_grid, a, b, dens, T0, width = 20*u.au) shift = Model.ChangeGeometry(GRID, center = np.array([dx+20, dy-20, 0])*u.au, rot_dict = { 'angles': [-np.pi/2, 1*np.pi/180*(posang+90 + 8), -np.pi/12], 'axis': ['y','z','y'] }) GRID.XYZ = shift.newXYZ prop_dict = {'dens_e': props[0], 'dens_ion': props[0], 'temp_gas': props[1]} shell = rt.Radmc3d(GRID) shell.submodel(prop_dict, output=tag) print ('Columns written into file:', shell.columns)
rho_s = 1.0e6 * 1e6 / 5 #from cgs to SI. Density at sonic radius q = 1.3 #Density powerlaw t_e = 1.e4 #K #------------------------------- #Parameters for the Pringle disc #------------------------------- MRate = 3e-4 * u.MSun_yr RStar = u.RSun * ( MStar/u.MSun )**0.8 #--------------- #GRID Definition #--------------- sizex = sizey = sizez = 2600 * u.au Nx = Ny = Nz = 63 #Number of divisions for each axis GRID = Model.grid([sizex, sizey, sizez], [Nx, Ny, Nz], rt_code = 'radmc3d') NPoints = GRID.NPoints #Final number of nodes in the grid #------------------- #PHYSICAL PROPERTIES #------------------- #-------- #ENVELOPE #-------- densEnv = Model.density_Keto_HII(MStar, r_min, r_max, rho_s, t_e, GRID, q = 1.5) #------- #DISC #------- Rd = 10*densEnv.rs #10 times the sonic radius, just to make it visible Rho0 = Res.Rho0(MRate, Rd, MStar)
import time t0 = time.time() #-------------------- #************** #GRID AND MODEL #************** r_max = 0.1 * u.pc #H II sphere size r_min = 0.02 * u.pc rho0 = 28 * 1e6 * u.pc**2 q = -2 sizex = sizey = sizez = 1.2 * r_max Nx = Ny = Nz = 100 #Number of divisions along each axis GRID = Model.grid([sizex, sizey, sizez], [Nx, Ny, Nz], rt_code='radmc3d') NPoints = GRID.NPoints #Number of nodes in the grid density = Model.density_Powerlaw2(r_max, r_min, rho0, q, GRID, rho_min=1.) temperature = Model.temperature_Constant(density, GRID, envTemp=10000., backTemp=2.725) vel = Model.velocity_random(15000, GRID.NPoints) #******************** #WRITING FOR RADMC-3D #******************** prop = { 'vel_x': vel.x, 'vel_y': vel.y,
MStar / u.MSun )**0.8 #Multiply by 10 Main Sequence relationship to account for bloated protostar LStar = 9 * u.LSun #u.LSun * ( MStar/u.MSun )**4 # 9Lsun from Li+2017 TStar = u.TSun * ((LStar / u.LSun) / (RStar / u.RSun)**2)**0.25 Rd = 68. * u.au print('RStar:', RStar / u.RSun, ', LStar:', LStar / u.LSun, ', TStar:', TStar) #--------------- #GRID Definition #--------------- #Cubic grid, each edge ranges [-100, 100] au. sizex = sizey = sizez = 100 * u.au Nx = Ny = Nz = 200 #Number of divisions for each axis GRID = Model.grid([sizex, sizey, sizez], [Nx, Ny, Nz]) NPoints = GRID.NPoints #Number of nodes in the grid #------------- #DENSITY #------------- #------- #DISC #------- if args.Arho: Arho = float(args.Arho) else: Arho = 150.0 # (Mdisk=0.106*1.4=Msun=0.149Msun) H0sf = 0.04 #Disc scale-height factor (H0 = H0sf * RStar) Rdisc = 1.0 * Rd Rho0 = Res.Rho0(MRate, Rd, MStar) #Normalization density
RStar = 26 * u.RSun * (MStar / u.MSun)**0.27 * (MRate / (1e-3 * u.MSun_yr))**0.41 LStar = 3.2e4 * u.LSun TStar = u.TSun * ((LStar / u.LSun) / (RStar / u.RSun)**2)**0.25 Rd = 152. * u.au print('RStar:', RStar / u.RSun, ', LStar:', LStar / u.LSun, ', TStar:', TStar) #--------------- #GRID Definition #--------------- #Cubic grid, each edge ranges [-500, 500] au. sizex = sizey = sizez = 500 * u.au Nx = Ny = Nz = 200 #Number of divisions for each axis GRID = Model.grid([sizex, sizey, sizez], [Nx, Ny, Nz]) NPoints = GRID.NPoints #Number of nodes in the grid #-------- #DENSITY #-------- Rho0 = Res.Rho0(MRate, Rd, MStar) Arho = 24.1 #Disc-envelope density factor Renv = 500 * u.au #Envelope radius Cavity = 40 * np.pi / 180 #Cavity opening angle density = Model.density_Env_Disc(RStar, Rd, Rho0, Arho, GRID, discFlag=True,
rho0 = 1e8 * 1e6 #[part/m3] Number density at r_min r_rho = [r_min, 200 * u.au, 300 * u.au, r_max] #r frontiers for density q_rho = [-2.0, -1.5, -2.5] #Powerlaws for density T0 = 1000. #[K] Temperature at r_min r_T = [r_min, 250 * u.au, r_max] #r frontiers for temperature q_T = [-0.5, -1.0] #Powerlaws for temperature #--------------- #GRID Definition #--------------- sizex = sizey = sizez = r_max Nx = Ny = Nz = 95 #Number of divisions for each axis GRID = Model.grid([sizex, sizey, sizez], [Nx, Ny, Nz], rt_code='lime') NPoints = GRID.NPoints #Final number of nodes in the grid #------------------- #PHYSICAL PROPERTIES #------------------- density = Model.density_PowerlawShells(r_rho, q_rho, rho0, GRID, rho_min=1.0e4) temperature = Model.temperature_PowerlawShells(r_T, q_T, T0, GRID, T_min=25.) #-------- #VELOCITY #-------- vel = Model.velocity_random(1800, GRID.NPoints) #------------------------------- #ABUNDANCE and GAS-to-DUST RATIO
RStar = 26 * u.RSun * (MStar / u.MSun)**0.27 * (MRate / (1e-3 * u.MSun_yr))**0.41 LStar = 3.2e4 * u.LSun TStar = u.TSun * ((LStar / u.LSun) / (RStar / u.RSun)**2)**0.25 Rd = 152. * u.au print('RStar:', RStar / u.RSun, ', LStar:', LStar / u.LSun, ', TStar:', TStar) #--------------- #GRID Definition #--------------- #Cubic grid, each edge ranges [-500, 500] au. sizex = sizey = sizez = 500 * u.au Nx = Ny = Nz = 100 #Number of divisions for each axis GRID = Model.grid([sizex, sizey, sizez], [Nx, Ny, Nz]) NPoints = GRID.NPoints #Number of nodes in the grid #-------- #DENSITY #-------- Rho0 = Res.Rho0(MRate, Rd, MStar) Arho = 24.1 #Disc-envelope density factor Renv = 500 * u.au #Envelope radius Cavity = 40 * np.pi / 180 #Cavity opening angle density = Model.density_Env_Disc(RStar, Rd, Rho0, Arho, GRID, discFlag=True,
MRate = 5.e-6 * u.MSun_yr RStar = u.RSun * (MStar / u.MSun)**0.8 LStar = u.LSun * (MStar / u.MSun)**4 TStar = u.TSun * ((LStar / u.LSun) / (RStar / u.RSun)**2)**0.25 Rd = 264. * u.au print('RStar:', RStar / u.RSun, ', LStar:', LStar / u.LSun, ', TStar:', TStar) #--------------- #GRID Definition #--------------- #Cubic grid, each edge ranges [-500, 500] au. sizex = sizey = sizez = 500 * u.au Nx = Ny = Nz = 200 #Number of divisions for each axis GRID = Model.grid([sizex, sizey, sizez], [Nx, Ny, Nz]) NPoints = GRID.NPoints #Number of nodes in the grid #------------- #DENSITY #------------- #-------- #ENVELOPE #-------- Rho0 = Res.Rho0(MRate, Rd, MStar) Arho = None Renv = 2.5 * Rd densEnv = Model.density_Env_Disc(RStar, Rd, Rho0,
RStar = None #26 * U.RSun * ( MStar/U.MSun )**0.27 * ( MRate / (1e-3*U.MSun_yr) )**0.41 LStar = None #8.6e4 * U.LSun # 4 TStar = None #U.TSun * ( (LStar/U.LSun) / (RStar/U.RSun)**2 )**0.25 BT = None Rd = None #centrifugal radius Tmin_disc = None #--------------- #GRID Definition #--------------- sizex = sizey = sizez = r_max Nx = Ny = Nz = 128 #Number of divisions for each axis GRID = Model.grid([sizex, sizey, sizez], [Nx, Ny, Nz], rt_code='lime') NPoints = GRID.NPoints #Final number of nodes in the grid #------------------- #PHYSICAL PROPERTIES #------------------- density = Model.density_Powerlaw(r_max, rho_mean, q, GRID, rho_min=1.0e4) temperature = Model.temperature(TStar, Rd, T10Env, RStar, MStar, MRate, BT, density,
MRate = 5.e-6 * u.MSun_yr RStar = u.RSun * (MStar / u.MSun)**0.8 LStar = u.LSun * (MStar / u.MSun)**4 TStar = u.TSun * ((LStar / u.LSun) / (RStar / u.RSun)**2)**0.25 Rd = 264. * u.au print('RStar:', RStar / u.RSun, ', LStar:', LStar / u.LSun, ', TStar:', TStar) #--------------- #GRID Definition #--------------- #Cubic grid, each edge ranges [-500, 500] au. sizex = sizey = sizez = 500 * u.au Nx = Ny = Nz = 100 #Number of divisions for each axis GRID = Model.grid([sizex, sizey, sizez], [Nx, Ny, Nz]) NPoints = GRID.NPoints #Number of nodes in the grid #------------- #DENSITY #------------- #-------- #ENVELOPE #-------- Rho0 = Res.Rho0(MRate, Rd, MStar) Arho = None Renv = 2.5 * Rd densEnv = Model.density_Env_Disc(RStar, Rd, Rho0,
#******************** import numpy as np import time import matplotlib.pyplot as plt import matplotlib.cm as cm import matplotlib.colors as colors t0 = time.time() #******** #GRIDDING #******** sizex = 100 * u.au sizey = sizez = 100 * u.au Nx = Ny = Nz = 100 GRID = Model.grid([sizex, sizey, sizez], [Nx, Ny, Nz], rt_code='lime') #******** #MERGING #******** files = ['disc.dat', 'outflow.dat'] #Old style #outflows = BGG.overlap(GRID, submodels = data2merge, rho_min = 1e6) #New style columns = [ 'id', 'x', 'y', 'z', 'dens_H2', 'dens_Hplus', 'temp_gas', 'vel_x', 'vel_y', 'vel_z', 'abundance', 'gtdratio' ] overlap = Overlap(GRID) finalprop = overlap.fromfiles(columns, submodels=files, rt_code='lime')
rho0 = 5e8 * 1e6 #[part/m3] Number density at r_min r_rho = [r_min, r_stellar, r_max] #r frontiers for density q_rho = [-1.5, -1.7] #Powerlaws for density T0 = 1000. #[K] Temperature at r_min r_T = [r_min, r_stellar, r_max] #r frontiers for temperature q_T = [-0.5, -1.0] #Powerlaws for temperature #--------------- #GRID Definition #--------------- sizex = sizey = sizez = r_max Nx = Ny = Nz = 95 #Number of divisions for each axis GRID = Model.grid([sizex, sizey, sizez], [Nx, Ny, Nz], rt_code='lime') NPoints = GRID.NPoints #Final number of nodes in the grid #------------------- #PHYSICAL PROPERTIES #------------------- density = Model.density_PowerlawShells(r_rho, q_rho, rho0, GRID, rho_min=1.0e4) temperature = Model.temperature_PowerlawShells(r_T, q_T, T0, GRID, T_min=25.) #-------- #VELOCITY #-------- dens_dict = {'dens_H': density.total} ff_factor = 1. vel = Model.velocity_infall(dens_dict, ff_factor, MStar, r_stellar, GRID)
from sf3dmodels.grid import Overlap #Overlap submodels #******************** #Extra libraries #******************** import numpy as np import time t0 = time.time() #******** #GRIDDING #******** sizex = 500 * u.au sizey = sizez = 500 * u.au Nx = Ny = Nz = 150 GRID = Model.grid([sizex, sizey, sizez], [Nx, Ny, Nz], rt_code='radmc3d') #******** #MERGING #******** files = ['datatab_outflow1.dat', 'datatab_outflow2.dat'] #Old style #outflows = BGG.overlap(GRID, submodels = data2merge, rho_min = 1e6) #New style columns = ['id', 'x', 'y', 'z', 'dens_e', 'dens_ion', 'temp_gas'] outflows = Overlap(GRID) finalprop = outflows.fromfiles(columns, submodels = files, rt_code = 'radmc3d') radmc = rt.Radmc3dDefaults(GRID) radmc.freefree(finalprop)
#------------------ from sf3dmodels import Model, Plot_model as Pm import sf3dmodels.utils.units as u import sf3dmodels.rt as rt from sf3dmodels.grid import Overlap #----------------- #Extra libraries #----------------- import numpy as np #******** #GRIDDING #******** sizex = sizey = sizez = 1000 * u.au Nx = Ny = Nz = 200 GRID = Model.grid([sizex, sizey, sizez], [Nx, Ny, Nz]) #********** #OVERLAPING #********** columns = ['id', 'x', 'y', 'z', 'dens_H2', 'temp_gas', 'vel_x', 'vel_y', 'vel_z', 'abundance_0', 'gtdratio'] data2merge = ['Main.dat', 'Burger.dat'] overlap = Overlap(GRID) finalprop = overlap.fromfiles(columns, submodels = data2merge) #********** #WRITING #********** lime = rt.Lime(GRID) lime.finalmodel(finalprop)
import matplotlib.pyplot as plt import time #------------------ #General Parameters #------------------ r_max = 2530 * u.au #H II sphere size dens_e = 1.4e5 * 1e6 #Electron number density, from cgs to SI t_e = 1.e4 #K #--------------- #GRID Definition #--------------- sizex = sizey = sizez = 2600 * u.au Nx = Ny = Nz = 63 #Number of divisions for each axis GRID = Model.grid([sizex, sizey, sizez], [Nx, Ny, Nz], rt_code='radmc3d') NPoints = GRID.NPoints #Final number of nodes in the grid #------------------- #PHYSICAL PROPERTIES #------------------- density = Model.density_Constant(r_max, GRID, envDens = dens_e) temperature = Model.temperature_Constant(density, GRID, envTemp = t_e, backTemp = 2.725) Model.PrintProperties(density, temperature, GRID) #Printing resultant properties (mass, mean temperature, etc) #---------------------- #WRITING RADMC-3D FILES #---------------------- prop = {'dens_e': density.total, 'dens_ion': density.total,
def do_overlap(): #****************************** #PATH AND TAG #****************************** cwd = os.getcwd() cloud_kind = cwd.split('Lime-arepo/')[-1].split('-Lime') cloud_kind = cloud_kind[0] + cloud_kind[1] home = os.environ['HOME'] base = home + '/Downloads/Manchester_2018/Rowan-data/Andres/data/datasets/' base += cloud_kind base_content = os.popen('ls ' + base).readlines() snapshot = '' for file in base_content: if 'Restest' in file: snapshot = '/' + file.split('\n')[0] #****************************** #AREPO 3D-grids (not projected) #****************************** rsnap.io_flags['mc_tracer'] = True rsnap.io_flags['time_steps'] = True rsnap.io_flags['sgchem'] = True rsnap.io_flags['variable_metallicity'] = False #rsnap.io_flags['MHD']=True #There is no magnetic field information #****************************** #READING SNAPSHOT #****************************** f = base + snapshot data, header = rsnap.read_snapshot(f) nparts = header['num_particles'] ngas = nparts[0] nsinks = nparts[5] for key in data: print(key, np.shape(data[key])) #**************************** #GLOBAL GRID #**************************** pos_max = np.max(data['pos'], axis=0) pos_min = np.min(data['pos'], axis=0) pos_mean = 0.5 * (pos_max + pos_min) * ulength / 100. sizex = sizey = sizez = 0.5 * np.max(pos_max - pos_min) * ulength / 100. #print (sizex, sizey, sizez) Nx = Ny = Nz = 200 GRID = Model.grid([sizex, sizey, sizez], [Nx, Ny, Nz], include_zero=False) #, rt_code='radmc3d') columns = [ 'id', 'x', 'y', 'z', 'dens_H2', 'dens_H', 'dens_Hplus', 'temp_gas', 'temp_dust', 'vel_x', 'vel_y', 'vel_z', 'abundance', 'gtdratio', 'doppler' ] """ overlap = grid.Overlap(GRID) overlap.min_values['dens_H2'] = 0.0 newprop = overlap.fromfiles(columns, submodels=['datatab.dat']) """ props2use = ['dens_H', 'dens_H2', 'abundance', 'dens_Hplus'] newprop = {} datatab = np.loadtxt('./Subgrids/datatab.dat') #[:-30000] header_tab = np.loadtxt('./Subgrids/header.dat') coords = np.array(GRID.XYZ).T data_prop = {} Lime = rt.Lime(GRID) for prop in props2use: column, = np.where(Lime.sf3d_header[prop] == header_tab) data_prop[prop] = datatab[:, column] subgrid = Model.Struct(XYZ=[datatab[:, i] for i in range(1, 4)], NPoints=len(datatab)) fill = grid.fillgrid.Random(subgrid) fill_rand = fill.spherical( data_prop, #prop_fill = {'dens_H2': 1.0}, r_min=10 * pc, r_max=np.max(subgrid.XYZ) * np.sqrt(3), n_dummy=subgrid.NPoints / 3) coords_sub = np.array(subgrid.XYZ).T for prop in props2use: print('Merging %s ...' % prop) ind_nodummie = data_prop[prop] > 2 * data_prop[prop][-1] min_val = data_prop[prop][ind_nodummie].min() newprop[prop] = griddata(coords_sub, data_prop[prop], coords, fill_value=0.0) #, method='nearest') newprop[prop][ newprop[prop] < min_val] = min_val #very low value, just to get rid of zeroes #newprop[prop][np.isnan(newprop[prop])] = datatab[:,column].min() #newprop[prop][np.isnan(newprop[prop])].min() sink_pos = data['pos'][ngas:] * ulength / 100 - pos_mean dummy_pos.append(coords_sub[-int(subgrid.NPoints / 2):]) return GRID, sizex, newprop, sink_pos, nsinks
offset = n_neighbours * np.dtype(struct_dtypes['i']).itemsize if n % 1000 == 0: progress(int(100 * n / npoints)) progress(100) sys.stdout.write('\n') data['xyz'] = np.array(data['xyz']) data['props'] = np.array(data['props']) return prop_tags, npoints, data t0 = time.time() filename = "grid_temp.dat" prop_tags, npoints, data = read_temp(filename) grid = Model.Struct(XYZ=data['xyz'].T, NPoints=npoints) prop = { 'dens_H2': data['props'][:, 0], 'temp_dust': data['props'][:, 1], 'temp_gas': data['props'][:, 2], } lime = rt.Lime(grid) lime.submodel(prop, output='datatab.dat', folder='./', lime_npoints=True, lime_header=True) print('Output columns', lime.columns) print('Ellapsed time:', time.time() - t0)
r_min = r_max / 256 #Minimum distance to the centre (!= 0 to avoid indeterminations) rho0 = 1e8 * 1e6 #[part/m3] Number density at r_min r_rho = [r_min, 200 * u.au, 300 * u.au, r_max] #r frontiers for density q_rho = [-2.0, -1.5, -2.5] #Powerlaws for density T0 = 1000. #[K] Temperature at r_min r_T = [r_min, 250 * u.au, r_max] #r frontiers for temperature q_T = [-0.5, -1.0] #Powerlaws for temperature #--------------- #GRID Definition #--------------- sizex = sizey = sizez = r_max Nx = Ny = Nz = 95 #Number of divisions for each axis GRID = Model.grid([sizex, sizey, sizez], [Nx, Ny, Nz], rt_code='radmc3d') NPoints = GRID.NPoints #Final number of nodes in the grid #------------------- #PHYSICAL PROPERTIES #------------------- density = Model.density_PowerlawShells(r_rho, q_rho, rho0, GRID, rho_min=1.0e4) temperature = Model.temperature_PowerlawShells(r_T, q_T, T0, GRID, T_min=25.) gtd0 = 100. #Gas to dust ratio gtdratio = Model.gastodust(gtd0, NPoints) #-------------------- #PRINTING and WRITING #-------------------- prop = {
ngas = len(data_gas) if nfrac and nfrac < ngas: ids_rand = np.random.choice(np.arange(0, ngas), size=nfrac, replace=False) data_gas = data_gas[ids_rand] print(data_gas.shape) data_gas[:, 0:3] *= u.au #a0 data_r = np.linalg.norm(data_gas[:, 0:3], axis=1) data_gas = data_gas[data_r <= 100 * u.au] data_gas[:, 5] *= 5.941031250291510E-07 * 1e3 / (2 * ct.mH) #0.05*Ms/a0**3/ct.mH #data_gas[:,5] = np.where(data_gas[:,5]<1.0, 1.0, data_gas[:,5]) data_gas[:, 6:9] *= 2.978460638675013E+06 * 0.01 #a0/P grid = Model.Struct(XYZ=data_gas[:, 0:3].T, NPoints=len(data_gas)) prop = { 'dens_H2': data_gas[:, 5], 'vel_x': data_gas[:, 6], 'vel_y': data_gas[:, 7], 'vel_z': data_gas[:, 8] } """ unique_cells = UniqueCells(prop,None) id_pos = unique_cells.getuniques(grid).astype(np.int) grid.XYZ = grid.XYZ.T[id_pos].T grid.NPoints = len(id_pos) for key in prop: prop[key] = prop[key][id_pos] """ fill = fillgrid.Random(grid)
#------------------ from sf3dmodels import Model, Plot_model as Pm import sf3dmodels.utils.units as u import sf3dmodels.rt as rt from sf3dmodels.grid import Overlap #----------------- #Extra libraries #----------------- import numpy as np #******** #GRIDDING #******** sizex = sizey = sizez = 0.3 * u.pc Nx = Ny = Nz = 145 GRID = Model.grid([sizex, sizey, sizez], [Nx, Ny, Nz], include_zero=False) #********** #OVERLAPING #********** columns = [ 'id', 'x', 'y', 'z', 'dens_H', 'temp_gas', 'vel_x', 'vel_y', 'vel_z', 'abundance', 'gtdratio' ] data2merge = ['filament.dat', 'envelope.dat'] overlap = Overlap(GRID) finalprop = overlap.fromfiles(columns, submodels=data2merge) #********** #WRITING #**********