Peano
Loading...
Searching...
No Matches
plot3D.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2
3# ----------------------------------------------------------------------------
4# Makes a 3D scatterplot of the results.
5#
6# Usage: python3 plotSolution.py <snapshot-time>
7#
8# The script will look for the snapshot output with simulation time closest to
9# the provided <snapshot-time> in `particles.pvd` and create a plot of that
10# time.
11# ----------------------------------------------------------------------------
12
13
14import matplotlib as mpl
15import matplotlib.pyplot as plt
16from mpl_toolkits.axes_grid1 import make_axes_locatable
17from matplotlib.colors import LogNorm
18import numpy as np
19import sys
20
22
23params = {
24 "xtick.labelsize": 12,
25 "ytick.labelsize": 12,
26 "xtick.direction": "in",
27 "ytick.direction": "in",
28 "xtick.top": True,
29 "ytick.right": True,
30 "figure.subplot.left": 0.045,
31 "figure.subplot.right": 0.99,
32 "figure.subplot.bottom": 0.05,
33 "figure.subplot.top": 0.93,
34 "figure.subplot.wspace": 0.15,
35 "text.usetex": True,
36}
37mpl.rcParams.update(params)
38
39
40if len(sys.argv) < 2:
41 time = 0.05
42else:
43 time = float(sys.argv[1])
44
45pvdfile = "particles.pvd"
46reader = ParticleVTUReader(pvdfile=pvdfile, snapshot_time=time)
47partData = reader.load()
48time = reader.get_snapshot_time()
49
50
51# show me what particle fields are stored
52# partData.show_attribute_list()
53
54x = partData.x[:, 0]
55y = partData.x[:, 1]
56z = partData.x[:, 2]
57vx = partData.v[:, 0]
58vy = partData.v[:, 1]
59vz = partData.v[:, 2]
60u = partData.u
61# S = partData.S # doesn't exist yet?
62P = partData.pressure
63rho = partData.density
64
65
66def plot(quantity):
67 """
68 Plot the specified quantity. Options:
69 - "rho" (density)
70 - "p" (pressure)
71 - "u" (internal energy)
72 """
73
74 if quantity == "rho":
75 # minval = 2e-2
76 # maxval = 4.
77 title = "Density "
78 qarr = rho
79
80 elif quantity == "p" or quantity == "P":
81 # minval = 1e-6
82 # maxval = 1000.
83 title = "Pressure "
84 qarr = P
85
86 elif quantity == "u":
87 # minval = 1e-6
88 # maxval = 1000.
89 title = "Internal Energy "
90 qarr = u
91
92 minval = None
93 maxval = None
94 alpha = 0.4 + 0.6 * qarr / qarr.max()
95 title += f"$t=${time:.2f}"
96
97 fig = plt.figure(figsize=(6, 6), dpi=300)
98 ax1 = fig.add_subplot(111, projection="3d", aspect="equal")
99 ax1.set_title(title, fontsize=16)
100
101 scatterkwargs = {
102 # "s": 4,
103 "lw": 0,
104 "marker": "o",
105 # "alpha": 0.6,
106 # "depthshade": True,
107 "depthshade": False,
108 }
109
110 sc = ax1.scatter(
111 x,
112 y,
113 z,
114 c=qarr,
115 s=2.0 + 4.0 * alpha / alpha.max(),
116 alpha=alpha,
117 norm=LogNorm(vmin=minval, vmax=maxval),
118 cmap="hot",
119 **scatterkwargs,
120 )
121 # ax1.view_init(elev=26, azim=81)
122 # ax1.view_init(elev=25, azim=13)
123 # ax1.view_init(elev=20, azim=60)
124 ax1.view_init(elev=14, azim=8)
125 fig.colorbar(sc, shrink=0.8, aspect=40, pad=0.0)
126
127 ax1.set_xlim(0, 1)
128 ax1.set_ylim(0, 1)
129 ax1.set_zlim(0, 1)
130
131 plt.tight_layout()
132 fname = quantity + "-" + f"_{time}.png"
133 plt.savefig(fname)
134 print("saved", fname)
135 plt.close()
136
137
138plot("p")
Reads in particle fields from a single .vtu file, or all .vtu at a given snapshot time specified in t...
-lift-drop-statistics