def simplegrid(): nzones = 7 gr = gpu.grid(nzones, xmin=0, xmax=1) gpu.drawGrid(gr, edgeTicks=0) # label a few cell-centers gpu.labelCenter(gr, nzones/2, r"$i$") gpu.labelCenter(gr, nzones/2-1, r"$i-1$") gpu.labelCenter(gr, nzones/2+1, r"$i+1$") # label a few edges gpu.labelEdge(gr, nzones/2, r"$i-1/2$") gpu.labelEdge(gr, nzones/2+1, r"$i+1/2$") # draw an average quantity gpu.drawCellAvg(gr, nzones/2, 0.4, color="r") gpu.labelCellAvg(gr, nzones/2, 0.4, r"$\,\langle a \rangle_i$", color="r") pylab.axis([gr.xmin-1.5*gr.dx,gr.xmax+1.5*gr.dx, -0.25, 1.5]) pylab.axis("off") pylab.subplots_adjust(left=0.05,right=0.95,bottom=0.05,top=0.95) f = pylab.gcf() f.set_size_inches(10.0,2.5) pylab.savefig("simplegrid2.png") pylab.savefig("simplegrid2.eps")
def simplegrid(): # grid info nzones = 7 ng = 1 gr = gpu.grid(nzones, ng, xmin=0.0, xmax=1.0) gpu.drawGrid(gr, emphasizeEnd=1, edgeTicks=0, drawGhost=1) # label a few gpu.labelCenter(gr, ng + nzones / 2, r"$i$") gpu.labelCenter(gr, ng + nzones / 2 - 1, r"$i-1$") gpu.labelCenter(gr, ng + nzones / 2 + 1, r"$i+1$") gpu.labelCenter(gr, ng - 1, r"$\mathrm{lo}-1$") gpu.labelCenter(gr, ng, r"$\mathrm{lo}$") gpu.labelCenter(gr, ng + nzones - 1, r"$\mathrm{hi}$") gpu.labelCenter(gr, ng + nzones, r"$\mathrm{hi+1}$") # label dx pylab.plot([gr.xl[ng + nzones / 2 - 2], gr.xl[ng + nzones / 2 - 2]], [-0.35, -0.25], color="k") pylab.plot([gr.xr[ng + nzones / 2 - 2], gr.xr[ng + nzones / 2 - 2]], [-0.35, -0.25], color="k") pylab.plot([gr.xl[ng + nzones / 2 - 2], gr.xr[ng + nzones / 2 - 2]], [-0.3, -0.3], color="k") pylab.text(gr.xc[ng + nzones / 2 - 2], -0.5, r"$\Delta x$", horizontalalignment="center") pylab.xlim(gr.xl[0] - 0.5 * gr.dx, gr.xr[2 * ng + nzones - 1] + 0.5 * gr.dx) pylab.ylim(-0.5, 1.5) pylab.axis("off") pylab.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=0.95) f = pylab.gcf() f.set_size_inches(10.0, 2.5) pylab.savefig("simplegrid_gc.png") pylab.savefig("simplegrid_gc.eps")
def riemann(): # grid info xmin = 0.0 xmax = 1.0 nzones = 1 ng = 0 gr = gpu.grid(nzones, xmin=xmin, xmax=xmax) #------------------------------------------------------------------------ # plot a domain without ghostcells gpu.drawGrid(gr) gpu.labelCenter(gr, 0, r"$i$") gpu.labelCellCenter(gr, 0, r"$q_i$") gpu.markCellLeftState(gr, 0, r"$q_{i-1/2,R}^{n+1/2}$", color="r") gpu.markCellRightState(gr, 0, r"$q_{i+1/2,L}^{n+1/2}$", color="r") pylab.arrow(gr.xc[0]-0.05*gr.dx, 0.5, -0.13*gr.dx, 0, shape='full', head_width=0.075, head_length=0.05, lw=1, width=0.01, edgecolor="none", facecolor="r", length_includes_head=True, zorder=100) pylab.arrow(gr.xc[0]+0.05*gr.dx, 0.5, 0.13*gr.dx, 0, shape='full', head_width=0.075, head_length=0.05, lw=1, width=0.01, edgecolor="none", facecolor="r", length_includes_head=True, zorder=100) pylab.xlim(gr.xl[0]-0.25*gr.dx,gr.xr[2*ng+nzones-1]+0.25*gr.dx) # pylab.ylim(-0.25, 0.75) pylab.axis("off") pylab.subplots_adjust(left=0.05,right=0.95,bottom=0.05,top=0.95) f = pylab.gcf() f.set_size_inches(4.0,2.5) pylab.savefig("states.png") pylab.savefig("states.eps")
def simplegrid(): # grid info nzones = 7 ng = 1 gr = gpu.grid(nzones, ng, xmin=0.0, xmax=1.0) gpu.drawGrid(gr, emphasizeEnd=1, edgeTicks=0, drawGhost=1) # label a few gpu.labelCenter(gr, ng+nzones/2, r"$i$") gpu.labelCenter(gr, ng+nzones/2-1, r"$i-1$") gpu.labelCenter(gr, ng+nzones/2+1, r"$i+1$") gpu.labelCenter(gr, ng-1, r"$\mathrm{lo}-1$") gpu.labelCenter(gr, ng, r"$\mathrm{lo}$") gpu.labelCenter(gr, ng+nzones-1, r"$\mathrm{hi}$") gpu.labelCenter(gr, ng+nzones, r"$\mathrm{hi+1}$") # label dx pylab.plot([gr.xl[ng+nzones/2-2], gr.xl[ng+nzones/2-2]], [-0.35,-0.25], color="k") pylab.plot([gr.xr[ng+nzones/2-2], gr.xr[ng+nzones/2-2]], [-0.35,-0.25], color="k") pylab.plot([gr.xl[ng+nzones/2-2], gr.xr[ng+nzones/2-2]], [-0.3,-0.3], color="k") pylab.text(gr.xc[ng+nzones/2-2], -0.5, r"$\Delta x$", horizontalalignment="center") pylab.xlim(gr.xl[0]-0.5*gr.dx,gr.xr[2*ng+nzones-1]+0.5*gr.dx) pylab.ylim(-0.5, 1.5) pylab.axis("off") pylab.subplots_adjust(left=0.05,right=0.95,bottom=0.05,top=0.95) f = pylab.gcf() f.set_size_inches(10.0,2.5) pylab.savefig("simplegrid_gc.png") pylab.savefig("simplegrid_gc.eps")
import math import numpy import pylab import grid_plot_util as gpu # plot two stacked fv grids of different (2x) resolution to show prolongation #----------------------------------------------------------------------------- nf = 5 nc = 3 grf = gpu.grid(nf, voff=2.0, fd=1) grc = gpu.grid(nc, fd=1) pylab.clf() gpu.drawGrid(grf) gpu.drawGrid(grc) gpu.labelCenter(grf, nf / 2 - 2, r"$i-2$") gpu.labelCenter(grf, nf / 2 - 1, r"$i-1$") gpu.labelCenter(grf, nf / 2, r"$i$") gpu.labelCenter(grf, nf / 2 + 1, r"$i+1$") gpu.labelCenter(grf, nf / 2 + 2, r"$i+2$") gpu.labelCenter(grc, nc / 2 - 1, r"$j-1$") gpu.labelCenter(grc, nc / 2, r"$j$") gpu.labelCenter(grc, nc / 2 + 1, r"$j+1$") gpu.labelCellCenter(grf, nf / 2 - 2, r"$\phi_{i-2}^h$")
import math import numpy import pylab import grid_plot_util as gpu # plot two stacked fv grids of different (2x) resolution to show prolongation #----------------------------------------------------------------------------- gr = [] nf = 8 gr.append(gpu.grid(nf, ng=1, voff=0.0)) gr.append(gpu.grid(nf, ng=1, voff=0.0, xmin=0.25, xmax=0.75)) pylab.clf() gpu.drawGrid(gr[0], emphasizeEnd=1, drawGhost=0, edgeTicks=0, color="0.75") gpu.drawGrid(gr[1], emphasizeEnd=1, drawGhost=0, edgeTicks=0) f = pylab.gcf() f.set_size_inches(7.0,1.0) grf = gr[0] pylab.xlim(grf.xmin-0.75*grf.dx,grf.xmax+0.25*grf.dx) pylab.axis("off") pylab.subplots_adjust(left=0.05,right=0.95,bottom=0.05,top=0.95)
import math import numpy import pylab import grid_plot_util as gpu # plot two stacked fv grids of different (2x) resolution to show prolongation #----------------------------------------------------------------------------- gr = [] nf = 8 gr.append(gpu.grid(nf, ng=1, voff=0.0)) gr.append(gpu.grid(nf, ng=1, voff=0.0, xmin=0.25, xmax=0.75)) pylab.clf() gpu.drawGrid(gr[0], emphasizeEnd=1, drawGhost=0, edgeTicks=0, color="0.75") gpu.drawGrid(gr[1], emphasizeEnd=1, drawGhost=0, edgeTicks=0) f = pylab.gcf() f.set_size_inches(7.0, 1.0) grf = gr[0] pylab.xlim(grf.xmin - 0.75 * grf.dx, grf.xmax + 0.25 * grf.dx) pylab.axis("off") pylab.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=0.95) pylab.savefig("nested1.png", dpi=200)
import math import numpy import pylab import grid_plot_util as gpu # plot two stacked fv grids of different (2x) resolution to show prolongation #----------------------------------------------------------------------------- gr = [] nf = 2 while (nf <= 16): gr.append(gpu.grid(nf, ng=1, voff=2.0*len(gr))) nf = nf*2 pylab.clf() for g in gr: gpu.drawGrid(g, emphasizeEnd=1, drawGhost=1, edgeTicks=0) f = pylab.gcf() f.set_size_inches(7.0,5.0) grf = gr[0] pylab.xlim(grf.xmin-1.1*grf.dx,grf.xmax+1.1*grf.dx) pylab.axis("off") pylab.subplots_adjust(left=0.05,right=0.95,bottom=0.05,top=0.95)
import math import numpy import pylab import grid_plot_util as gpu # plot two stacked fv grids of different (2x) resolution to show prolongation # ----------------------------------------------------------------------------- nf = 5 nc = 3 grf = gpu.grid(nf, voff=2.0, fd=1) grc = gpu.grid(nc, fd=1) pylab.clf() gpu.drawGrid(grf) gpu.drawGrid(grc) gpu.labelCenter(grf, nf / 2 - 2, r"$i-2$") gpu.labelCenter(grf, nf / 2 - 1, r"$i-1$") gpu.labelCenter(grf, nf / 2, r"$i$") gpu.labelCenter(grf, nf / 2 + 1, r"$i+1$") gpu.labelCenter(grf, nf / 2 + 2, r"$i+2$") gpu.labelCenter(grc, nc / 2 - 1, r"$j-1$") gpu.labelCenter(grc, nc / 2, r"$j$") gpu.labelCenter(grc, nc / 2 + 1, r"$j+1$")
import math import numpy import pylab import grid_plot_util as gpu # plot a simple finite-difference grid #----------------------------------------------------------------------------- nzones = 8 # data that lives on the grid #a = numpy.array([0.3, 1.0, 0.9, 0.8, 0.25, 0.15, 0.5, 0.55]) a = numpy.array([0.3, 1.0, 0.9, 0.8, 0.25, 0.1, 0.5, 0.55]) gr = gpu.grid(nzones, fd=1) pylab.clf() gpu.drawGrid(gr) gpu.labelCenter(gr, nzones / 2, r"$i$") gpu.labelCenter(gr, nzones / 2 - 1, r"$i-1$") gpu.labelCenter(gr, nzones / 2 + 1, r"$i+1$") gpu.labelCenter(gr, nzones / 2 - 2, r"$i-2$") gpu.labelCenter(gr, nzones / 2 + 2, r"$i+2$") # draw the data i = 0 while i < nzones: gpu.drawFDData(gr, i, a[i], color="r")
def riemann(): # grid info xmin = 0.0 xmax = 1.0 nzones = 4 ng = 2 gr = gpu.grid(nzones, ng=ng) # interior atemp = numpy.array([0.8, 0.7, 0.4, 0.5]) a = numpy.zeros(2*gr.ng + gr.nx, dtype=numpy.float64) # fill interior and ghost cells a[gr.ilo:gr.ihi+1] = atemp[:] a[0:gr.ilo] = a[gr.ihi-1:gr.ihi+1] a[gr.ihi:2*gr.ng+gr.nx] = a[gr.ihi] #------------------------------------------------------------------------ # plot a domain without ghostcells gpu.drawGrid(gr, emphasizeEnd=1, drawGhost=1) gpu.labelCenter(gr, gr.ng-2, r"$\mathrm{lo-2}$") gpu.labelCenter(gr, gr.ng-1, r"$\mathrm{lo-1}$") gpu.labelCenter(gr, gr.ng, r"$\mathrm{lo}$") gpu.labelCenter(gr, gr.ng+1, r"$\mathrm{lo+1}$") gpu.labelEdge(gr, gr.ng, r"$\mathrm{lo}-1/2$") # draw cell averages n = 0 while n < gr.ng+gr.nx: gpu.drawCellAvg(gr, n, a[n], color="0.5", ls=":") n += 1 # get slopes lda = gpu.lslopes(a, nolimit=1) n = gr.ilo-1 while (n <= gr.ihi): gpu.drawSlope(gr, n, lda[n], a[n], color="r") n += 1 # compute the states to the left and right of lo-1/2 C = 0.7 # CFL al = a[gr.ilo-1] + 0.5*gr.dx*(1.0 - C)*lda[gr.ilo-1] ar = a[gr.ilo] - 0.5*gr.dx*(1.0 + C)*lda[gr.ilo] # L gpu.markCellRightState(gr, ng-1, r"$a_{\mathrm{lo}+1/2,L}^{n+1/2}$", value=al, vertical="top", color="b") # R gpu.markCellLeftState(gr, ng, r"$a_{\mathrm{lo}+1/2,R}^{n+1/2}$", value=ar, vertical="top", color="b") pylab.xlim(gr.xl[0]-0.15*gr.dx,gr.xr[ng+1]+0.15*gr.dx) pylab.ylim(-0.25, 1.1) pylab.axis("off") pylab.subplots_adjust(left=0.05,right=0.95,bottom=0.05,top=0.95) f = pylab.gcf() f.set_size_inches(8.0,2.0) pylab.tight_layout() pylab.savefig("riemann-bc.png") pylab.savefig("riemann-bc.eps")
acell = 0.5 * (anode[0:nnodes - 1] + anode[1:nnodes]) # periodic ghost cells if (ng == 1): anode = numpy.insert(anode, 0, anode[nnodes - 1]) anode = numpy.append(anode, anode[ng]) acell = numpy.insert(acell, 0, acell[ncells - 1]) acell = numpy.append(acell, acell[ng]) print "anode: ", len(anode), nnodes, ng #----------------------------------------------------------------------------- # finite difference gr = gpu.grid(nnodes, ng=ng, fd=1) pylab.clf() gpu.drawGrid(gr, emphasizeEnd=1, drawGhost=1) gpu.labelCenter(gr, ng + nnodes / 2, r"$i$") gpu.labelCenter(gr, ng + nnodes / 2 - 1, r"$i-1$") gpu.labelCenter(gr, ng + nnodes / 2 + 1, r"$i+1$") #gpu.labelCenter(gr, ng+nnodes/2-2, r"$i-2$") #gpu.labelCenter(gr, ng+nnodes/2+2, r"$i+2$") # draw the data i = 0 while i < nnodes + 2 * ng: gpu.drawFDData(gr, i, anode[i], color="r")
import math import numpy import pylab import grid_plot_util as gpu # plot a simple finite-difference grid #----------------------------------------------------------------------------- nzones = 9 # data that lives on the grid #a = numpy.array([0.3, 1.0, 0.9, 0.8, 0.25, 0.15, 0.5, 0.55]) a = numpy.array([0.55, 0.3, 1.0, 0.9, 0.8, 0.25, 0.1, 0.5, 0.55]) gr = gpu.grid(nzones, ng=1, fd=1) pylab.clf() gpu.drawGrid(gr, drawGhost=1) labels = ["-1", "0", "1", "", "i-1", "i", "i+1", "", "N-2", "N-1", "N"] i = gr.ilo - gr.ng while (i < gr.ng + gr.nx + 1): if not labels[i] == "": gpu.labelCenter(gr, i, r"$%s$" % (labels[i]), fontsize="medium") i += 1 # draw the data
import math import numpy import pylab import grid_plot_util as gpu # plot two stacked fv grids of different (2x) resolution to show prolongation # ----------------------------------------------------------------------------- nf = 4 nc = nf / 2 grf = gpu.grid(nf) grc = gpu.grid(nc, voff=2.0) pylab.clf() gpu.drawGrid(grf) gpu.drawGrid(grc) gpu.labelCenter(grf, nf / 2 - 2, r"$i-2$") gpu.labelCenter(grf, nf / 2 - 1, r"$i-1$") gpu.labelCenter(grf, nf / 2, r"$i$") gpu.labelCenter(grf, nf / 2 + 1, r"$i+1$") gpu.labelCenter(grc, nc / 2 - 1, r"$j-1$") gpu.labelCenter(grc, nc / 2, r"$j$") gpu.labelCellCenter(grf, nf / 2 - 2, r"$\phi_{i-2}^h$")
import math import numpy import pylab import grid_plot_util as gpu # plot two stacked fv grids of different (2x) resolution to show prolongation #----------------------------------------------------------------------------- nf = 4 nc = nf/2 grf = gpu.grid(nf, voff=2.0) grc = gpu.grid(nc) pylab.clf() gpu.drawGrid(grf) gpu.drawGrid(grc) gpu.labelCenter(grf, nf/2-2, r"$i-2$") gpu.labelCenter(grf, nf/2-1, r"$i-1$") gpu.labelCenter(grf, nf/2, r"$i$") gpu.labelCenter(grf, nf/2+1, r"$i+1$") gpu.labelCenter(grc, nc/2-1, r"$j-1$") gpu.labelCenter(grc, nc/2, r"$j$") gpu.labelCellCenter(grf, nf/2-2, r"$\phi_{i-2}^h$")
import math import numpy import pylab import grid_plot_util as gpu # plot a simple finite-difference grid #----------------------------------------------------------------------------- nzones = 8 # data that lives on the grid #a = numpy.array([0.3, 1.0, 0.9, 0.8, 0.25, 0.15, 0.5, 0.55]) a = numpy.array([0.3, 1.0, 0.9, 0.8, 0.25, 0.1, 0.5, 0.55]) gr = gpu.grid(nzones, fd=1) pylab.clf() gpu.drawGrid(gr) gpu.labelCenter(gr, nzones/2, r"$i$") gpu.labelCenter(gr, nzones/2-1, r"$i-1$") gpu.labelCenter(gr, nzones/2+1, r"$i+1$") gpu.labelCenter(gr, nzones/2-2, r"$i-2$") gpu.labelCenter(gr, nzones/2+2, r"$i+2$") # draw the data i = 0
def riemann(): # grid info xmin = 0.0 xmax = 1.0 nzones = 1 ng = 0 gr = gpu.grid(nzones, xmin=xmin, xmax=xmax) #------------------------------------------------------------------------ # plot a domain without ghostcells gpu.drawGrid(gr) gpu.labelCenter(gr, 0, r"$i$") gpu.labelCellCenter(gr, 0, r"$q_i$") gpu.markCellLeftState(gr, 0, r"$q_{i-1/2,R}^{n+1/2}$", color="r") gpu.markCellRightState(gr, 0, r"$q_{i+1/2,L}^{n+1/2}$", color="r") pylab.arrow(gr.xc[0] - 0.05 * gr.dx, 0.5, -0.13 * gr.dx, 0, shape='full', head_width=0.075, head_length=0.05, lw=1, width=0.01, edgecolor="none", facecolor="r", length_includes_head=True, zorder=100) pylab.arrow(gr.xc[0] + 0.05 * gr.dx, 0.5, 0.13 * gr.dx, 0, shape='full', head_width=0.075, head_length=0.05, lw=1, width=0.01, edgecolor="none", facecolor="r", length_includes_head=True, zorder=100) pylab.xlim(gr.xl[0] - 0.25 * gr.dx, gr.xr[2 * ng + nzones - 1] + 0.25 * gr.dx) # pylab.ylim(-0.25, 0.75) pylab.axis("off") pylab.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=0.95) f = pylab.gcf() f.set_size_inches(4.0, 2.5) pylab.savefig("states.png") pylab.savefig("states.eps")
import math import numpy import pylab import grid_plot_util as gpu # plot two stacked fv grids of different (2x) resolution to show prolongation #----------------------------------------------------------------------------- nf = 4 nc = nf / 2 grf = gpu.grid(nf, voff=2.0) grc = gpu.grid(nc) pylab.clf() gpu.drawGrid(grf) gpu.drawGrid(grc) gpu.labelCenter(grf, nf / 2 - 2, r"$i-2$") gpu.labelCenter(grf, nf / 2 - 1, r"$i-1$") gpu.labelCenter(grf, nf / 2, r"$i$") gpu.labelCenter(grf, nf / 2 + 1, r"$i+1$") gpu.labelCenter(grc, nc / 2 - 1, r"$j-1$") gpu.labelCenter(grc, nc / 2, r"$j$") gpu.labelCellCenter(grf, nf / 2 - 2, r"$\phi_{i-2}^h$") gpu.labelCellCenter(grf, nf / 2 - 1, r"$\phi_{i-1}^h$") gpu.labelCellCenter(grf, nf / 2, r"$\phi_i^h$")
import math import numpy import pylab import grid_plot_util as gpu #----------------------------------------------------------------------------- nzones = 8 # data that lives on the grid #a = numpy.array([0.3, 1.0, 0.9, 0.8, 0.25, 0.15, 0.5, 0.55]) a = numpy.array([0.3, 1.0, 1.0, 0.8, 0.2, 0.15, 0.5, 0.55]) gr = gpu.grid(nzones) pylab.clf() gpu.drawGrid(gr, centerOnly=1) gpu.labelCenter(gr, nzones/2-1, r"$i$") gpu.labelCenter(gr, nzones/2, r"$i+1$") # compute the parabolic coefficients ap, am, a6 = gpu.ppm(a, nolimit=1) lap, lam, la6 = gpu.ppm(a) n = gr.nx/2-1 while (n <= gr.nx/2):
import math import numpy import pylab import grid_plot_util as gpu # plot two stacked fv grids of different (2x) resolution to show prolongation #----------------------------------------------------------------------------- nf = 4 nc = nf/2 grf = gpu.grid(nf) grc = gpu.grid(nc, voff=2.0) pylab.clf() gpu.drawGrid(grf) gpu.drawGrid(grc) gpu.labelCenter(grf, nf/2-2, r"$i-2$") gpu.labelCenter(grf, nf/2-1, r"$i-1$") gpu.labelCenter(grf, nf/2, r"$i$") gpu.labelCenter(grf, nf/2+1, r"$i+1$") gpu.labelCenter(grc, nc/2-1, r"$j-1$") gpu.labelCenter(grc, nc/2, r"$j$") gpu.labelCellCenter(grf, nf/2-2, r"$\phi_{i-2}^h$")
def riemann(): # grid info xmin = 0.0 xmax = 1.0 nzones = 4 ng = 2 gr = gpu.grid(nzones, ng=ng) # interior atemp = numpy.array([0.8, 0.7, 0.4, 0.5]) a = numpy.zeros(2 * gr.ng + gr.nx, dtype=numpy.float64) # fill interior and ghost cells a[gr.ilo:gr.ihi + 1] = atemp[:] a[0:gr.ilo] = a[gr.ihi - 1:gr.ihi + 1] a[gr.ihi:2 * gr.ng + gr.nx] = a[gr.ihi] #------------------------------------------------------------------------ # plot a domain without ghostcells gpu.drawGrid(gr, emphasizeEnd=1, drawGhost=1) gpu.labelCenter(gr, gr.ng - 2, r"$\mathrm{lo-2}$") gpu.labelCenter(gr, gr.ng - 1, r"$\mathrm{lo-1}$") gpu.labelCenter(gr, gr.ng, r"$\mathrm{lo}$") gpu.labelCenter(gr, gr.ng + 1, r"$\mathrm{lo+1}$") gpu.labelEdge(gr, gr.ng, r"$\mathrm{lo}-1/2$") # draw cell averages n = 0 while n < gr.ng + gr.nx: gpu.drawCellAvg(gr, n, a[n], color="0.5", ls=":") n += 1 # get slopes lda = gpu.lslopes(a, nolimit=1) n = gr.ilo - 1 while (n <= gr.ihi): gpu.drawSlope(gr, n, lda[n], a[n], color="r") n += 1 # compute the states to the left and right of lo-1/2 C = 0.7 # CFL al = a[gr.ilo - 1] + 0.5 * gr.dx * (1.0 - C) * lda[gr.ilo - 1] ar = a[gr.ilo] - 0.5 * gr.dx * (1.0 + C) * lda[gr.ilo] # L gpu.markCellRightState(gr, ng - 1, r"$a_{\mathrm{lo}+1/2,L}^{n+1/2}$", value=al, vertical="top", color="b") # R gpu.markCellLeftState(gr, ng, r"$a_{\mathrm{lo}+1/2,R}^{n+1/2}$", value=ar, vertical="top", color="b") pylab.xlim(gr.xl[0] - 0.15 * gr.dx, gr.xr[ng + 1] + 0.15 * gr.dx) pylab.ylim(-0.25, 1.1) pylab.axis("off") pylab.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=0.95) f = pylab.gcf() f.set_size_inches(8.0, 2.0) pylab.tight_layout() pylab.savefig("riemann-bc.png") pylab.savefig("riemann-bc.eps")
# simple zero-gradient a[0:gr.ilo] = a[gr.ilo] a[gr.ihi:2*gr.ng+gr.nx] = a[gr.ihi] #----------------------------------------------------------------------------- atemp = numpy.array([1.0, 1.0, 0.9, 0.8, 0.25, 0.1, 0.1, 0.1]) nzones = len(atemp) # CFL number C = 0.6 gr = gpu.grid(nzones, ng=4) a = numpy.zeros(2*gr.ng + gr.nx, dtype=numpy.float64) a[gr.ilo:gr.ihi+1] = atemp[:] fillgc(gr, a) #----------------------------------------------------------------------------- # first frame -- the original cell-averages pylab.clf() gpu.drawGrid(gr) gpu.labelCenter(gr, gr.ng + nzones/2, r"$i$")
import math import numpy import pylab import grid_plot_util as gpu # plot two stacked fv grids of different (2x) resolution to show prolongation #----------------------------------------------------------------------------- gr = [] nf = 2 while (nf <= 16): gr.append(gpu.grid(nf, ng=1, voff=2.0 * len(gr))) nf = nf * 2 pylab.clf() for g in gr: gpu.drawGrid(g, emphasizeEnd=1, drawGhost=1, edgeTicks=0) f = pylab.gcf() f.set_size_inches(7.0, 5.0) grf = gr[0] pylab.xlim(grf.xmin - 1.1 * grf.dx, grf.xmax + 1.1 * grf.dx) pylab.axis("off") pylab.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=0.95)
import math import numpy import pylab import grid_plot_util as gpu # plot a simple finite-difference grid #----------------------------------------------------------------------------- nzones = 9 # data that lives on the grid #a = numpy.array([0.3, 1.0, 0.9, 0.8, 0.25, 0.15, 0.5, 0.55]) a = numpy.array([0.55, 0.3, 1.0, 0.9, 0.8, 0.25, 0.1, 0.5, 0.55]) gr = gpu.grid(nzones, ng=1, fd=1) pylab.clf() gpu.drawGrid(gr, drawGhost=1) labels = ["-1", "0", "1", "", "i-1", "i", "i+1", "", "N-2", "N-1", "N"] i = gr.ilo-gr.ng while (i < gr.ng+gr.nx+1): if not labels[i] == "": gpu.labelCenter(gr, i, r"$%s$" % (labels[i]), fontsize="medium") i += 1