Skip to content

Commit 6213bc5

Browse files
author
corrooli
committed
(Probably) last cleanup push
1 parent cd75691 commit 6213bc5

13 files changed

+94
-255
lines changed

example_1D.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pytARD_1D.interface import InterfaceData1D
44

55
from common.parameters import SimulationParameters
6-
from common.impulse import Gaussian, Unit, WaveFile, ExperimentalUnit
6+
from common.impulse import Gaussian, Unit, WaveFile
77
from common.microphone import Microphone
88
from common.plotter import Plotter
99

pytARD_1D/interface.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def __init__(
5353
FDTD accuracy.
5454
'''
5555

56-
self.part_data = partitions
56+
self.partitions = partitions
5757
self.fdtd_acc = fdtd_acc
5858

5959
# 1D FDTD coefficents calculation. Normalize FDTD coefficents with space divisions and speed of sound.
@@ -79,18 +79,18 @@ def handle_interface(self, interface_data: InterfaceData1D):
7979
shape=[2 * self.INTERFACE_SIZE])
8080

8181
# Left rod
82-
pressure_field_around_interface[0: self.INTERFACE_SIZE] = self.part_data[
82+
pressure_field_around_interface[0: self.INTERFACE_SIZE] = self.partitions[
8383
interface_data.part1_index].pressure_field[-self.INTERFACE_SIZE:].copy()
8484

8585
# Right rod
8686
pressure_field_around_interface[self.INTERFACE_SIZE: 2 *
87-
self.INTERFACE_SIZE] = self.part_data[interface_data.part2_index].pressure_field[0: self.INTERFACE_SIZE].copy()
87+
self.INTERFACE_SIZE] = self.partitions[interface_data.part2_index].pressure_field[0: self.INTERFACE_SIZE].copy()
8888

8989
new_forces_from_interface = np.matmul(
9090
pressure_field_around_interface, self.FDTD_COEFFS)
9191

9292
# Add everything together
93-
self.part_data[interface_data.part1_index].new_forces[-self.INTERFACE_SIZE:
93+
self.partitions[interface_data.part1_index].new_forces[-self.INTERFACE_SIZE:
9494
] += new_forces_from_interface[0:self.INTERFACE_SIZE]
95-
self.part_data[interface_data.part2_index].new_forces[:
95+
self.partitions[interface_data.part2_index].new_forces[:
9696
self.INTERFACE_SIZE] += new_forces_from_interface[self.INTERFACE_SIZE: self.INTERFACE_SIZE * 2]

pytARD_2D/ard.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __init__(
4141
self.sim_param = sim_param
4242

4343
# List of partition data (PartitionData objects)
44-
self.part_data = partitions
44+
self.partitions = partitions
4545

4646
# List of interfaces (InterfaceData objects)
4747
self.interface_data = interface_data
@@ -59,8 +59,8 @@ def preprocessing(self):
5959
Preprocessing stage. Refers to Step 1 in the paper.
6060
'''
6161

62-
for i in range(len(self.part_data)):
63-
self.part_data[i].preprocessing()
62+
for i in range(len(self.partitions)):
63+
self.partitions[i].preprocessing()
6464

6565
def simulation(self):
6666
'''
@@ -77,21 +77,21 @@ def simulation(self):
7777
self.interfaces.handle_interface(interface)
7878

7979
# Calling all interfaces to simulate wave propagation locally
80-
for i in range(len(self.part_data)):
81-
self.part_data[i].simulate(t_s, self.normalization_factor)
80+
for i in range(len(self.partitions)):
81+
self.partitions[i].simulate(t_s, self.normalization_factor)
8282

8383
# Per-partition microphone handling
8484
for m_i in range(len(self.mics)):
8585
p_num = self.mics[m_i].partition_number
86-
pressure_field_y = int(self.part_data[p_num].space_divisions_y * (
87-
self.mics[m_i].location[1] / self.part_data[p_num].dimensions[1]))
88-
pressure_field_x = int(self.part_data[p_num].space_divisions_x * (
89-
self.mics[m_i].location[0] / self.part_data[p_num].dimensions[0]))
86+
pressure_field_y = int(self.partitions[p_num].space_divisions_y * (
87+
self.mics[m_i].location[1] / self.partitions[p_num].dimensions[1]))
88+
pressure_field_x = int(self.partitions[p_num].space_divisions_x * (
89+
self.mics[m_i].location[0] / self.partitions[p_num].dimensions[0]))
9090

9191
# Recording sound data at given location
92-
self.mics[m_i].record(self.part_data[p_num].pressure_field.copy().reshape([
93-
self.part_data[p_num].space_divisions_y,
94-
self.part_data[p_num].space_divisions_x, 1]
92+
self.mics[m_i].record(self.partitions[p_num].pressure_field.copy().reshape([
93+
self.partitions[p_num].space_divisions_y,
94+
self.partitions[p_num].space_divisions_x, 1]
9595
)[pressure_field_y][pressure_field_x], t_s)
9696

9797
if self.sim_param.verbose:

pytARD_2D/interface.py

+20-20
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def __init__(
7171
FDTD accuracy.
7272
'''
7373

74-
self.part_data = partitions
74+
self.partitions = partitions
7575
self.fdtd_acc = fdtd_acc
7676

7777
# 2D FDTD coefficents calculation. Normalize FDTD coefficents with space divisions and speed of sound.
@@ -92,28 +92,28 @@ def handle_interface(self, interface_data: InterfaceData2D):
9292
InterfaceData instance. Determines which two partitions pass sound waves to each other.
9393
'''
9494
if interface_data.direction == Direction2D.X:
95-
p_left = self.part_data[interface_data.part1_index].pressure_field[:, -self.INTERFACE_SIZE:]
96-
p_right = self.part_data[interface_data.part2_index].pressure_field[:, :self.INTERFACE_SIZE]
95+
p_left = self.partitions[interface_data.part1_index].pressure_field[:, -self.INTERFACE_SIZE:]
96+
p_right = self.partitions[interface_data.part2_index].pressure_field[:, :self.INTERFACE_SIZE]
9797

9898
# Calculate new forces transmitted into room
9999
pressures_along_y = np.hstack((p_left, p_right))
100100
new_forces_from_interface_y = np.matmul(pressures_along_y, self.FDTD_COEFFS_Y)
101101

102102
# Add everything together
103-
self.part_data[interface_data.part1_index].new_forces[:, -self.INTERFACE_SIZE:] += new_forces_from_interface_y[:, :self.INTERFACE_SIZE]
104-
self.part_data[interface_data.part2_index].new_forces[:, :self.INTERFACE_SIZE] += new_forces_from_interface_y[:, -self.INTERFACE_SIZE:]
103+
self.partitions[interface_data.part1_index].new_forces[:, -self.INTERFACE_SIZE:] += new_forces_from_interface_y[:, :self.INTERFACE_SIZE]
104+
self.partitions[interface_data.part2_index].new_forces[:, :self.INTERFACE_SIZE] += new_forces_from_interface_y[:, -self.INTERFACE_SIZE:]
105105

106106
elif interface_data.direction == Direction2D.Y:
107-
p_top = self.part_data[interface_data.part1_index].pressure_field[-self.INTERFACE_SIZE:, :]
108-
p_bot = self.part_data[interface_data.part2_index].pressure_field[:self.INTERFACE_SIZE, :]
107+
p_top = self.partitions[interface_data.part1_index].pressure_field[-self.INTERFACE_SIZE:, :]
108+
p_bot = self.partitions[interface_data.part2_index].pressure_field[:self.INTERFACE_SIZE, :]
109109

110110
# Calculate new forces transmitted into room
111111
pressures_along_x = np.vstack((p_top, p_bot))
112112
new_forces_from_interface_x = np.matmul(self.FDTD_COEFFS_X, pressures_along_x)
113113

114114
# Add everything together
115-
self.part_data[interface_data.part1_index].new_forces[-self.INTERFACE_SIZE:, :] += new_forces_from_interface_x[:self.INTERFACE_SIZE, :]
116-
self.part_data[interface_data.part2_index].new_forces[:self.INTERFACE_SIZE, :] += new_forces_from_interface_x[-self.INTERFACE_SIZE:, :]
115+
self.partitions[interface_data.part1_index].new_forces[-self.INTERFACE_SIZE:, :] += new_forces_from_interface_x[:self.INTERFACE_SIZE, :]
116+
self.partitions[interface_data.part2_index].new_forces[:self.INTERFACE_SIZE, :] += new_forces_from_interface_x[-self.INTERFACE_SIZE:, :]
117117

118118

119119
class Interface2DLooped():
@@ -144,7 +144,7 @@ def __init__(
144144
FDTD accuracy.
145145
'''
146146

147-
self.part_data = partitions
147+
self.partitions = partitions
148148

149149
# 2D FDTD coefficents calculation. Normalize FDTD coefficents with space divisions and speed of sound.
150150
fdtd_coeffs_not_normalized: np.ndarray = FiniteDifferences.get_laplacian_matrix(fdtd_order, fdtd_acc)
@@ -164,28 +164,28 @@ def handle_interface(self, interface_data: InterfaceData2D):
164164
Contains data which two partitions are involved, and in which direction the sound will travel.
165165
'''
166166
if interface_data.direction == Direction2D.X:
167-
for y in range(self.part_data[interface_data.part1_index].space_divisions_y):
167+
for y in range(self.partitions[interface_data.part1_index].space_divisions_y):
168168
pressure_field_around_interface_y = np.zeros(shape=[2 * self.INTERFACE_SIZE])
169-
pressure_field_around_interface_y[0 : self.INTERFACE_SIZE] = self.part_data[interface_data.part1_index].pressure_field[y, -self.INTERFACE_SIZE : ].copy()
170-
pressure_field_around_interface_y[self.INTERFACE_SIZE : 2 * self.INTERFACE_SIZE] = self.part_data[interface_data.part2_index].pressure_field[y, 0 : self.INTERFACE_SIZE].copy()
169+
pressure_field_around_interface_y[0 : self.INTERFACE_SIZE] = self.partitions[interface_data.part1_index].pressure_field[y, -self.INTERFACE_SIZE : ].copy()
170+
pressure_field_around_interface_y[self.INTERFACE_SIZE : 2 * self.INTERFACE_SIZE] = self.partitions[interface_data.part2_index].pressure_field[y, 0 : self.INTERFACE_SIZE].copy()
171171

172172
# Calculate new forces transmitted into room
173173
new_forces_from_interface_y = np.matmul(pressure_field_around_interface_y, self.FDTD_COEFFS_Y)
174174

175175
# Add everything together
176-
self.part_data[interface_data.part1_index].new_forces[y, -self.INTERFACE_SIZE:] += new_forces_from_interface_y[0:self.INTERFACE_SIZE]
177-
self.part_data[interface_data.part2_index].new_forces[y, :self.INTERFACE_SIZE] += new_forces_from_interface_y[self.INTERFACE_SIZE : self.INTERFACE_SIZE * 2]
176+
self.partitions[interface_data.part1_index].new_forces[y, -self.INTERFACE_SIZE:] += new_forces_from_interface_y[0:self.INTERFACE_SIZE]
177+
self.partitions[interface_data.part2_index].new_forces[y, :self.INTERFACE_SIZE] += new_forces_from_interface_y[self.INTERFACE_SIZE : self.INTERFACE_SIZE * 2]
178178

179179

180180
elif interface_data.direction == Direction2D.Y:
181-
for x in range(self.part_data[interface_data.part1_index].space_divisions_x):
181+
for x in range(self.partitions[interface_data.part1_index].space_divisions_x):
182182
pressure_field_around_interface_x = np.zeros(shape=[2 * self.INTERFACE_SIZE])
183-
pressure_field_around_interface_x[0 : self.INTERFACE_SIZE] = self.part_data[interface_data.part1_index].pressure_field[-self.INTERFACE_SIZE : , x].copy()
184-
pressure_field_around_interface_x[self.INTERFACE_SIZE : 2 * self.INTERFACE_SIZE] = self.part_data[interface_data.part2_index].pressure_field[0 : self.INTERFACE_SIZE, x].copy()
183+
pressure_field_around_interface_x[0 : self.INTERFACE_SIZE] = self.partitions[interface_data.part1_index].pressure_field[-self.INTERFACE_SIZE : , x].copy()
184+
pressure_field_around_interface_x[self.INTERFACE_SIZE : 2 * self.INTERFACE_SIZE] = self.partitions[interface_data.part2_index].pressure_field[0 : self.INTERFACE_SIZE, x].copy()
185185

186186
# Calculate new forces transmitted into room
187187
new_forces_from_interface_x = np.matmul(pressure_field_around_interface_x, self.FDTD_COEFFS_X)
188188

189189
# Add everything together
190-
self.part_data[interface_data.part1_index].new_forces[-self.INTERFACE_SIZE:, x] += new_forces_from_interface_x[0:self.INTERFACE_SIZE]
191-
self.part_data[interface_data.part2_index].new_forces[:self.INTERFACE_SIZE, x] += new_forces_from_interface_x[self.INTERFACE_SIZE : self.INTERFACE_SIZE * 2]
190+
self.partitions[interface_data.part1_index].new_forces[-self.INTERFACE_SIZE:, x] += new_forces_from_interface_x[0:self.INTERFACE_SIZE]
191+
self.partitions[interface_data.part2_index].new_forces[:self.INTERFACE_SIZE, x] += new_forces_from_interface_x[self.INTERFACE_SIZE : self.INTERFACE_SIZE * 2]

pytARD_3D/ard.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __init__(
4141
self.sim_param = sim_param
4242

4343
# List of partition data (PartitionData objects)
44-
self.part_data = partitions
44+
self.partitions = partitions
4545

4646
# List of interfaces (InterfaceData objects)
4747
self.interface_data = interface_data
@@ -61,8 +61,8 @@ def preprocessing(self):
6161
Preprocessing stage. Refers to Step 1 in the paper.
6262
'''
6363

64-
for i in range(len(self.part_data)):
65-
self.part_data[i].preprocessing()
64+
for i in range(len(self.partitions)):
65+
self.partitions[i].preprocessing()
6666

6767

6868
def simulation(self):
@@ -80,24 +80,24 @@ def simulation(self):
8080
self.interfaces.handle_interface(interface)
8181

8282
# Reverberation generation sensation
83-
for i in range(len(self.part_data)):
84-
self.part_data[i].simulate(t_s, self.normalization_factor)
83+
for i in range(len(self.partitions)):
84+
self.partitions[i].simulate(t_s, self.normalization_factor)
8585

8686
# Microphone handling
8787
for m_i in range(len(self.mics)):
8888
p_num = self.mics[m_i].partition_number
89-
pressure_field_z = int(self.part_data[p_num].space_divisions_z * (
90-
self.mics[m_i].location[2] / self.part_data[p_num].dimensions[2]))
91-
pressure_field_y = int(self.part_data[p_num].space_divisions_y * (
92-
self.mics[m_i].location[1] / self.part_data[p_num].dimensions[1]))
93-
pressure_field_x = int(self.part_data[p_num].space_divisions_x * (
94-
self.mics[m_i].location[0] / self.part_data[p_num].dimensions[0]))
95-
96-
self.mics[m_i].record(self.part_data[p_num].pressure_field.copy().reshape(
89+
pressure_field_z = int(self.partitions[p_num].space_divisions_z * (
90+
self.mics[m_i].location[2] / self.partitions[p_num].dimensions[2]))
91+
pressure_field_y = int(self.partitions[p_num].space_divisions_y * (
92+
self.mics[m_i].location[1] / self.partitions[p_num].dimensions[1]))
93+
pressure_field_x = int(self.partitions[p_num].space_divisions_x * (
94+
self.mics[m_i].location[0] / self.partitions[p_num].dimensions[0]))
95+
96+
self.mics[m_i].record(self.partitions[p_num].pressure_field.copy().reshape(
9797
[
98-
self.part_data[p_num].space_divisions_z,
99-
self.part_data[p_num].space_divisions_y,
100-
self.part_data[p_num].space_divisions_x, 1
98+
self.partitions[p_num].space_divisions_z,
99+
self.partitions[p_num].space_divisions_y,
100+
self.partitions[p_num].space_divisions_x, 1
101101
])[pressure_field_z][pressure_field_y][pressure_field_x], t_s)
102102

103103
if self.sim_param.verbose:

verify_1D_fdtd_accuracy.py

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from common.impulse import ExperimentalUnit, Gaussian
1+
from common.impulse import Gaussian
22
from common.parameters import SimulationParameters as SIMP
33
from common.microphone import Microphone as Mic
44

@@ -14,21 +14,18 @@
1414
For each accuracy, a csv file is generated with seperate iteration time results.
1515
'''
1616

17-
# Room parameters
1817
src_pos = [0] # m
1918
duration = 2 # seconds
2019
Fs = 8000 # sample rate
2120
upper_frequency_limit = 300 # Hz
2221
c = 342 # m/s
2322
spatial_samples_per_wave_length = 6
2423

25-
# Procedure parameters
2624
auralize = False
2725
verbose = False
2826
visualize = True
2927
filename = "verify_1D_interface_reflection"
3028

31-
# Compilation of room parameters into parameter class
3229
sim_param = SIMP(
3330
upper_frequency_limit,
3431
duration,
@@ -48,22 +45,16 @@
4845

4946
for accuracy in [4, 6, 10]:
5047
for i in range(10):
51-
# Define test rooms
5248
test_partition_1 = PARTD(np.array([c]), sim_param, impulse)
5349
test_partition_2 = PARTD(np.array([c]), sim_param)
5450
test_room = [test_partition_1, test_partition_2]
5551

56-
# Define Interfaces
5752
interfaces = []
5853
interfaces.append(InterfaceData1D(0, 1, fdtd_acc=accuracy))
5954

60-
# Define and position mics
61-
62-
# Initialize & position mics.
6355
mic = Mic(0, int(c / 2), sim_param, filename + "_" +"mic")
6456
test_mics = [mic]
6557

66-
# Instantiating and executing simulation
6758
test_sim = ARDS(sim_param, test_room, 1, interface_data=interfaces, mics=test_mics)
6859
test_sim.preprocessing()
6960
if accuracy == 4:

verify_1D_fdtd_accuracy_plot.py

-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
from matplotlib import ft2font
2-
from common.impulse import ExperimentalUnit, Gaussian
3-
from common.parameters import SimulationParameters as SIMP
4-
from common.microphone import Microphone as Mic
5-
6-
from pytARD_1D.ard import ARDSimulator1D as ARDS
7-
from pytARD_1D.partition import AirPartition1D as PARTD
8-
from pytARD_1D.interface import InterfaceData1D
9-
101
from matplotlib import pyplot as plt
112

123
'''

verify_1D_interface_absorption.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from common.impulse import ExperimentalUnit, Gaussian
1+
from common.impulse import Gaussian
22
from common.parameters import SimulationParameters as SIMP
33
from common.microphone import Microphone as Mic
44

@@ -8,7 +8,6 @@
88

99
from utility_wavdiff import wav_diff, visualize_multiple_waveforms
1010

11-
import matplotlib.pyplot as plt
1211
import numpy as np
1312

1413
'''

verify_1D_interface_reflection.py

+4-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from matplotlib import ft2font
2-
from common.impulse import ExperimentalUnit, Gaussian
1+
from common.impulse import Gaussian
32
from common.parameters import SimulationParameters as SIMP
43
from common.microphone import Microphone as Mic
54

@@ -46,27 +45,19 @@
4645
impulse = Gaussian(sim_param, [0], 10000)
4746

4847
for accuracy in [4, 6, 10]:
49-
# Define test rooms
5048
test_partition_1 = PARTD(np.array([c]), sim_param, impulse)
5149
test_partition_2 = PARTD(np.array([c]), sim_param)
5250
test_room = [test_partition_1, test_partition_2]
53-
54-
# Define Interfaces
5551
interfaces = []
5652
interfaces.append(InterfaceData1D(0, 1, fdtd_acc=accuracy))
5753

58-
# Define and position mics
59-
60-
# Initialize & position mics.
6154
mic = Mic(0, int(c / 2), sim_param, filename + "_" +"mic")
6255
test_mics = [mic]
6356

64-
# Instantiating and executing simulation
6557
test_sim = ARDS(sim_param, test_room, 1, interface_data=interfaces, mics=test_mics)
6658
test_sim.preprocessing()
6759
test_sim.simulation()
6860

69-
# Normalizing + writing recorded mic tracks
7061
def find_best_peak(mics):
7162
peaks = []
7263
for i in range(len(mics)):
@@ -100,12 +91,12 @@ def visualize_ripple(path):
10091
plt.rc('xtick', labelsize=sizerino) #fontsize of the x tick labels
10192
plt.rc('ytick', labelsize=sizerino) #fontsize of the y tick labels
10293
plt.rc('legend', fontsize=sizerino) #fontsize of the legend
103-
plt.plot(t, y, label=f"FDTD-Genauigkeit = {accuracy}")
104-
plt.xlabel('Zeit s')
94+
plt.plot(t, y, label=f"FDTD accuracy = {accuracy}")
95+
plt.xlabel('Time s')
10596
plt.ylabel('Amplitude dBA')
10697
plt.ylim(top=-45, bottom=-47.5)
10798
plt.xlim(left=1.53, right=1.6)
108-
print(f"Peak bei FDTD-Genauigkeit = {accuracy}: {np.max(y[int(1.53*Fs) : int(1.6*Fs)])}")
99+
print(f"Peak at FDTD accuracy = {accuracy}: {np.max(y[int(1.53*Fs) : int(1.6*Fs)])}")
109100
plt.grid()
110101

111102
visualize_ripple(filename + "_" +"mic.wav")

0 commit comments

Comments
 (0)