Skip to content

Commit

Permalink
Add parameters for min, max, and number of freqs for spectrum
Browse files Browse the repository at this point in the history
  • Loading branch information
tridelat committed Jan 23, 2024
1 parent 56ff4b1 commit 146b224
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 11 deletions.
5 changes: 4 additions & 1 deletion demos/sphere/demo_sphere_irreg_waves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ int main(int argc, char* argv[]) {
wave_inputs.ramp_duration_ = 60.0;
wave_inputs.wave_height_ = 2.0;
wave_inputs.wave_period_ = 12.0;
wave_inputs.frequency_min_ = 0.001;
wave_inputs.frequency_max_ = 1.0;
wave_inputs.nfrequencies_ = 1000;

std::shared_ptr<IrregularWaves> my_hydro_inputs; // declare outside the try-catch block

Expand Down Expand Up @@ -231,4 +234,4 @@ int main(int argc, char* argv[]) {
}

return 0;
}
}
3 changes: 3 additions & 0 deletions demos/sphere/demo_sphere_irreg_waves_eta_import.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ int main(int argc, char* argv[]) {
params.simulation_duration_ = simulationDuration;
params.ramp_duration_ = 0.0;
params.eta_file_path_ = (DATADIR / "sphere" / "eta" / "eta.txt").lexically_normal().generic_string();
params.frequency_min_ = 0.001;
params.frequency_max_ = 1.0;
params.nfrequencies_ = 1000;

std::shared_ptr<IrregularWaves> my_hydro_inputs; // declare outside the try-catch block

Expand Down
21 changes: 12 additions & 9 deletions demos/sphere/sphere_irreg_waves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,18 @@ int main(int argc, char* argv[]) {
spring_1->SetDampingCoefficient(damping_coef);
system.AddLink(spring_1);

auto my_hydro_inputs = std::make_shared<IrregularWave>();
//my_hydro_inputs->mode = WaveMode::irregular; // uses regular wave mode
my_hydro_inputs->wave_height_ = 2.0;
my_hydro_inputs->wave_period_ = 12.0;
my_hydro_inputs->simulation_duration_ = simulationDuration;
my_hydro_inputs->simulation_dt_ = timestep;
my_hydro_inputs->ramp_duration_ = 60.0;
//my_hydro_inputs->ramp_duration = 0.0;
//my_hydro_inputs->SetSpectrumFrequencies(0.001, 1.0, 1000);
IrregularWaveParams wave_inputs;
wave_inputs.num_bodies_ = bodies.size();
wave_inputs.simulation_dt_ = timestep;
wave_inputs.simulation_duration_ = simulationDuration;
wave_inputs.ramp_duration_ = 60.0;
wave_inputs.wave_height_ = 2.0;
wave_inputs.wave_period_ = 12.0;
wave_inputs.frequency_min_ = 0.001;
wave_inputs.frequency_max_ = 1.0;
wave_inputs.nfrequencies_ = 1000;

auto my_hydro_inputs = std::make_shared<IrregularWave>(wave_inputs);
//TODO add option for PiersonMoskowitzSpectrumHz or other spectrum, have a default, do PM for now

std::vector<std::shared_ptr<ChBody>> bodies;
Expand Down
3 changes: 3 additions & 0 deletions include/hydroc/wave_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ struct IrregularWaveParams {
std::string eta_file_path_;
double wave_height_ = 0.0;
double wave_period_ = 0.0;
double frequency_min_ = 0.001;
double frequency_max_ = 1.0;
double nfrequencies_ = 0;
double peak_enhancement_factor_ = 1.0;
bool is_normalized_ = false;
int seed_ = 1;
Expand Down
11 changes: 10 additions & 1 deletion src/wave_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,16 @@ Eigen::VectorXd IrregularWaves::SetSpectrumFrequencies(double start, double end,

void IrregularWaves::CreateSpectrum() {
// Define the frequency vector
spectrum_frequencies_ = Eigen::VectorXd::LinSpaced(1000, 0.001, 1.0);
int nf;
if (params_.nfrequencies_ == 0) {
// automatically calculate number of frequencies necessary so that timeseries does not repeat itself
double df = 1.0 / params_.simulation_duration_;
nf = std::ceil((params_.frequency_max_-params_.frequency_min_) / df);

} else {
nf = params_.nfrequencies_;
}
spectrum_frequencies_ = Eigen::VectorXd::LinSpaced(nf, params_.frequency_min_, params_.frequency_max_);

// Calculate the Pierson-Moskowitz Spectrum
spectral_densities_ =
Expand Down

0 comments on commit 146b224

Please sign in to comment.