<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Introduction to Pyro
Michael Zingale, Alice Harpole
Stony Brook University
Why pyro?
Python is a good introductory language&mdash;it helps make the way these algorithms work clearer
High level introduction to core hydro algorithms for students
Supplemented with extensive notes deriving the methods ( https
Step1:  Grids
Step2:  Data is stored as an ArrayIndexer object, which makes it easy to implement differencing on the entire array.
To implement
Step3:  Running
Each solver has a collection of problem setups (initial conditions) and inputs files
Commandline
Step4:  Example
Step5:  Example
<ASSISTANT_TASK:>
Python Code:
import mesh.patch as patch
import mesh.boundary as bnd
import numpy as np
g = patch.Grid2d(16, 16, ng=2)
print(g)
bc = bnd.BC(xlb="periodic", xrb="periodic", ylb="reflect", yrb="outflow")
print(bc)
d = patch.CellCenterData2d(g)
d.register_var("a", bc)
d.create()
print(d)
Explanation: Introduction to Pyro
Michael Zingale, Alice Harpole
Stony Brook University
Why pyro?
Python is a good introductory language&mdash;it helps make the way these algorithms work clearer
High level introduction to core hydro algorithms for students
Supplemented with extensive notes deriving the methods ( https://github.com/Open-Astrophysics-Bookshelf/numerical_exercises)
Enables easy ability to rapidly prototype code&mdash;core intrastructure is in place
Allows for sharing exploration in Jupyter notebooks
Design ideas:
Clarity is emphasized over performance
Single driver implements core evolution
Object-oriented structure: each solver provides a simulation class to manage the different parts of the update
All solvers are 2-d: right balance of complexity and usefulness
Realtime visualization when run in commandline mode
History:
First version in 2003: python + Numeric + C extensions
May 2004: switch to python + numarray + C extensions
cvs commit:
convert from Numeric to numarray, since numarray seems to be the future.
May 2012: revived, rewritten in python + NumPy + f2py
Nov 2018: python + NumPy + Numba
Our usage
We start new undergraduate researchers out with pyro to learn about simulation workflows
Typically have UG add a new problem setup
Current Solvers
linear advection: 2nd and 4th order FV, WENO; CTU, RK, and SDC time integration
compressible hydrodynamics: 2nd order CTU PLM, 2nd order MOL RK, 4th order FV solver with RK or SDC integration
shallow water hydrodynamics
multigrid: force non-constant coefficient general elliptic equations
implicit thermal diffusion: using multigrid
incompressible hydrodynamics: 2nd order accurate approximate projection method
low Mach number atmospheric hydrodynamics: pseudo-imcompressible method
special relativistic compressible hydrodynamics
Main driver:
parse runtime parameters
setup the grid
initialize the data for the desired problem
do any necessary pre-evolution initialization
evolve while t < tmax and n < max_steps
fill boundary conditions
get the timestep
evolve for a single timestep
t = t + dt
output
visualization
clean-up
<div class="alert alert-block alert-info">
&nbsp;This driver is flexible enough for all of the time-dependent solvers
</div>
Grids
patch module manages grids and data that lives on them
Fills boundaries, does prolongation/restriction for multigrid
Many convenience functions
End of explanation
a = d.get_var("a")
Explanation: Grids
End of explanation
b = g.scratch_array()
b.v()[:,:] = (a.ip(1) - a.ip(-1))/(2.0*a.g.dx)
Explanation: Data is stored as an ArrayIndexer object, which makes it easy to implement differencing on the entire array.
To implement:
$$ b = \frac{a_{i+1,j} - a_{i-1,j}}{2 \Delta x}$$
End of explanation
from pyro import Pyro
pyro_sim = Pyro("advection")
pyro_sim.initialize_problem("tophat", "inputs.tophat",
                            other_commands=["mesh.nx=8", "mesh.ny=8",
                                            "vis.dovis=0"])
pyro_sim.run_sim()
Explanation: Running
Each solver has a collection of problem setups (initial conditions) and inputs files
Commandline:
./pyro.py solver problem inputs
Jupyter: all functionality accessible through Pyro class.
Example: advection
End of explanation
dens = pyro_sim.get_var("density")
dens.pretty_print(show_ghost=True, fmt="%6.2f")
Explanation: Example: advection
End of explanation
pyro_sim.sim.dovis()
Explanation: Example: advection
End of explanation
<END_TASK>