示例#1
0
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")
示例#2
0
gr = gpu.grid(nzones)

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$")

n = 0
while (n < nzones):
    gpu.drawCellAvg(gr, n, a[n], color="r")
    n += 1

pylab.axis([gr.xmin - 0.5 * gr.dx, gr.xmax + 0.5 * gr.dx, -0.25, 1.2])
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.savefig("piecewise-constant.eps")
pylab.savefig("piecewise-constant.png")

#------------- PLM -------------
pylab.clf()
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")
示例#4
0
pylab.clf()

gpu.drawGrid(gr)

gpu.labelCenter(gr, gr.ng + nzones/2,   r"$i$")
gpu.labelCenter(gr, gr.ng + nzones/2-1, r"$i-1$")
gpu.labelCenter(gr, gr.ng + nzones/2+1, r"$i+1$")
gpu.labelCenter(gr, gr.ng + nzones/2-2, r"$i-2$")
gpu.labelCenter(gr, gr.ng + nzones/2+2, r"$i+2$")


# draw cell averages
n = gr.ilo
while (n <= gr.ihi):
    gpu.drawCellAvg(gr, n, a[n], color="r")
    n += 1

pylab.axis([gr.xmin-0.5*gr.dx,gr.xmax+0.5*gr.dx, -0.25, 1.2])
pylab.axis("off")

print gr.xmin-0.5*gr.dx, gr.xmax+0.5*gr.dx

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.savefig("rea-start.eps")
pylab.savefig("rea-start.png")
gpu.drawGrid(gr)

gpu.labelCenter(gr, nzones/2,   r"$x_i$")
gpu.labelAvg(gr, nzones/2,   a[nzones/2], r"$\langle f\rangle_i$")

gpu.labelCenter(gr, nzones/2-1, r"$x_{i-1}$")
gpu.labelCenter(gr, nzones/2+1, r"$x_{i+1}$")
gpu.labelCenter(gr, nzones/2-2, r"$x_{i-2}$")
gpu.labelCenter(gr, nzones/2+2, r"$x_{i+2}$")

gpu.labelEdge(gr, nzones/2,   r"$x_{i-1/2}$")
gpu.labelEdge(gr, nzones/2+1, r"$x_{i+1/2}$")

n = 0
while (n < nzones):
    gpu.drawCellAvg(gr, n, a[n])
    n += 1


pylab.axis([gr.xmin-0.5*gr.dx,gr.xmax+0.5*gr.dx, -0.25, 1.2])
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.savefig("fv.png", dpi=200)
pylab.savefig("fv.eps")
               
示例#6
0

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$")


n = 0
while (n < nzones):
    gpu.drawCellAvg(gr, n, a[n], color="r")
    n += 1


pylab.axis([gr.xmin-0.5*gr.dx,gr.xmax+0.5*gr.dx, -0.25, 1.2])
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.savefig("piecewise-constant.eps")
pylab.savefig("piecewise-constant.png")

示例#7
0
gpu.labelCenter(gr, gr.ilo, r"$\mathrm{lo}$")
gpu.labelCenter(gr, gr.ilo-1, r"$\mathrm{lo-1}$")
gpu.labelCenter(gr, gr.ilo-2, r"$\mathrm{lo-2}$")

gpu.labelCenter(gr, gr.ihi, r"$\mathrm{hi}$")
gpu.labelCenter(gr, gr.ihi+1, r"$\mathrm{hi+1}$")
gpu.labelCenter(gr, gr.ihi+2, r"$\mathrm{hi+2}$")

gpu.labelEdge(gr, ng+nzones/2,   r"$i-1/2$")
gpu.labelEdge(gr, ng+nzones/2+1,   r"$i+1/2$")

# draw the data
i = 0
while i < nzones:
    gpu.drawCellAvg(gr, ng+i, a[i], color="r")    
    i += 1
    
gpu.labelCellAvg(gr, ng+nzones/2, a[nzones/2], r"$\langle a\rangle_i$", color="r")

# label dx
pylab.plot([gr.xr[gr.ng+nzones/2-1], gr.xr[gr.ng+nzones/2-1]], [-0.35,-0.25], color="k")
pylab.plot([gr.xr[gr.ng+nzones/2], gr.xr[gr.ng+nzones/2]], [-0.35,-0.25], color="k")
pylab.plot([gr.xr[gr.ng+nzones/2-1], gr.xr[gr.ng+nzones/2]], [-0.3,-0.3], color="k")
pylab.text(gr.xc[gr.ng+nzones/2], -0.55, r"$\Delta x$", 
           horizontalalignment="center", fontsize=16)



pylab.axis([gr.xmin-2.02*gr.dx,gr.xmax+2.02*gr.dx, -0.5, 1.6])
pylab.axis("off")
示例#8
0
gr = gpu.grid(nzones)

gpu.drawGrid(gr)

gpu.labelCenter(gr, nzones / 2, r"$x_i$")
gpu.labelAvg(gr, nzones / 2, a[nzones / 2], r"$\langle f\rangle_i$")

gpu.labelCenter(gr, nzones / 2 - 1, r"$x_{i-1}$")
gpu.labelCenter(gr, nzones / 2 + 1, r"$x_{i+1}$")
gpu.labelCenter(gr, nzones / 2 - 2, r"$x_{i-2}$")
gpu.labelCenter(gr, nzones / 2 + 2, r"$x_{i+2}$")

gpu.labelEdge(gr, nzones / 2, r"$x_{i-1/2}$")
gpu.labelEdge(gr, nzones / 2 + 1, r"$x_{i+1/2}$")

n = 0
while (n < nzones):
    gpu.drawCellAvg(gr, n, a[n])
    n += 1

pylab.axis([gr.xmin - 0.5 * gr.dx, gr.xmax + 0.5 * gr.dx, -0.25, 1.2])
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.savefig("fv.png", dpi=200)
pylab.savefig("fv.eps")
示例#9
0
def evolve(gr, a, C, num, nolimit=1):

    #-------------------------------------------------------------------------
    # first frame -- the original cell-averages

    pylab.clf()

    gpu.drawGrid(gr)

    gpu.labelCenter(gr, gr.ng + nzones / 2, r"$i$", fontsize="medium")
    gpu.labelCenter(gr, gr.ng + nzones / 2 - 1, r"$i-1$", fontsize="medium")
    gpu.labelCenter(gr, gr.ng + nzones / 2 + 1, r"$i+1$", fontsize="medium")
    gpu.labelCenter(gr, gr.ng + nzones / 2 - 2, r"$i-2$", fontsize="medium")
    gpu.labelCenter(gr, gr.ng + nzones / 2 + 2, r"$i+2$", fontsize="medium")

    # draw cell averages
    n = gr.ilo
    while (n <= gr.ihi):
        gpu.drawCellAvg(gr, n, a[n], color="r")
        n += 1

    pylab.axis([gr.xmin - 0.5 * gr.dx, gr.xmax + 0.5 * gr.dx, -1.25, 2.0])
    pylab.axis("off")

    print gr.xmin - 0.5 * gr.dx, gr.xmax + 0.5 * gr.dx

    pylab.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=0.95)

    ax = pylab.gca()

    pylab.text(0.5,
               0.75,
               "initial state (cell averages)",
               horizontalalignment="center",
               fontsize=16,
               color="b",
               transform=ax.transAxes)

    pylab.text(0.5,
               0.95,
               "Piecewise Linear Method for Linear Advection",
               horizontalalignment="center",
               fontsize=20,
               color="k",
               transform=ax.transAxes)

    f = pylab.gcf()
    f.set_size_inches(12.8, 7.2)

    if (nolimit):
        pylab.savefig("rea-nolimit-start_%3.3d.png" % (num))
        pylab.savefig("rea-nolimit-start_%3.3d.eps" % (num))
    else:
        pylab.savefig("rea-start_%3.3d.png" % (num))
        pylab.savefig("rea-start_%3.3d.eps" % (num))

    #-------------------------------------------------------------------------
    # second frame -- reconstruction

    # compute the slopes
    lda = gpu.lslopes(a, nolimit=nolimit)

    # draw
    pylab.clf()

    gpu.drawGrid(gr)

    gpu.labelCenter(gr, gr.ng + nzones / 2, r"$i$", fontsize="medium")
    gpu.labelCenter(gr, gr.ng + nzones / 2 - 1, r"$i-1$", fontsize="medium")
    gpu.labelCenter(gr, gr.ng + nzones / 2 + 1, r"$i+1$", fontsize="medium")
    gpu.labelCenter(gr, gr.ng + nzones / 2 - 2, r"$i-2$", fontsize="medium")
    gpu.labelCenter(gr, gr.ng + nzones / 2 + 2, r"$i+2$", fontsize="medium")

    # draw cell averages
    n = gr.ilo
    while (n <= gr.ihi):
        gpu.drawCellAvg(gr, n, a[n], color="0.5", ls=":")
        n += 1

    n = gr.ilo
    while (n <= gr.ihi):
        gpu.drawSlope(gr, n, lda[n], a[n], color="r")
        n += 1

    pylab.axis([gr.xmin - 0.5 * gr.dx, gr.xmax + 0.5 * gr.dx, -1.25, 2.0])
    pylab.axis("off")

    pylab.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=0.95)

    pylab.text(0.5,
               0.75,
               "reconstructed slopes",
               horizontalalignment="center",
               fontsize=16,
               color="b",
               transform=ax.transAxes)

    pylab.text(0.5,
               0.95,
               "Piecewise Linear Method for Linear Advection",
               horizontalalignment="center",
               fontsize=20,
               color="k",
               transform=ax.transAxes)

    f = pylab.gcf()
    f.set_size_inches(12.8, 7.2)

    if (nolimit):
        pylab.savefig("rea-nolimit-reconstruction_%3.3d.png" % (num))
        pylab.savefig("rea-nolimit-reconstruction_%3.3d.eps" % (num))
    else:
        pylab.savefig("rea-reconstruction_%3.3d.png" % (num))
        pylab.savefig("rea-reconstruction_%3.3d.eps" % (num))

    #-------------------------------------------------------------------------
    # third frame -- evolve

    # draw

    pylab.clf()

    gpu.drawGrid(gr)

    gpu.labelCenter(gr, gr.ng + nzones / 2, r"$i$", fontsize="medium")
    gpu.labelCenter(gr, gr.ng + nzones / 2 - 1, r"$i-1$", fontsize="medium")
    gpu.labelCenter(gr, gr.ng + nzones / 2 + 1, r"$i+1$", fontsize="medium")
    gpu.labelCenter(gr, gr.ng + nzones / 2 - 2, r"$i-2$", fontsize="medium")
    gpu.labelCenter(gr, gr.ng + nzones / 2 + 2, r"$i+2$", fontsize="medium")

    # draw cell slopes
    n = gr.ilo
    while (n <= gr.ihi):
        gpu.drawSlope(gr, n, lda[n], a[n], color="0.75", ls=":")
        n += 1

    # evolve
    n = gr.ilo
    while (n <= gr.ihi):
        gpu.evolveToRight(gr, n, lda, a, C, color="r")
        n += 1

    pylab.axis([gr.xmin - 0.5 * gr.dx, gr.xmax + 0.5 * gr.dx, -1.25, 2.0])
    pylab.axis("off")

    print gr.xmin - 0.5 * gr.dx, gr.xmax + 0.5 * gr.dx

    pylab.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=0.95)

    pylab.text(0.5,
               0.75,
               "evolved with C = {}".format(C),
               horizontalalignment="center",
               fontsize=16,
               color="b",
               transform=ax.transAxes)

    pylab.text(0.5,
               0.95,
               "Piecewise Linear Method for Linear Advection",
               horizontalalignment="center",
               fontsize=20,
               color="k",
               transform=ax.transAxes)

    f = pylab.gcf()
    f.set_size_inches(12.8, 7.2)

    if (nolimit):
        pylab.savefig("rea-nolimit-evolve_%3.3d.png" % (num))
        pylab.savefig("rea-nolimit-evolve_%3.3d.eps" % (num))
    else:
        pylab.savefig("rea-evolve_%3.3d.png" % (num))
        pylab.savefig("rea-evolve_%3.3d.eps" % (num))

    #-------------------------------------------------------------------------
    # fourth frame -- re-average

    # left states (we don't need the right state when u > 0)
    al = numpy.zeros(2 * gr.ng + gr.nx, dtype=numpy.float64)

    n = gr.ilo
    while (n <= gr.ihi + 1):
        al[n] = a[n - 1] + 0.5 * (1 - C) * lda[n - 1]
        n += 1

    # the Riemann problem just picks the left state.  Do a conservative
    # update
    anew = numpy.zeros(2 * gr.ng + gr.nx, dtype=numpy.float64)

    anew[gr.ilo:gr.ihi+1] = a[gr.ilo:gr.ihi+1] + \
        C*(al[gr.ilo:gr.ihi+1] - al[gr.ilo+1:gr.ihi+2])

    pylab.clf()

    gpu.drawGrid(gr)

    gpu.labelCenter(gr, gr.ng + nzones / 2, r"$i$", fontsize="medium")
    gpu.labelCenter(gr, gr.ng + nzones / 2 - 1, r"$i-1$", fontsize="medium")
    gpu.labelCenter(gr, gr.ng + nzones / 2 + 1, r"$i+1$", fontsize="medium")
    gpu.labelCenter(gr, gr.ng + nzones / 2 - 2, r"$i-2$", fontsize="medium")
    gpu.labelCenter(gr, gr.ng + nzones / 2 + 2, r"$i+2$", fontsize="medium")

    # show the evolved profiles from the old time
    n = gr.ilo
    while (n <= gr.ihi):
        gpu.evolveToRight(gr, n, lda, a, C, color="0.5", ls=":")
        n += 1

    # draw new averages
    n = gr.ilo
    while (n <= gr.ihi):
        gpu.drawCellAvg(gr, n, anew[n], color="red")
        n += 1

    pylab.axis([gr.xmin - 0.5 * gr.dx, gr.xmax + 0.5 * gr.dx, -1.25, 2.0])
    pylab.axis("off")

    print gr.xmin - 0.5 * gr.dx, gr.xmax + 0.5 * gr.dx

    pylab.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=0.95)

    pylab.text(0.5,
               0.75,
               "averaged profile (final state)",
               horizontalalignment="center",
               fontsize=16,
               color="b",
               transform=ax.transAxes)

    pylab.text(0.5,
               0.95,
               "Piecewise Linear Method for Linear Advection",
               horizontalalignment="center",
               fontsize=20,
               color="k",
               transform=ax.transAxes)

    f = pylab.gcf()
    f.set_size_inches(12.8, 7.2)

    if (nolimit):
        pylab.savefig("rea-nolimit-final_%3.3d.png" % (num))
        pylab.savefig("rea-nolimit-final_%3.3d.eps" % (num))
    else:
        pylab.savefig("rea-final_%3.3d.png" % (num))
        pylab.savefig("rea-final_%3.3d.eps" % (num))

    return anew
示例#10
0
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$")

gpu.labelEdge(gr, nzones/2,   r"$i-1/2$")
gpu.labelEdge(gr, nzones/2+1,   r"$i+1/2$")

# draw the data
i = 0
while i < nzones:
    gpu.drawCellAvg(gr, i, a[i], color="r")    
    i += 1
    
gpu.labelCellAvg(gr, nzones/2, a[nzones/2], r"$\langle f\rangle_i$", color="r")

# label dx
pylab.plot([gr.xr[gr.ng+nzones/2-1], gr.xr[gr.ng+nzones/2-1]], [-0.35,-0.25], color="k")
pylab.plot([gr.xr[gr.ng+nzones/2], gr.xr[gr.ng+nzones/2]], [-0.35,-0.25], color="k")
pylab.plot([gr.xr[gr.ng+nzones/2-1], gr.xr[gr.ng+nzones/2]], [-0.3,-0.3], color="k")
pylab.text(gr.xc[gr.ng+nzones/2], -0.45, r"$\Delta x$", 
           horizontalalignment="center")



pylab.axis([gr.xmin-0.5*gr.dx,gr.xmax+0.5*gr.dx, -0.5, 1.2])
pylab.axis("off")
示例#11
0
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")
def evolve(gr, a, C, num, nolimit=1):
    
    #-------------------------------------------------------------------------
    # first frame -- the original cell-averages

    pylab.clf()

    gpu.drawGrid(gr)

    gpu.labelCenter(gr, gr.ng + nzones/2,   r"$i$", fontsize="medium")
    gpu.labelCenter(gr, gr.ng + nzones/2-1, r"$i-1$", fontsize="medium")
    gpu.labelCenter(gr, gr.ng + nzones/2+1, r"$i+1$", fontsize="medium")
    gpu.labelCenter(gr, gr.ng + nzones/2-2, r"$i-2$", fontsize="medium")
    gpu.labelCenter(gr, gr.ng + nzones/2+2, r"$i+2$", fontsize="medium")


    # draw cell averages
    n = gr.ilo
    while (n <= gr.ihi):
        gpu.drawCellAvg(gr, n, a[n], color="r")
        n += 1

    pylab.axis([gr.xmin-0.5*gr.dx,gr.xmax+0.5*gr.dx, -0.25, 1.2])
    pylab.axis("off")

    print gr.xmin-0.5*gr.dx, gr.xmax+0.5*gr.dx

    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)

    if (nolimit):
        pylab.savefig("rea-nolimit-start_%3.3d.png" % (num))
        pylab.savefig("rea-nolimit-start_%3.3d.eps" % (num))
    else:
        pylab.savefig("rea-start_%3.3d.png" % (num))
        pylab.savefig("rea-start_%3.3d.eps" % (num))

    #-------------------------------------------------------------------------
    # second frame -- reconstruction

    # compute the slopes
    lda = gpu.lslopes(a, nolimit=nolimit)

    # draw
    pylab.clf()

    gpu.drawGrid(gr)

    gpu.labelCenter(gr, gr.ng + nzones/2,   r"$i$", fontsize="medium")
    gpu.labelCenter(gr, gr.ng + nzones/2-1, r"$i-1$", fontsize="medium")
    gpu.labelCenter(gr, gr.ng + nzones/2+1, r"$i+1$", fontsize="medium")
    gpu.labelCenter(gr, gr.ng + nzones/2-2, r"$i-2$", fontsize="medium")
    gpu.labelCenter(gr, gr.ng + nzones/2+2, r"$i+2$", fontsize="medium")


    # draw cell averages
    n = gr.ilo
    while (n <= gr.ihi):
        gpu.drawCellAvg(gr, n, a[n], color="0.5", ls=":")
        n += 1

    n = gr.ilo
    while (n <= gr.ihi):
        gpu.drawSlope(gr, n, lda[n], a[n], color="r")
        n += 1

    pylab.axis([gr.xmin-0.5*gr.dx,gr.xmax+0.5*gr.dx, -0.25, 1.2])
    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)

    if (nolimit):
        pylab.savefig("rea-nolimit-reconstruction_%3.3d.png" % (num))
        pylab.savefig("rea-nolimit-reconstruction_%3.3d.eps" % (num))
    else:
        pylab.savefig("rea-reconstruction_%3.3d.png" % (num))
        pylab.savefig("rea-reconstruction_%3.3d.eps" % (num))


    #-------------------------------------------------------------------------
    # third frame -- evolve

    # draw

    pylab.clf()

    gpu.drawGrid(gr)

    gpu.labelCenter(gr, gr.ng + nzones/2,   r"$i$", fontsize="medium")
    gpu.labelCenter(gr, gr.ng + nzones/2-1, r"$i-1$", fontsize="medium")
    gpu.labelCenter(gr, gr.ng + nzones/2+1, r"$i+1$", fontsize="medium")
    gpu.labelCenter(gr, gr.ng + nzones/2-2, r"$i-2$", fontsize="medium")
    gpu.labelCenter(gr, gr.ng + nzones/2+2, r"$i+2$", fontsize="medium")


    # draw cell slopes
    n = gr.ilo
    while (n <= gr.ihi):
        gpu.drawSlope(gr, n, lda[n], a[n], color="0.75", ls=":")
        n += 1

    # evolve
    n = gr.ilo
    while (n <= gr.ihi):
        gpu.evolveToRight(gr, n, lda, a, C, color="r")
        n += 1


    pylab.axis([gr.xmin-0.5*gr.dx,gr.xmax+0.5*gr.dx, -0.25, 1.2])
    pylab.axis("off")

    print gr.xmin-0.5*gr.dx, gr.xmax+0.5*gr.dx
    
    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)

    if (nolimit):
        pylab.savefig("rea-nolimit-evolve_%3.3d.png" % (num))
        pylab.savefig("rea-nolimit-evolve_%3.3d.eps" % (num))
    else:
        pylab.savefig("rea-evolve_%3.3d.png" % (num))
        pylab.savefig("rea-evolve_%3.3d.eps" % (num))


    #-------------------------------------------------------------------------
    # fourth frame -- re-average

    # left states (we don't need the right state when u > 0)
    al = numpy.zeros(2*gr.ng + gr.nx, dtype=numpy.float64)

    n = gr.ilo
    while (n <= gr.ihi+1):
        al[n] = a[n-1] + 0.5*(1 - C)*lda[n-1]
        n += 1


    # the Riemann problem just picks the left state.  Do a conservative
    # update
    anew = numpy.zeros(2*gr.ng + gr.nx, dtype=numpy.float64)

    anew[gr.ilo:gr.ihi+1] = a[gr.ilo:gr.ihi+1] + \
        C*(al[gr.ilo:gr.ihi+1] - al[gr.ilo+1:gr.ihi+2])


    pylab.clf()

    gpu.drawGrid(gr)

    gpu.labelCenter(gr, gr.ng + nzones/2,   r"$i$", fontsize="medium")
    gpu.labelCenter(gr, gr.ng + nzones/2-1, r"$i-1$", fontsize="medium")
    gpu.labelCenter(gr, gr.ng + nzones/2+1, r"$i+1$", fontsize="medium")
    gpu.labelCenter(gr, gr.ng + nzones/2-2, r"$i-2$", fontsize="medium")
    gpu.labelCenter(gr, gr.ng + nzones/2+2, r"$i+2$", fontsize="medium")


    # show the evolved profiles from the old time
    n = gr.ilo
    while (n <= gr.ihi):
        gpu.evolveToRight(gr, n, lda, a, C, color="0.5", ls=":")
        n += 1

    # draw new averages
    n = gr.ilo
    while (n <= gr.ihi):
        gpu.drawCellAvg(gr, n, anew[n], color="red")
        n += 1

    pylab.axis([gr.xmin-0.5*gr.dx,gr.xmax+0.5*gr.dx, -0.25, 1.2])
    pylab.axis("off")

    print gr.xmin-0.5*gr.dx, gr.xmax+0.5*gr.dx

    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)

    if (nolimit):
        pylab.savefig("rea-nolimit-final_%3.3d.png" % (num))
        pylab.savefig("rea-nolimit-final_%3.3d.eps" % (num))
    else:
        pylab.savefig("rea-final_%3.3d.png" % (num))
        pylab.savefig("rea-final_%3.3d.eps" % (num))

    return anew