2.4Going further
15
We implement boundary conditions by extending the computational grid beyond
the physical domain. These additional zones are called ghost cells. They exist solely
to handle the boundary conditions and allow us to use the same update equ
22
Chapter 3. Advection
1.0
C =0.5
C =1.0
C =10.0
0.8
exact
a
0.6
0.4
0.2
0.0
0.0
0.2
0.4
x
0.6
0.8
1.0
Figure 3.3: Finite-difference solution to the implicit rst-order nite-difference upwind method for advection, using 65 points and a variety of CFL numb
12
Chapter 2. Finite-Volume Grids
fi
2
1
i
i
+1
i
+2
i
i
i
+1
i
+2
i
+1
i
+2
x
fi
2
1
i
i
i
x
f
2
1
i
i
1/2
i
i
i
i
+1/2
x
Figure 2.2: Different types of structured grids. Top: a nite-difference gridthe
discrete data are associated with a specic point in
16
Chapter 2. Finite-Volume Grids
Figure 2.5: Domain decomposition of the computational domain into 6 separate
sub-domains. Each sub-domain here has 5 5 zones. For one of the sub-domains,
the perimeter of ghost cells is illustrated as the red boundary.
V
10.5Atmospheric ows
125
with an initial condition of
p0 jlo =
10.5.2
1
Nx
pinitial
i,jlo
(10.35)
i
Equation Set
The compressible momentum equation (written in terms of velocity is):
U
+ U U + p = g
(10.36)
t
Subtracting off the base state, and dening the
2
Chapter 1. Simulation Overview
There is no uber-code. Every algorithm begins with approximations and has
limitations. Comparisons between different codes are important and common in
our eld, and build condence in the results that we are on the right tra
3.2Second-order advection in 1-d and the nite-volume method
i
2
i
1
i
i +1
i +2
i
2
i
1
i
i +1
i +2
i
2
i
1
i
i +1
i +2
i
2
i
1
i
i +1
i +2
i
2
i
1
i
i +1
i +2
i
2
i
1
i
i +1
27
i +2
Figure 3.8: Initially discontinuous data evolved for several steps with
92
Chapter 7. Diffusion
This time-discretization is called Crank-Nicolson. Again, using kt/x2 , and
grouping all the n + 1 terms on the left we have:
n
2in + in 1
(7.20)
in+1
in+1 2in+1 + in+1 = in +
+1
1
2
2 i +1
and grouping together the the n + 1 te
5.8Going further
73
(here we use an overline to indicate limiting).
This is attractive because it is more in the spirit of the linear advection equation and the formalism that was developed there. A potential downside
is that when you limit on the charact
80
Chapter 6. Multigrid and Elliptic Equations
1.0
N=1
N = 10
N = 100
N = 1000
0.8
0.6
0.4
0.2
0.0
0.0
0.2
0.2
0.4
0.6
0.8
1.0
0.4
0.6
0.8
Figure 6.3: Error in the solution to = 0 given an initial guess with 3 different
wavenumbers of noise. The different
10.4Combustion
123
10-2
error
10-3
10-4
10-5
10-6 1
10
102
N
103
Figure 10.2:
Convergence of the variable-coefcient multigrid solver for
the test problem dened in Eq. 10.25.
This test can be run with pyro
multigrid/mg vc periodic test.py.
10.4
Combustion
2.3Finite-volume grids
13
a
1 i1/2
i
i
i
i +1/2
i +1
Figure 2.3: A simple 1-d nite-volume grid with the zone-centered and zone-edge
indexes. Here we show only the data associated with zone i.
Exercise 2.2: A conservative interpolant is used to reconstruct
126
Chapter 10. Low Mach Number Methods
MAC Projection
For the MAC projection, we have edge-centered velocities (in their respective coordinate direction). We dene an edge-centered 0 as
0 j+1/2 =
1
( 0 j + 0 j +1 )
2
(10.44)
and then the divergence term
18
Chapter 3. Advection
ai
1
0
1
i
1
x
i
i
+1
N
2
N
1
N
Figure 3.1: A simple nite-difference grid. The solution is stored at each of the
labeled points. The dotted lines show the ghost points used to extend our grid past
the physical boundaries to accommo
100
Chapter 8. Multiphysics Applications
1.6
=0.005000
=0.000500
=0.000050
1.4
1.2
1.0
0.8
0.6
0.4
0.0
0.2
0.4
0.6
0.8
1.0
Figure 8.2: Solution to the viscous Burgers equation with a variety of different
viscosities. The initial conditions was a single
6
Chapter 1. Simulation Overview
y
n
n
t
y
analytic solution
half-dt k1 step
slope
n
t
+1
y
n
n
t
analytic solution
half-dt k1 step
slope
half-dt k2 step
full-dt k3 step
n
y
analytic solution
half-dt k1 step
slope
half-dt k2 step
n
t
+1
analytic solution
3.2Second-order advection in 1-d and the nite-volume method
21
1, then the coefcient of the diffusion is negativethis is unphysical. This
means that the diffusion would act to take smooth features and make them
more strongly peakedthe opposite of physical
7.4Implicit multi-dimensional diffusion via multigrid
implicit diffusion, N = 128, C = 0.80
1.7
t =0.00038147
1.6
1.5
s
s
s
t =0.00152588 s
t =0.00305176 s
t =0.000190735
t =0.00038147
1.6
t =0.000762939
1.5
1.4
1.4
implicit diffusion, N = 128, C = 8.00
1
3.2Second-order advection in 1-d and the nite-volume method
2
i
1
i
i
i +1
29
i +2
Figure 3.10: A nite-volume grid showing the cell averages (gray horizontal lines),
unlimited center-difference slopes (blue) and MC limited slopes (red). Note that in
zones
2.3Finite-volume grids
11
tions.
Consider the set of grids show in Figure 2.2. On the top is a class nite-difference
grid. The discrete data, f i , are stored as points regularly spaced in x. With this
discretization, the spatial locations of the points a
138
BIBLIOGRAPHY
[41] V. Springel. E pur si muove: Galilean-invariant cosmological hydrodynamical simulations on a moving mesh. 401:791851, January 2010.
[42] J. M. Stone, T. A. Gardiner, P. Teuben, J. F. Hawley, and J. B. Simon. Athena: A
New Code for As
24
Chapter 3. Advection
A suitable estimate is needed for the slope of a that appears in these expressions
(as a/x). We can approximate this simply as
a
x
=
i
a i +1 a i 1
2x
(3.20)
We can think of this method as reconstructing the function form of the da
Chapter
1
Simulation Overview
1.1
What Is Simulation?
Astronomy is an observational science. Unlike in terrestrial physics, we do not
have the luxury of being able to build a model system and do physical experimentation on it to understand the core physic
9.3Cell-centered approximate projection solver
111
discretizing the advective terms (U U). We express the advective terms for u as
(u),n+1/2
(v),n+1/2
Ai,j
and those for v as Ai,j
. These have the form:
(u),n+1/2
Ai,j
(v),n+1/2
Ai,j
=
=
+1/2
+1/2
uin+1/2,
More details on the codes available in hydro examples are described in Appendix A.
2. The pyro code is a 2-d simulation code that has solvers for advection, diffusion, compressible and incompressible hydrodynamcs, as well as multigrid.
Low Mach solvers ar