@@ -478,9 +478,11 @@ IrregularWaves::IrregularWaves(const IrregularWaveParams& params)
478478 eta_file_path_(params.eta_file_path_),
479479 wave_height_(params.wave_height_),
480480 wave_period_(params.wave_period_),
481+ peak_enhancement_factor_(params.peak_enhancement_factor_),
481482 simulation_dt_(params.simulation_dt_),
482483 simulation_duration_(params.simulation_duration_),
483- ramp_duration_(params.ramp_duration_) {
484+ ramp_duration_(params.ramp_duration_),
485+ seed_(params.seed_) {
484486 std::cout << " Creating IrregularWaves object..." << std::endl;
485487 ex_irf_resampled_.resize (num_bodies_);
486488 ex_irf_time_resampled_.resize (num_bodies_);
@@ -675,7 +677,7 @@ void IrregularWaves::CreateSpectrum() {
675677 spectrum_frequencies_ = Eigen::VectorXd::LinSpaced (1000 , 0.001 , 1.0 );
676678
677679 // Calculate the Pierson-Moskowitz Spectrum
678- spectral_densities_ = PiersonMoskowitzSpectrumHz (spectrum_frequencies_, wave_height_, wave_period_);
680+ spectral_densities_ = JONSWAPSpectrumHz (spectrum_frequencies_, wave_height_, wave_period_, peak_enhancement_factor_ );
679681
680682 // Open a file stream for writing
681683 std::ofstream outputFile (" spectral_densities.txt" );
@@ -711,6 +713,23 @@ Eigen::VectorXd PiersonMoskowitzSpectrumHz(Eigen::VectorXd& f, double Hs, double
711713 return spectral_densities;
712714}
713715
716+ Eigen::VectorXd JONSWAPSpectrumHz (Eigen::VectorXd& f, double Hs, double Tp, double gamma) {
717+ auto spectral_densities = PiersonMoskowitzSpectrumHz (f, Hs, Tp);
718+
719+ // Scale spectral densities from PM to JONSWAP with gamma factor
720+ for (size_t i = 0 ; i < spectral_densities.size (); ++i) {
721+ double sigma;
722+ if (f[i] <= 1.0 / Tp) {
723+ sigma = 0.07 ;
724+ } else {
725+ sigma = 0.09 ;
726+ }
727+ spectral_densities[i] *= pow (gamma, exp (-(1.0 / (2.0 * pow (sigma, 2 ))) * pow (f[i] * Tp - 1.0 , 2 )));
728+ }
729+
730+ return spectral_densities;
731+ }
732+
714733void IrregularWaves::CreateFreeSurfaceElevation () {
715734 // Create a time index vector
716735 // UpdateNumTimesteps();
@@ -719,7 +738,8 @@ void IrregularWaves::CreateFreeSurfaceElevation() {
719738 Eigen::VectorXd time_index = Eigen::VectorXd::LinSpaced (num_timesteps, 0 , simulation_duration_);
720739
721740 // Calculate the free surface elevation
722- free_surface_elevation_ = FreeSurfaceElevation (spectrum_frequencies_, spectral_densities_, time_index, sim_data_.water_depth );
741+ free_surface_elevation_ =
742+ FreeSurfaceElevation (spectrum_frequencies_, spectral_densities_, time_index, sim_data_.water_depth , seed_);
723743
724744 // Apply ramp if ramp_duration is greater than 0
725745 if (ramp_duration_ > 0.0 ) {
0 commit comments