Created
June 21, 2020 20:55
-
-
Save uselesslemma/f269f04dc78934491ed7127702694d80 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import os | |
import shutil | |
#range of model masses [solar masses] | |
m_grid = np.array([0.3, 0.5, 0.8, 1.0, 1.2, 1.5, 2.0, 3.0, 5.0, 6.5, 8.0, 10.0]) | |
#range of He abundance fractions | |
y_grid = np.array([0.20, 0.25, 0.30, 0.35]) | |
#range of metal abundance fractions | |
z_grid = np.array([0.0042, 0.013, 0.025, 0.04]) | |
#directories | |
init_dir = '/milkyway/tpicard/final_project/' | |
default_dir = '/milkyway/tpicard/final_project/example' | |
#loops through the mass range... | |
i = 0 | |
while i < len(m_grid): | |
#loops through the He abundance fraction range... | |
j = 0 | |
while j < len(y_grid): | |
#loops through the metal abundance fraction range... | |
k = 0 | |
while k < len(z_grid): | |
#finds the working directory | |
os.chdir(init_dir) | |
#calculates an H abundance fraction range | |
x_grid = 1.0 - y_grid - z_grid | |
#creates a directory for a particular model | |
mod_dir = 'M_'+str(m_grid[i])+'_Y_'+str(y_grid[j])+'_Z_'+str(z_grid[k]) | |
os.mkdir(mod_dir) | |
#changes the working directory to the new model directory | |
shutil.copytree(default_dir, mod_dir + '/WORK_DIR') | |
os.chdir(mod_dir + '/WORK_DIR') | |
#opens the inlist files, replaces initial mass, He abundance fraction, and | |
#metal abundance fraction to match the current model being run, then closes | |
#the inlist files | |
def_inlist = open('INLIST_DEFAULT','r') | |
new_inlist = open('inlist_project','w') | |
for line in def_inlist: | |
line = line.replace("INIT_M", str(m_grid[i])) | |
line = line.replace("INIT_Y", str(y_grid[j])) | |
line = line.replace("INIT_Z", str(z_grid[k])) | |
new_inlist.write(line) | |
def_inlist.close() | |
new_inlist.close() | |
#runs a MESA star model track using the specified model parameters | |
os.system("init_mesa") | |
os.system("./mk") | |
os.system("./rn") | |
os.system("./clean") | |
#iterates each parameter for the next model | |
k += 1 | |
j += 1 | |
i += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment