예제 #1
0
def simplegrid():

    # grid info
    xmin = 0.0
    xmax = 1.0

    nzones = 2
    ng = 0

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

    #------------------------------------------------------------------------
    # plot a domain without ghostcells
    gr.draw_grid(draw_end=False, edge_ticks=False)

    gr.label_center(0, r"$i$")
    gr.label_center(1, r"$i+1$")

    gr.label_edge(1, r"$q_{i+\myhalf,R}^{n+\myhalf}$")

    # draw waves
    # u - c
    plt.plot([gr.xr[0], gr.xr[0] - 0.75 * gr.dx], [0, 1.0],
             color="0.5",
             ls="-")
    plt.text(gr.xr[0] - 0.75 * gr.dx,
             1.0 + 0.05,
             "$\lambda^{(-)} =\, u - c$",
             horizontalalignment="center")

    # u
    plt.plot([gr.xr[0], gr.xr[0] - 0.2 * gr.dx], [0, 1.0], color="0.5", ls="-")
    plt.text(gr.xr[0] - 0.2 * gr.dx,
             1.0 + 0.05,
             "$\lambda^{(\circ)} =\, u$",
             horizontalalignment="center")

    # u + c
    plt.plot([gr.xr[0], gr.xr[0] + 0.4 * gr.dx], [0, 1.0], color="0.5", ls="-")
    plt.text(gr.xr[0] + 0.4 * gr.dx,
             1.0 + 0.05,
             "$\lambda^{(+)} =\, u + c$",
             horizontalalignment="center")

    # label regions
    plt.text(gr.xr[0] - 0.5 * gr.dx, 0.2, r"$L$", color="r")
    plt.text(gr.xr[0] - 0.33 * gr.dx, 0.6, r"$L^*$", color="r")
    plt.text(gr.xr[0] + 0.05 * gr.dx, 0.6, r"$R^*$", color="r")
    plt.text(gr.xr[0] + 0.3 * gr.dx, 0.2, r"$R$", color="r")

    gr.clean_axes(padding=False)
    plt.ylim(-0.2, 1.2)

    plt.tight_layout()

    f = plt.gcf()
    f.set_size_inches(5, 2.5)

    plt.savefig("riemann-waves.pdf")
예제 #2
0
def simplegrid():

    # grid info
    xmin = 0.0
    xmax = 1.0

    nzones = 2
    ng = 0

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

    #------------------------------------------------------------------------
    # plot a domain without ghostcells
    gr.draw_grid(draw_end=False, edge_ticks=False)

    gr.label_center(0, r"$i$")
    gr.label_center(1, r"$i+1$")

    gr.label_edge(1, r"$q_{i+\myhalf}$")

    # draw waves
    # u - c
    plt.plot([gr.xr[0], gr.xr[0] - 0.75 * gr.dx], [0, 1.0], color="C0", ls="-")
    plt.text(gr.xr[0] - 0.75 * gr.dx,
             1.0 + 0.05,
             "$\lambda^{(-)} =\, u - c$",
             horizontalalignment="center")

    # u
    plt.plot([gr.xr[0], gr.xr[0] - 0.2 * gr.dx], [0, 1.0], color="C0", ls="-")
    plt.text(gr.xr[0] - 0.2 * gr.dx,
             1.0 + 0.05,
             "$\lambda^{(\circ)} =\, u$",
             horizontalalignment="center")

    # u + c
    plt.plot([gr.xr[0], gr.xr[0] + 0.4 * gr.dx], [0, 1.0], color="C0", ls="-")
    plt.text(gr.xr[0] + 0.4 * gr.dx,
             1.0 + 0.05,
             "$\lambda^{(+)} =\, u + c$",
             horizontalalignment="center")

    plt.plot([gr.xl[0], gr.xr[0]], [0.3, 0.3], color="C1", linewidth=2)
    plt.text(gr.xc[0], 0.33, r"$\langle q \rangle_i$", color="C1")

    plt.plot([gr.xl[1], gr.xr[1]], [0.6, 0.6], color="C1", linewidth=2)
    plt.text(gr.xc[1], 0.63, r"$\langle q \rangle_{i+1}$", color="C1")

    gr.clean_axes(padding=False)
    plt.ylim(-0.2, 1.2)

    plt.tight_layout()

    f = plt.gcf()
    f.set_size_inches(6, 3.5)

    plt.savefig("riemann-waves-jump.png", dpi=150)
def riemann():

    # grid info
    xmin = 0.0
    xmax = 1.0

    nzones = 2
    ng = 0

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


    #------------------------------------------------------------------------
    # plot a domain without ghostcells
    gr.draw_grid(emphasize_end=True)

    # label a few
    gr.label_center(0, r"$i$", fontsize="medium")
    gr.label_center(1, r"$i+1$", fontsize="medium")
    gr.label_edge(1, r"$i+1/2$", fontsize="medium")

    gr.mark_cell_left_state(1, r"$q_{i+1/2,R}^{n+1/2}$", fontsize="large",
                            color="b")
    gr.mark_cell_right_state(0, r"$q_{i+1/2,L}^{n+1/2}$", fontsize="large",
                             color="b")

    gr.label_cell_center(0, r"$q_i$")
    gr.label_cell_center(1, r"$q_{i+1}$")



    # flux
    plt.arrow(gr.xl[ng+nzones/2]-0.25*gr.dx, 1.05, 0.5*gr.dx, 0, 
                shape='full', head_width=0.075, head_length=0.05, 
                lw=1, width=0.03,
                edgecolor="none", facecolor="red",
                length_includes_head=True, zorder=100)
    
    plt.text(gr.xl[ng+nzones/2], 1.15, r"$F(U(q_{i+1/2}^{n+1/2}))$", color="red",
               horizontalalignment="center")


    gr.clean_axes(padding=False)
    plt.ylim(-0.25, 1.25)

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

    f = plt.gcf()
    f.set_size_inches(6.0,2.25)


    plt.tight_layout()

    plt.savefig("riemann_comp_q.pdf")
    plt.savefig("riemann_comp_q.png")
예제 #4
0
def simplegrid():

    # grid info
    nzones = 7
    ng = 1

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

    gr.draw_grid(emphasize_end=1, edge_ticks=0, draw_ghost=1)

    # label a few
    gr.label_center(ng + nzones / 2, r"$i$", fontsize="medium")
    gr.label_center(ng + nzones / 2 - 1, r"$i-1$", fontsize="medium")
    gr.label_center(ng + nzones / 2 + 1, r"$i+1$", fontsize="medium")

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

    # label dx
    plt.plot([gr.xl[ng + nzones / 2 - 2], gr.xl[ng + nzones / 2 - 2]],
             [-0.35, -0.25],
             color="k")

    plt.plot([gr.xr[ng + nzones / 2 - 2], gr.xr[ng + nzones / 2 - 2]],
             [-0.35, -0.25],
             color="k")

    plt.plot([gr.xl[ng + nzones / 2 - 2], gr.xr[ng + nzones / 2 - 2]],
             [-0.3, -0.3],
             color="k")

    plt.text(gr.xc[ng + nzones / 2 - 2],
             -0.5,
             r"$\Delta x$",
             horizontalalignment="center")

    plt.xlim(gr.xl[0] - 0.05 * gr.dx,
             gr.xr[2 * ng + nzones - 1] + 0.25 * gr.dx)
    plt.ylim(-0.5, 1.5)
    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(10.0, 2.5)

    plt.tight_layout()

    plt.savefig("simplegrid_gc.png")
    plt.savefig("simplegrid_gc.pdf", bbox_inches="tight")
예제 #5
0
def riemann(with_time=True):

    # grid info
    xmin = 0.0
    xmax = 1.0

    nzones = 1
    ng = 0

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

    plt.clf()

    #------------------------------------------------------------------------
    # plot a domain without ghostcells
    gr.draw_grid()

    gr.label_center(0, r"$i$", fontsize="medium")

    gr.label_edge(0, r"$i-\myhalf$", fontsize="medium")
    gr.label_edge(0, r"$i+\myhalf$", fontsize="medium", right_edge=True)


    plt.arrow(gr.xc[0]+0.05*gr.dx, 0.5, 0.12*gr.dx, 0,
                shape='full', head_width=0.05, head_length=0.025,
                lw=1, width=0.02,
                edgecolor="none", facecolor="r",
                length_includes_head=True, zorder=100)

    plt.arrow(gr.xc[0]-0.05*gr.dx, 0.5, -0.12*gr.dx, 0,
                shape='full', head_width=0.05, head_length=0.025,
                lw=1, width=0.02,
                edgecolor="none", facecolor="r",
                length_includes_head=True, zorder=100)

    gr.mark_cell_left_state(0, r"$a_{i-\myhalf,R}$", fontsize="large",
                            color="b")
    gr.mark_cell_right_state(0, r"$a_{i+\myhalf,L}$", fontsize="large",
                             color="b")

    gr.label_cell_center(0, r"$a_i$")

    gr.clean_axes(pad_fac=0.125, ylim=(-0.25, 1.0))

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

    plt.tight_layout()

    plt.savefig("advection-states.png")
예제 #6
0
def riemann():

    # grid info
    xmin = 0.0
    xmax = 1.0

    nzones = 1
    ng = 0

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


    #------------------------------------------------------------------------
    # plot a domain without ghostcells
    gr.draw_grid()

    gr.label_center(0, r"$i$")

    gr.label_cell_center(0, r"$q_i$")

    gr.mark_cell_left_state(0, r"$q_{i-1/2,R}^{n+1/2}$", color="r")
    gr.mark_cell_right_state(0, r"$q_{i+1/2,L}^{n+1/2}$", color="r")


    plt.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)

    plt.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)


    plt.xlim(gr.xl[0]-0.25*gr.dx,gr.xr[2*ng+nzones-1]+0.25*gr.dx)
    # plt.ylim(-0.25, 0.75)
    plt.axis("off")

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

    f = plt.gcf()
    f.set_size_inches(4.0,2.5)


    plt.savefig("states.png")
    plt.savefig("states.pdf")
def laplace():

    # grid info
    xmin = 0.0
    xmax = 1.0

    nzones = 3
    ng = 0

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


    #------------------------------------------------------------------------
    # plot a domain without ghostcells
    gr.draw_grid(emphasize_end=True)

    # label a few
    gr.label_center(0, r"$i-1$", fontsize="medium")
    gr.label_center(1, r"$i$", fontsize="medium")
    gr.label_center(2, r"$i+1$", fontsize="medium")
    gr.label_edge(1, r"$i-\myhalf$", fontsize="medium")
    gr.label_edge(2, r"$i+\myhalf$", fontsize="medium")

    gr.label_cell_center(0, r"$\phi_{i-1}$")
    gr.label_cell_center(1, r"$\phi_{i}$", value=0.7)
    gr.label_cell_center(2, r"$\phi_{i+1}$")

    gr.mark_cell_edge(1, r"$\left .\frac{d\phi}{dx} \right |_{i-\myhalf}$", color="C0")
    gr.mark_cell_edge(2, r"$\left .\frac{d\phi}{dx} \right |_{i+\myhalf}$", color="C0")
    
    gr.label_cell_center(1, r"$\left .\frac{d^2\phi}{dx^2} \right |_{i}$", 
                         value=0.3, color="C1")

    gr.clean_axes(padding=False)
    plt.ylim(-0.25, 1.25)

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

    f = plt.gcf()
    f.set_size_inches(6.0,2.25)


    plt.tight_layout()

    plt.savefig("laplacian.pdf")
예제 #8
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 simplegrid():

    # grid info
    nzones = 7
    ng = 1

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

    gr.draw_grid(emphasize_end=1, edge_ticks=0, draw_ghost=1)

    # label a few
    gr.label_center(ng + nzones // 2, r"$i$", fontsize="medium")
    gr.label_center(ng + nzones // 2 - 1, r"$i-1$", fontsize="medium")
    gr.label_center(ng + nzones // 2 + 1, r"$i+1$", fontsize="medium")

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

    # label dx
    gr.label_dx(ng + nzones // 2 - 2)

    gr.clean_axes(show_ghost=True,
                  ylim=(-0.5, 1.5),
                  padding=True,
                  pad_fac=0.05)
    #plt.xlim(gr.xl[0]-0.05*gr.dx,gr.xr[2*ng+nzones-1]+0.25*gr.dx)
    #plt.ylim(-0.5, 1.5)
    #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(10.0, 2.5)

    plt.tight_layout()

    plt.savefig("simplegrid_gc.pdf", bbox_inches="tight")
def simplegrid():

    nzones = 7

    gr = gp.FVGrid(nzones, xmin=0, xmax=1)

    gr.draw_grid(edge_ticks=0)

    # label a few cell-centers
    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$")

    # label a few edges
    gr.label_edge(nzones / 2, r"$i-1/2$")
    gr.label_edge(nzones / 2 + 1, r"$i+1/2$")

    # sample data
    A = 0.4
    a = A * np.ones(nzones, dtype=np.float64)

    pc = gp.PiecewiseConstant(gr, a)

    # draw an average quantity
    pc.draw_cell_avg(nzones / 2, color="r")
    pc.label_cell_avg(nzones / 2, r"$\,\langle a \rangle_i$", color="r")

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

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

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

    plt.savefig("simplegrid2.png")
    plt.savefig("simplegrid2.pdf")
예제 #11
0
import numpy as np
import matplotlib.pyplot as plt
import grid_plot as gp


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

nzones = 8

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

gr = gp.FVGrid(nzones)


plt.clf()

gr.draw_grid(center_only=1)

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


ppm = gp.PiecewiseParabolic(gr, a)

for n in range(gr.nx//2-1, gr.nx//2+1):
    ppm.draw_parabola(n, color="r")

nn = gr.nx//2-1
sigma = 0.6
def simplegrid():

    # grid info
    xmin = 0.0
    xmax = 1.0

    nzones = 2
    ng = 0

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

    #------------------------------------------------------------------------
    # plot a domain without ghostcells
    gr.draw_grid(draw_end=False, edge_ticks=False)

    gr.label_center(0, r"$i$")
    gr.label_center(1, r"$i+1$")

    gr.label_edge(1, r"$q_{i+\myhalf}$")

    # draw waves
    # u - c
    plt.plot([gr.xr[0], gr.xr[0] - 0.75 * gr.dx], [0, 1.0], color="C0", ls="-")
    plt.text(gr.xr[0] - 0.75 * gr.dx,
             1.0 + 0.05,
             "$\lambda^{(-)} =\, u - c$",
             horizontalalignment="center")

    # u
    plt.plot([gr.xr[0], gr.xr[0] - 0.2 * gr.dx], [0, 1.0], color="C0", ls="-")
    plt.text(gr.xr[0] - 0.2 * gr.dx,
             1.0 + 0.05,
             "$\lambda^{(\circ)} =\, u$",
             horizontalalignment="center")

    # u + c
    plt.plot([gr.xr[0], gr.xr[0] + 0.4 * gr.dx], [0, 1.0], color="C0", ls="-")
    plt.text(gr.xr[0] + 0.4 * gr.dx,
             1.0 + 0.05,
             "$\lambda^{(+)} =\, u + c$",
             horizontalalignment="center")

    # label regions
    plt.text(gr.xr[0] - 0.5 * gr.dx,
             0.3,
             r"$L$",
             horizontalalignment="center",
             color="C1")
    plt.text(gr.xr[0] - 0.5 * gr.dx,
             0.22,
             r"$(\rho_L, u_L, p_L)$",
             horizontalalignment="center",
             color="C1",
             fontsize="small")

    plt.text(gr.xr[0] - 0.33 * gr.dx,
             0.75,
             r"$L_*$",
             horizontalalignment="center",
             color="C1")
    plt.text(gr.xr[0] - 0.33 * gr.dx,
             0.67,
             r"$(\rho_{\star L}, u_\star, p_\star)$",
             horizontalalignment="center",
             color="C1",
             fontsize="small")

    plt.text(gr.xr[0] + 0.1 * gr.dx,
             0.75,
             r"$R_*$",
             horizontalalignment="center",
             color="C1")
    plt.text(gr.xr[0] + 0.1 * gr.dx,
             0.67,
             r"$(\rho_{\star R}, u_\star, p_\star)$",
             horizontalalignment="center",
             color="C1",
             fontsize="small",
             zorder=1000)

    plt.text(gr.xr[0] + 0.3 * gr.dx,
             0.3,
             r"$R$",
             horizontalalignment="center",
             color="C1")
    plt.text(gr.xr[0] + 0.3 * gr.dx,
             0.22,
             r"$(\rho_R, u_R, p_R)$",
             horizontalalignment="center",
             color="C1",
             fontsize="small")

    gr.clean_axes(padding=False)
    plt.ylim(-0.2, 1.2)

    plt.tight_layout()

    f = plt.gcf()
    f.set_size_inches(6, 3.5)

    plt.savefig("riemann-waves.pdf")
예제 #13
0
def riemann(with_time=True):

    # grid info
    xmin = 0.0
    xmax = 1.0

    nzones = 2
    ng = 0

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

    plt.clf()

    #------------------------------------------------------------------------
    # plot a domain without ghostcells
    gr.draw_grid()

    gr.label_center(0, r"$i$", fontsize="medium")
    gr.label_center(0,
                    r"${\tt a[i]}$",
                    fontsize="medium",
                    extra_voff=-0.3,
                    color="r")

    gr.label_center(1, r"$i+1$", fontsize="medium")
    gr.label_center(1,
                    r"${\tt a[i+1]}$",
                    fontsize="medium",
                    extra_voff=-0.3,
                    color="r")

    gr.label_edge(0, r"$i-\myhalf$", fontsize="medium")
    gr.label_edge(0,
                  r"${\tt aint[i]}$",
                  fontsize="medium",
                  extra_voff=-0.3,
                  color="r")

    gr.label_edge(1, r"$i+\myhalf$", fontsize="medium")
    gr.label_edge(1,
                  r"${\tt aint[i+1]}$",
                  fontsize="medium",
                  extra_voff=-0.3,
                  color="r")

    gr.label_edge(1, r"$i+\mythreehalf$", fontsize="medium", right_edge=True)
    gr.label_edge(1,
                  r"${\tt aint[i+2]}$",
                  fontsize="medium",
                  extra_voff=-0.3,
                  color="r",
                  right_edge=True)

    gr.mark_cell_edge(0, r"$a_{i-\myhalf}$", fontsize="large", color="r")
    gr.mark_cell_edge(1, r"$a_{i+\myhalf}$", fontsize="large", color="r")
    gr.mark_cell_edge(1,
                      r"$a_{i+\mythreehalf}$",
                      fontsize="large",
                      color="r",
                      right_edge=True)

    gr.label_cell_center(0, r"$a_i$", color="r")
    gr.label_cell_center(1, r"$a_{i+1}$", color="r")

    gr.clean_axes(pad_fac=0.125, ylim=(-0.25, 1.0))

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

    plt.tight_layout()

    plt.savefig("array-labels.png")
import numpy as np
import matplotlib.pyplot as plt
import grid_plot as gp

# plot two stacked fv grids of different (2x) resolution to show prolongation

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

nf = 4
nc = nf // 2

grf = gp.FVGrid(nf, voff=2.0)
grc = gp.FVGrid(nc)

plt.clf()

grf.draw_grid()
grc.draw_grid()

grf.label_center(nf // 2 - 2, r"$i-2$")
grf.label_center(nf // 2 - 1, r"$i-1$")
grf.label_center(nf // 2, r"$i$")
grf.label_center(nf // 2 + 1, r"$i+1$")

grc.label_center(nc // 2 - 1, r"$j-1$")
grc.label_center(nc // 2, r"$j$")

grf.label_cell_center(nf // 2 - 2, r"$\phi_{i-2}^f$")
grf.label_cell_center(nf // 2 - 1, r"$\phi_{i-1}^f$")
grf.label_cell_center(nf // 2, r"$\phi_i^f$")
grf.label_cell_center(nf // 2 + 1, r"$\phi_{i+1}^f$")
예제 #15
0
import matplotlib.pyplot as plt
import grid_plot as gp

# plot two stacked fv grids of different (2x) resolution to show prolongation

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

gr = []

nzones = [2, 4, 8, 16]
for nf in nzones:
    gr.append(gp.FVGrid(nf, ng=1, voff=2.0 * len(gr)))

plt.clf()

for g in gr:
    g.draw_grid(emphasize_end=1, draw_ghost=1, edge_ticks=0)

f = plt.gcf()
f.set_size_inches(7.0, 5.0)

grf = gr[0]
plt.xlim(grf.xmin - 1.1 * grf.dx, grf.xmax + 1.1 * grf.dx)

plt.axis("off")

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

plt.savefig("mgtower.pdf")
예제 #16
0
def riemann():

    # grid info
    xmin = 0.0
    xmax = 1.0

    nzones = 2
    ng = 0

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

    #------------------------------------------------------------------------
    # plot a domain without ghostcells
    gr.draw_grid()

    gr.label_center(0, r"$i$", fontsize="medium")
    gr.label_center(1, r"$i+1$", fontsize="medium")

    gr.label_edge(1, r"$i+1/2$", fontsize="medium")

    plt.arrow(gr.xc[0] + 0.05 * gr.dx,
              0.5,
              0.12 * gr.dx,
              0,
              shape='full',
              head_width=0.05,
              head_length=0.025,
              lw=1,
              width=0.02,
              edgecolor="none",
              facecolor="r",
              length_includes_head=True,
              zorder=100)

    plt.arrow(gr.xc[1] - 0.1 * gr.dx,
              0.5,
              -0.12 * gr.dx,
              0,
              shape='full',
              head_width=0.05,
              head_length=0.025,
              lw=1,
              width=0.02,
              edgecolor="none",
              facecolor="r",
              length_includes_head=True,
              zorder=100)

    gr.mark_cell_left_state(1,
                            r"$a_{i+1/2,L}^{n+1/2}$",
                            fontsize="large",
                            color="b")
    gr.mark_cell_right_state(0,
                             r"$a_{i+1/2,R}^{n+1/2}$",
                             fontsize="large",
                             color="b")

    gr.label_cell_center(0, r"$a_i$")
    gr.label_cell_center(1, r"$a_{i+1}$")

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

    plt.ylim(-0.25, 1.0)
    plt.axis("off")

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

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

    plt.tight_layout()

    plt.savefig("riemann-adv.pdf")
        else:
            for n in range(5):
                x3 = self.x0 + self.dx * np.tan(
                    np.radians(self.right_pos + 2 * n))
                plt.plot([self.x0, x3], [0, self.dx], color="C0", lw=1)


if __name__ == "__main__":

    xmin = 0.0
    xmax = 8.0

    nzones = 4
    ng = 0

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

    gr.draw_grid()

    gr.label_edge(0, r"$i-\mythreehalf$", fontsize="medium")
    gr.label_edge(1, r"$i-\myhalf$", fontsize="medium")
    gr.label_edge(2, r"$i+\myhalf$", fontsize="medium")
    gr.label_edge(3, r"$i+\mythreehalf$", fontsize="medium")
    gr.label_edge(3, r"$i+\myfivehalf$", fontsize="medium", right_edge=True)

    gr.label_center(0, r"$i-1$", fontsize="medium")
    gr.label_center(1, r"$i$", fontsize="medium")
    gr.label_center(2, r"$i+1$", fontsize="medium")
    gr.label_center(3, r"$i+2$", fontsize="medium")

    riemann = []
예제 #18
0
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")
예제 #19
0
import matplotlib.pyplot as plt
import grid_plot as gp

# plot two stacked fv grids of different (2x) resolution to show prolongation

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

gr = []

nf = 8
gr.append(gp.FVGrid(nf, ng=1, voff=0.0))
gr.append(gp.FVGrid(nf, ng=1, voff=0.0, xmin=0.25, xmax=0.75))

plt.clf()

gr[0].draw_grid(emphasize_end=1, draw_ghost=0, edge_ticks=0, color="0.75")
gr[1].draw_grid(emphasize_end=1, draw_ghost=0, edge_ticks=0)

f = plt.gcf()
f.set_size_inches(7.0, 1.0)

grf = gr[0]
plt.xlim(grf.xmin - 0.75 * grf.dx, grf.xmax + 0.25 * grf.dx)

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

plt.savefig("nested1.pdf")

#-----------------------------------------------------------------------------
예제 #20
0
         [-0.35 + voff, -0.25 + voff],
         color="k")
plt.plot([gr.xc[gr.ng + nzones / 2 - 1], gr.xc[gr.ng + nzones / 2]],
         [-0.3 + voff, -0.3 + voff],
         color="k")
plt.text(0.5 * (gr.xc[gr.ng + nzones / 2 - 1] + gr.xc[gr.ng + nzones / 2]),
         -0.45 + voff,
         r"$\Delta x$",
         horizontalalignment="center")

# finite-volume
av = 0.5 * (a[0:nzones - 1] + a[1:])
nzones = len(av)
ng = 1

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

gr.draw_grid(emphasize_end=True, draw_ghost=True)

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

gr.label_center(ng + nzones - 1, r"$\mathrm{hi}$", fontsize="large")
gr.label_center(ng + nzones, r"$\mathrm{hi+1}$", fontsize="large")

gr.label_center(gr.ilo, r"$\mathrm{lo}$", fontsize="large")
gr.label_center(gr.ilo - 1, r"$\mathrm{lo-1}$", fontsize="large")

a = gr.scratch_array()
a[gr.ilo:gr.ihi + 1] = av
예제 #21
0
import matplotlib.pyplot as plt
import grid_plot as gp

# plot two stacked fv grids of different (2x) resolution to show prolongation

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

nf = 4
nc = nf / 2

grf = gp.FVGrid(nf)
grc = gp.FVGrid(nc, voff=2.0)

plt.clf()

grf.draw_grid()
grc.draw_grid()

grf.label_center(nf / 2 - 2, r"$i-2$")
grf.label_center(nf / 2 - 1, r"$i-1$")
grf.label_center(nf / 2, r"$i$")
grf.label_center(nf / 2 + 1, r"$i+1$")

grc.label_center(nc / 2 - 1, r"$j-1$")
grc.label_center(nc / 2, r"$j$")

grf.label_cell_center(nf / 2 - 2, r"$\phi_{i-2}^h$")
grf.label_cell_center(nf / 2 - 1, r"$\phi_{i-1}^h$")
grf.label_cell_center(nf / 2, r"$\phi_i^h$")
grf.label_cell_center(nf / 2 + 1, r"$\phi_{i+1}^h$")