Skip to content

Commit 146b224

Browse files
committed
Add parameters for min, max, and number of freqs for spectrum
1 parent 56ff4b1 commit 146b224

5 files changed

Lines changed: 32 additions & 11 deletions

File tree

demos/sphere/demo_sphere_irreg_waves.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ int main(int argc, char* argv[]) {
118118
wave_inputs.ramp_duration_ = 60.0;
119119
wave_inputs.wave_height_ = 2.0;
120120
wave_inputs.wave_period_ = 12.0;
121+
wave_inputs.frequency_min_ = 0.001;
122+
wave_inputs.frequency_max_ = 1.0;
123+
wave_inputs.nfrequencies_ = 1000;
121124

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

@@ -231,4 +234,4 @@ int main(int argc, char* argv[]) {
231234
}
232235

233236
return 0;
234-
}
237+
}

demos/sphere/demo_sphere_irreg_waves_eta_import.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ int main(int argc, char* argv[]) {
120120
params.simulation_duration_ = simulationDuration;
121121
params.ramp_duration_ = 0.0;
122122
params.eta_file_path_ = (DATADIR / "sphere" / "eta" / "eta.txt").lexically_normal().generic_string();
123+
params.frequency_min_ = 0.001;
124+
params.frequency_max_ = 1.0;
125+
params.nfrequencies_ = 1000;
123126

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

demos/sphere/sphere_irreg_waves.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,18 @@ int main(int argc, char* argv[]) {
139139
spring_1->SetDampingCoefficient(damping_coef);
140140
system.AddLink(spring_1);
141141

142-
auto my_hydro_inputs = std::make_shared<IrregularWave>();
143-
//my_hydro_inputs->mode = WaveMode::irregular; // uses regular wave mode
144-
my_hydro_inputs->wave_height_ = 2.0;
145-
my_hydro_inputs->wave_period_ = 12.0;
146-
my_hydro_inputs->simulation_duration_ = simulationDuration;
147-
my_hydro_inputs->simulation_dt_ = timestep;
148-
my_hydro_inputs->ramp_duration_ = 60.0;
149-
//my_hydro_inputs->ramp_duration = 0.0;
150-
//my_hydro_inputs->SetSpectrumFrequencies(0.001, 1.0, 1000);
142+
IrregularWaveParams wave_inputs;
143+
wave_inputs.num_bodies_ = bodies.size();
144+
wave_inputs.simulation_dt_ = timestep;
145+
wave_inputs.simulation_duration_ = simulationDuration;
146+
wave_inputs.ramp_duration_ = 60.0;
147+
wave_inputs.wave_height_ = 2.0;
148+
wave_inputs.wave_period_ = 12.0;
149+
wave_inputs.frequency_min_ = 0.001;
150+
wave_inputs.frequency_max_ = 1.0;
151+
wave_inputs.nfrequencies_ = 1000;
152+
153+
auto my_hydro_inputs = std::make_shared<IrregularWave>(wave_inputs);
151154
//TODO add option for PiersonMoskowitzSpectrumHz or other spectrum, have a default, do PM for now
152155

153156
std::vector<std::shared_ptr<ChBody>> bodies;

include/hydroc/wave_types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ struct IrregularWaveParams {
242242
std::string eta_file_path_;
243243
double wave_height_ = 0.0;
244244
double wave_period_ = 0.0;
245+
double frequency_min_ = 0.001;
246+
double frequency_max_ = 1.0;
247+
double nfrequencies_ = 0;
245248
double peak_enhancement_factor_ = 1.0;
246249
bool is_normalized_ = false;
247250
int seed_ = 1;

src/wave_types.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,16 @@ Eigen::VectorXd IrregularWaves::SetSpectrumFrequencies(double start, double end,
401401

402402
void IrregularWaves::CreateSpectrum() {
403403
// Define the frequency vector
404-
spectrum_frequencies_ = Eigen::VectorXd::LinSpaced(1000, 0.001, 1.0);
404+
int nf;
405+
if (params_.nfrequencies_ == 0) {
406+
// automatically calculate number of frequencies necessary so that timeseries does not repeat itself
407+
double df = 1.0 / params_.simulation_duration_;
408+
nf = std::ceil((params_.frequency_max_-params_.frequency_min_) / df);
409+
410+
} else {
411+
nf = params_.nfrequencies_;
412+
}
413+
spectrum_frequencies_ = Eigen::VectorXd::LinSpaced(nf, params_.frequency_min_, params_.frequency_max_);
405414

406415
// Calculate the Pierson-Moskowitz Spectrum
407416
spectral_densities_ =

0 commit comments

Comments
 (0)