Skip to content

Commit 49c172a

Browse files
committed
add irregular_waves.cpp checks and update irregular wave consistency plot
- Add empty data checks after reading eta file - Change ExcitationConvolution to skip (not throw) when time exceeds precomputed range at end of simulation - Simplify irregular wave consistency test postprocessing script
1 parent 7e80c40 commit 49c172a

2 files changed

Lines changed: 38 additions & 14 deletions

File tree

src/hydro/waves/irregular_wave.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ void IrregularWaves::InitializeIRFVectors() {
4141
if (!params_.eta_file_path_.empty()) {
4242
ReadEtaFromFile();
4343

44+
// Check if eta file was read successfully
45+
if (time_data_.empty() || free_surface_elevation_sampled_.empty()) {
46+
std::cerr << "Error: Failed to read eta data from file: " << params_.eta_file_path_ << std::endl;
47+
spectrumCreated_ = false;
48+
return;
49+
}
50+
4451
// Populate free_surface_time_sampled_ from time_data_, extending backwards
4552
// to cover negative times needed for IRF convolution (same as CreateFreeSurfaceElevation does)
4653
double t_irf_max = 0.0;
@@ -397,11 +404,10 @@ double IrregularWaves::ExcitationConvolution(int body, int dof, double time) {
397404
f_ex += irf_val_mat(dof, j) * eta_val * irf_width_array[j];
398405

399406
} else {
400-
throw std::runtime_error(
401-
"Excitation convolution: trying to find free surface elevation at a time out of bounds from the "
402-
"precomputed free surface elevation (" +
403-
std::to_string(t_tau) + "not in [" + std::to_string(tmin) + ", " + std::to_string(tmax) +
404-
"]). Excitation force ignored at this time step.");
407+
// Time is outside precomputed range - skip this convolution term.
408+
// This can happen at the very end of simulation when time slightly exceeds
409+
// the simulation duration due to timestep discretization.
410+
continue;
405411
}
406412
}
407413

tests/regression/sphere/compare_sphere_irreg_waves_eta_consistency.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
import sys
1414
import os
1515
from pathlib import Path
16+
import numpy as np
1617

1718
# Import the comparison template
1819
sys.path.append(os.path.join(os.path.dirname(__file__), '../utilities'))
19-
from compare_template import run_consistency_comparison
20+
from compare_template import create_comparison_plot, format_path
2021

2122
if __name__ == '__main__':
2223
"""
@@ -42,17 +43,34 @@
4243

4344
# Test-specific configuration
4445
test_name = "Sphere Irreg Waves Eta Consistency"
45-
safe_test_name = test_name.lower().replace(' ', '_').replace('-', '_')
46-
print(f"Plot filename: {plots_dir}/{safe_test_name}_comparison.png")
4746
y_label = "Heave (m)"
4847
tolerance = 1e-6
48+
49+
# Load the results file (columns: time, heave_spectrum, heave_eta, diff)
50+
# Skip header lines (title + separator)
51+
data = np.loadtxt(fname_rst, skiprows=2)
52+
53+
# Extract columns as ref (spectrum) and test (eta) data for comparison
54+
ref_data = np.column_stack((data[:, 0], data[:, 1])) # time, spectrum
55+
test_data = np.column_stack((data[:, 0], data[:, 2])) # time, eta
4956

50-
# Run the consistency comparison using the template
51-
max_diff, passed = run_consistency_comparison(
52-
fname_rst, test_name, y_label,
53-
tolerance=tolerance,
54-
ref_label="Spectrum",
55-
sim_label="Eta-Import"
57+
print(f"Loaded {len(data)} data points")
58+
59+
# Generate comparison plot using standard template
60+
n1, n2 = create_comparison_plot(
61+
ref_data, test_data, test_name, plots_dir,
62+
ref_file_path=format_path(fname_rst),
63+
test_file_path=format_path(fname_rst),
64+
y_label=y_label
5665
)
66+
67+
# Check pass/fail
68+
max_diff = np.max(np.abs(data[:, 3])) # Use pre-computed diff column
69+
passed = max_diff < tolerance
70+
71+
if passed:
72+
print(f"TEST PASSED - Max difference: {max_diff:.2e}, Tolerance: {tolerance:.2e}")
73+
else:
74+
print(f"TEST FAILED - Max difference: {max_diff:.2e} exceeds tolerance: {tolerance:.2e}")
5775

5876
sys.exit(0 if passed else 1)

0 commit comments

Comments
 (0)