19-Convection (template)#

We start by importing the modules

  • Numpy – operations on arrays and matrixes (and pi)

  • Matplotlib pyplot – plotting library

  • Astropy units – defined quantities with units. We also import the CDS conversions

import matplotlib.pyplot as plt
import numpy as np, copy
%matplotlib inline

from astropy import constants as const
import astropy.units as u
from astropy.units import cds
cds.enable() 

import matplotlib.colors as cl
from matplotlib.collections import LineCollection

1. To execute: Opening Mesa structure models#

We have been using models from the MESA structure and evolution code already. Please take some time to read the paper describing the code: http://iopscience.iop.org/article/10.1088/0067-0049/192/1/3/pdf. (Note, make sure to download it while on campus for free access).

You can open the file with text edit, and you can see that it contains a whole set of columns with the values of parameters at different depths in the star.

For this notebook, I provide you with two models:

  1. present-day model of the Sun (19-Sun-profile.data)

  2. model of a star with an initial mass of 10\(M_\odot\), as a similar evolution stage (19-M10-profile.data)

The function below reads in a MESA model into a numpy “rec array”.

def read_model(file):

    return np.genfromtxt(file, skip_header=5, names=True)

Here’s a command that will show you the names of all the columns in the file. You can access a column by doing: data[‘column name’].

file_url = 'https://raw.githubusercontent.com/veropetit/PHYS633-F2024/main/Book/L19-Convection/19-Sun-profile8.data'

data = read_model(file_url)

print(data.dtype.names)
('zone', 'logT', 'logRho', 'logP', 'logR', 'luminosity', 'eps_grav', 'signed_log_eps_grav', 'net_energy', 'signed_log_power', 'velocity', 'entropy', 'mixing_type', 'csound', 'v_div_csound', 'eta', 'mu', 'logdq', 'dq_ratio', 'q', 'log_q', 'radius', 'rmid', 'temperature', 'tau', 'logtau', 'pressure', 'pgas_div_ptotal', 'logPgas', 'grada', 'free_e', 'x_mass_fraction_H', 'y_mass_fraction_He', 'z_mass_fraction_metals', 'abar', 'ye', 'log_opacity', 'eps_nuc', 'd_lnepsnuc_dlnd', 'd_lnepsnuc_dlnT', 'non_nuc_neu', 'mlt_mixing_length', 'mlt_mixing_type', 'gradT_sub_grada', 'gradT_div_grada', 'log_mlt_Gamma', 'log_D_mix', 'log_conv_vel', 'conv_vel_div_csound', 'log_mlt_D_mix', 'pressure_scale_height', 'gradT', 'gradr', 'mass', 'logxq', 'logxm', 'x', 'y', 'z', 'h1', 'he3', 'he4', 'c12', 'n14', 'o16', 'o18', 'ne20', 'ne22', 'mg24', 'pp', 'cno', 'tri_alfa', 'burn_c', 'burn_n', 'burn_o', 'burn_ne', 'burn_na', 'burn_mg', 'burn_si', 'burn_s', 'burn_ar', 'burn_ca', 'burn_ti', 'burn_cr', 'burn_fe', 'c12_c12', 'c12_o16', 'o16_o16', 'pnhe4', 'photo', 'other')

2. To execute: I will show you how to use a quite nifty function that creates colored lines#

def color_lines(x, y, z, min_col, max_col, cmap):
    points = np.array([x, y]).T.reshape(-1, 1, 2)

    segments = np.concatenate([points[:-1], points[1:]], axis=1)

    lc = LineCollection(segments, cmap=plt.get_cmap(cmap),
                    norm=plt.Normalize(min_col, max_col))
    lc.set_array(z)
    lc.set_linewidth(2)
    
    return lc

Here I create a color map that is called cm_plusmin, by defining 256 RGB values.

This is taken from an excellent compilation of B&W and color-blind friendly color maps: https://personal.sron.nl/~pault/

cols = []
for x in np.linspace(0,1, 256):
    rcol = 0.237 - 2.13*x + 26.92*x**2 - 65.5*x**3 + 63.5*x**4 - 22.36*x**5
    gcol = ((0.572 + 1.524*x - 1.811*x**2)/(1 - 0.291*x + 0.1574*x**2))**2
    bcol = 1/(1.579 - 4.03*x + 12.92*x**2 - 31.4*x**3 + 48.6*x**4 - 23.36*x**5)
    cols.append((rcol, gcol, bcol))

cm_plusmin = cl.LinearSegmentedColormap.from_list("PaulT_plusmin", cols)

3. Let’s first look at the opacity inside of stars.#

As we discussed in class, the convection is more likely when the \(\nabla_\mathrm{rad}\) (\(=\nabla_\mathrm{med}\)) is large.

As the opacity is part of the equation for \(\nabla_\mathrm{rad}\), it would be a good idea to see how it varies inside of stars.

We will look at a graph of \(\log(T)\) versus \(\log(\rho)\), which will also be very useful to visualize the radial profile of stars of various masses.

a. In class: we will do the Sun.#

b. At home: add a colored line for the \(10 M_\odot\) model.#

TODO: Add a colored line in the graph for the \(10 M_\odot\) model. Dont’ forget to label your axes.

fig, ax = plt.subplots(1,1, figsize=(6,5))

ax.set_xlim(-10,4)
ax.set_ylim(3,8)

# Define the min and max values for the color range
min_col = -6
max_col = 6

###########################
###########################
# In class

file_url = 'https://raw.githubusercontent.com/veropetit/PHYS633-F2024/main/Book/L19-Convection/19-Sun-profile8.data'

# Create a line collection for the solar model


# Add dashed lines to show the data better


# Add a color bar and a label



###########################
###########################
# At home: add the colored line for the M10 model.

file_url = 'https://raw.githubusercontent.com/veropetit/PHYS633-F2024/main/Book/L19-Convection/19-M10-profile8.data'

# Create a line collection for the 10Msun model
../_images/13b42abc167b5a9e2f6b22c19cb58200ceced35ae2de77d1c562ee3918345e23.png

TODO: Interpretatation:

  1. In the graph, which end of the curves represents the stellar surface?

  2. How does the opacity compares with Fig. 3 of Paxton et al. 2011?

  3. Comment on the change in opacity as a function of position inside of the star for each model. This will be useful for your intrepretation of #4

4. Convections in main sequence stars.#

In the models, the values of \(\nabla_\mathrm{real}\), \(\nabla_\mathrm{rad}\) (\(=\nabla_\mathrm{medium}\)), and \(\nabla_\mathrm{ad}\) are in columns named gradT, gradr, and grada, respectively.

Note: the radius is in units of solar radii for all models.

a. In class: Let’s see how these look in a solar model.#

b. At home: Do the same for the 10\(M_\odot\) model.#

TODO Do the same for the 10\(M_\odot\) model in the right-hand plot. Don’t forget to label your axes and add legend items for each curves

fig, ax = plt.subplots(1,2, figsize=(15,6))



###########################
###########################
# In class
file_url = 'https://raw.githubusercontent.com/veropetit/PHYS633-F2024/main/Book/L19-Convection/19-Sun-profile8.data'




###########################
###########################
# At home
file_url = 'https://raw.githubusercontent.com/veropetit/PHYS633-F2024/main/Book/L19-Convection/19-M10-profile8.data'
../_images/4232489f7cad2a50f43f838affb7e0ce782479932f6314c8562270c391f932d3.png

TODO: Interpretation:

  1. For each star, where is the condition for instability fulfilled?

  2. For each star, explain the behavior of the real temperature gradient outside of the core (in other words, which term in the equation for \(\nabla_\mathrm{rad}\) makes the most difference between a sun-like and high mass star?).

  3. There is a very famous graph in the Kippenhahn (22.7 in first edition, reproduced in the lecture slides). Based on this graph and the ones you just made, comment on the change in energy transport as a function of stellar mass.