Peano
Loading...
Searching...
No Matches
plotSolution.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2
3# Computes the analytical solution of the Sod shock and plots the SPH answer
4
5import sys
6import matplotlib
7
8matplotlib.use("Agg")
9from matplotlib import pyplot as plt
10import numpy as np
11import h5py
13import exaparty
14import exaparty.api.sphtools as sphtools
15
16
17# Generates the analytical solution for the Sod shock test case
18# The script works for a given left (x<0) and right (x>0) state and computes the solution at a later time t.
19# This follows the solution given in (Toro, 2009)
20
21# Parameters
22gas_gamma = 5.0 / 3.0 # Polytropic index
23rho_L = 1.0 # Density left state
24rho_R = 0.125 # Density right state
25v_L = 0.0 # Velocity left state
26v_R = 0.0 # Velocity right state
27P_L = 1.0 # Pressure left state
28P_R = 0.1 # Pressure right state
29
30if len(sys.argv) < 2:
31 time = 0.1
32else:
33 time = float(sys.argv[1])
34
35
36pvdfile = "particles.pvd"
37reader = ParticleVTUReader(pvdfile=pvdfile, snapshot_time=time, verbose=False)
38partData = reader.load()
39# update the actual time of the snapshot
40time = reader.get_snapshot_time()
41
42# show me what particle fields are stored
43# partData.show_attribute_list()
44
45x = partData.x[:, 0]
46# y = partData.x[:,1]
47v = partData.v[:, 0]
48u = partData.u
49# S = partData.S # doesn't exist yet?
50P = partData.pressure
51rho = partData.density
52
53
54N = 1000 # Number of points
55x_min = 0.0
56x_max = 2.0
57
58x += x_min
59
60# Prepare reference solution
61solver = sphtools.RiemannSolver(gas_gamma)
62
63delta_x = (x_max - x_min) / N
64center = (x_max + x_min) / 2
65x_s = np.arange(x_min - center, x_max - center, delta_x)
66rho_s, v_s, P_s, _ = solver.solve(rho_L, v_L, P_L, rho_R, v_R, P_R, x_s / time)
67x_s += center
68
69# Additional arrays
70u_s = P_s / (rho_s * (gas_gamma - 1.0)) # internal energy
71s_s = P_s / rho_s**gas_gamma # entropic function
72
73# Shock position (since we want to overplot it in the viscosity/diffusion plot
74c_R = np.sqrt(gas_gamma * P_R / rho_R)
75x_shock = (c_R + v_R) * time
76
77# Plot the interesting quantities
78plt.figure(figsize=(7, 7 / 1.6))
79
80rows = 2
81cols = 2
82
83# Velocity profile --------------------------------
84plt.subplot(rows, cols, 1)
85plt.plot(x, v, ".", color="r", ms=4.0)
86plt.plot(x_s, v_s, "--", color="k", alpha=0.8, lw=1.2)
87plt.xlabel("${\\rm{Position}}~x$", labelpad=0)
88plt.ylabel("${\\rm{Velocity}}~v_x$", labelpad=0)
89plt.xlim(0.5, 1.5)
90plt.ylim(-0.1, 0.95)
91
92# Density profile --------------------------------
93plt.subplot(rows, cols, 2)
94plt.plot(x, rho, ".", color="r", ms=4.0)
95plt.plot(x_s, rho_s, "--", color="k", alpha=0.8, lw=1.2)
96plt.ylabel("${\\rm{Density}}~\\rho$", labelpad=0)
97plt.ylim(0.05, 1.1)
98
99plt.xlabel("${\\rm{Position}}~x$", labelpad=0)
100plt.xlim(0.5, 1.5)
101
102# Pressure profile --------------------------------
103plt.subplot(rows, cols, 3)
104plt.plot(x, P, ".", color="r", ms=4.0)
105plt.plot(x_s, P_s, "--", color="k", alpha=0.8, lw=1.2)
106plt.xlabel("${\\rm{Position}}~x$", labelpad=0)
107plt.ylabel("${\\rm{Pressure}}~P$", labelpad=0)
108plt.xlim(0.5, 1.5)
109plt.ylim(0.01, 1.1)
110
111# Internal energy profile -------------------------
112plt.subplot(rows, cols, 4)
113plt.plot(x, u, ".", color="r", ms=4.0)
114plt.plot(x_s, u_s, "--", color="k", alpha=0.8, lw=1.2)
115plt.xlabel("${\\rm{Position}}~x$", labelpad=0)
116plt.ylabel("${\\rm{Internal~Energy}}~u$", labelpad=0)
117plt.xlim(0.5, 1.5)
118plt.ylim(0.8, 2.2)
119
120plt.tight_layout()
121
122plt.savefig("SodShock{0:.5f}.png".format(time), dpi=200)
Reads in particle fields from a single .vtu file, or all .vtu at a given snapshot time specified in t...
This file is part of the ExaParty project.
Definition __init__.py:1