Exemplo n.º 1
0
import grid_plot as gp

# plot a simple finite-difference grid showing the boundary data
# and a finite-volume grid with the same data, showing it's boundary

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

# finite-difference

# 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, 0.9, 0.8, 0.25, 0.1, 0.2, 0.5, 0.55])
nzones = len(a)

voff = 2.0
gr = gp.FDGrid(nzones, voff=voff)

gr.draw_grid(emphasize_end=True)

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

# draw the data
for i in range(nzones):
    gr.draw_data(i, a[i], color="r")

gr.label_value(nzones / 2, a[nzones / 2], r"$f_i$", color="r")
Exemplo n.º 2
0
import numpy as np
import matplotlib.pyplot as plt
import grid_plot as gp

# plot a simple finite-difference grid

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

nzones = 9

# 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.55, 0.3, 1.0, 0.9, 0.8, 0.25, 0.1, 0.5, 0.55])

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

plt.clf()

gr.draw_grid(draw_ghost=1)

labels = [
    "\mathrm{lo}-1", "\mathrm{lo}", "\mathrm{lo}+1", "", "i-1", "i", "i+1", "",
    "\mathrm{hi}-1", "\mathrm{hi}", "\mathrm{hi}+1"
]

for i in range(gr.ilo - gr.ng, gr.ng + gr.nx + 1):
    if not labels[i] == "":
        gr.label_node(i, r"$%s$" % (labels[i]), fontsize="medium")

# draw the data
for i in range(gr.ilo, gr.ihi + 1):
Exemplo n.º 3
0
import matplotlib.pyplot as plt
import numpy as np
import grid_plot as gp

# plot a simple finite-difference grid

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

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, 0.9, 0.8, 0.25, 0.1, 0.5, 0.55])

gr = gp.FDGrid(nzones)

plt.clf()

gr.draw_grid()

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

# draw the data
for i in range(nzones):
    gr.draw_data(i, a[i], color="r")

gr.label_value(nzones / 2, a[nzones / 2], r"$f_i$", color="r")
Exemplo n.º 4
0
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 = 5
nc = 3

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

plt.clf()

grf.draw_grid()
grc.draw_grid()

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

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

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