-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathplot_particle_density.py
46 lines (37 loc) · 1.26 KB
/
plot_particle_density.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
""" Example for particle density visualization of sound sources """
import numpy as np
import matplotlib.pyplot as plt
import sfs
# simulation parameters
pw_angle = 45 # traveling direction of plane wave
xs = [0, 0, 0] # source position
f = 300 # frequency
# angular frequency
omega = 2 * np.pi * f
# normal vector of plane wave
npw = sfs.util.direction_vector(np.radians(pw_angle))
# random grid for velocity
grid = [np.random.uniform(-3, 3, 40000), np.random.uniform(-3, 3, 40000), 0]
def plot_particle_displacement(title):
# compute displacement
X = grid + amplitude * sfs.fd.displacement(v, omega)
# plot displacement
plt.figure(figsize=(15, 15))
plt.cla()
sfs.plot2d.particles(X, facecolor='black', s=3, trim=[-3, 3, -3, 3])
plt.axis('off')
plt.title(title)
plt.grid()
plt.savefig(title + '.png')
# point source
v = sfs.fd.source.point_velocity(omega, xs, grid)
amplitude = 1.5e6
plot_particle_displacement('particle_displacement_point_source')
# line source
v = sfs.fd.source.line_velocity(omega, xs, grid)
amplitude = 1.3e6
plot_particle_displacement('particle_displacement_line_source')
# plane wave
v = sfs.fd.source.plane_velocity(omega, xs, npw, grid)
amplitude = 1e5
plot_particle_displacement('particle_displacement_plane_wave')