Docsity

Enzo: An Adaptive Mesh Refinement Code for Astrophysics, Lecture notes of Astrophysics

Toggle sidebar
bg1
Draft version July 22, 2013
Preprint typeset using L
A
T
E
X style emulateap j v. 04/17/13
ENZO: AN ADAPTIVE MESH REFINEMENT CODE FOR ASTROPHYSICS
The Enzo Collaboration: Greg L. Bryan1, Michael L. Norman2,3, Brian W. O’Shea4,5 , Tom Abel6, 20, John H.
Wise7, Matthew J. Turk1, Daniel R. Reynolds8, David C. Collins9, Peng Wang6, Samuel W. Skillman10,11,
Britton Smith4, Robert P. Harkness12, James Bordner2, Ji-hoon Kim13, Michael Kuhlen14,15 , Hao Xu2, Nathan
Goldbaum15, Cameron Hummels16, Alexei G. Kritsuk2, Elizabeth Tasker17, Stephe n Skory10, Christine M.
Simpson1, Oliver Hahn18, Jeffrey S. Oishi19 , Geoffrey C So2, Fen Zhao20, Renyue Cen21, and Yuan Li1
Draft version July 22, 2013
ABSTRACT
This paper describes the open-source code Enzo, which uses block-structured adaptive mesh refine-
ment to provide high spatial and temporal resolution for modeling astrophysical fluid flows. The
code is Cartesian, can be run in 1, 2, and 3 dimensions, and supports a wide variety of physics in-
cluding hydrodynamics, ideal and non-ideal magnetohydrodynamics, N-body dynamics (and, more
broadly, self-gravity of fluids and particles), primordial gas chemistry, optically-thin radiative cooling
of primordial and metal-enriched plasmas (as well as some optically-thick cooling models), radiation
transport, cosmological expansion, and models for star formation and feedback in a cosmological con-
text. In addition to explaining the algorithms implemented, we present solutions for a wide range of
test problems, demonstrate the code’s parallel performance, and discuss the Enzo collaboration’s code
development methodology.
Keywords: methods: numerical — hydrodynamics
1. INTRODUCTION
Due to the high spatial and temporal dynamical ranges involved, astrophysical and cosmological phenomena present
a taxing challenge for simulators. To tackle such situations, a number of numerical techniques have been developed that
can be broadly split into gridless, Lagrangian methods and grid-based, Eulerian schemes. The most commonly used
is an example of the first type known as Smoothed Particle Hydrodynamics (SPH; Lucy 1977; Gingold & Monaghan
1977). It has achieved much success, particularly in regimes dominated by gravity. However, its development to
include an increasing number of sought-after physical processes is still at a relatively early stage when compared
with the effort put into the latter type of Eulerian grid-based hydrodynamic schemes (e.g., Laney 1998; Toro 1997;
Woodward & Colella 1984b).
Despite this invested expertise, the Eulerian solvers in their original form have a serious drawback: they do not
provide an easy method of adaptively increasing the spatial and temporal resolution in small volumes of the simulation.
Such flexibility is essential for following physical processes such as gravitational instability. A solution to this problem
was first proposed by Berger & Colella (1989) in the Computational Fluid Dynamics (CFD) community, and became
known as Structured Adaptive Mesh Refinement (SAMR). The principle is to adaptively add and modify additional,
finer meshes (“grids”) over regions that require higher resolution. In addition, it is possible to add other, more
advanced physics including – for the AMR implementation in the astrophysics code presented in this paper – comoving
coordinates, self-gravity, radiative cooling, chemistry, heat conduction, collisionless fluids, magnetohydrodynamics,
radiation transport, star formation and a range of other physical effects.
1Columbia University, Department of Astronomy, New York, NY, 10025, USA
2CASS, University of California, San Diego, 9500 Gilman Drive La Jolla, CA 92093-0424, USA
3SDSC, University of California, San Diego, 9500 Gilman Drive La Jolla, CA 92093-0505, USA
4Department of Physics and Astronomy, Michigan State University, East Lansing, MI 48824, USA
5Lyman Briggs College and Institute for Cyber-Enabled Research, Michigan State University, East Lansing, MI 48824, USA
6Kavli Institute for Particle Astrophysics and Cosmology, Stanford University, Menlo Park, CA 94025, USA
7Center for Relativistic Astrophysics, School of Physics, Georgia Institute of Technology, 837 State Street, Atlanta, GA, USA
8Department of Mathematics, Southern Methodist University, Box 750156, Dallas, TX 75205-0156, USA
9Theoretical Division, Los Alamos National Laboratory, Los Alamos, NM 87544
10 Center for Astrophysics and Space Astronomy, Department of Astrophysical and Planetary Science, University of Colorado, Boulder,
CO 80309, USA
11 DOE Computational Science Graduate Fellow
12 NICS, Oak Ridge National Laboratory, 1 Bethel Valley Rd, Oak Ridge, TN 37831, USA
13 Department of Astronomy and Astrophysics, University of California, Santa Cruz, CA 95064, USA
14 Theoretical Astrophysics Center, University of California Berkeley, Hearst Field Annex, Berkeley, CA 94720, USA
15 Department of Astronomy and Astrophysics, University of California, 1156 High Street, Santa Cruz, CA 95064, USA
16 Department of Astronomy/Steward Observatory, University of Arizona, 933 N. Cherry Ave., Tucson, AZ, 85721, USA
17 Physics Department, Faculty of Science, Hokkaido University, Kita-10 Nishi 8, Kita-ku, Sapporo 060-0810, Japan
18 ETH Zurich Institute for Astronomy. CH-8093 Zurich. Switzerland
19 Department of Astrophysics, American Museum of Natural History, Central Park West at 81st St, New York, NY 10024
20 Department of Physics, Stanford University, Stanford, CA 94305, USA
21 Department of Astrophysical Sciences, Princeton University, Peyton Hall, Princeton, NJ 08544, USA
Work supported in part by US Department of Energy under contract DE-AC02-76SF00515.
Published in arXiv:1307.2265.
SLAC-PUB-15890
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c

Partial preview of the text

Download Enzo: An Adaptive Mesh Refinement Code for Astrophysics and more Lecture notes Astrophysics in PDF only on Docsity!

Draft version July 22, 2013 Preprint typeset using LATEX style emulateapj v. 04/17/

ENZO: AN ADAPTIVE MESH REFINEMENT CODE FOR ASTROPHYSICS

The Enzo Collaboration: Greg L. Bryan^1 , Michael L. Norman2,3, Brian W. O’Shea4,5, Tom Abel6, 20, John H. Wise^7 , Matthew J. Turk^1 , Daniel R. Reynolds^8 , David C. Collins^9 , Peng Wang^6 , Samuel W. Skillman10,11, Britton Smith^4 , Robert P. Harkness^12 , James Bordner^2 , Ji-hoon Kim^13 , Michael Kuhlen14,15, Hao Xu^2 , Nathan Goldbaum^15 , Cameron Hummels^16 , Alexei G. Kritsuk^2 , Elizabeth Tasker^17 , Stephen Skory^10 , Christine M. Simpson^1 , Oliver Hahn^18 , Jeffrey S. Oishi^19 , Geoffrey C So^2 , Fen Zhao^20 , Renyue Cen^21 , and Yuan Li^1 Draft version July 22, 2013

ABSTRACT This paper describes the open-source code Enzo, which uses block-structured adaptive mesh refine- ment to provide high spatial and temporal resolution for modeling astrophysical fluid flows. The code is Cartesian, can be run in 1, 2, and 3 dimensions, and supports a wide variety of physics in- cluding hydrodynamics, ideal and non-ideal magnetohydrodynamics, N-body dynamics (and, more broadly, self-gravity of fluids and particles), primordial gas chemistry, optically-thin radiative cooling of primordial and metal-enriched plasmas (as well as some optically-thick cooling models), radiation transport, cosmological expansion, and models for star formation and feedback in a cosmological con- text. In addition to explaining the algorithms implemented, we present solutions for a wide range of test problems, demonstrate the code’s parallel performance, and discuss the Enzo collaboration’s code development methodology. Keywords: methods: numerical — hydrodynamics

  1. INTRODUCTION Due to the high spatial and temporal dynamical ranges involved, astrophysical and cosmological phenomena present a taxing challenge for simulators. To tackle such situations, a number of numerical techniques have been developed that can be broadly split into gridless, Lagrangian methods and grid-based, Eulerian schemes. The most commonly used is an example of the first type known as Smoothed Particle Hydrodynamics (SPH; Lucy 1977; Gingold & Monaghan 1977). It has achieved much success, particularly in regimes dominated by gravity. However, its development to include an increasing number of sought-after physical processes is still at a relatively early stage when compared with the effort put into the latter type of Eulerian grid-based hydrodynamic schemes (e.g., Laney 1998; Toro 1997; Woodward & Colella 1984b). Despite this invested expertise, the Eulerian solvers in their original form have a serious drawback: they do not provide an easy method of adaptively increasing the spatial and temporal resolution in small volumes of the simulation. Such flexibility is essential for following physical processes such as gravitational instability. A solution to this problem was first proposed by Berger & Colella (1989) in the Computational Fluid Dynamics (CFD) community, and became known as Structured Adaptive Mesh Refinement (SAMR). The principle is to adaptively add and modify additional, finer meshes (“grids”) over regions that require higher resolution. In addition, it is possible to add other, more advanced physics including – for the AMR implementation in the astrophysics code presented in this paper – comoving coordinates, self-gravity, radiative cooling, chemistry, heat conduction, collisionless fluids, magnetohydrodynamics, radiation transport, star formation and a range of other physical effects.

(^1) Columbia University, Department of Astronomy, New York, NY, 10025, USA (^2) CASS, University of California, San Diego, 9500 Gilman Drive La Jolla, CA 92093-0424, USA (^3) SDSC, University of California, San Diego, 9500 Gilman Drive La Jolla, CA 92093-0505, USA (^4) Department of Physics and Astronomy, Michigan State University, East Lansing, MI 48824, USA (^5) Lyman Briggs College and Institute for Cyber-Enabled Research, Michigan State University, East Lansing, MI 48824, USA (^6) Kavli Institute for Particle Astrophysics and Cosmology, Stanford University, Menlo Park, CA 94025, USA (^7) Center for Relativistic Astrophysics, School of Physics, Georgia Institute of Technology, 837 State Street, Atlanta, GA, USA (^8) Department of Mathematics, Southern Methodist University, Box 750156, Dallas, TX 75205-0156, USA (^9) Theoretical Division, Los Alamos National Laboratory, Los Alamos, NM 87544 (^10) Center for Astrophysics and Space Astronomy, Department of Astrophysical and Planetary Science, University of Colorado, Boulder, CO 80309, USA 11 DOE Computational Science Graduate Fellow (^12) NICS, Oak Ridge National Laboratory, 1 Bethel Valley Rd, Oak Ridge, TN 37831, USA (^13) Department of Astronomy and Astrophysics, University of California, Santa Cruz, CA 95064, USA (^14) Theoretical Astrophysics Center, University of California Berkeley, Hearst Field Annex, Berkeley, CA 94720, USA (^15) Department of Astronomy and Astrophysics, University of California, 1156 High Street, Santa Cruz, CA 95064, USA (^16) Department of Astronomy/Steward Observatory, University of Arizona, 933 N. Cherry Ave., Tucson, AZ, 85721, USA (^17) Physics Department, Faculty of Science, Hokkaido University, Kita-10 Nishi 8, Kita-ku, Sapporo 060-0810, Japan (^18) ETH Zurich Institute for Astronomy. CH-8093 Zurich. Switzerland (^19) Department of Astrophysics, American Museum of Natural History, Central Park West at 81st St, New York, NY 10024 (^20) Department of Physics, Stanford University, Stanford, CA 94305, USA (^21) Department of Astrophysical Sciences, Princeton University, Peyton Hall, Princeton, NJ 08544, USA

Work supported in part by US Department of Energy under contract DE-AC02-76SF00515.

Published in arXiv:1307.2265.

SLAC-PUB-

There have been a number of numerical methods described in the astronomical literature that contain elements of SAMR or have a similar aim. For example, the N-body solver developed by Villumsen (1989) used non-adaptive mesh- ing to increase the resolution in pre-selected regions. This static approach was later used extensively when applied to hydrodynamics (e.g., Ruffert 1994; Anninos et al. 1994). Adding adaptivity is a more recent enhancement, and there are now a number of codes that possess this feature, both with and without hydrodynamics (Couchman 1991; Jessop et al. 1994; Suisalu & Saar 1995; Splinter 1996; Gelato et al. 1997; Kravtsov et al. 1997; Truelove et al. 1998; Fryxell et al. 2000; Knebe et al. 2001; Yahagi & Yoshii 2001; Teyssier 2002; Quilis 2004; Ziegler 2005; Zhang & MacFadyen 2006; Cunningham et al. 2009; Mignone et al. 2012; Schive et al. 2010; Almgren et al. 2013). Of these, perhaps the most comparable and widely used are FLASH (Fryxell et al. 2000), which uses grid blocks of fixed size, and RAMSES (Teyssier 2002) and ART (Kravtsov et al. 1997), both of which refine individual cells. It is also possible to deform the grid to obtain high resolution (e.g., Gnedin 1995a; Xu 1997; Pen 1998), and more recently a few codes have adopted an unstructured approach based on a moving Voronoi mesh (Springel 2010; Duffell & MacFadyen 2011). In this paper, we present Enzo 2.3, a structured adaptive mesh refinement (SAMR) code. Originally developed for cosmological hydrodynamics, Enzo has since been used on a wide variety of problems. It has grown to become a general tool for astrophysical fluid dynamics and is intended to be efficient, accurate and easily extended to include new capabilities. Although many of the components of the Enzo code have been described in previous publications (Bryan et al. 1995; Bryan 1996; Bryan & Norman 1997b,a; Norman & Bryan 1999; Bryan 1999; Bryan et al. 2001; O’Shea et al. 2004; Norman et al. 2007; Wang et al. 2008; Reynolds et al. 2009; Collins et al. 2010; Wise & Abel 2011), there has previously been no systematic and complete description of the code. In this paper we provide that description, filling in many previous omissions and showing the code’s performance for a wide variety of test problems. The Enzo code has been extensively used over the last two decades in a wide variety of problems, resulting in the publication of more than 100 peer-reviewed papers. The variety of astrophysical systems that Enzo has been used for in- clude galaxies (Tassis et al. 2003; Lackner et al. 2012; Simpson et al. 2013), galaxy clusters (Loken et al. 2002; Xu et al. 2011; Skillman et al. 2012), the interstellar medium (Slyz et al. 2005), the intergalactic medium (Fang & Bryan 2001; Smith et al. 2011), the circumgalactic medium (Hummels et al. 2013), cooling flows (Li & Bryan 2012; Skory et al. 2013), turbulence (Kritsuk & Norman 2004; Kritsuk et al. 2007, 2009a; Collins et al. 2011), the formation of the first stars (Abel et al. 2002; O’Shea & Norman 2007; Turk et al. 2009; Xu et al. 2008), and the formation of stars in our own Galaxy (Collins et al. 2011; Kritsuk et al. 2011b; Collins et al. 2012). Numerical simulations of astronomical phenomena now play a key role, along with observations and analytic theory, in pushing forward our understanding of the cosmos (e.g., Astronomy and Astrophysics Survey Committee 2001, 2010). But along with this role comes responsibility. We believe that those developing simulation tools must fulfill two key obligations: the first is to make those tools available to the community as a whole, much in the way that astronomical data are now regularly made publicly available. The second is to document, test and refine those methods so that they can be critically evaluated and expanded upon by others. Our public release of the Enzo code (which can be found at http://enzo-project.org) represents our attempt to meet the first of these obligations; this paper represents our attempt to meet the second. The structure of this paper is as follows. In Section 2, we first provide a top-level overview of the code method and structure. This is designed to give a broad-brush picture of the equations solved by Enzo and the methods used to solve them. Next, in Sections 3 through 10, we describe the methods we use in detail, reserving some of the longer descriptions of particular components for the appendix in order to not interrupt the flow of the paper. The Enzo testing framework and code tests are described in Section 11. The parallelism strategy and scaling results are described in Section 12. Finally, we discuss the code’s development methodology (which is, as far as we know, unique in the astrophysics community) in Section 13.

  1. PHYSICAL EQUATIONS AND OVERVIEW OF NUMERICAL METHODOLOGY We begin this section by first writing down the complete set of physical equations that can be solved by Enzo, and then briefly describe the numerical algorithms that we use to solve these equations. This section is intended to be an overview of Enzo’s capabilities: thus, we gather all of the equations solved into a single place and provide a brief and high-level introduction to the numerics of the code. Detailed descriptions of the individual components are then provided in Sections 3-10. In Table 1 we provide a convenient summary of all variables and physical constants used throughout this manuscript.

Table 1 Summary of symbols used in this manuscript

Symbol Description Fluid Quantities E comoving total fluid energy density e comoving thermal energy density T baryon temperature S fluid entropy ρ comoving baryonic density ρX comoving mass density of component X (gas, dark matter, stars, metals, total, etc.) t time

Table 1 — Continued

Symbol Description G gravitational constant H Hubble constant kB Boltzmann constant M⊙ mass of Sun mH mass of hydrogen atom me mass of electron c speed of light cs sound speed z redshift

2.1. Physical Equations The Eulerian equations of ideal magnetohydrodynamics (MHD) including gravity, in a coordinate systems comoving with the cosmological expansion, are given by

∂ρ ∂t

a

∇ · (ρv) = 0, (1)

∂ρv ∂t

a

ρvv + Ip∗^ −

BB

a

a˙ a

ρv −

a

ρ∇φ, (2)

∂E ∂t

a

[

(E + p∗)v −

a

B(B · v)

]

a˙ a

2 E −

B^2

2 a

ρ a

v · ∇φ − Λ + Γ +

a^2

∇ · Fcond, (3)

∂B ∂t

a

∇ × (v × B) = 0 (4)

In these equations, E, ρ, v, and B are the comoving total fluid energy density, comoving gas density, peculiar velocity, and comoving magnetic field strength, respectively. The matrix I is the identity matrix, and a is the cosmological expansion parameter (discussed in more detail below). The first equation represents conservation of mass, the second conservation of momentum, and the third conservation of total (kinetic plus thermal plus magnetic) fluid energy. They are respectively, the first, second, and third moments of the Boltzmann equation. The fourth equation is the magnetic induction equation. Terms representing radiative cooling (Λ) and heating (Γ) enter on the right-hand side of the energy equation (3), as does the flux due to thermal heat conduction (Fcond). The comoving total fluid energy density E is given by

E = e +

ρv^2 2

B^2

2 a

where e is the comoving thermal energy density. The total comoving isotropic pressure p∗^ is given by

p∗^ = p +

B^2

2 a

and the quantity p is the thermal pressure. We use units such that the magnetic permeability is unity (μ 0 = 1). The equations are closed by an equation of state and Poisson’s equation for the gravitational potential φ:

e =

p (γ − 1)

∇^2 φ =

4 πG a

(ρtotal − ρ 0 ) (8)

The equation of state is shown here for an ideal gas with a ratio of specific heats γ. The gravitational potential φ is sourced by the total mass density contrast, where ρtotal = ρgas + ρdm + ρstars and ρ 0 is the mean density. Although we write the equations including both magnetic field terms and comoving coordinates, the code is frequently used both in the purely hydrodynamic limit (B = 0, referred to as HD below) and without cosmological expansion (a = 1, ˙a = 0). For completeness, we note here that we have defined several key quantities in the comoving frame to make the previous equations more readable. Specifically, we define:

x = x′/a, (9) v = a x˙ = v′^ − a˙x, (10) ρ = a^3 ρ′, (11) p = a^3 p′, (12)

E = a^3

E′^ − a˙ x · v′^ −

a˙^2 x^2

φ = φ′^ +

a¨a x^2 , (14)

B = a^2 B′, (15)

where primes indicate quantities in proper coordinates (fixed frame). We note that the definition of comoving B used here is such that a uniform field is constant in a homogeneous expanding universe and is also the quantity used in the MHD-CT solver described below; however, it is not universal, and is slightly different from that used both in Li et al. (2008) and in the MHD-Dedner solver (see section 4.2 for more details). The expansion parameter a ≡ 1 /(1 + z) follows the expansion of a smooth, homogeneous background, where z, the redshift, is a function only of t. All spatial derivatives are determined with respect to the comoving position x, which removes the universal expansion from the coordinate system. The evolution of a(t) is governed by the second Friedmann equation for the expansion of a spatially homogeneous and isotropic universe

¨a a

4 πG 3 a^3

(ρ 0 + 3p 0 /c^2 ) + Λcc^2 / 3. (16)

Here ρ 0 is the mean comoving mass density (including both baryonic and dark matter), p 0 is the comoving background pressure contribution, and Λc is the cosmological constant. This system of equations is limited to the non-relativistic regime and assumes that curvature effects are not important — both assumptions are reasonable as long as the size of the simulated region is small compared to the radius of curvature and the Hubble length c/H, where c is the speed of light and H = ˙a/a is the Hubble constant. The comoving evolution equations are equivalent to the fixed coordinate version in the non-cosmological limit (a = 1, ˙a = 0). We include the cosmological terms with the understanding that Enzo is not restricted to cosmological applications – while historically the code was written with cosmological situations in mind (e.g., galaxy clusters), in more recent years it has been used to simulate a much broader range of astrophysical environments. Any collisionless components (such as dark matter and stars) are modeled by N-body particles, whose dynamics are governed by Newton’s equations in comoving coordinates:

dx dt

a

v, (17)

dv dt

a˙ a

v −

a

∇φ, (18)

The particles contribute to the gravitational potential through Poisson’s equation (Equation 8). In addition, Enzo can solve the mass conservation equations for a set of chemical species and their reactions. For any species i with comoving number density ni, these equations have the form:

∂ni ∂t

a

∇ · (niv) =

j

kij (T ) ninj +

j

Γph j nj (19)

where kij are the rate coefficients for the two-body reactions and are usually functions of only temperature (we will

specifically note the cases where we either include three-body reactions or have density-dependent rates). The Γph j are destruction/creation rates due to photoionizations and/or photodissociations. Currently the species Enzo can follow include H, H+, He, He+, He++, and e−, and through additional options also H−, H 2 , H+ 2 , and HD, D, and D+. Lastly, Enzo can also track the advection of one or more comoving metal density fields, which can contribute to the radiative cooling and star formation processes. The code can include either a homogeneous radiation background or evolve an inhomogeneous radiation field either by directly solving the radiative transfer equation along rays or by solving a set of moment equations derived from the radiative transfer equation. In comoving coordinates (e.g., Gnedin & Ostriker 1997) the radiative transfer equation reads 1 c

∂Iν ∂t

aem a

nˆ · ∇Iν −

H

c

ν

∂Iν ∂ν

− 3 Iν

= −κν Iν + jν. (20)

Here Iν ≡ I(ν, x, Ω, t) is specific intensity of the radiation, with dimensions of energy per time t per solid angle Ω per unit area per frequency ν. The second term represents the propagation of radiation, where the factor aem/a accounts for cosmic expansion since the time of emission. The third term describes both the cosmological redshift and dilution of radiation. On the right hand side, the first term captures absorption (κν ≡ κν (x, ν, t)), and the second term emission (jν ≡ jν (x, ν, t)) from any sources of radiation (whether point or diffuse). As an alternative to the ray-casting strategy, Enzo can also solve the angle-averaged radiative transfer equation through a flux-limited diffusion approximation, with couplings to both the gas energy and chemical number densities. The equations solved are

∂Er ∂t

a

∇ · (Er v) = ∇ · (D∇Er ) −

a˙ a

Er − cκEr + η, (21)

2.2.2. (Magneto)-hydrodynamic solver methods Four different (magneto)-hydrodynamic methods are implemented in Enzo: (i) the hydrodynamic-only piecewise parabolic method (PPM) developed by Colella & Woodward (1984) and extended to cosmology by Bryan et al. (1995); (ii) the MUSCL-like Godunov scheme (van Leer 1977b) with or without magnetic fields and Dedner-based divergence cleaning, described in more detail in Wang et al. (2008) and Wang & Abel (2009a); (iii) a constrained transport stag- gered MHD scheme (Collins et al. 2010), and (iv) the second-order finite difference hydrodynamics method described in ZEUS (Stone & Norman 1992a,b).

Godunov PPM method (HD only) — We begin with the direct-Eulerian PPM implementation. This is an explicit, higher- order accurate version of Godunov’s method for ideal gas dynamics with the spatially third-order accurate piecewise parabolic monotonic interpolation and a nonlinear Riemann solver for shock capturing. It advances the hydrodynamic equations in the following steps: (i) Construct monotonic parabolic interpolation of cell average data, for each fluid quantity; (ii) Compute interface states by averaging the parabola over the domain of dependence for each interface; (iii) Use interface data to solve the Riemann problem; (iv) Difference the interface fluxes to update the cell average quantities. The PPM implementation does an excellent job of capturing strong shocks across a few cells. Multidimensional schemes are built up by directional splitting and produce a method that is formally second-order accurate in space and time and which explicitly conserves mass, linear momentum, and energy (Hawley et al. 1984; Norman & Winkler 1986). A variety of Riemann solvers have been implemented. As described in Bryan et al. (1995), we modify the method for use in hypersonic flows when the thermal energy e is extremely small compared to the total energy E. This situation presents a problem because in the total energy method the thermal energy is computed by subtracting one large number from another (i.e. the kinetic energy from the total energy), which tends to generate large numerical inaccuracies. We overcome this difficulty by additionally solving a thermal energy equation and using e from this equation when we expect the error to be large.

Godunov MUSCL (HD) with Dedner divergence cleaning (MHD) — This solver was developed to attack problems in magnetic field amplification during the formation of galaxies (Wang & Abel 2009b) and to understand the role of proto-stellar jets for the theory of star formation (Wang et al. 2009). It combines the standard approach of Godunov (Godunov 1959) for finite volume techniques with the method of lines as described by LeVeque (2002) and Toro (1997). In addition, it implements the hyperbolic divergence cleaning algorithm of Dedner et al. (2002). It supports multiple approximate Riemann solvers and non-ideal equations of states. Consequently, this suite of solvers can be used for hydro and magneto-hydrodynamic simulations. This class of solvers, as well as a version of the PPM hydro solver, has been ported to nVidia’s CUDA framework, allowing Enzo to take advantage of modern graphics hardware (Wang et al. 2010).

Godunov MHD with Constrained Transport (MHD) — This MHD method is second-order in time and space, and pre- serves the divergence constraint, ∇ · B = 0, to machine precision through the Constrained Transport (CT) method (Collins et al. 2010). CT, originally described by Evans & Hawley (1988), updates the magnetic field with the curl of an electric field, suitably formulated to preserve ∇ · B. We employ the CT methods described by Balsara & Spicer (1999) and Gardiner & Stone (2005) with the second-order hyperbolic solver of Li et al. (2008) and the divergence-free AMR scheme of Balsara (2001).

Second-order finite difference method (HD only) — Lastly, we briefly describe the ZEUS method, a finite difference al- gorithm originally used in the ZEUS code (Stone & Norman 1992a). Note that Enzo is entirely independent of the ZEUS code, and only the hydrodynamical algorithm of ZEUS has been implemented in Enzo; the MHD and radiation- hydrodynamics schemes have not. The ZEUS method uses a staggered mesh such that velocities are face-centered, while density and internal energy are cell-centered. It splits the solution up into two steps. The first is the so-called source step, in which the momentum and energy values are updated to reflect the pressure and gravity forces, including an artificial viscosity required for stability. The second step, known as the transport step, accounts for the advection of conserved quantities (mass, momentum, and energy) across the grid.

2.2.3. Gravity The current implementation of self-gravity in Enzo uses a Fast Fourier technique (Hockney & Eastwood 1988) to solve Poisson’s equation on the root grid on each timestep. The advantage of using this method is that it is fast, accurate, and naturally allows both periodic and isolated boundary conditions for the gravity, choices which are very common in astrophysics and cosmology. On subgrids, we interpolate the boundary conditions from the parent grid (either the root grid or some other subgrid). The Poisson equation is then solved on every timestep using a multigrid technique on one subgrid at a time. Aside from self-consistently calculating the gravitational potential arising from the baryon fields and particles in the simulation, there are also a number of options for specifying static gravitational fields.

2.2.4. N-body Dynamics Collisionless matter (e.g. dark matter, stars, etc.) is modeled with particles that interact with the baryons only via gravity. These particles are advanced through a single timestep using a drift-kick-drift algorithm (Hockney & Eastwood

  1. to provide second-order accuracy even in the presence of varying timesteps. Since the particles follow the collapse of structure, they are not adaptively refined. Nor are there duplicate sets of particles for each level; instead, each particle is associated with the highest refined level available at its position in the domain and particles are moved between grids as the hierarchy is rebuilt. Thus a particle has the same timestep and feels the same gravitational force as a grid cell at that refinement level. Although the particles are fixed in mass once initialized (with the exception of star particles, which can lose mass in the feedback process), we can create them with any initial set of masses and positions. For example, in many cosmological simulations static subgrids are included from the beginning in order to improve the initial spatial and baryonic mass resolution, and these subgrids are populated with lower-mass particles to correspondingly improve the collisionless mass resolution.

2.2.5. Chemistry Enzo includes the capability of following up to 12 particle species using a non-equilibrium chemical network. The species can be turned on in sets, with the simplest model including just atomic hydrogen and helium (H, H+, He, He+, He++, e−), and more complete models adding first species important for gas-phase molecular hydrogen formation (H−, H 2 and H+ 2 ), and then HD formation (HD, D, D+). The cooling and heating due to these species is included (see the next section). The solution of the rate equations is carried out using one Jacobi iteration of an implicit Euler time discretization to ensure stability. To ensure accuracy the rate equations are sub-cycled within one hydrodynamic timestep, subject to the constraint that the electron and neutral fractions do not change by more than 10% in one sub-cycle.

2.2.6. Radiative Cooling and Heating Enzo can operate in a number of different modes with regard to radiative cooling and heating. In the simplest mode, where the multi-species flag is turned off and no individual chemical species are tracked, the cooling rate is computed from a simple temperature-dependent cooling function, taken from Sarazin & White (1987). If chemistry is turned on, then the code can include cooling from all species of hydrogen and helium (including H 2 and Deuterium-related species such as HD) – and the primordial cooling rates are computed in the same Jacobi iteration as the chemistry. It is also possible to include metal cooling based on a set of multi-dimensional lookup tables computed with the Cloudy code (Ferland et al. 1998) as described in Smith et al. (2008) and Smith et al. (2011). Note that the cooling and heating is most commonly treated in the optically-thin limit, but the code can also follow radiative transfer in a limited set of energy bins.

2.2.7. Homogeneous radiation backgrounds The chemical networks and heating rates described in the previous sections can be affected by external radiation fields, and the code includes a number of pre-calculated meta-galactic UV radiation backgrounds that are uniform in space but can vary in time. These are generally based on the redshift-dependent rates given in Haardt & Madau (1996) and Haardt & Madau (2012), but can also include a uniform H 2 photo-dissociating background that is either constant in time or varying as in Wise & Abel (2005).

2.2.8. Radiation transport: ray tracing Enzo includes a photon-conserving radiative transfer algorithm that is based on an adaptive ray-tracing method utilizing the HEALPix pixelization of a sphere (Abel & Wandelt 2002). Photons are integrated outwards from sources using an adaptive timestepping scheme that preserves accuracy in ionization fronts even in the optically-thin limit. This has been coupled to the chemistry and cooling network to provide ionization and heating rates on a cell-by-cell basis. The method is described in detail (including numerous code tests) in Wise & Abel (2011).

2.2.9. Radiation transport: Flux-limited diffusion A second option for radiative transfer is a moment-based method that adds an additional field tracking the radiation energy density. This field is evolved using the flux-limited diffusion method, which transitions smoothly between streaming (optically thin) and opaque limits and is coupled to an ionization network of either purely hydrogen, or both hydrogen and helium. The resulting set of linear equations is solved using the parallel HYPRE framework. Full details on the Enzo implementation of this method can be found in Reynolds et al. (2009).

2.2.10. Heat Conduction Heat conduction, both isotropic and anisotropic, can be included using a sub-cycled, operator-split method. The heat fluxes are computed with simple second-order accurate finite differences, and stability is ensured by restricting the timestep and using flux-limiters where appropriate.

2.2.11. Star Formation and Feedback A family of simple heuristic methods are used to model the formation of stars and their feedback of metals and energy into the gas. These methods are based on the work of Cen & Ostriker (1992), and involve the identification of plausible sites of star formation based on a set of criteria (for example, dense gas with a short cooling time, which

dt

dt/2 dt/

dt/4 dt/4 dt/4 dt/

level 0

level 1

level 2

Timesteps Order of steps

time

Figure 2. Left: Example of the timesteps on a 2-level AMR hierarchy. Enzo does not restrict the timesteps on the finer levels to be a factor of 1/ 2 n^ smaller. Right: The order in which the AMR grids are evaluated on each level. Timesteps are determined on each level as described in Section 9, and the hierarchy is advanced on a level-by-level basis in a W-Cycle. Beginning with the coarsest level, l, all grids on that level are advanced one timestep. Then, one timestep is taken on all grids at the next level of refinement, l + 1, and so on until the finest level is resolved. The finest level is then advanced, using as many steps as it takes to reach the level immediately above. The finest level is then synched to the level above it, which then proceeds forward in time one more step. This is shown graphically in Figure 2. At the end of every timestep on every level, each grid updates its ghost zones by exchanging information with its neighboring grid patches (if any exist) and/or by interpolating from a parent grid. In addition, cells are examined to see where refinement is required and the entire grid hierarchy is rebuilt at that level (including all more highly refined levels). The timestepping and hierarchy advancement/rebuilding process described here is repeated recursively on every level to the specified maximum level of refinement in the simulation. The basic control algorithm looks very much like any used in a grid-based code of a single resolution, and can be written schematically as:

InitializeHierarchy While (Time < StopTime): dt = ComputeTimeStep(0) EvolveLevel(0, dt) Time = Time + dt CheckForOutput(Time)

The AMR control algorithm is contained within the recursive EvolveLevel algorithm, which takes the level upon which to operate as an argument. This looks something like the following pseudo-code:

EvolveLevel(level): SetBoundaryValues while (Time < ParentTime): dt = ComputeTimeStep(level) SolveHydroEquations(dt) SolveOtherEquations(dt) Time = Time + dt SetBoundaryValues EvolveLevel(level+1, dt) FluxCorrection Projection RebuildHierarchy(level+1)

Each function operates on all the grids on the given level. In the following sections, we will address each of the major elements in turn.

3.1. Setting the boundary values In order to solve the hydrodynamic equations on a patch, it is necessary to specify the boundary conditions on that patch. There are two cases. The first is that the boundary is external to the computational domain. This occurs for all the boundaries of the root grid. The second possibility is that the boundary is within the computational domain, which is true for most, but not all, subgrids. In the first case, we allow for four types of boundary conditions (for simplicity, represented here as being at x = 0, with positive x interior and negative x exterior to the domain):

  1. Reflecting. In this case, the boundary behaves like a mirror, with the solution on the boundary reflecting the solution in the computational domain (q(−x) = q(+x)) but with the velocity normal to the boundary reversed: vx(−x) = −vx(+x).
  1. Outflow. We approximate outflow boundary conditions by duplicating the solution at the edge of the computa- tional domain: q(−x) = q(0).
  2. Inflow. In this case, the boundary values are fixed by a pre-determined function (q(−x) = q0(−x, t)). The code provides a simple way to set inflow values that are constant in both time and space over an entire face, or hooks are provided for special cases where the boundary must be time-varying.
  3. Periodic. The boundary solution is obtained from the other side of the grid: q(−x) = q(xmax − x).

In the second case, the value must be either (1) interpolated from a parent or (2) copied from a sibling. In practice, we solve this problem by first interpolating all boundaries from the grid’s parent and then performing the sibling copy wherever possible, since these values will always be as good as, or superior to, interpolation. We focus first on conserved, cell-centered quantities. The interpolation function should be conservative in the sense that the mean over the interpolated quantity, in a given cell, must return the cell-centered value. It should also be monotonic, so that new extrema are not introduced into a smoothly varying field. In one dimension, such functions are well known; examples include donor cell, Van Leer, and piecewise parabolic interpolation, which are first-, second-, and third-order accurate respectively (e.g., Stone & Norman 1992a). However, we require fully multi-dimensional interpolation functions, and so focus on second-order schemes since they are tractable and relatively accurate^22. In Appendix A, we explicitly write down functions in one, two and three dimensions, but here we discuss the general design considerations. In two dimensions, it is relatively easy to build a linear, monotonic, conservative function by requiring, first, that the function at the center of the cell return the cell-centered quantity (and since it is linear, this implies that an average over the cell will also be equal to this value), and second, by treating the cell-diagonals as one-dimensional Van Leer-type functions. The reason to focus on the cell diagonals is that for a linear function, the extrema will occur at the cell corners, which are in turn linked by the diagonals. This process can be done in two dimensions since there are three constraints (one at the center and one along each diagonal), and three parameters in a two-dimensional linear function. In three dimensions this process breaks down since the number of constraints (center + four diagonals = five) exceeds the number of parameters (four). One way to solve this problem would be to perform a least-squares fit under the given constraints; however, this is too computationally expensive. Therefore, in Appendix A we describe a heuristic approach that satisfies four constaints analytically and then adjusts the interpolation parameters in such a way as to satisfy the fifth. While the result is not necessarily optimal, it does appear to perform adequately in our tests.

3.2. Solving the hydrodynamic equations on a grid Given the grid and its boundary conditions, the process of solving equations (1)–(3) can be detached from the rest of the SAMR technique, so that it is possible to experiment with a number of different methods. The restrictions are that the method should be flux-conservative, or at least produce an accurate estimate of the flux of conserved quantities at cell interfaces. This is required in the flux-correction step (see 3.4). There is also the issue of centering, which refers to the position of physical quantities within a cell (the primary types are cell-centered, face-centered, and node-centered). The interpolation step, described in Section 3.1, must correctly interpolate with the selected centering.

3.3. Projection Since a refined region is simulated with (at least) two different resolutions (one fine and one coarse), it has two or more “solutions” (i.e. values of density, velocity, etc.) that represent the same volume of space. This is one important aspect of the SAMR method – some physical regions are represented by grids at multiple resolutions. To maintain consistency, the coarse grid quantities are updated with the finer values, using a volume-weighted average of the conserved quantities:

qcoarse^ = r−d^

q i,j,kfine (26)

where r is the refinement factor, and the sum is over all fine cells that “cover” the coarse cell. The exponent, d, refers to the weight of the average. For cell-centered quantities, this is the dimensionality of the problem. For face-centered quantities, this is one less than the dimensionality, and for edge-centered quantities this is one.

3.4. Flux correction One of the significant advantages of flux-conservative methods is, of course, their ability to maintain conserved quantities to machine precision. Unfortunately, the projection step upsets this flux conservation since, at the boundary of a refined region, the coarse and fine cells on either side of the border are updated with different estimates of the flux across the boundary. At one refinement level this comes from the coarse grid computation, and in the other from the fine grid solution. Conservation can be restored by correcting all coarse cells that lie outside the boundary of a fine region with the difference between the coarse and fine estimates of the flux across the boundary:

(^22) We could, in principle, build a multi-dimensional interpolator out of a one-dimensional interpolation function; however, at higher order, this would not necessarily satisfy our constraint regarding not introducing new extrema in interpolated quantities.

  1. Jeans length. Following Truelove et al. (1998), the code can be forced to refine the Jeans length by a fixed number of cells, or, more specifically, whenever the following criterion is not met:

∆x <

πkB T N (^) J^2 GρmH

where JJ is the required number of cells per Jeans length (4 by default).

  1. Cooling time. Often in cosmological simulations, cooling is a rapid process and we do not necessarily want to be limited by the cooling time. However, in some cases it is desirable to resolve the cooling process, in which case we flag cells that have a cooling time shorter than their sound crossing time. The cooling time is given by tcool = 1. 5 kBT /(n Λ(T )) and the sound crossing time is tcross = ∆x/cs, where cs is the sound speed.
  2. Must-refine particles. In order to allow for refinement in moving regions, it is possible to generate “must-refine” particles that ensure local refinement of the 8 nearest cells to a specific level. The particles feel gravitational forces and their trajectories are followed as for any other collisionless particle. This feature can be used to ensure that a specific Lagrangian region stays refined to a specified level of resolution.
  3. Shear. As described in Kritsuk et al. (2006), turbulence calculations can be successfully modeled with AMR if the shear is used as a refinement parameter; in particular, refinement occurs when the finite difference version of the following inequality holds:

i

j

∂vi ∂xj

i

∂vi ∂xi

ǫs

c^2 s ∆x^2

where ǫs is a dimensionless parameter.

  1. Optical depth. This refinement criterion, typically used for simulations using radiation transport, flags cells for refinement if they have an H I optical depth lower than unity. The optical depth of a cell is estimated to be:

τ = σHInHI∆x (31)

where σHI is the neutral atomic hydrogen absorption cross section, nHI is the proper H I number density, and ∆x is the cell width (which is assumed to be the same along each axis). If τ > 1, the cell is refined further, up to the maximum level of refinement.

  1. Resistive length. In a way similar to the Jeans length criterion described above, the code can be forced to locally resolve the resistive length scale by a minimum of a fixed number of cells. This is done by ensuring that the resistive length scale, defined as

LR = |B|/|∇ × B| (32)

is always refined by at least NR cells locally (i.e. we refine a given cell further if LR ≤ NR∆x). Note that Enzo does not actually solve the resistive MHD equations – this is the “characteristic” local resistive length, rather than one calculated within the MHD solver.

  1. Must refine region. This refinement criterion is used to ensure that all cells in a given subvolume of the simulation are refined to at least some minimum level of refinement. The subvolume is user-specified, and may evolve over time (e.g., to follow a structure of interest that is traveling through the simulation volume).
  2. Metallicity. This refinement criterion ensures that all cells with a metallicity (defined as Z ≡ ρZ /ρb/ 0 .022, where ρZ is the density of metals in the cell, ρb is the total baryon density (including metals), and 0.022 is the solar mass fraction of metals) above a user-defined value is refined to at least some minimum level of refinement.
  3. Second Derivative. This is similar to the refinement criteria used in Paramesh and was originally developed by Loehner et al. (1987). This method calculates the second derivative of a user-defined field normalized by the first derivative, and sets a threshold for refinement. More background information can be found in the FLASH user guide^23 , but we reproduce the relevant equation here for completeness. The multi-dimensional version of the criteria takes in to account all cross-derivatives, and is expressed by

(^23) http://flash.uchicago.edu/site/flashcode/user_support/flash4_ug/

S =

ij

∂^2 f ∂xi∂xj

ij

[

1 2∆xj

∣ (^) ∂x∂fi

xi+∆xi

∣ (^) ∂x∂fi

xi−∆xi

  • ǫ |^

f¯ij | ∆xi∆xj

] 2

1 / 2

where f is the user-defined field,

∣ (^) f¯ij

∣ (^) is an average of f over cells in the i and j dimensions, and ǫ is a user- controlled value that provides a method of ignoring small fluctuations, set by default to 10−^2. If S is larger than a specified threshold (bounded by [0,1]) a cell is marked for refinement. This threshold is chosen at runtime and can vary for each of the fields under consideration.

Finally, it is also possible to specify a rectangular region that is statically refined to a certain level. These static refined regions are in place throughout the simulation regardless of the grid quantities and can be used for testing purposes, or for multiply-zoomed initial conditions (in cosmology simulations, for example) that would not otherwise be refined.

  1. FLUID METHODS In this section, we describe the four solvers that we have implemented for solving the fluid equations. We describe the PPM method in considerably more detail than the other methods in part because its implementation in Enzo has not previously been described, but mostly because it introduces many of the ideas and methods used for the MUSCL-Dedner and MHDCT schemes (including expansion terms, reconstruction, Riemann solvers, and dual energy formalism).

4.1. Hydrodynamics: The PPM method One (purely) hydrodynamic method used in Enzo is closely based on the piecewise parabolic method (PPM) of Colella & Woodward (1984) – henceforth referred to as CW84 – which has been modified for the study of cosmological fluid flows. CW84 describe two variants on this method: Lagrangian Remap and Direct Eulerian. We use the Direct Eulerian version in Enzo, which is better suited for AMR simulations. The Lagrangian Remap version has previously been adapted for cosmological use as described in Bryan et al. (1995), and the implementation we use here is closely based on that work. The first term on the right hand side of equations (2) and (3) comes from our choice of comoving coordinates (a similar term also appears in equation (18), the velocity relation for the dark matter particles). A similar term does not appear in the mass conservation equation (1) because of the comoving density definition. We note that these expansion terms could be eliminated entirely by the proper choice of variables (including time), although we have not done so here as they do not constitute a major source of error. We solve these terms using the same technique – they are split from the rest of the terms and solved using an (implicit) time-centered method, which is straightforward as there are no spatial gradients. Note that we use this method for all four of the hydro solvers. The remainder of the terms in the fluid equations involve derivatives. Because we are interested in phenomena with no special geometry, we will restrict discussion to Cartesian coordinates. We can dimensionally split the equations and rewrite the one-dimensional (Eulerian) versions of equations (1)–(3) without expansion terms in conservative form as,

∂ρ ∂t

a

∂ρv ∂x

∂ρv ∂t

a

∂ρv^2 ∂x

a

∂p ∂x

= ρ

g a

∂ρE ∂t

a

∂ρvE ∂x

= ρv

g a

Here x and v refer to the one dimensional comoving position and peculiar velocity of the baryonic gas, and g is the acceleration at the cell center. These equations are now in a form that can be solved by the split PPM scheme. We now restrict ourselves to the solution of equations (34)–(36) in one dimension. In the Direct Eulerian version of PPM, this is accomplished by a three-step process. First, we compute effective left and right states at each grid boundary by constructing a piecewise parabolic description of the primative variables (ρ, u and E) and then averaging over the regions corresponding to the distance each characteristic wave can travel (u, u − cs and u + cs, where cs is the sound speed). Second, a Riemann problem is solved using these effective left and right states, and finally the fluxes are computed based on the solution to this Riemann problem and the conserved quantities are updated. This is described in detail in CW84, but we will briefly outline the procedure here both for completeness and to put the changes we will make in context. The Eulerian difference equations are:

ρn j +1= ρnj + ∆t

ρj+1/ 2 vj+1/ 2 − ρj− 1 / 2 vj− 1 / 2 ∆xj

To overcome this, we also solve the internal energy equation: ∂e ∂t

a

v · ∇e = − 3

a˙ a

p ρ

p aρ

∇ · v (42)

in comoving coordinates. The structure is similar to the total energy equation; the second term on the left hand side represents transport, while the first term on the right is due to expansion of the coordinate system. It is differenced (again, in Eulerian form without the expansion term) as,

ρn j +1en j +1= ρnj enj + ∆t

ρj+1/ 2 vj+1/ 2 ej+1/ 2 − ρj− 1 / 2 vj− 1 / 2 ej− 1 / 2 ∆xj

− ∆t pnj

vj+1/ 2 − vj− 1 / 2 ∆xj

Note that because of the structure of this equation, it is not in flux-conservative form. In particular, the pressure is evaluated at the cell center. Unfortunately, time-centering of this pressure has proved difficult to do without generating large errors in the internal energy and so we leave the pressure at the old time in this difference equation. This leads to some spreading of shocks; however, we note that this equation is only used in hypersonic flows. It is necessary, however, to conserve the total energy so that the conversion of kinetic to thermal energy is performed properly. We must therefore combine the two formulations without allowing the separately-advected internal energy e to play a role in the gas dynamics. This is done by carrying both terms through the simulation and using the total energy E for hydrodynamic routines and the internal energy e when the temperature profile is required. One way to view this procedure is to treat e as enhanced precision (extra digits) for E that automatically ‘floats’ to where it is needed. We only require that they be kept synchronized when the two levels of precision overlap. When the pressure is required solely for dynamic purposes, the selection criterion operates on a cell by cell basis using,

p =

ρ(γ − 1)(E − v^2 /2), (E − v^2 /2)/E > η 1 ; ρ(γ − 1)e, (E − v^2 /2)/E < η 1.

It should be stressed that as long as the parameter η 1 is small enough the dual energy method will have no dynamical effect. We use η 1 = 10−^3 , which is consistent with the truncation error of the scheme for grid sizes that are typically used in our simulations. We are now free to select the method by which the internal energy field variable e is updated so that it will not become contaminated with errors advected by the total energy formulation but still give the correct distribution in shocked regions. Since we are concerned with the advection of errors, the selection criterion must look at each cell’s local neighbourhood. In one dimension, this is done with,

e =

(E − v^2 /2), ρ(E − v^2 /2)/ max(ρj− 1 Ej− 1 , ρj Ej , ρj+1Ej+1) > η 2 , e, ρ(E − v^2 /2)/ max(ρj− 1 Ej− 1 , ρj Ej , ρj+1Ej+1) < η 2.

Thus, η 2 determines when the synchronization (of e with E) occurs. Too high a value may mask relatively weak shocks, while spurious heating (via contamination) may occur if it is set too low. After some experimentation, we have chosen η 2 = 0.1, a somewhat conservative value. This scheme is optional and is generally only required in large-scale cosmological simulations where the gas cools due to the expansion of the universe but large bulk flows develop due to the formation of structure. We note that others have independently developed a similar but distinct scheme for dealing with this problem, which is endemic to methods adopting the total energy equation. In Ryu et al. (1993), the two variables adopted are total energy and entropy (rather than total energy and thermal energy), with an analogous scheme for choosing which variable to employ.

4.1.2. Riemann Solvers and Fallback In this section, we describe the methods we adopt to solve the Riemann problem, which is generally required to compute the fluxes in any Godunov-based scheme. This section therefore applies to all three of our Godunov-based schemes. The Riemann problem we are solving involves two constant states separated by a single discontinuity at t = 0. The subsequent evolution has an exact analytic solution. This solution is described in detail in many texts on computational fluid dynamics (e.g., Toro 1997). In brief, there are three waves that propagate away from the initial discontinuity. The central wave, characterized by a density jump but not a pressure jump, is called the contact discontinuity. The waves traveling to the left and right of the contact discontinuity can be either shocks, if characteristics converge on the wave front, or rarefaction fans if characteristics diverge. While there exists an exact solution to this problem, finding it is expensive. There are four possible combination of left- and right- traveling shocks and rarefactions, only one of which is fully consistent with the initial conditions. Once the correct physical state is determined, the pressure in the central region can only be computed by finding the root to an algebraic equation, which is necessarily an iterative process. Thus a series of approximate Riemann solvers are typically used. There are four approximate Riemann solvers in Enzo: two-shock (Toro 1997), Harten-Lax-van Leer (HLL, Toro 1997), HLL with a contact discontinuity (HLLC, Toro 1997), and HLL with multiple discontinuities (HLLD, Miyoshi & Kusano 2005). Two-shock is used only with the PPM method. HLL and HLLC are used with PPM, MUSCL (both with and without MHD) and MHD-CT. HLLD is exclusively an MHD solver, and works with both the MUSCL and MHD-CT methods.

The only approximation that two-shock makes is that both left- and right-moving waves are shocks. This solution still requires an iterative method for finding the pressure in between the two waves. The HLL method alleviates this iteration by assuming that there is no central contact discontinuity, and the signal speed in the central region is approximated by an average over the left- and right- moving waves. This method is significantly faster than the two-shock method, but it is also quite a bit more dissipative. The HLLC is a three-wave method that improves upon the HLL method by also including the third wave, the contact discontinuity. For the MHD equations, there are seven waves instead of three. This makes the exact solution to the Riemann problem quite a bit more expensive. Both the HLL and HLLC approximations can be formulated for the MHD equations, and are employed in both the Dedner and CT solvers in Enzo. The HLLD solver includes two of the additional waves, the rotational discontinuities, making it a five-wave solver. On rare occasions, high-order solutions can cause negative densities or energies. Both our PPM and MUSCL solvers employ a Riemann solver fallback mechanism (Lemaster & Stone 2009). If a negative density is found at a particular interface, the more diffusive HLL Riemann solver is used to compute the fluxes associated with that cell, and the flux update is repeated.

4.2. Hydrodynamics and Magnetohydrodynamics: MUSCL with Dedner cleaning The second method we describe is a MUSCL-based solver than can be used in both HD and MHD modes. The description here will be very brief both because the ideas are similar to those described in the previous section, and because this implementation has previously been described in more detail elsewhere (Wang et al. 2008; Wang & Abel 2009a). Much like the PPM solver, we have three basic steps: the first is reconstruction of the variables, the second is a solution of the Riemann problem, and the third is is updating the conserved quanties with the fluxes as written above. For the reconstruction scheme we have implemented only the simple piecewise linear reconstruction (van Leer 1979; Colella & Glaz 1985), with options for both primitive and conservative variable reconstruction. The available Riemann solvers are HLL, HLLC, and HLLD, as described earlier. To more clearly describe the Dedner divergence cleaning modifications, we write the equations of compressible inviscid hydrodynamics in the form of conservation laws as,

∂U ∂t

∂F x ∂x

∂F y ∂y

∂F z ∂z

The conserved variable U is given by

U = (ρ, ρvx, ρvy , ρvz , ρE)T^ , (47)

where ρ is density, vi are the three components of velocity for i = x, y, z, E = v^2 /2 + e denotes the specific total energy and e the specific internal energy (note that in this section only, we use the specific energy). For the generalized Lagrange multiplier (GLM) formulation of the MHD equations (Dedner et al. 2002), we consider these conserved variables

U = (ρ, ρvx, ρvy , ρvz , ρE + B^2 / 2 , Bx, By , Bz , ψ)T^ , (48)

where Bi with i = x, y, z are the three components of magnetic fields and ψ is the additional scalar field introduced in the GLM formulation for the divergence cleaning. The fluxes then are

F x^ = (ρvx, ρv x^2 + p + B^2 / 2 − B^2 x, ρvy vx − By Bx,

ρvz vx − Bz Bx, ρ(

v^2 2

  • h)vx + B^2 vx − BxB · v,

ψ, vxBy − vy Bx, −vz Bx + vxBz , c^2 hBx)T^ , (49) F y^ = (ρvy , ρvxvy − BxBy , ρv y^2 + p + B^2 / 2 − B^2 y ,

ρvz vy − Bz By , ρ(

v^2 2

  • h)vy + B^2 vy − By B · v,

vy Bz − vz By , ψ, −vxBy + vy Bx, c^2 hBy )T^ , (50) F z^ = (ρvz , ρvxvz − BxBz , ρvy vz − By Bz , ρv^2 z + p + B^2 / 2 − B z^2 ,

ρ(

v^2 2

  • h)vz + B^2 vz − Bz B · v,

−vy Bz + vz By , vz Bx − vxBz , ψ, c^2 hBz )T^ , (51)

where ch is a constant controlling the propagation speed and damping rate of ∇ · B, and h = e + p/ρ denotes the specific enthalpy. All quantities are cell-centered. The method is dimensionally un-split in that the fluxes are computed for all dimensions first and the conserved quantities are updated in one step, in contrast to the Strang splitting employed in the other fluid methods described

times the cell spacing. In our Cartesian coordinate system, the finite difference version of these equations is particularly simple, although there is one important complication. In the ZEUS formalism, the velocity is a face-centered quantity – that is, the velocity is recorded on a grid that is staggered as compared to the density, pressure and energy, which are at the cell center. Therefore we must remember that vj is at position xj− 1 / 2 (we use this notation, rather than writing vj+1/ 2 both to match the original ZEUS paper and also to make it easier to compare these equations to what is actually in the code). As in the original ZEUS paper, the source terms are added in three steps. First we add the pressure and gravity forces:

vnj +a= vnj −

∆t ∆xj

pnj − pnj− 1 (ρnj + ρnj− 1 )/ 2

Partial updates are denoted by the n + a, n + b notation. We show updates in one dimension as the extension to the multi-dimensional case is straightforward (note that all dimensions are carried out for each substep before progressing to the next substep). We then add the artificial viscosity:

vjn +b= vjn +a−

∆t ∆xj

qjn +a− qjn−+ 1 a (ρnj + ρnj− 1 )/ 2

enj +b= enj −

∆t ∆xj

qnj +a(vnj+1+a − vnj +a). (56)

The artificial viscosity coefficient qj is given by:

qj =

QAVρj (vj+1 − vj )^2 if (vj+1 − vj) < 0 0 otherwise (57)

where QAV is a constant with a typical value of 2. We refer the interested reader to Stone & Norman (1992a) and Anninos & Norman (1994) for more details. We also include the option (turned off by default) of adding a linear artificial viscosity as suggested in the ZEUS paper for stagnant flow regions. This is given by

qlin,j = QLINρcj (vj+1 − vj ) (58)

where c^2 j = γp/ρ is the adiabatic sounds speed. Finally, the third source step is the compression term and is given by

enj +c= enj+b

1 − (∆t/2)(γ − 1)(∇ · v)j 1 + (∆t/2)(γ − 1)(∇ · v)j

We have used the notation (∇ · v)j to indicate the (potentially) multi-dimensional velocity divergence evaluated at the cell center position xj. This equation differs from the previous ones in that in the multi-dimensional case, still only one finite difference equation is evaluated, but the divergence becomes multi-dimensional. We next examine the transport step, which is conservative. Once again, we dimensionally split the equations and present only the one-dimensional version. The finite difference equations actually solved are:

ρnj +d= ρnj −

∆t ∆x

(vnj+1+c/ 2 ρ∗ j+1/ 2 − vnj−+ 1 c/ 2 ρ∗ j− 1 / 2 ) (60)

Here ρ∗ j is the correctly upwinded value of ρ evaluated at the cell-face corresponding to vj , making ρ∗ j vj the mass flux at the cell boundary and guaranteeing mass conservation. This requires interpolating each cell-centered quantity to the cell edge. As recommended in Stone & Norman (1992a), we use the second-order van Leer scheme, which uses piecewise linear functions. These are given by Equations (48) and (49) of Stone & Norman (1992a). The transport steps for the other variables are similar. Note that we advect the specific energy and specific momenta using the mass flux, as dictated by the principle of consistent transport. This requires appropriate averaging for the momenta in the perpendicular directions as outlined in equations (57)-(72) of Stone & Norman (1992a). A limitation of a technique that uses an artificial viscosity is that, while the correct Rankine-Hugoniot jump condi- tions are achieved, shocks are broadened over 3-4 mesh cells. This may cause unphysical pre-heating of gas upstream of the shock wave, as discussed in Anninos & Norman (1994). On the other hand, it is much more robust than PPM and is easy to add additional physics. We also note that this method solves only the internal energy equation rather than total energy, so the dual energy formulation discussed in Section 4.1 is unnecessary.

  1. GRAVITY AND N-BODY 5.1. Gravity Solving for the accelerations of the cells and particles on the grid due to self-gravity involves three steps: (i) computing the total gravitating mass, (ii) solving for the gravitational potential field with the appropriate boundary conditions,

and (iii) differencing the potential to get the acceleration, and, if necessary, interpolating the acceleration back to the particles. These steps are described in detail below. First, the massive (dark matter and star) particles are distributed onto the grids using the second-order cloud-in-cell (CIC) interpolation technique (Hockney & Eastwood 1988) to form a spatially-discretized density field ρDM. During the CIC interpolation, particle positions are (temporarily) advanced by 0. 5 vn∆t so that we generate an estimate of the time-centered density field. Particles on subgrids within the grid’s volume are also added to its gravitating field using the same method. In addition, since the gravitating field for a grid is defined beyond the grid edges (see below), massive particles from sibling grids and sub grids that lie within the entire gravitating field are used. This step can involve communication. Next, we add the baryonic grid densities in a similar fashion. In particular, we treat baryonic cells as virtual CIC particles that are are placed at the grid center but are advanced by 0. 5 vn∆t in order to approximately time-center the gravitating mass field. Cells that are covered by further-refined grids are treated in a similar way (i.e., we also use the

subgrid cells as virtual CIC particles). This procedure results in a total gravitating mass field ρntotal+1/ 2. To compute the potential field from this gravitating mass field on the root grid, we use a a fast Fourier transform. For periodic boundary conditions, we can use either a simple Greens function kernel of −k−^2 , or the finite difference equivalent (Hockney & Eastwood 1988):

G(k) = −

∆x 2 (sin(kx∆x/2)^2 + sin(ky ∆y/2)^2 + sin(kz ∆z/2)^2 )

where k^2 = k^2 x + k y^2 + k^2 z is the wavenumber in Fourier space and the potential is calculated in k-space as usual with

φ˜(k) = G(k)˜ρ(k). For isolated boundary conditions, we use the James method (James 1977). In this case, the Greens function is generated in real-space so as to have the correct zero-padding properties and then transformed into the Fourier domain. In both cases, the potential is then transformed back into the real domain to get potential values at the cell centers. These are differenced with a two-point centered difference scheme to obtain accelerations at the cell centers (except if we are using the staggered ZEUS-like solver, in which case the accelerations are computed at the cell faces to match the velocities). Particle accelerations are obtained using a (linear) CIC interpolation from the grid. In order to calculate more accurate potentials on the subgrids, Enzo uses a similar but slightly different technique from the root grid. The generation of the total gravitating mass field is essentially identical, using CIC interpolation for both the particles and baryons, including subgrids as before. To compute the potential on subgrids, however, we use the standard seven-point (in three dimensions) second-order finite difference approximation to Poisson’s equation. Boundary conditions are then interpolated from the potential values on the parent grid. We use either tri-linear interpolation or a natural second-order spline for this: both methods give similar results, but the default is the tri- linear interpolation, which empirically provides a resonable compromise between speed and accuracy. The potential equation on each subgrid is then solved with the given Dirichlet boundary conditions with a multigrid relaxation technique. This is applied to each subgrid separately. The region immediately next to the boundary can contain unwanted oscillations (e.g., Anninos et al. 1994), and so we use an expanded buffer zone around the grid, of size three parent grid boundary zones (so typically six refined zones for a refinement factor of 2). The density is computed in this region and the potential solved, but only the region that overlaps with the active region of the grid itself is used to calculate accelerations. Simply interpolating the potential without feeding it back to higher levels leads to errors in the potential at more refined levels, due to the build-up of errors during the interpolation of coarse boundary values. In addition, neighboring subgrids are not guaranteed to generate the same potential values because of the lack of a coherent potential solve including the whole grid hierarchy. In an attempt to partially alleviate this problem, we allow for an iterative procedure across sibling grids, in which the potential values on the boundary of grids can be updated with the potential in ‘active’ regions of neighboring subgrids. To prevent overshoot, we average the potential on the boundary and allow for (by default) 4 iterations, with the number of iterations determined by a parameter specified at runtime. This procedure can help in many cases, but does not necessarily produce a coherent solution across all grids and so does not completely solve the problem; we are working on a slower but more accurate method that does a multigrid solve across the whole grid (Reynolds et al., in preparation). At this point it is useful to emphasize that the effective force resolution of an adaptive particle-mesh calculation is approximately twice as coarse as the grid spacing at a given level of resolution.

5.2. N-body Dynamics Enzo uses a particle-mesh N-body method to calculate the dynamics of collisionless systems (Hockney & Eastwood 1988). This method follows trajectories of a representative sample of individual particles that sample the phase space of the dark matter distribution, and is much more efficient than a direct solution of the Boltzmann equation in essentially all astrophysical situations for the levels of accuracy that are required for simulations of structure formation. As described earlier, the gravitational potential is computed by solving the elliptic Poisson’s equation (Eq. 8) and differencing the potential to find accelerations, which are then interpolated back to particles. This acceleration is time- centered (because the underlying gravitating mass field is approximately time-centered), and so we have accelerations gn+1/^2 for each particle. These are used to update the particle positions and velocities starting from xn^ and vn^ using