|
18 | 18 | #include <sstream> |
19 | 19 | #include <unsupported/Eigen/Splines> |
20 | 20 |
|
21 | | -#include <hydroc/helper.h> |
22 | 21 | #include <hydroc/logging.h> |
23 | 22 |
|
24 | | -IrregularWaves::IrregularWaves(const IrregularWaveParams& params) : params_(params) {} |
| 23 | +IrregularWaves::IrregularWaves(const IrregularWaveParams& params) : params_(params) { |
| 24 | + wave_stretching_ = params.wave_stretching_; |
| 25 | +} |
25 | 26 |
|
26 | 27 | void IrregularWaves::InitializeIRFVectors() { |
27 | 28 | ex_irf_sampled_.resize(params_.num_bodies_); |
@@ -151,38 +152,18 @@ void IrregularWaves::AddH5Data(std::vector<HydroData::IrregularWaveInfo>& irreg_ |
151 | 152 | InitializeIRFVectors(); |
152 | 153 | } |
153 | 154 |
|
154 | | -Eigen::Vector3d IrregularWaves::GetVelocity(const Eigen::Vector3d& position, double time) { |
155 | | - auto position_stretched = position; |
156 | | - if (params_.wave_stretching_) { |
157 | | - position_stretched = GetWheelerStretchedPosition(position, GetElevation(position, time), water_depth_, mwl_); |
158 | | - } |
159 | | - |
160 | | - return GetWaterVelocityIrregular(position_stretched, |
161 | | - time, |
162 | | - spectrum_frequencies_, |
163 | | - spectral_densities_, |
164 | | - spectral_widths_, |
165 | | - wave_phases_, |
166 | | - wavenumbers_, |
167 | | - water_depth_, |
168 | | - mwl_); |
| 155 | +Eigen::Vector3d IrregularWaves::GetVelocity(const Eigen::Vector3d& position, double time, double elevation) { |
| 156 | + auto position_stretched = |
| 157 | + params_.wave_stretching_ ? GetWheelerStretchedPosition(position, elevation, water_depth_, mwl_) : position; |
| 158 | + return GetWaterVelocityIrregular(position_stretched, time, spectrum_frequencies_, spectral_densities_, |
| 159 | + spectral_widths_, wave_phases_, wavenumbers_, water_depth_, mwl_); |
169 | 160 | } |
170 | 161 |
|
171 | | -Eigen::Vector3d IrregularWaves::GetAcceleration(const Eigen::Vector3d& position, double time) { |
172 | | - auto position_stretched = position; |
173 | | - if (params_.wave_stretching_) { |
174 | | - position_stretched = GetWheelerStretchedPosition(position, GetElevation(position, time), water_depth_, mwl_); |
175 | | - } |
176 | | - |
177 | | - return GetWaterAccelerationIrregular(position_stretched, |
178 | | - time, |
179 | | - spectrum_frequencies_, |
180 | | - spectral_densities_, |
181 | | - spectral_widths_, |
182 | | - wave_phases_, |
183 | | - wavenumbers_, |
184 | | - water_depth_, |
185 | | - mwl_); |
| 162 | +Eigen::Vector3d IrregularWaves::GetAcceleration(const Eigen::Vector3d& position, double time, double elevation) { |
| 163 | + auto position_stretched = |
| 164 | + params_.wave_stretching_ ? GetWheelerStretchedPosition(position, elevation, water_depth_, mwl_) : position; |
| 165 | + return GetWaterAccelerationIrregular(position_stretched, time, spectrum_frequencies_, spectral_densities_, |
| 166 | + spectral_widths_, wave_phases_, wavenumbers_, water_depth_, mwl_); |
186 | 167 | } |
187 | 168 |
|
188 | 169 | double IrregularWaves::GetElevation(const Eigen::Vector3d& position, double time) { |
@@ -356,6 +337,25 @@ void IrregularWaves::CalculateWidthIRF() { |
356 | 337 | } |
357 | 338 | } |
358 | 339 |
|
| 340 | +// Return last index of vector element below value. |
| 341 | +// - value: Input value |
| 342 | +// - ticks: Array of ticks from which to find lower-bound index (assuming ascending order) |
| 343 | +static size_t get_lower_index(double value, const std::vector<double>& ticks) { |
| 344 | + auto it = std::upper_bound(ticks.begin(), ticks.end(), value); |
| 345 | + // get nearest-below index |
| 346 | + size_t idx = it - ticks.begin() - 1; |
| 347 | + // remove one if equal to value |
| 348 | + if (ticks[idx] == value) { |
| 349 | + idx -= 1; |
| 350 | + } |
| 351 | + if (idx <= 0 || idx >= ticks.size() - 1) { |
| 352 | + throw std::runtime_error("Could not find index for value " + std::to_string(value) + " in array with bounds (" + |
| 353 | + std::to_string(ticks.front()) + ", " + std::to_string(ticks.back()) + ")."); |
| 354 | + } |
| 355 | + // return index |
| 356 | + return idx; |
| 357 | +} |
| 358 | + |
359 | 359 | double IrregularWaves::ExcitationConvolution(int body, int dof, double time) { |
360 | 360 | double f_ex = 0.0; |
361 | 361 | auto& irf_time_array = ex_irf_time_sampled_[body]; |
|
0 commit comments