From 77514764f94ecd90e27c7322023904f80da43bb7 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Thu, 11 Jan 2024 14:38:52 -0500 Subject: [PATCH 1/2] change link to multigrid notebook (#182) we split up the old notebook, so this points to the basic example now --- README.md | 6 +++--- docs/source/multigrid_basics.rst | 2 +- docs/source/notes.rst | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4fe0b512b..b86f90abf 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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: diff --git a/docs/source/multigrid_basics.rst b/docs/source/multigrid_basics.rst index 81fff110c..1cb057c9a 100644 --- a/docs/source/multigrid_basics.rst +++ b/docs/source/multigrid_basics.rst @@ -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 `_ gives an introduction to solving elliptic equations, including multigrid. +of grids. Chapter 9 of the `pdf notes `_ gives an introduction to solving elliptic equations, including multigrid. There are three solvers: diff --git a/docs/source/notes.rst b/docs/source/notes.rst index 59640e862..a54cab07b 100644 --- a/docs/source/notes.rst +++ b/docs/source/notes.rst @@ -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 -`_, +`_, part of the `Open Astrophysics Bookshelf `_. From 2b227d9980a78833c0521091a6edab21a9d858c9 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Thu, 11 Jan 2024 14:39:46 -0500 Subject: [PATCH 2/2] some updates to the plotvar script (#178) we can now set dpi ghost cells are filled and vort is an allowed variable --- pyro/analysis/plotvar.py | 60 +++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/pyro/analysis/plotvar.py b/pyro/analysis/plotvar.py index b4cd4b4e1..6dce779ef 100755 --- a/pyro/analysis/plotvar.py +++ b/pyro/analysis/plotvar.py @@ -1,4 +1,9 @@ #!/usr/bin/env python3 +""" +plot a single variable from an output file + +Usage: ./plotvar.py filename variable +""" import argparse @@ -8,16 +13,13 @@ 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 @@ -25,29 +27,45 @@ def makeplot(plotfile, variable, outfile, 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() @@ -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", @@ -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, @@ -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)