-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverify_3D_pml.py
110 lines (89 loc) · 2.87 KB
/
verify_3D_pml.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# -*- coding: utf-8 -*-
from pytARD_3D.ard import ARDSimulator3D
from pytARD_3D.partition import AirPartition3D, PMLPartition3D, DampingProfile
from pytARD_3D.interface import InterfaceData3D, Direction3D
from common.parameters import SimulationParameters
from common.impulse import Unit
from common.plotter import Plotter
from common.animation_plotter import AnimationPlotter
import numpy as np
duration = 0.5 # seconds
Fs = 630 # sample rate
upper_frequency_limit = 60 # Hz
c = 4 # m/s
spatial_samples_per_wave_length = 2
verbose = True
visualize = True
use_animation_plotter = False
sim_param = SimulationParameters(
upper_frequency_limit,
duration,
c=c,
Fs=Fs,
spatial_samples_per_wave_length=spatial_samples_per_wave_length,
verbose=verbose,
visualize=visualize,
visualize_source=False
)
SCALE = 150 # Scale of room. Gets calculated by speed of sound divided by SCALE
impulse_location = np.array([
[int(1)], # X, width
[int(1)], # Y, depth
[int(1)] # Z, height
])
impulse = Unit(sim_param, impulse_location, 20, upper_frequency_limit - 1)
room_width = int(2)
dp = DampingProfile(room_width, c, 1e-3)
partitions = []
partitions.append(AirPartition3D(np.array([
[room_width], # X, width
[room_width], # Y, depth
[room_width] # Z, height
]), sim_param, impulse))
partitions.append(PMLPartition3D(np.array([
[1.5], # X, width
[room_width], # Y, depth
[room_width] # Z, height
]), sim_param, dp))
interfaces = []
title = ''
TEST_KIND = ['X', 'Y', 'Z', 'all'][0]
if TEST_KIND == 'X':
axis = 2
interfaces.append(InterfaceData3D(0, 1, Direction3D.X))
title = 'YZ-PML-WALL'
elif TEST_KIND == 'Y':
axis = 1
interfaces.append(InterfaceData3D(0, 1, Direction3D.Y))
title = 'XZ-PML-WALL'
elif TEST_KIND == 'Z':
axis = 0
interfaces.append(InterfaceData3D(0, 1, Direction3D.Z))
title = 'XY-PML-WALL'
mics = []
sim = ARDSimulator3D(sim_param, partitions, 1, interfaces, mics)
sim.preprocessing()
sim.simulation()
if visualize:
a = 0
if use_animation_plotter:
pfX0 = partitions[0].pressure_field_results
pfX1 = partitions[1].pressure_field_results
pf_t = [np.concatenate((pfX0[t], pfX1[t]), axis=axis)
for t in range(sim_param.number_of_samples)]
fps = 30
anim = AnimationPlotter().plot_3D(pf_t,
sim_param,
title,
interval=1000 / fps, # in ms
source_zyx=partitions[0].src_grid_loc)
else:
plotter = Plotter()
plot_structure = [
[2, 2, 1],
[2, 2, 2],
[2, 2, 3],
[2, 2, 4]
]
plotter.set_data_from_simulation(sim_param, partitions, plot_structure=plot_structure)
plotter.plot_3D()