def build_models(Mcore, rho_core, L_M_whittle, L_M_start, L_M_end, NL, Teq, Xstart, Xend, Nenv, planet_dir, Xbondi, istart=0, jstart=1): # this function builds many models with envolope mass fractions and luminosities #create initial population import os import numpy as np import math import mesa as ms import shutil import planet_prop as pp curr_dir = os.getcwd() cs = (1.38e-16 * Teq / (2.35 * 1.67e-24))**0.5 if istart == 0 and jstart == 1: build_starting_models(Mcore, rho_core, L_M_whittle, L_M_start, Teq, Xstart, Xend, Nenv, planet_dir) else: print "Resuming from previous models..." L_M_grid = np.logspace(math.log10(L_M_start), math.log10(L_M_end), NL) for i in range(istart, Nenv): if i == istart: j0 = jstart else: j0 = 1 for j in range(j0, NL): print "***123", i, j #read in history file and check planet radius his_file = "his_%d_L%d.data" % (i, j - 1) shutil.copyfile("%s/%s" % (planet_dir, his_file), "history.data") try: his = ms.history_data('.', clean_starlog=True) except: # avoid errors from bad files break rad = 10**(his.get('log_R')) * pp.rsun mass = his.get('star_mass') * pp.msun Rbondi = 6.67e-8 * mass[-1] / (2.0 * cs**2.0) XB = rad[-1] / Rbondi if XB > Xbondi: break # else heat-up to next value L_M_curr = (np.float64(L_M_grid[j]).item()) heat_up_model(planet_dir, L_M_curr, Teq, i, j) os.chdir(curr_dir)
def load(widget): clear_output() data = None mass = float(frame.get_attribute("mass", "value")) Z = float(frame.get_attribute("Z", "value")) dir = frame.get_attribute("address_bar", "value") if frame.get_attribute("model_select", "value") != "": model = int(frame.get_attribute("model_select", "value")) else: model = 1 module = frame.get_attribute("select_module", "value") if module == "H5 out": if manual_data_select: data = mp.se(dir) else: data = mp.se(mass=mass, Z=Z) frame.set_state("nugrid_w_data") properties = ["mass", "radius", "rho", "temperature"] frame.set_attributes("xaxis", options=properties + data.se.isotopes) frame.set_attributes("yaxis", options=properties + data.se.isotopes) elif module == "History": if manual_data_select: data = ms.history_data(dir) else: data = ms.history_data(mass=mass, Z=Z) frame.set_state("mesa_w_data") frame.set_attributes("xaxis", options=sorted(data.cols.keys())) frame.set_attributes("yaxis", options=sorted(data.cols.keys())) elif module == "Profile": if manual_data_select: data = ms.mesa_profile(dir, num=model) else: data = ms.mesa_profile(mass=mass, Z=Z, num=model) frame.set_state("mesa_w_data") frame.set_attributes("xaxis", options=sorted(data.cols.keys())) frame.set_attributes("yaxis", options=sorted(data.cols.keys())) else: nugrid_or_mesa = frame.get_attribute("select_nugrid_mesa", 'value') if nugrid_or_mesa == "NuGrid": frame.set_state("nugrid") elif nugrid_or_mesa == "Mesa": frame.set_state("mesa") frame.set_state_data("class_instance", data) frame.set_attributes("select_plot", selected_label="")
def load(widget): clear_output() data = None mass = float(frame.get_attribute("mass", "value")) Z = float(frame.get_attribute("Z", "value")) dir = frame.get_attribute("address_bar", "value") if frame.get_attribute("model_select", "value") != "": model = int(frame.get_attribute("model_select", "value")) else: model = 1 module = frame.get_attribute("select_module", "value") if module == "H5 out": if manual_data_select: data = mp.se(dir) else: data = mp.se(mass=mass, Z=Z) frame.set_state("nugrid_w_data") properties = ["mass", "radius", "rho", "temperature"] frame.set_attributes("xaxis", options=properties+data.se.isotopes) frame.set_attributes("yaxis", options=properties+data.se.isotopes) elif module == "History": if manual_data_select: data = ms.history_data(dir) else: data = ms.history_data(mass=mass, Z=Z) frame.set_state("mesa_w_data") frame.set_attributes("xaxis", options=sorted(data.cols.keys())) frame.set_attributes("yaxis", options=sorted(data.cols.keys())) elif module == "Profile": if manual_data_select: data = ms.mesa_profile(dir, num=model) else: data = ms.mesa_profile(mass=mass, Z=Z, num=model) frame.set_state("mesa_w_data") frame.set_attributes("xaxis", options=sorted(data.cols.keys())) frame.set_attributes("yaxis", options=sorted(data.cols.keys())) else: nugrid_or_mesa = frame.get_attribute("select_nugrid_mesa", 'value') if nugrid_or_mesa == "NuGrid": frame.set_state("nugrid") elif nugrid_or_mesa == "Mesa": frame.set_state("mesa") frame.set_state_data("class_instance", data) frame.set_attributes("select_plot", selected_label="")
def run_models(Teq, sep, NL, Nenv, planet_dir, min_mass, Xbondi, Tevolve, Evolve_star): import os import numpy as np import math import mesa as ms import shutil import planet_prop as pp import mesa_namelist as mn curr_dir = os.getcwd() file_in = "model_in.mod" file_out = "model_out.mod" run_dir = "make_planets" sb = 5.6704e-5 Flux = 4.0 * sb * Teq**4.0 Sigma = 250 # heating depth in F-Sigma routine cs = (1.38e-16 * Teq / (2.35 * 1.67e-24))**0.5 for i in range(0, Nenv): for j in range(0, NL): print "***123", i, j #read in history file and check planet radius his_file = "his_%d_L%d.data" % (i, j) shutil.copyfile("%s/%s" % (planet_dir, his_file), "history.data") try: his = ms.history_data('.', clean_starlog=True) except ZeroDivisionError: # arises when trying to read in bad model break rad = 10**(his.get('log_R')) * pp.rsun mass = his.get('star_mass') * pp.msun Rbondi = 6.67e-8 * mass[-1] / (2.0 * cs**2.0) XB = rad[-1] / Rbondi if XB > Xbondi: break # can run model os.chdir(run_dir) mod_file = "model_%d_L%d.mod" % (i, j) shutil.copyfile("%s/%s" % (planet_dir, mod_file), file_in) nml = mn.build_namelist_ev_Fsigma_we(Tevolve, Flux, Sigma, Teq, sep, min_mass, Evolve_star) nml.write('inlist', force=True) os.system("./create_planet") his_out = "e_his_%d_L%d.data" % (i, j) shutil.copyfile("LOGS/history.data", "%s/%s" % (planet_dir, his_out)) os.chdir(curr_dir)
dir1 = [] dir2 = [] m1 = [] m2 = [] for j in range(len(direct)): dir1.append(j) dir2.append(j) dir1[j] = direct[j] + '/LOGS1' dir2[j] = direct[j] + '/LOGS2' m1.append(j) m2.append(j) for path, dirs, files in os.walk( dir1[j]): #os.walk avoids [Errno21] Is a directory m1[j] = ms.history_data(dir1[j], clean_starlog=False) for path, dirs, files in os.walk(dir2[j]): m2[j] = ms.history_data(dir2[j], clean_starlog=False) log_center_Rho_1.append(j) log_center_T_1.append(j) log_center_P_1.append(j) star_age_1.append(j) star_mass_1.append(j) model_number_1.append(j) #log_L_1.append(j) #log_R_1.append(j) #log_Teff_1.append(j) #log_g_1.append(j) #center_h1_1.append(j) #center_he4_1.append(j)
"/Users/tassos/Dropbox/Projects/CE/SINGLEgrid/4.0/LOGS/", "/Users/tassos/Dropbox/Projects/CE/SINGLEgrid/5.0/LOGS/", "/Users/tassos/Dropbox/Projects/CE/SINGLEgrid/7.0/LOGS/",] profileN = [100, 1000, 1500, 2000, 2500] fig = plt.figure(figsize=(8.267, 11.692)) # gridspec inside gridspec gs = gridspec.GridSpec(5, 4, wspace=0.1, hspace=0.1) for i in range(4): h=ms.history_data(model_paths[i]) for j in range(5): ax = plt.subplot(gs[j,i]) print i,j p=ms.mesa_profile(model_paths[i],profileN[j],num_type='nearest_model') mass = p.get('mass') * u.Msun # solar mass dm = copy.deepcopy(mass) dm[:-1] = mass[:-1]-mass[1:] r = p.get('radius') * u.Rsun# solar radius dr = copy.deepcopy(r) dr[:-1] = r[:-1]-r[1:] csound = p.get('csound') * u.cm/u.s #cm/s t_sc = dr/(csound) mdot_sc = dm/t_sc t_ff = math.pi/2. * r**(3./2.) / np.sqrt(2.*const.G*(mass))
# Get the final masses from the folders #masses = [] for file in os.listdir(i): # Check if it's a directory, if it's a file, we'll ignore it if os.path.isdir(i+'/'+file) == True: if os.path.isdir(i+'/'+file) == i+'/data': print(file+' is the data folder, ignoring...') else: os.chdir(i+'/'+file) currd = os.getcwd() print('Now in directory... '+os.getcwd()) os.system('rm ./LOGS/history.datasa') s = ms.history_data() lum = s.get('log_L') mass = s.get('star_mass') fl = lum[ len(lum)-1 ] fm = mass[ len(mass)-1 ] rv = ReadInls('inlist_1.0','Reimers_scaling') bv = ReadInls('inlist_1.0','Blocker_scaling') if fl < 0. : masses.append(fm) reims.append(rv) block.append(bv) print('Final mass is: '+str(fm)) print('Reimers: '+str(rv))
inl = open(inlist, 'r') for line in inl: if str(value) in line: a = line val = float(a.split()[-1]) return val # We compute the c_k values using the results of the MESA run, # and the results of the midpoints of the intervals, ytilde # Meaning if our x_1 = [0.3,0.9] and x_2 = [0.01,0.1] then # ytile = final mass from MESA run with x_1 = 0.6 and x_2 = 0.05 midrun = '/data/mhoffman/NUQ/new_midpoints/tile4' # This should be a path the the ytilde folder os.chdir(midrun) s = ms.history_data() mass = s.get('star_mass') ytilde = mass[(len(mass) - 1)] # obtain the last mass # now read in all the star masses # Name of top directory and current directory #path = raw_input('Please provide path of top folder using: ') #os.chdir(path) paths = ['/data/mhoffman/NUQ/cdtiles/tile4'] kvals = [] masses = [] reims = [] block = []
# Creates a title which includes some parts of the current work directory. I am removing all the "/" and other characters title = '_' #+os.path.dirname(path)[-22:-18]+'_'+os.path.dirname(path)[-12:-8]+'_'+os.path.dirname(path)[-7:] # Start an instance of the history.data dir1 = path + '/LOGS1' dir2 = path + '/LOGS2' #dir1='/../' #dir2='/../' #dir1 = raw_input ('Please, insert the name of the directory where the first history.data and profiles are:\n') #dir2 = raw_input ('Please, insert the name of the directory where the second history.data and profiles are:\n') for path, dirs, files in os.walk( dir1): #os.walk avoids [Errno21] Is a directory m1 = ms.history_data(dir1, clean_starlog=False) for path, dirs, files in os.walk(dir2): m2 = ms.history_data(dir2, clean_starlog=False) log_center_Rho_1 = m1.get('log_center_Rho') log_center_T_1 = m1.get('log_center_T') log_center_P_1 = m1.get('log_center_P') star_age_1 = m1.get('star_age') star_mass_1 = m1.get('star_mass') model_number_1 = m1.get('model_number') #log_L_1=m1.get('log_L') #log_R_1=m1.get('log_R') #log_Teff_1=m1.get('log_Teff') #log_g_1=m1.get('log_g') #center_h1_1=m1.get('center_h1')
RED_PURPLE = (0.80,0.60,0.70) #hexcols[0] dark bluish #hexcols[1] light blue #hexcols[2] greenish #hexcols[3] dark green #hexcols[4] brownish #hexcols[5] light brown #hexcols[6] pinkish #hexcols[7] dark something redish #hexcols[8] magentish hexcols = ['#332288', '#88CCEE', '#44AA99', '#117733', '#999933', '#DDCC77',\ '#CC6677', '#882255', '#AA4499', '#661100', '#6699CC', '#AA4466','#4477AA'] hist1 = ms.history_data("double_bh_Z50/1.9_0.8_1.10/LOGS1", slname = "history.data") hist2 = ms.history_data("double_bh_Z50/1.9_0.8_1.10/LOGS2", slname = "history.data") plt.plot(hist1.get("log_Teff")[279:],hist1.get("log_L")[279:], '-', color = hexcols[0]) plt.plot(hist2.get("log_Teff")[279:],hist2.get("log_L")[279:], '-', color = hexcols[5], lw=1.5) plt.gca().text(0.12, 0.9, "$M_1=79M_\odot,M_2=64M_\odot,\;P_\mathrm{i}=1.1\;\mathrm{d}$", fontsize = 13, transform=plt.gca().transAxes) plt.legend(loc=2) plt.xlim([5.25,4.68]) plt.ylim([5.65,6.55]) plt.xlabel("$\log\;T_{\mathrm{eff}}$") plt.ylabel("$\log\;L/L_\odot$") ax = plt.gca()
import mesa as ms import os # Start an instance of the history.data #pathwork=os.getcwd() # Current work directory #direc=pathwork+'/LOGS' #direc='/../' direc = raw_input( 'Please, insert the name of the directory where the history.data and profiles are:\n' ) for path, dirs, files in os.walk( direc): #os.walk avoids [Errno21] Is a directory m1 = ms.history_data(direc, clean_starlog=False) star_age = m1.get('star_age') model_number = m1.get('model_number') ## Profiles # Start from the first profile and find the corresponding model_number prof_index = Table.read(direc + '/profiles.index', format='ascii.fixed_width') idx = [] idxa = [] idxb = [] idxc = [] index = [] for i in range(len(prof_index)):
#Zmass = 0.007167 #Porb = 235.29852 # orbital period in days, needed for delta-ln-e #t0 = 2e9 # age in years to begin integrating star (set near end of MS phase) f = 1.0 # fudge factors are fun (read the paper, it's ~1), needed for delta-ln-e idxstart = 10 # timestamp at which to begin plotting points (default = 20) q = Mcomp/Mstar # mass ratio = M_comp/M # ***** DEFINE AT MOST ONE OF THESE TWO THINGS ***** # Rnow = Rstar # option to stop integration at some radius #idxstop = 2890 # option to stop integration at some index # ***** DEFINE AT MOST ONE OF THESE TWO THINGS ***** # # Read in MESA stellar model data from a history file # Save only values corresponding to age > t0 years model = ms.history_data(modeldir) times = model.get('star_age') t0idx = np.argmax(times > t0) times = times[t0idx:] logTeffs = model.get('log_Teff')[t0idx:] logRs = model.get('log_R')[t0idx:] cz_masses = model.get('cz_xm')[t0idx:] loggs = model.get('log_g')[t0idx:] Teffs = np.power(10, logTeffs) Rads = np.power(10, logRs) #len1 = len(times) #original length of timestamps #times = np.array([time for time in times if time >= 1e7]) #len2 = len(times) #truncated length of timestamps >= 1e7