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