How to compute disk models in vertical hydrostatic equilibrium

How to compute disk models in vertical hydrostatic equilibrium#

When setting up a disk with AnalyticalYSOModel, the vertical structure of the disk is given by an analytical prescription (a flared disk with a scale height that depends on radius). In a disk in vertical hydrostatic equilibrium, the vertical density structure instead depends on the temperature in the disk, which in turn depends on the density structure. Hyperion includes a helper function, run_with_vertical_hseq(), which finds a self-consistent solution by alternating between computing the temperature with the radiative transfer and recomputing the vertical density structure.

Note

run_with_vertical_hseq() is still experimental, so you should check the results carefully.

Setting up and running the model#

The model has to meet the following requirements:

The following example sets up a flared disk around a low-mass star, and then runs it with run_with_vertical_hseq() instead of calling write and run directly:

from hyperion.model import AnalyticalYSOModel
from hyperion.model.helpers import run_with_vertical_hseq
from hyperion.util.constants import au, lsun, rsun, tsun, msun
from hyperion_dust import get_dust

# Initialize model
m = AnalyticalYSOModel()

# Use the KMH94 dust model with Henyey-Greenstein scattering
dust = get_dust('kmh94_3.1_hg')

# Set up star (the stellar mass is required to compute the hydrostatic
# equilibrium)
m.star.radius = 2. * rsun
m.star.temperature = 4000.
m.star.luminosity = 5 * lsun
m.star.mass = 0.5 * msun

# Set up disk
d = m.add_flared_disk()
d.rmin = 10 * rsun
d.rmax = 10. * au
d.mass = 0.001 * msun
d.p = -1
d.beta = 1.25
d.r_0 = 100. * au
d.h_0 = 10. * au
d.dust = dust

# Set up a cylindrical polar grid. The second argument is the number of cells
# in the vertical (z) direction, which needs to be large enough to resolve the
# vertical density profiles that are computed for the hydrostatic equilibrium
m.set_cylindrical_polar_grid_auto(100, 300, 1)

# Set up the temperature calculation, using the modified random walk and the
# partial diffusion approximation to speed up the calculation in the optically
# thick midplane
m.set_n_initial_iterations(5)
m.set_n_photons(initial=1000000, imaging=0)
m.set_mrw(True)
m.set_pda(True)

# Iterate the radiative transfer and the vertical density structure 6 times,
# running each model in parallel with MPI on 4 processes (if Hyperion was not
# compiled with MPI, remove the mpi and n_processes arguments)
run_with_vertical_hseq('hseq', m, n_iter=6, overwrite=True,
                       mpi=True, n_processes=4)

Note

This example uses the kmh94_3.1_hg dust model provided by the hyperion-dust package, which can be installed with pip install hyperion-dust.

Since the density structure is recomputed separately in each vertical column of cells, the grid should have enough cells in the vertical direction to resolve the vertical density profiles. This is set by the second argument of set_cylindrical_polar_grid_auto(), which is set to 300 here.

The first argument of run_with_vertical_hseq() is a prefix for the files written out. The model is first written out and run with the initial (analytical) density structure, as hseq_00000.rtin and hseq_00000.rtout. Then, for each of the n_iter iterations, the temperatures from the previous output file are used to compute a new density structure, and the resulting model is written out and run as hseq_00001.rtin and hseq_00001.rtout, hseq_00002.rtin and hseq_00002.rtout, and so on. The last output file contains the final model. As for run(), you can use mpi=True and n_processes= to run each model in parallel, as is done above with four processes (this requires Hyperion to have been compiled with MPI; otherwise, remove these two arguments to run in serial mode), and logfile=True writes the output of each run to a log file (hseq_00000.log, etc.) instead of to the terminal.

When recomputing the density structure, the following assumptions are made:

  • The surface density of the disks (i.e. the mass in each vertical column of cells) is preserved, and only the vertical distribution is changed.

  • The hydrostatic equilibrium is computed in the gravitational potential of the star only, so self-gravity of the disk is ignored (this may be important for massive disks).

  • The gas is assumed to be a mix of molecular hydrogen and helium, with a mean molecular weight of 2.279. Whether the densities and dust opacities are specified for dust or gas+dust does not matter for this calculation.

  • Only the density of the disks is modified. Other components such as envelopes and ambient media are left unchanged.

  • Cells with no temperature (for example cells that no photons reached) are assigned the maximum temperature in the same vertical column.

Checking convergence#

The number of iterations is fixed by n_iter, and no check is made of whether the density structure has converged, so you should check this yourself. The following script reads in the output files for all the iterations, plots the vertical density and temperature profiles at a radius of 5au for the initial model, the first iteration, and the last iteration, and prints out the fraction of the disk mass that has moved between successive iterations:

import glob

import numpy as np
import matplotlib.pyplot as plt

from hyperion.model import ModelOutput
from hyperion.util.constants import au

# Find the output files for all the iterations
filenames = sorted(glob.glob('hseq_?????.rtout'))

fig = plt.figure(figsize=(10, 4))
ax1 = fig.add_subplot(1, 2, 1)
ax2 = fig.add_subplot(1, 2, 2)

previous = None
change = []

for iteration, filename in enumerate(filenames):

    # Extract the grid and the physical quantities
    g = ModelOutput(filename).get_quantities()
    density = g['density'][0].array[0, :, :]
    temperature = g['temperature'][0].array[0, :, :]

    # Find the radial cell closest to 5au
    iw = np.argmin(np.abs(g.w - 5. * au))

    # Plot the vertical density and temperature profiles at that radius
    if iteration in (0, 1, len(filenames) - 1):
        label = 'Iteration {0}'.format(iteration)
        ax1.plot(g.z / au, density[:, iw], label=label)
        ax2.plot(g.z / au, temperature[:, iw], label=label)

    # Find the fraction of the disk mass that has moved compared to the
    # previous iteration
    if previous is not None:
        volumes = g.volumes[0, :, :]
        change.append(np.sum(np.abs(density - previous) * volumes) /
                      np.sum(density * volumes))

    previous = density

for i, c in enumerate(change):
    print('Fraction of mass moved in iteration {0}: {1:.3f}'.format(i + 1, c))

ax1.set_xlim(-4., 4.)
ax1.set_yscale('log')
ax1.set_ylim(1.e-20, 1.e-11)
ax1.set_xlabel('z (au)')
ax1.set_ylabel('Density (g/cm^3)')
ax1.legend(loc='lower center', fontsize='small')

ax2.set_xlim(-4., 4.)
ax2.set_xlabel('z (au)')
ax2.set_ylabel('Temperature (K)')

fig.suptitle('Vertical profiles at w = {0:.0f} au'.format(g.w[iw] / au))
fig.savefig('hseq_profiles.png', bbox_inches='tight')

which gives:

../_images/hseq_profiles.png

and prints out:

Fraction of mass moved in iteration 1: 0.088
Fraction of mass moved in iteration 2: 0.118
Fraction of mass moved in iteration 3: 0.034
Fraction of mass moved in iteration 4: 0.018
Fraction of mass moved in iteration 5: 0.018
Fraction of mass moved in iteration 6: 0.017

In this case, the density structure has converged after about four iterations: the remaining changes of around 2% are due to the Monte-Carlo noise in the temperatures, and can be reduced by using more photons. If the density structure has not converged, you can run more iterations.

This model takes about 9 minutes to run with four MPI processes.

Visualizing the density structure#

To see how the structure of the disk as a whole has changed, the following script plots the density in the (w, z) plane for the initial model and for the last iteration, using the same color scale, both for the whole disk and zoomed in on its inner edge:

import glob

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm

from hyperion.model import ModelOutput
from hyperion.util.constants import au

# Find the output files for all the iterations
filenames = sorted(glob.glob('hseq_?????.rtout'))

# Top row: the whole disk, bottom row: the inner edge of the disk
fig, axes = plt.subplots(2, 2, figsize=(10, 8.5))

# Use the same logarithmic color scale for all panels, and show cells with
# zero density or a density below the color scale in the lowest color
norm = LogNorm(vmin=1.e-20, vmax=1.e-7)
cmap = plt.get_cmap('viridis')
cmap = cmap.with_extremes(bad=cmap(0.), under=cmap(0.))

# Show the initial model and the last iteration
for column, iteration in enumerate((0, len(filenames) - 1)):

    # Extract the grid and the density in the (w, z) plane
    g = ModelOutput(filenames[iteration]).get_quantities()
    density = g['density'][0].array[0, :, :]

    for row in (0, 1):

        ax = axes[row, column]

        # Plot the density using the cell walls, so that the cells are shown
        # with their actual sizes
        image = ax.pcolormesh(g.w_wall / au, g.z_wall / au, density,
                              norm=norm, cmap=cmap)

        # Show a few density contours to make the changes easier to see,
        # ignoring the empty cells inside the inner radius of the disk
        ax.contour(g.w / au, g.z / au, np.ma.masked_equal(density, 0.),
                   levels=[1.e-17, 1.e-14, 1.e-11, 1.e-8],
                   colors='white', linewidths=0.75)

        if row == 0:
            # The radial cells are spaced logarithmically, so show w on a log
            # scale, on which all the cells have the same width (the first
            # wall is at w=0)
            ax.set_xscale('log')
            ax.set_xlim(g.w_wall[1] / au, 10.)
            ax.set_ylim(-6., 6.)
            ax.set_title('Iteration {0}'.format(iteration))
        else:
            # Zoom in on the inner edge of the disk
            ax.set_xlim(0., 0.1)
            ax.set_ylim(-0.03, 0.03)

        ax.set_xlabel('w (au)')
        if column == 0:
            ax.set_ylabel('z (au)')

fig.colorbar(image, ax=axes, label='Density (g/cm^3)', extend='both')
fig.savefig('hseq_density_maps.png', bbox_inches='tight')

which gives:

../_images/hseq_density_maps.png

The white lines show contours of constant density (at 10-17, 10-14, 10-11, and 10-8 g/cm3). The upper layers of the disk are heated directly by the star and are much warmer than the midplane, so in hydrostatic equilibrium the disk is more extended vertically than the initial model, especially in the outer parts of the disk. Since the mass in each vertical column is preserved, the density in the midplane is correspondingly lower.

The zoom on the inner edge of the disk (bottom row) shows that in hydrostatic equilibrium the disk becomes thicker right at its inner edge than just behind it: the inner edge of the disk is illuminated directly by the star and is therefore hotter, and it shadows the disk behind it. This is the puffed-up inner rim that is expected for disks around young stars.