TA-assistant Xiang Ji
MESA is short for Modules for Experiments in Stellar Astrophysics
| Reference | Description |
|---|---|
| Paxton et al. (2011) | Initial release |
| Paxton et al. (2013) | Planets, oscillation, rotation, and massive stars |
| Paxton et al. (2015) | Binaries, pulsations, and explosions |
| Paxton et al. (2018) | Convective boundaries, element diffusion and massive star explosions |
| Paxton et al. (2019) | Pulsating variable stars, rotation, convective boundaries, and energy conservation |
| Jermyn et al. (2023) | Time-dependent convection, energy conservation, automatic differentiation, and infrastructure |
| .... |
A Stars & Planet tutorial by TA-assistant Xiang Ji
A quick start guide to the MESA template project
We offer three methods to run MESA simulations
These are identified by different colors
Europa, which is adminstered by us
| Run simulations on | Pros | Cons |
|---|---|---|
| Local machine | Real-time visualization of computational results No Internet required Fully control of simulations | Installation required (Linux and Mac only!) |
Europa | No installation required Fully control of simulations | Internet access required No on-the-fly visualization |
| MESA-web | No installation required Visualization of results after completion | Internet access required Partial control of simulations |
| Choose the method according to your needs. |
Please follow the instruction here to install MESA.
binutils, make, Perl, X11, Z and C shell on Linux and Xcode, Xcode command line tools and Xquanrtz on Mac. For example, on Ubuntu system you may run the following command to get them:
sudo apt install binutils make perl libx11-6 libx11-dev zlib1g zlib1g-dev tsch
NOTE!
Unfortunately, MESA doesn't work on Windows system. You need to download Windows Subsystem for Linux firstly. See https://learn.microsoft.com/en-us/windows/wsl/install for instructions.
TA Zhixuan & Xiang are happy to help you out with any installation issues
We show the installation on Ubuntu system as an example. For Mac users, please follow the instructions on its website.
tar xvfz $package_name -C ~/
~/.bashrc:
export MESASDK_ROOT=~/mesasdk
source ~/.bashrc
source $MESASDK_ROOT/bin/mesasdk_init.sh
gfortran --version in the terminal and the output should begin with: GNU Fortran (GCC) 9.2.0
source ~/.bashrc
cd $MESA_DIR
./install
MESA installation was successful is expected once it is done.
export MESA_DIR=/Users/my_username/Software/mesa-r24.08.1
export OMP_NUM_THREADS=2
export MESASDK_ROOT=/Applications/mesasdk
source $MESASDK_ROOT/bin/mesasdk_init.sh
export PATH=$PATH:$MESA_DIR/scripts/shmesa
Please set MESA_DIR to be the directory to which you downloaded MESA, and set OMP_NUM_THREADS to be the number of cores on your machine. The third and fourth command should be already added when you set up the MESA SDK.
We are now going to simulate the evolution of a 15 mass star from a pre-main sequence model until the zero-age main sequence (ZAMS) is reached. The code has already been written in the directory $MESA_DIR/star/work. However, instead of running the code in that directory, it's highly recommended to store and perform the work somewhere else. Let's run the following command:
cp -r $MESA_DIR/star/work ~/work_dir/mesa_tutorial
Please, modified the second directory according to your machine.
Next, compile and run the code by typing:
cd ~/work_dir/mesa_tutorial
./mk
./rn
A new directory star is expected after the second command.
Once MESA is running, it will keep your updated through terminal output. As we promised before, MESA can automatically convert data into real-time HR diagram and internal temperature-density profile shown on the right.
The simulation should terminate after 207 steps with the following message:
stop because Lnuc_div_L>=Lnuc_div_L_zams_limit
New directory LOGS and photos are expected after the code finishes.
The photos files are machine readable binaries, where the models from MESA are saved. The LOGS include all you need for data analysis. They are text-based and can be fed into your favourite plotting program.
Continue with → Resuming Model
Europa Firstly, one needs to get connection to Europa, for which ssh (secure shell) is recommended.
~/.ssh:
ssh-keygen -t ed25519
Windows users: execute in VScode; see instructions →
~/.ssh/id_ed25519.pub and submit to one of the TAs (Zhixuan & Xiang). We will make sure that Europa recognizes your identification.
~/.ssh/config file according to the example on the right.
Europa by running the command ssh Europa in the terminal (windows: VScode) and typing in the password mesaproject.
Host Jupiter
HostName 166.111.121.30
Port 2222
User ormel
IdentityFile C:\\... #windows only
Host Europa
HostName 166.111.191.205
User starplanet
ProxyCommand ssh -W %h:%p Jupiter
NOTE!
For Windows system users, you should install vscode and run all the commands above therein. Also, you need to inform the machine where to find your private key. Please, add IdentityFile "C:\\Users\\$USERNAME\\.ssh\\id_ed25519" to the end of Host Jupiter block.
Europa starplanet. This is shared among all students. Therefore, each of you works in a separate directory
cd ~/Students/$NAME #go to your directory. #Always do this first!
cp -r $MESA_DIR/star/work ~/Students/$NAME/tutorial #copy essential information
where $NAME has been given to you by your TA
cd ~/Students/$NAME/tutorial
./mk
./rn
NOTE!
Please ensure all the change you make on Europa is in the ~/Students/$NAME directory. DO NOT EDIT OTHER STUDENT'S FILES! Only create files under ~/Students/$NAME dir
MESA-web is a web-based interface that allows users to run MESA without installing any software locally. Follow this instruction to have fun on MESA-web.
Submit!.
Several output files are provided:
.mp4 format)
profile*.data files, which can be used to analyze the process
A Stars & Planet tutorial by TA-assistant Xiang Ji
MESA offers a variety of input options. The code get these information from input files inlist and inlist_project.
inlist file is the first input file that MESA reads, which is often used to direct MESA to other input files.
inlist_project file includes options that we use to construct the model.
See all the options in $MESA_DIR/star/defaults/controls.defaults.
MESA-web can automatically generate a MESA-style inlist from the options you make on the calculation submission page. You can download it together with the outputs. Copy that file to Europa and see if you can get the same results!
A star firstly becomes ZAMS, then exhausted its central hydrogen through nuclear reaction.
Let's figure out what's the stellar structure when exhausting its central hydrogen. Firstly, turn off the first stopping criterion by editing:
stop_near_zams = .false.
It's not necessary to run the simulation from the very beginning, since you may notice there was a message in the terminal reads:
save photos/x207 for model 207
We can simply restart using the photo and our new setting by running:
./re x207
If everything goes smoothly, this time the simulation will terminate at model 304.
If you run it on your local machine, pgplot figures on the right are expected. The star goes to upper-left in the HR diagram, which is expected.
From time to time, MESA seems to "get stuck" and evolves quite slowly. To speed it up, you may want to change:
| Variable Name | Description |
|---|---|
max_years_for_timestep = 0 | max_years_for_timestep <= 0 means no limit. Adjust this value to sample the Main Sequence better. |
mesh_delta_coeff = 1.0d0 | The number of grids will roughly be cut by half if you double the value. |
varcontrol_target = 1d-3 | This is the target value for relative variation in the structure from one model to the next. |
| .... |
Find more options in $MESA_DIR/star/defaults/controls.defaults yourself!
We can also select inputs, like the stopping criterion, on MESA-web. By default, MESA-web will terminate the simulation when the iron core collapse. Let's change it to be consistent with our simulation.
The automatic visualization may not satisfy you all the times. Fortunately, MESA provides us with a Python module mesa_reader to help us visualize and analyze the models. To install it, run the following command:
pip install mesa_reader
In the LOGS directory, two kind of files are expected.
profile_interval = 20 in the !output section in inlist_project.
history_interval = 5 in the !output section in inlist_project.
NOTE!
upon restarting a model, MESA will not remove any (old/newer) output files. (You may want to do this manually)
NOTE!
By default, MESA will only save 100 profile.data files. Once the number exceeds this limit, it will overwrite the previous files in a circular manner (e.g., saving model 101 in profile2.data). You are able to reset the limit by adding max_num_profile_models = 300 in the !output section in inlist_project, but we do recommend you to adjust profile_interval first to see if that can meet your needs. If there's no limit on the profiles saved, one can easily fill up his disk!
To load history.data through mesa_reader, one can use the class MesaData:
import mesa_reader as mr
history = mr.MesaData("LOGS/history.data")
ages = history.data("star_age") # Alternatively, simply ages = h.star_age
The string in the bracket should be the same as the column name in the second line of history.data.
To load profile*.data, one can use the class MesaLogDir:
import mesa_reader as mr
log = mr.MesaLogDir("./LOGS")
p_100 = log.profile_data(100)
p_100 = log.profile_data(model_number = 100) # This works the same as the previous line.
p_12 = log.profile_data(profile_number = 10) # You can also use PROFILE number to load the data
p_last = log.profile_data() # To load the last profile, model number can be omitted
rho_100 = p_100.Rho # Then it works similarly as previous function mr.MesaData
By default, rather limited information can be acquired from profile.data files. In order to draw a Kippenhahn plot, for example, one would be happy to know the mixing type of each grid point. Fortunately, the output files can be easily modified with the following steps, as long as you are not using
MESA-web
. Firstly, copy the namelist file to your own directory.
cp $MESA_DIR/star/defaults/profile_columns.list .
chmod u+w profile_columns.list
Next, search for the quantity in profile_columns.list, which you want to add to the output files, and remove the ! in front of it (i.e., uncomment). In our case, it's mixing_type, so the file should look like:
519 !#Mixing
520 mixing_type ! mixing types are defined in mesa/const/public/const_def
521 !log_D_mix ! log10 diffusion coefficient for mixing in units of ...
mixing_type=0 means no mixing; 1 is mixing due to convection; 2 mixing due to convective overshoot, etc.
You also need to inform MESA where to get the newly edited output options, which is just the use of inlist file. Please, add the following line to its star_job section:
&star_job
...
profile_columns_file = 'profile_columns.list'
/ ! end of star_job namelist
Finally, run MESA with the command ./rn. Another column with index 10 and name mixing_type is expected in all the profile.data files. If one wants to add more quantities in the history.data file, just repeat the above process, but do replace all profile with history.
For MESA-web users, you won't have the opportunity to modify your output files. But still, you can infer the mixing type from the column with index 20 and name conv_vel in its default output files.
Run a 1 solar mass model with MESA until at least the onset of the Helium flash. See mesaguide.pdf for details. Save the relevant *.data tables. Then use these data tables to make two plots:
This is a "space-time" plot where the space (y) dimension represent the mass coordinate of the star and the time (x) dimension time. In this plot you indicate:
NOTE! you should make these plots yourself! Do not post the output of MesaWeb