Skip to content

Commit

Permalink
Merge branch 'main' into zingale-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
zingale authored Jan 21, 2024
2 parents a691feb + 2b227d9 commit ec754bb
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 24 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ on the grid are described in a jupyter notebook:
https://github.com/python-hydro/pyro2/blob/main/pyro/mesh/mesh-examples.ipynb
Many of the methods here rely on multigrid. The multigrid solver is
Many of the methods here rely on multigrid. The basic multigrid solver is
demonstrated in the juputer notebook:
https://github.com/python-hydro/pyro2/blob/main/pyro/multigrid/multigrid-examples.ipynb
https://github.com/python-hydro/pyro2/blob/main/pyro/multigrid/multigrid-constant-coefficients.ipynb
## Solvers
Expand Down Expand Up @@ -251,7 +251,7 @@ with their data.
There is a set of notes that describe the background and details of the
algorithms that pyro implements:
http://bender.astro.sunysb.edu/hydro_by_example/CompHydroTutorial.pdf
http://open-astrophysics-bookshelf.github.io/numerical_exercises/
The source for these notes is also available on github:
Expand Down
2 changes: 1 addition & 1 deletion docs/source/multigrid_basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Multigrid Class Overview
pyro solves elliptic problems (like Laplace's equation or Poisson's
equation) through multigrid. This accelerates the convergence of
simple relaxation by moving the solution down and up through a series
of grids. Chapter 9 of the `pdf notes <http://bender.astro.sunysb.edu/hydro_by_example/CompHydroTutorial.pdf>`_ gives an introduction to solving elliptic equations, including multigrid.
of grids. Chapter 9 of the `pdf notes <http://open-astrophysics-bookshelf.github.io/numerical_exercises/CompHydroTutorial.pdf>`_ gives an introduction to solving elliptic equations, including multigrid.

There are three solvers:

Expand Down
2 changes: 1 addition & 1 deletion docs/source/notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Notes on the numerical methods
Detailed discussions and derivations of the numerical methods used in
pyro are given in the set of notes `Introduction to Computational
Astrophysical Hydrodynamics
<http://bender.astro.sunysb.edu/hydro_by_example/CompHydroTutorial.pdf>`_,
<http://open-astrophysics-bookshelf.github.io/numerical_exercises/CompHydroTutorial.pdf>`_,
part of the `Open Astrophysics Bookshelf
<https://github.com/Open-Astrophysics-Bookshelf>`_.

60 changes: 41 additions & 19 deletions pyro/analysis/plotvar.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#!/usr/bin/env python3
"""
plot a single variable from an output file
Usage: ./plotvar.py filename variable
"""

import argparse

Expand All @@ -8,46 +13,59 @@
import pyro.util.io_pyro as io
from pyro.mesh import patch

# plot a single variable from an output file
#
# Usage: ./plotvar.py filename variable


def makeplot(plotfile, variable, outfile,
width=6.5, height=5.25,
width=6.5, height=5.25, dpi=100, notitle=False,
log=False, compact=False, quiet=False):

sim = io.read(plotfile)
sim.cc_data.fill_BC_all()

if isinstance(sim, patch.CellCenterData2d):
myd = sim
else:
myd = sim.cc_data
myg = myd.grid

plt.figure(num=1, figsize=(width, height), dpi=100, facecolor='w')
fig = plt.figure(num=1, figsize=(width, height), dpi=100, facecolor='w')
ax = fig.add_subplot(111)

if variable == "vort":
vx = myd.get_var("x-velocity")
vy = myd.get_var("y-velocity")

var = myg.scratch_array()

var = myd.get_var(variable)
var[myg.ilo:myg.ihi+1, myg.jlo:myg.jhi+1] = \
0.5*(vy[myg.ilo+1:myg.ihi+2, myg.jlo:myg.jhi+1] -
vy[myg.ilo-1:myg.ihi, myg.jlo:myg.jhi+1])/myg.dx - \
0.5*(vx[myg.ilo:myg.ihi+1, myg.jlo+1:myg.jhi+2] -
vx[myg.ilo:myg.ihi+1, myg.jlo-1:myg.jhi])/myg.dy

else:
var = myd.get_var(variable)

if log:
var = np.log10(var)

img = plt.imshow(np.transpose(var.v()),
interpolation="nearest", origin="lower",
extent=[myg.xmin, myg.xmax, myg.ymin, myg.ymax])
img = ax.imshow(np.transpose(var.v()),
interpolation="nearest", origin="lower",
extent=[myg.xmin, myg.xmax, myg.ymin, myg.ymax])

if not compact:
plt.colorbar(img)

plt.xlabel("x")
plt.ylabel("y")
fig.colorbar(img)
if not notitle:
fig.suptitle(f"{variable}")
ax.set_xlabel("x")
ax.set_ylabel("y")

if compact:
plt.axis("off")
plt.subplots_adjust(bottom=0.0, top=1.0, left=0.0, right=1.0)
plt.savefig(outfile)
ax.axis("off")
fig.subplots_adjust(bottom=0.0, top=1.0, left=0.0, right=1.0)
fig.savefig(outfile, bbox_inches="tight")
else:
plt.savefig(outfile, bbox_inches="tight")
fig.tight_layout()
fig.savefig(outfile, bbox_inches="tight", dpi=dpi)

if not quiet:
plt.show()
Expand All @@ -61,6 +79,8 @@ def get_args():
metavar="plot.png", help="output file name")
parser.add_argument("--log", action="store_true",
help="plot log of variable")
parser.add_argument("--notitle", action="store_true",
help="suppress the title at the top of the figure")
parser.add_argument("--compact", action="store_true",
help="remove axes and border")
parser.add_argument("--quiet", action="store_true",
Expand All @@ -69,6 +89,8 @@ def get_args():
metavar="width", help="plot width (inches)")
parser.add_argument("-H", type=float, default=5.25,
metavar="height", help="plot height (inches)")
parser.add_argument("--dpi", type=int, default=100,
metavar="dpi", help="dots per inch")
parser.add_argument("plotfile", type=str, nargs=1,
help="the plotfile you wish to plot")
parser.add_argument("variable", type=str, nargs=1,
Expand All @@ -82,5 +104,5 @@ def get_args():
args = get_args()

makeplot(args.plotfile[0], args.variable[0], args.o,
width=args.W, height=args.H,
width=args.W, height=args.H, dpi=args.dpi, notitle=args.notitle,
log=args.log, compact=args.compact, quiet=args.quiet)

0 comments on commit ec754bb

Please sign in to comment.