Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test, tweaks, and and fix for irregular waves #54

Merged
merged 5 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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