Skip to content

Commit 1bf29b7

Browse files
authored
Merge pull request #54 from tridelat/tridelat/ex_fix
Test, tweaks, and and fix for irregular waves
2 parents 234fcc7 + 146b224 commit 1bf29b7

8 files changed

Lines changed: 40150 additions & 71 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)

demos/sphere/demo_sphere_irreg_waves.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ int main(int argc, char* argv[]) {
118118
wave_inputs.ramp_duration_ = 60.0;
119119
wave_inputs.wave_height_ = 2.0;
120120
wave_inputs.wave_period_ = 12.0;
121+
wave_inputs.frequency_min_ = 0.001;
122+
wave_inputs.frequency_max_ = 1.0;
123+
wave_inputs.nfrequencies_ = 1000;
121124

122125
std::shared_ptr<IrregularWaves> my_hydro_inputs; // declare outside the try-catch block
123126

@@ -231,4 +234,4 @@ int main(int argc, char* argv[]) {
231234
}
232235

233236
return 0;
234-
}
237+
}

demos/sphere/demo_sphere_irreg_waves_eta_import.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ int main(int argc, char* argv[]) {
120120
params.simulation_duration_ = simulationDuration;
121121
params.ramp_duration_ = 0.0;
122122
params.eta_file_path_ = (DATADIR / "sphere" / "eta" / "eta.txt").lexically_normal().generic_string();
123+
params.frequency_min_ = 0.001;
124+
params.frequency_max_ = 1.0;
125+
params.nfrequencies_ = 1000;
123126

124127
std::shared_ptr<IrregularWaves> my_hydro_inputs; // declare outside the try-catch block
125128

0 commit comments

Comments
 (0)