Пример #1
0
    e = p/rho/(gamma - 1.0)

    # output the solution
    with open(outfile, "w") as f:
        f.write("# left: {}\n".format(left))
        f.write("# right: {}\n".format(right))
        f.write("# gamma = {}\n".format(gamma))
        f.write("# time = {}\n".format(time))
        f.write("# {:^20} {:^20} {:^20} {:^20} {:^20}\n".format("x", "rho", "u", "p", "e"))
        for n in range(len(x)):
            f.write("  {:20.10g} {:20.10g} {:20.10g} {:20.10g} {:20.10g}\n".format(x[n], rho[n], u[n], p[n], e[n]))


# Sod
left = riemann.State(p=1.0, u=0.0, rho=1.0)
right = riemann.State(p=0.1, u=0.0, rho=0.125)
time = 0.2
gamma = 1.4
outfile = "sod_exact.out"

store(left, right, time, gamma, outfile=outfile)

# double rarefaction
left = riemann.State(p=0.4, u=-2.0, rho=1.0)
right = riemann.State(p=0.4, u=2.0, rho=1.0)
time = 0.15
gamma = 1.4
outfile = "double_rarefaction_exact.out"

store(left, right, time, gamma, outfile=outfile)
Пример #2
0
mpl.rcParams['mathtext.fontset'] = 'cm'
mpl.rcParams['mathtext.rm'] = 'serif'
mpl.rcParams['font.size'] = 12
mpl.rcParams['legend.fontsize'] = 'large'
mpl.rcParams['figure.titlesize'] = 'medium'

if __name__ == "__main__":

    # setup the problem -- slow shock

    # stationary shock
    #left = riemann.State(p=100.0, u=-1.9336, rho=5.6698)
    #right = riemann.State(p=1.0, u=-10.9636, rho=1.0)

    # slow shock
    left = riemann.State(p=100.0, u=-1.4701, rho=5.6698)
    right = riemann.State(p=1.0, u=-10.5, rho=1.0)

    rp = riemann.RiemannProblem(left, right)
    rp.find_star_state()

    x, rho, u, p = rp.sample_solution(1.0, 128)

    plt.subplot(311)

    plt.plot(x, rho)

    plt.ylabel(r"$\rho$")

    plt.xlim(0, 1)
    plt.tick_params(axis="x", labelbottom="off")
Пример #3
0
    def draw_var_avg(self, var, scale=1.0):
        for n in range(self.gr.nx):
            self.vars[var].draw_cell_avg(n, color="r")


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



# multipage PDF
# http://matplotlib.org/examples/pylab_examples/multipage_pdf.html


# left state
q_l = riemann.State(rho=1.0, u=0.0, p=1.0)

# right state
q_r = riemann.State(rho=0.125, u=0.0, p=0.1)

r = RiemannProblem(q_l, q_r)


subidx = [311, 312, 313]
states = ["rho", "u", "p"]
state_labels = [r"$\rho$", r"$u$", r"$p$"]


#-----------------------------------------------------------------------------
#  plot 1: initial state
plt.clf()
Пример #4
0
# plot the Hugoniot loci for a compressible Riemann problem

from __future__ import print_function

import matplotlib.pyplot as plt
import numpy as np
import riemann

import matplotlib as mpl

# Use LaTeX for rendering
mpl.rcParams['mathtext.fontset'] = 'cm'
mpl.rcParams['mathtext.rm'] = 'serif'
mpl.rcParams['font.size'] = 12
mpl.rcParams['legend.fontsize'] = 'large'
mpl.rcParams['figure.titlesize'] = 'medium'

if __name__ == "__main__":

    # setup the problem -- Sod
    left = riemann.State(p=1.0, u=0.0, rho=1.0)
    right = riemann.State(p=0.1, u=0.0, rho=0.125)

    rp = riemann.RiemannProblem(left, right)
    rp.find_star_state()
    rp.plot_hugoniot()

    plt.savefig("riemann-phase.pdf")

    print(rp.pstar, rp.ustar)
Пример #5
0
mpl.rcParams['mathtext.fontset'] = 'cm'
mpl.rcParams['mathtext.rm'] = 'serif'
mpl.rcParams['font.size'] = 12
mpl.rcParams['legend.fontsize'] = 'large'
mpl.rcParams['figure.titlesize'] = 'medium'

if __name__ == "__main__":

    # setup the problem -- slow shock

    # stationary shock
    #left = riemann.State(p=100.0, u=-1.9336, rho=5.6698)
    #right = riemann.State(p=1.0, u=-10.9636, rho=1.0)

    # slow shock
    left = riemann.State(p=100.0, u=-1.5336, rho=5.6698)
    right = riemann.State(p=1.0, u=-10.5636, rho=1.0)

    rp = riemann.RiemannProblem(left, right)
    rp.find_star_state()

    x, rho, u, p = rp.sample_solution(0.2, 128)

    plt.subplot(311)

    plt.plot(x, rho)

    plt.ylabel(r"$\rho$")

    plt.xlim(0, 1)
    plt.tick_params(axis="x", labelbottom="off")