@@ -232,40 +232,31 @@ void WriteFreeSurfaceMeshObj(const std::vector<std::array<double, 3>>& points,
232232}
233233
234234IrregularWaves::IrregularWaves (const IrregularWaveParams& params)
235- : num_bodies_(params.num_bodies_),
236- eta_file_path_(params.eta_file_path_),
237- wave_height_(params.wave_height_),
238- wave_period_(params.wave_period_),
239- peak_enhancement_factor_(params.peak_enhancement_factor_),
240- is_normalized_(params.is_normalized_),
241- simulation_dt_(params.simulation_dt_),
242- simulation_duration_(params.simulation_duration_),
243- ramp_duration_(params.ramp_duration_),
244- seed_(params.seed_) {}
235+ : params_(params) {}
245236
246237void IrregularWaves::InitializeIRFVectors () {
247- ex_irf_sampled_.resize (num_bodies_);
248- ex_irf_time_sampled_.resize (num_bodies_);
249- ex_irf_width_sampled_.resize (num_bodies_);
238+ ex_irf_sampled_.resize (params_. num_bodies_ );
239+ ex_irf_time_sampled_.resize (params_. num_bodies_ );
240+ ex_irf_width_sampled_.resize (params_. num_bodies_ );
250241
251- std::vector<Eigen::MatrixXd> ex_irf_old (num_bodies_);
252- std::vector<Eigen::VectorXd> ex_irf_time_old (num_bodies_);
242+ std::vector<Eigen::MatrixXd> ex_irf_old (params_. num_bodies_ );
243+ std::vector<Eigen::VectorXd> ex_irf_time_old (params_. num_bodies_ );
253244
254- for (unsigned int b = 0 ; b < num_bodies_; b++) {
245+ for (unsigned int b = 0 ; b < params_. num_bodies_ ; b++) {
255246 ex_irf_sampled_[b] = GetExcitationIRF (b);
256247 ex_irf_time_sampled_[b] = wave_info_[b].excitation_irf_time ;
257248 CalculateWidthIRF ();
258249 }
259250
260251 // Resample excitation IRF time series
261- if (simulation_dt_ > 0.0 ) {
262- ResampleIRF (simulation_dt_);
252+ if (params_. simulation_dt_ > 0.0 ) {
253+ ResampleIRF (params_. simulation_dt_ );
263254 }
264255
265- if (!eta_file_path_.empty ()) {
256+ if (!params_. eta_file_path_ .empty ()) {
266257 ReadEtaFromFile ();
267258 spectrumCreated_ = false ;
268- } else if (wave_height_ != 0.0 && wave_period_ != 0.0 ) {
259+ } else if (params_. wave_height_ != 0.0 && params_. wave_period_ != 0.0 ) {
269260 CreateSpectrum ();
270261 CreateFreeSurfaceElevation ();
271262 spectrumCreated_ = true ;
@@ -289,10 +280,10 @@ std::vector<double> IrregularWaves::GetEtaTimeData() {
289280}
290281
291282void IrregularWaves::ReadEtaFromFile () {
292- std::cout << " Reading eta file " << eta_file_path_ << " ." << std::endl;
293- std::ifstream file (eta_file_path_);
283+ std::cout << " Reading eta file " << params_. eta_file_path_ << " ." << std::endl;
284+ std::ifstream file (params_. eta_file_path_ );
294285 if (!file) {
295- throw std::runtime_error (" Unable to open file at: " + eta_file_path_ + " ." );
286+ throw std::runtime_error (" Unable to open file at: " + params_. eta_file_path_ + " ." );
296287 }
297288
298289 std::string line;
@@ -322,13 +313,13 @@ void IrregularWaves::AddH5Data(std::vector<HydroData::IrregularWaveInfo>& irreg_
322313}
323314
324315Eigen::VectorXd IrregularWaves::GetForceAtTime (double t) {
325- unsigned int total_dofs = num_bodies_ * 6 ;
316+ unsigned int total_dofs = params_. num_bodies_ * 6 ;
326317 Eigen::VectorXd f (total_dofs);
327318 for (int i = 0 ; i < total_dofs; i++) {
328319 f[i] = 0.0 ;
329320 }
330321
331- for (int body = 0 ; body < num_bodies_; body++) {
322+ for (int body = 0 ; body < params_. num_bodies_ ; body++) {
332323 // Loop through the DOFs
333324 for (int dof = 0 ; dof < 6 ; ++dof) {
334325 // Compute the convolution for the current DOF
@@ -342,7 +333,7 @@ Eigen::VectorXd IrregularWaves::GetForceAtTime(double t) {
342333}
343334
344335void IrregularWaves::ResampleIRF (double dt) {
345- for (unsigned int b = 0 ; b < num_bodies_; b++) {
336+ for (unsigned int b = 0 ; b < params_. num_bodies_ ; b++) {
346337 auto & time_array = ex_irf_time_sampled_[b];
347338 auto & width_array = ex_irf_width_sampled_[b];
348339 auto & val_array = ex_irf_sampled_[b];
@@ -378,7 +369,7 @@ void IrregularWaves::ResampleIRF(double dt) {
378369}
379370
380371void IrregularWaves::CalculateWidthIRF () {
381- for (unsigned int b = 0 ; b < num_bodies_; b++) {
372+ for (unsigned int b = 0 ; b < params_. num_bodies_ ; b++) {
382373 auto & time_array = ex_irf_time_sampled_[b];
383374 auto & width_array = ex_irf_width_sampled_[b];
384375
@@ -414,7 +405,7 @@ void IrregularWaves::CreateSpectrum() {
414405
415406 // Calculate the Pierson-Moskowitz Spectrum
416407 spectral_densities_ =
417- JONSWAPSpectrumHz (spectrum_frequencies_, wave_height_, wave_period_, peak_enhancement_factor_, is_normalized_);
408+ JONSWAPSpectrumHz (spectrum_frequencies_,params_. wave_height_,params_. wave_period_, params_. peak_enhancement_factor_ , params_. is_normalized_ );
418409
419410 // Open a file stream for writing
420411 std::ofstream outputFile (" spectral_densities.txt" );
@@ -475,7 +466,7 @@ Eigen::VectorXd JONSWAPSpectrumHz(Eigen::VectorXd& f, double Hs, double Tp, doub
475466void IrregularWaves::CreateFreeSurfaceElevation () {
476467 // Create a time index vector
477468 // UpdateNumTimesteps();
478- int num_timesteps = static_cast <int >(simulation_duration_ / simulation_dt_) + 1 ;
469+ int num_timesteps = static_cast <int >(params_. simulation_duration_ / params_. simulation_dt_ ) + 1 ;
479470
480471 double t_irf_min = 0.0 ;
481472 double t_irf_max = 0.0 ;
@@ -494,7 +485,7 @@ void IrregularWaves::CreateFreeSurfaceElevation() {
494485 }
495486 }
496487
497- auto time_array = Eigen::VectorXd::LinSpaced (num_timesteps, 0 , simulation_duration_ + 2 * (t_irf_max - t_irf_min));
488+ auto time_array = Eigen::VectorXd::LinSpaced (num_timesteps, 0 , params_. simulation_duration_ + 2 * (t_irf_max - t_irf_min));
498489
499490 // Save time array as a std::vector
500491 free_surface_time_sampled_.resize (time_array.size ());
@@ -509,12 +500,12 @@ void IrregularWaves::CreateFreeSurfaceElevation() {
509500
510501 // Calculate the free surface elevation
511502 free_surface_elevation_sampled_ =
512- FreeSurfaceElevation (spectrum_frequencies_, spectral_densities_, time_array, sim_data_.water_depth , seed_);
503+ FreeSurfaceElevation (spectrum_frequencies_, spectral_densities_, time_array, sim_data_.water_depth , params_. seed_ );
513504
514505 // Apply ramp if ramp_duration is greater than 0
515- if (ramp_duration_ > 0.0 ) {
506+ if (params_. ramp_duration_ > 0.0 ) {
516507 // UpdateRampTimesteps();
517- int ramp_timesteps = static_cast <int >(ramp_duration_ / simulation_dt_) + 1 ;
508+ int ramp_timesteps = static_cast <int >(params_. ramp_duration_ / params_. simulation_dt_ ) + 1 ;
518509 Eigen::VectorXd ramp = Eigen::VectorXd::LinSpaced (ramp_timesteps, 0.0 , 1.0 );
519510
520511 for (size_t i = 0 ; i < ramp.size (); ++i) {
@@ -612,8 +603,8 @@ double IrregularWaves::ExcitationConvolution(int body, int dof, double time) {
612603
613604void IrregularWaves::SetUpWaveMesh (std::string filename) {
614605 mesh_file_name_ = filename;
615- int num_timesteps = static_cast <int >(simulation_duration_ / simulation_dt_) + 1 ;
616- Eigen::VectorXd time_index = Eigen::VectorXd::LinSpaced (num_timesteps, 0 , simulation_duration_);
606+ int num_timesteps = static_cast <int >(params_. simulation_duration_ / params_. simulation_dt_ ) + 1 ;
607+ Eigen::VectorXd time_index = Eigen::VectorXd::LinSpaced (num_timesteps, 0 , params_. simulation_duration_ );
617608 std::vector<std::array<double , 3 >> free_surface_3d_pts =
618609 CreateFreeSurface3DPts (free_surface_elevation_sampled_, time_index);
619610 std::vector<std::array<size_t , 3 >> free_surface_triangles = CreateFreeSurfaceTriangles (time_index.size ());
0 commit comments