Skip to content

Commit 25e9fb2

Browse files
committed
Add test for irregular waves
1 parent 48fcb96 commit 25e9fb2

3 files changed

Lines changed: 40076 additions & 12 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import numpy as np
2+
import sys
3+
4+
# Function to read two wave data files
5+
def read_wave_data(file_path):
6+
with open(file_path, 'r') as file:
7+
lines = file.readlines()
8+
9+
wave_data = {}
10+
11+
heave_data = []
12+
for line in lines[1:]:
13+
time, heave = line.split()
14+
heave_data.append(float(heave))
15+
wave_data['heave'] = np.array(heave_data)
16+
17+
return wave_data
18+
19+
def calculate_l2_norm(heave_data1, heave_data2):
20+
yd = heave_data1 - heave_data2
21+
nval = yd.shape[0]
22+
l2 = np.linalg.norm(yd)/nval
23+
return l2
24+
25+
def compare_wave_files(file_path1, file_path2):
26+
wave_data1 = read_wave_data(file_path1)
27+
wave_data2 = read_wave_data(file_path2)
28+
29+
# calculate the l2 norm of the difference in heave
30+
diff_heave = calculate_l2_norm(wave_data1['heave'],wave_data2['heave'])
31+
32+
# If the difference is more than 1e-6 then error out
33+
if (diff_heave > 1e-6): sys.exit(1) # error
34+
35+
36+
37+
if __name__ == "__main__":
38+
39+
fname_ref = sys.argv[1]
40+
fname_rst = sys.argv[2]
41+
42+
compare_wave_files(fname_ref, fname_rst)

0 commit comments

Comments
 (0)