Example #1
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")
Example #2
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")
Example #3
0
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)

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

    pylab.xlim(gr.xl[0] - 0.5 * gr.dx,
               gr.xr[2 * ng + nzones - 1] + 0.5 * gr.dx)

    # 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.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=0.95)

    pylab.ylim(-0.5, 1.5)
    pylab.axis("off")

    f = pylab.gcf()
    f.set_size_inches(10.0, 2.5)

    pylab.savefig("simplegrid.png")
    pylab.savefig("simplegrid.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)


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


    pylab.xlim(gr.xl[0]-0.5*gr.dx,gr.xr[2*ng+nzones-1]+0.5*gr.dx)

    # 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.subplots_adjust(left=0.05,right=0.95,bottom=0.05,top=0.95)

    pylab.ylim(-0.5, 1.5)
    pylab.axis("off")


    f = pylab.gcf()
    f.set_size_inches(10.0,2.5)


    pylab.savefig("simplegrid.png")
    pylab.savefig("simplegrid.eps")
Example #5
0
#-----------------------------------------------------------------------------

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)

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)
Example #6
0
#-----------------------------------------------------------------------------

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):
    gpu.drawParabola(gr, n, lap[n], lam[n], la6[n], color="r")
    n += 1

nn = gr.nx/2-1
sigma = 0.6
gpu.ppmTraceLeft(gr, nn, lap[nn], lam[nn], la6[nn], sigma, color="0.75")
nzones = 7
ng = 2

# 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])
a = numpy.array([1.0, 0.9, 0.8, 0.25, 0.1, 0.5, 0.55])

gr = gpu.grid(nzones, ng)

pylab.clf()

gpu.drawGrid(gr, drawGhost=1, emphasizeEnd=1)

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, 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
# -----------------------------------------------------------------------------

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$")
gpu.labelCellCenter(grf, nf / 2 - 1, r"$\phi_{i-1}^h$")
gpu.labelCellCenter(grf, nf / 2, r"$\phi_i^h$")
gpu.labelCellCenter(grf, nf / 2 + 1, r"$\phi_{i+1}^h$")
gpu.labelCellCenter(grf, nf / 2 + 2, r"$\phi_{i+2}^h$")
#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
i = gr.ilo
while i < gr.ihi + 1:
    gpu.drawFDData(gr, i, a[i - gr.ng], color="r")
    i += 1

gpu.labelFD(gr, gr.ilo + 4, a[gr.ilo + 4 - gr.ng], r"$a_i$", color="r")

# label dx
pylab.plot([gr.xc[gr.ng + nzones / 2 - 1], gr.xc[gr.ng + nzones / 2 - 1]],
           [-0.35, -0.25],
           color="k")
pylab.plot([gr.xc[gr.ng + nzones / 2], gr.xc[gr.ng + nzones / 2]],
Example #10
0
#-----------------------------------------------------------------------------

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")    
    i += 1
    

gpu.labelFD(gr, nzones/2, a[nzones/2], r"$f_i$", color="r")
Example #11
0
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
i = gr.ilo
while i < gr.ihi+1:
    gpu.drawFDData(gr, i, a[i-gr.ng], color="r")    
    i += 1
    

gpu.labelFD(gr, gr.ilo+4, a[gr.ilo+4-gr.ng], r"$a_i$", color="r")

# label dx
pylab.plot([gr.xc[gr.ng+nzones/2-1], gr.xc[gr.ng+nzones/2-1]], [-0.35,-0.25], color="k")
pylab.plot([gr.xc[gr.ng+nzones/2], gr.xc[gr.ng+nzones/2]], [-0.35,-0.25], color="k")
import numpy
import pylab
import grid_plot_util as gpu


nzones = 5

# data that lives on the grid
a = numpy.array([0.3, 1.0, 0.9, 0.8, 0.25, 0.15, 0.5])

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
Example #13
0
import math
import numpy
import pylab
import grid_plot_util as gpu

nzones = 5

# data that lives on the grid
a = numpy.array([0.3, 1.0, 0.9, 0.8, 0.25, 0.15, 0.5])

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])
Example #14
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")
Example #15
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
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")
    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")
    i += 1

gpu.labelFD(gr, ng + nnodes / 2, anode[ng + nnodes / 2], r"$f_i$", color="r")

# label dx
pylab.plot([gr.xc[gr.ng + nnodes / 2 - 1], gr.xc[gr.ng + nnodes / 2 - 1]],
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")
Example #19
0
# 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$")
gpu.labelCellCenter(grf, nf / 2 - 1, r"$\phi_{i-1}^h$")
gpu.labelCellCenter(grf, nf / 2, r"$\phi_i^h$")
gpu.labelCellCenter(grf, nf / 2 + 1, r"$\phi_{i+1}^h$")
gpu.labelCellCenter(grf, nf / 2 + 2, r"$\phi_{i+2}^h$")
Example #20
0
nzones = 7
ng = 2

# 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])
a = numpy.array([1.0, 0.9, 0.8, 0.25, 0.1, 0.5, 0.55])

gr = gpu.grid(nzones, ng)


pylab.clf()

gpu.drawGrid(gr, drawGhost=1, emphasizeEnd=1)

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, 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
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