Exemple #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")
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])
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)
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")
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
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$", 
# 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])
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)
Exemple #6
0
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$")

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$", 
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")
gpu.drawGrid(gr, emphasizeEnd=1, drawGhost=1)

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

gpu.labelCenter(gr, ng + 0, r"$\mathrm{lo}$")
gpu.labelCenter(gr, ng - 1, r"$\mathrm{lo-1}$")

gpu.labelCenter(gr, ng + gr.nx - 1, r"$\mathrm{hi}$")
gpu.labelCenter(gr, ng + gr.nx, r"$\mathrm{hi+1}$")

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

gpu.labelEdge(gr, ng + gr.nx, r"$b$")
gpu.labelEdge(gr, ng + 0, r"$a$")

# draw the data
i = 0
while i < ncells + 2 * ng:
    gpu.drawCellAvg(gr, i, acell[i], color="r")
    i += 1

gpu.labelCellAvg(gr,
                 ng + ncells / 2,
                 acell[ng + ncells / 2],
                 r"$\langle f\rangle_i$",