@@ -19,6 +19,14 @@ bool is_in_deep_water(double wavenumber, double water_depth) {
1919 }
2020}
2121
22+ Eigen::Vector3d GetWheelerStretchedPosition (const Eigen::Vector3d& position, double eta, double water_depth, double mwl) {
23+ // position relative to mean water level
24+ auto z_pos = position.z () - mwl;
25+ // Wheeler stretching
26+ auto z_stretched = water_depth * (z_pos - eta) / (water_depth + eta);
27+ return Eigen::Vector3d (position.x (), position.y (), z_stretched + mwl);
28+ }
29+
2230double GetEta (const Eigen::Vector3d& position,
2331 double time,
2432 double omega,
@@ -310,12 +318,7 @@ Eigen::Vector3d RegularWave::GetVelocity(const Eigen::Vector3d& position, double
310318 // apply wave stretching (if enabled)
311319 auto position_stretched = position;
312320 if (wave_stretching_) {
313- auto eta = GetElevation (position, time);
314- // position relative to mean water level
315- auto z_pos = position.z () - mwl_;
316- // Wheeler stretching
317- auto z_stretched = water_depth_ * (z_pos - eta) / (water_depth_ + eta);
318- position_stretched[2 ] = z_stretched + mwl_;
321+ position_stretched = GetWheelerStretchedPosition (position, GetElevation (position, time), water_depth_, mwl_);
319322 }
320323 return GetWaterVelocity (position_stretched, time, regular_wave_omega_, regular_wave_amplitude_, regular_wave_phase_,
321324 wavenumber_, water_depth_, mwl_);
@@ -325,12 +328,7 @@ Eigen::Vector3d RegularWave::GetAcceleration(const Eigen::Vector3d& position, do
325328 // apply wave stretching (if enabled)
326329 auto position_stretched = position;
327330 if (wave_stretching_) {
328- auto eta = GetElevation (position, time);
329- // position relative to mean water level
330- auto z_pos = position.z () - mwl_;
331- // Wheeler stretching
332- auto z_stretched = water_depth_ * (z_pos - eta) / (water_depth_ + eta);
333- position_stretched[2 ] = z_stretched + mwl_;
331+ position_stretched = GetWheelerStretchedPosition (position, GetElevation (position, time), water_depth_, mwl_);
334332 }
335333 return GetWaterAcceleration (position_stretched, time, regular_wave_omega_, regular_wave_amplitude_, regular_wave_phase_,
336334 wavenumber_, water_depth_, mwl_);
@@ -541,13 +539,7 @@ Eigen::Vector3d IrregularWaves::GetVelocity(const Eigen::Vector3d& position, dou
541539 // apply wave stretching (if enabled)
542540 auto position_stretched = position;
543541 if (params_.wave_stretching_ ) {
544- auto eta = GetEtaIrregular (position, time, spectrum_frequencies_, spectral_densities_, spectral_widths_,
545- wave_phases_, wavenumbers_);
546- // position relative to mean water level
547- auto z_pos = position.z () - mwl_;
548- // Wheeler stretching
549- auto z_stretched = water_depth_ * (z_pos - eta) / (water_depth_ + eta);
550- position_stretched[2 ] = z_stretched + mwl_;
542+ position_stretched = GetWheelerStretchedPosition (position, GetElevation (position, time), water_depth_, mwl_);
551543 }
552544
553545 return GetWaterVelocityIrregular (position_stretched, time, spectrum_frequencies_, spectral_densities_,
@@ -558,13 +550,7 @@ Eigen::Vector3d IrregularWaves::GetAcceleration(const Eigen::Vector3d& position,
558550 // apply wave stretching (if enabled)
559551 auto position_stretched = position;
560552 if (params_.wave_stretching_ ) {
561- auto eta = GetEtaIrregular (position, time, spectrum_frequencies_, spectral_densities_, spectral_widths_,
562- wave_phases_, wavenumbers_);
563- // position relative to mean water level
564- auto z_pos = position.z () - mwl_;
565- // Wheeler stretching
566- auto z_stretched = water_depth_ * (z_pos - eta) / (water_depth_ + eta);
567- position_stretched[2 ] = z_stretched + mwl_;
553+ position_stretched = GetWheelerStretchedPosition (position, GetElevation (position, time), water_depth_, mwl_);
568554 }
569555
570556 return GetWaterAccelerationIrregular (position_stretched, time, spectrum_frequencies_, spectral_densities_,
0 commit comments