Skip to content

Commit

Permalink
Merge pull request #54 from tridelat/tridelat/ex_fix
Browse files Browse the repository at this point in the history
Test, tweaks, and and fix for irregular waves
  • Loading branch information
tridelat authored Feb 1, 2024
2 parents 234fcc7 + 146b224 commit 1bf29b7
Show file tree
Hide file tree
Showing 8 changed files with 40,150 additions and 71 deletions.
42 changes: 42 additions & 0 deletions demos/sphere/compare_irreg_waves.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import numpy as np
import sys

# Function to read two wave data files
def read_wave_data(file_path):
with open(file_path, 'r') as file:
lines = file.readlines()

wave_data = {}

heave_data = []
for line in lines[1:]:
time, heave = line.split()
heave_data.append(float(heave))
wave_data['heave'] = np.array(heave_data)

return wave_data

def calculate_l2_norm(heave_data1, heave_data2):
yd = heave_data1 - heave_data2
nval = yd.shape[0]
l2 = np.linalg.norm(yd)/nval
return l2

def compare_wave_files(file_path1, file_path2):
wave_data1 = read_wave_data(file_path1)
wave_data2 = read_wave_data(file_path2)

# calculate the l2 norm of the difference in heave
diff_heave = calculate_l2_norm(wave_data1['heave'],wave_data2['heave'])

# If the difference is more than 1e-6 then error out
if (diff_heave > 1e-6): sys.exit(1) # error



if __name__ == "__main__":

fname_ref = sys.argv[1]
fname_rst = sys.argv[2]

compare_wave_files(fname_ref, fname_rst)
5 changes: 4 additions & 1 deletion demos/sphere/demo_sphere_irreg_waves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ int main(int argc, char* argv[]) {
wave_inputs.ramp_duration_ = 60.0;
wave_inputs.wave_height_ = 2.0;
wave_inputs.wave_period_ = 12.0;
wave_inputs.frequency_min_ = 0.001;
wave_inputs.frequency_max_ = 1.0;
wave_inputs.nfrequencies_ = 1000;

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

Expand Down Expand Up @@ -231,4 +234,4 @@ int main(int argc, char* argv[]) {
}

return 0;
}
}
3 changes: 3 additions & 0 deletions demos/sphere/demo_sphere_irreg_waves_eta_import.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ int main(int argc, char* argv[]) {
params.simulation_duration_ = simulationDuration;
params.ramp_duration_ = 0.0;
params.eta_file_path_ = (DATADIR / "sphere" / "eta" / "eta.txt").lexically_normal().generic_string();
params.frequency_min_ = 0.001;
params.frequency_max_ = 1.0;
params.nfrequencies_ = 1000;

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

Expand Down
Loading

0 comments on commit 1bf29b7

Please sign in to comment.