Exemple #1
0
def main():

    ainit = np.array([1.0, 1.0, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1])
    nzones = len(ainit)

    nolimit = 1

    # CFL number
    C = 0.7

    gr = gp.FVGrid(nzones, ng=4)

    a = gr.scratch_array()
    a[gr.ilo:gr.ihi + 1] = ainit[:]

    pl = gp.PiecewiseLinear(gr, a, nolimit=nolimit)

    # loop
    for i in range(1, 9):
        pl.fill_zero_gradient()
        evolve(gr, pl, C, i, nolimit=nolimit)
def riemann():

    # grid info
    xmin = 0.0
    xmax = 1.0

    nzones = 4
    ng = 2

    gr = gp.FVGrid(nzones, ng=ng, xmin=xmin, xmax=xmax)

    # interior and ghost cell initialization
    a = gr.scratch_array()

    a[gr.ilo:gr.ihi + 1] = np.array([0.8, 0.7, 0.4, 0.5])
    a[0:gr.ilo] = a[gr.ihi - 1:gr.ihi + 1]
    a[gr.ihi:2 * gr.ng + gr.nx] = a[gr.ihi]

    pc = gp.PiecewiseConstant(gr, a)
    pl = gp.PiecewiseLinear(gr, a, nolimit=1)

    #------------------------------------------------------------------------
    # plot a domain without ghostcells
    gr.draw_grid(draw_ghost=1, emphasize_end=1)

    gr.label_center(gr.ng - 2, r"$\mathrm{lo-2}$", fontsize="medium")
    gr.label_center(gr.ng - 1, r"$\mathrm{lo-1}$", fontsize="medium")
    gr.label_center(gr.ng, r"$\mathrm{lo}$", fontsize="medium")
    gr.label_center(gr.ng + 1, r"$\mathrm{lo+1}$", fontsize="medium")

    gr.label_edge(gr.ng, r"$\mathrm{lo}-\myhalf$", fontsize="medium")

    # draw cell averages
    for n in range(0, gr.ng + gr.nx - 1):
        pc.draw_cell_avg(n, color="0.5", ls=":")

    # draw slopes
    for n in range(gr.ilo - 1, gr.ihi):
        pl.draw_slope(n, color="r")

    # 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) * pl.slope[gr.ilo - 1]
    ar = a[gr.ilo] - 0.5 * gr.dx * (1.0 + C) * pl.slope[gr.ilo]

    # L
    gr.mark_cell_right_state(ng - 1,
                             r"$a_{\mathrm{lo}+\myhalf,L}^{n+\myhalf}$",
                             value=al,
                             vertical="top",
                             color="b")

    # R
    gr.mark_cell_left_state(ng,
                            r"$a_{\mathrm{lo}+\myhalf,R}^{n+\myhalf}$",
                            value=ar,
                            vertical="top",
                            color="b")

    plt.xlim(gr.xl[0] - 0.025 * gr.dx, gr.xr[ng + 1] + 0.15 * gr.dx)
    plt.ylim(-0.25, 1.1)
    plt.axis("off")

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

    f = plt.gcf()
    f.set_size_inches(8.0, 2.0)

    plt.tight_layout()

    plt.savefig("riemann-bc.pdf")
import math
import numpy as np
import matplotlib.pyplot as plt
import grid_plot as gp

nzones = 7

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

gr = gp.FVGrid(nzones)
a = gr.scratch_array()
a[gr.ilo:gr.ihi + 1] = ainit[:]

pl_nolim = gp.PiecewiseLinear(gr, a, nolimit=1)
pl = gp.PiecewiseLinear(gr, a)

gr.draw_grid()

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

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

for n in range(nzones):
    pl.draw_cell_avg(n, ls=":", color="0.5")
    pl_nolim.draw_slope(n, color="0.5")
Exemple #4
0
import grid_plot as gp

#-----------------------------------------------------------------------------

atemp = np.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 = gp.FVGrid(nzones, ng=4)

a = gr.scratch_array()
a[gr.ilo:gr.ihi + 1] = atemp[:]

pl = gp.PiecewiseLinear(gr, a)
pl.fill_zero_gradient()

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

plt.clf()

gr.draw_grid()

labels = ["$i-2$", "$i-1$", "$i$", "$i+1$", "$i+2$"]
indices = [
    gr.ng + nzones / 2 - 2, gr.ng + nzones / 2 - 1, gr.ng + nzones / 2,
    gr.ng + nzones / 2 + 1, gr.ng + nzones / 2 + 2
]
    if nolimit:
        plt.savefig("rea-nolimit-final_%3.3d.pdf" % (num))
    else:
        plt.savefig("rea-final_%3.3d.pdf" % (num))

    return anew


#-----------------------------------------------------------------------------
ainit = np.array([1.0, 1.0, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1])
nzones = len(ainit)

# CFL number
C = 0.7
nolimit = 1

gr = gp.FVGrid(nzones, ng=4)

a = gr.scratch_array()
a[gr.ilo:gr.ihi + 1] = ainit[:]

pl = gp.PiecewiseLinear(gr, a, nolimit=nolimit)

# loop
for i in range(1, 9):

    pl.fill_zero_gradient()
    print i, pl.a[:]
    evolve(pl, C, i, nolimit=nolimit)
Exemple #6
0
plt.savefig("piecewise-constant.pdf")
plt.savefig("piecewise-constant.png")

#------------- PLM -------------
plt.clf()

gr.draw_grid()

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

# not limited and limited
pl_n = gp.PiecewiseLinear(gr, a, nolimit=1)
pl_y = gp.PiecewiseLinear(gr, a)

for n in range(nzones):
    pc.draw_cell_avg(n, color="0.5")

for n in range(2, nzones - 2):
    pl_n.draw_slope(n, color="r", ls=":")
    pl_y.draw_slope(n, color="r")

gr.clean_axes()
plt.ylim(-0.25, 1.2)

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

f = plt.gcf()