Skip to content

Commit ccc5e2e

Browse files
committed
Add optional normalizing factor for JONSWAP spectrum
1 parent 25e9fb2 commit ccc5e2e

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

include/hydroc/wave_types.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
// todo move this helper function somewhere else?
1414
Eigen::VectorXd PiersonMoskowitzSpectrumHz(Eigen::VectorXd& f, double Hs, double Tp);
1515

16-
Eigen::VectorXd JONSWAPSpectrumHz(Eigen::VectorXd& f, double Hs, double Tp, double gamma = 3.3);
16+
Eigen::VectorXd JONSWAPSpectrumHz(Eigen::VectorXd& f,
17+
double Hs,
18+
double Tp,
19+
double gamma = 3.3,
20+
bool is_normalized = false);
1721

1822
std::vector<double> FreeSurfaceElevation(const Eigen::VectorXd& freqs_hz,
1923
const Eigen::VectorXd& spectral_densities,
@@ -239,6 +243,7 @@ struct IrregularWaveParams {
239243
double wave_height_ = 0.0;
240244
double wave_period_ = 0.0;
241245
double peak_enhancement_factor_ = 1.0;
246+
bool is_normalized_ = false;
242247
int seed_ = 1;
243248
};
244249

@@ -327,6 +332,7 @@ class IrregularWaves : public WaveBase {
327332
double wave_height_;
328333
double wave_period_;
329334
double peak_enhancement_factor_;
335+
bool is_normalized_ = false;
330336
int seed_;
331337
std::vector<double> spectrum_;
332338
std::vector<double> time_data_;

src/wave_types.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ IrregularWaves::IrregularWaves(const IrregularWaveParams& params)
237237
wave_height_(params.wave_height_),
238238
wave_period_(params.wave_period_),
239239
peak_enhancement_factor_(params.peak_enhancement_factor_),
240+
is_normalized_(params.is_normalized_),
240241
simulation_dt_(params.simulation_dt_),
241242
simulation_duration_(params.simulation_duration_),
242243
ramp_duration_(params.ramp_duration_),
@@ -413,7 +414,7 @@ void IrregularWaves::CreateSpectrum() {
413414

414415
// Calculate the Pierson-Moskowitz Spectrum
415416
spectral_densities_ =
416-
JONSWAPSpectrumHz(spectrum_frequencies_, wave_height_, wave_period_, peak_enhancement_factor_);
417+
JONSWAPSpectrumHz(spectrum_frequencies_, wave_height_, wave_period_, peak_enhancement_factor_, is_normalized_);
417418

418419
// Open a file stream for writing
419420
std::ofstream outputFile("spectral_densities.txt");
@@ -449,9 +450,12 @@ Eigen::VectorXd PiersonMoskowitzSpectrumHz(Eigen::VectorXd& f, double Hs, double
449450
return spectral_densities;
450451
}
451452

452-
Eigen::VectorXd JONSWAPSpectrumHz(Eigen::VectorXd& f, double Hs, double Tp, double gamma) {
453+
Eigen::VectorXd JONSWAPSpectrumHz(Eigen::VectorXd& f, double Hs, double Tp, double gamma, bool is_normalized) {
453454
auto spectral_densities = PiersonMoskowitzSpectrumHz(f, Hs, Tp);
454455

456+
// only used if is_normalized is true
457+
double normalization_factor = (1 - 0.287 * log(gamma));
458+
455459
// Scale spectral densities from PM to JONSWAP with gamma factor
456460
for (size_t i = 0; i < spectral_densities.size(); ++i) {
457461
double sigma;
@@ -461,8 +465,10 @@ Eigen::VectorXd JONSWAPSpectrumHz(Eigen::VectorXd& f, double Hs, double Tp, doub
461465
sigma = 0.09;
462466
}
463467
spectral_densities[i] *= pow(gamma, exp(-(1.0 / (2.0 * pow(sigma, 2))) * pow(f[i] * Tp - 1.0, 2)));
468+
if (is_normalized) {
469+
spectral_densities[i] *= normalization_factor;
470+
}
464471
}
465-
466472
return spectral_densities;
467473
}
468474

0 commit comments

Comments
 (0)