|
| 1 | +# plot the Hugoniot loci for a compressible Riemann problem |
| 2 | + |
| 3 | +from __future__ import print_function |
| 4 | + |
| 5 | +import numpy as np |
| 6 | +import riemann |
| 7 | + |
| 8 | + |
| 9 | +def store(left, right, time, gamma, outfile="riemann.out"): |
| 10 | + |
| 11 | + rp = riemann.RiemannProblem(left, right, gamma=gamma) |
| 12 | + rp.find_star_state() |
| 13 | + |
| 14 | + x, rho, u, p = rp.sample_solution(time, 128) |
| 15 | + |
| 16 | + e = p/rho/(gamma - 1.0) |
| 17 | + |
| 18 | + # output the solution |
| 19 | + with open(outfile, "w") as f: |
| 20 | + f.write("# left: {}\n".format(left)) |
| 21 | + f.write("# right: {}\n".format(right)) |
| 22 | + f.write("# gamma = {}\n".format(gamma)) |
| 23 | + f.write("# time = {}\n".format(time)) |
| 24 | + f.write("# {:^20} {:^20} {:^20} {:^20} {:^20}\n".format("x", "rho", "u", "p", "e")) |
| 25 | + for n in range(len(x)): |
| 26 | + f.write(" {:20.10g} {:20.10g} {:20.10g} {:20.10g} {:20.10g}\n".format(x[n], rho[n], u[n], p[n], e[n])) |
| 27 | + |
| 28 | + |
| 29 | +# Sod |
| 30 | +left = riemann.State(p=1.0, u=0.0, rho=1.0) |
| 31 | +right = riemann.State(p=0.1, u=0.0, rho=0.125) |
| 32 | +time = 0.2 |
| 33 | +gamma = 1.4 |
| 34 | +outfile = "sod_exact.out" |
| 35 | + |
| 36 | +store(left, right, time, gamma, outfile=outfile) |
| 37 | + |
| 38 | +# double rarefaction |
| 39 | +left = riemann.State(p=0.4, u=-2.0, rho=1.0) |
| 40 | +right = riemann.State(p=0.4, u=2.0, rho=1.0) |
| 41 | +time = 0.15 |
| 42 | +gamma = 1.4 |
| 43 | +outfile = "double_rarefaction_exact.out" |
| 44 | + |
| 45 | +store(left, right, time, gamma, outfile=outfile) |
| 46 | + |
| 47 | +# strong shock |
| 48 | +left = riemann.State(p=1000.0, u=0.0, rho=1.0) |
| 49 | +right = riemann.State(p=0.01, u=0.0, rho=1.0) |
| 50 | +time = 0.012 |
| 51 | +gamma = 1.4 |
| 52 | +outfile = "strong_shock_exact.out" |
| 53 | + |
| 54 | +store(left, right, time, gamma, outfile=outfile) |
| 55 | + |
| 56 | +# slow shock |
| 57 | +left = riemann.State(p=100.0, u=-1.4701, rho=5.6698) |
| 58 | +right = riemann.State(p=1.0, u=-10.5, rho=1.0) |
| 59 | +time = 1.0 |
| 60 | +gamma = 1.4 |
| 61 | +outfile = "slow_shock_exact.out" |
| 62 | + |
| 63 | +store(left, right, time, gamma, outfile=outfile) |
0 commit comments