diff --git a/CMakeLists.txt b/CMakeLists.txt index 2236f788..9a0e9e15 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,7 +35,7 @@ endif() #-------------------------------------------------------------- project(HydroChrono - VERSION 0.2.6 + VERSION 0.2.8 DESCRIPTION "A hydrodynamic library for use with Project Chrono." LANGUAGES CXX ) @@ -228,6 +228,7 @@ set_target_properties(HydroChrono target_link_libraries(HydroChrono PUBLIC + ${CHRONO_LIBRARIES} ${CHRONO_TARGETS} # Chrono::Chrono_core;Chrono::Chrono_irrlicht;... $<$:Eigen3::Eigen> PRIVATE @@ -366,4 +367,8 @@ export( ) # Set build type to Release but enable debug symbols -set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi /O2") +if(MSVC) + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi /O2") +else() + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -g -O2") +endif() diff --git a/include/hydroc/logging.h b/include/hydroc/logging.h index 874decdd..841119c9 100644 --- a/include/hydroc/logging.h +++ b/include/hydroc/logging.h @@ -27,6 +27,7 @@ #include #include #include +#include #ifdef _WIN32 #include diff --git a/include/hydroc/wave_types.h b/include/hydroc/wave_types.h index ed7993c1..e1f52657 100644 --- a/include/hydroc/wave_types.h +++ b/include/hydroc/wave_types.h @@ -165,6 +165,7 @@ class RegularWave : public WaveBase { double regular_wave_amplitude_; double regular_wave_omega_; double regular_wave_phase_ = 0.0; + bool wave_stretching_ = true; /** * @brief Initializes other member variables for timestep calculations later. diff --git a/src/wave_types.cpp b/src/wave_types.cpp index f0959472..53a6294c 100644 --- a/src/wave_types.cpp +++ b/src/wave_types.cpp @@ -11,6 +11,22 @@ #include +bool is_in_deep_water(double wavenumber, double water_depth) { + if (wavenumber * water_depth > 89.4) { + return true; + } else { + return false; + } +} + +Eigen::Vector3d GetWheelerStretchedPosition(const Eigen::Vector3d& position, double eta, double water_depth, double mwl) { + // position relative to mean water level + auto z_pos = position.z() - mwl; + // Wheeler stretching + auto z_stretched = water_depth * (z_pos - eta) / (water_depth + eta); + return Eigen::Vector3d(position.x(), position.y(), z_stretched + mwl); +} + double GetEta(const Eigen::Vector3d& position, double time, double omega, @@ -73,7 +89,7 @@ Eigen::Vector3d GetWaterVelocity(const Eigen::Vector3d& position, // get water velocity auto water_velocity = Eigen::Vector3d(0.0, 0.0, 0.0); - if (2 * M_PI / wavenumber > water_depth || wavenumber * water_depth > 500.0) { + if (is_in_deep_water(wavenumber, water_depth)) { // deep water water_velocity[0] = omega * amplitude * std::exp(wavenumber * z_pos) * cos(wavenumber * x_pos - omega * time + phase); @@ -105,7 +121,7 @@ Eigen::Vector3d GetWaterAcceleration(const Eigen::Vector3d& position, // get water velocity auto water_acceleration = Eigen::Vector3d(0.0, 0.0, 0.0); - if (2 * M_PI / wavenumber > water_depth || wavenumber * water_depth > 500.0) { + if (is_in_deep_water(wavenumber, water_depth)) { // deep water water_acceleration[0] = omega * omega * amplitude * std::exp(wavenumber * z_pos) * sin(wavenumber * x_pos - omega * time + phase); @@ -299,12 +315,22 @@ void RegularWave::AddH5Data(std::vector& reg_h5_data } Eigen::Vector3d RegularWave::GetVelocity(const Eigen::Vector3d& position, double time) { - return GetWaterVelocity(position, time, regular_wave_omega_, regular_wave_amplitude_, regular_wave_phase_, + // apply wave stretching (if enabled) + auto position_stretched = position; + if (wave_stretching_) { + position_stretched = GetWheelerStretchedPosition(position, GetElevation(position, time), water_depth_, mwl_); + } + return GetWaterVelocity(position_stretched, time, regular_wave_omega_, regular_wave_amplitude_, regular_wave_phase_, wavenumber_, water_depth_, mwl_); }; Eigen::Vector3d RegularWave::GetAcceleration(const Eigen::Vector3d& position, double time) { - return GetWaterAcceleration(position, time, regular_wave_omega_, regular_wave_amplitude_, regular_wave_phase_, + // apply wave stretching (if enabled) + auto position_stretched = position; + if (wave_stretching_) { + position_stretched = GetWheelerStretchedPosition(position, GetElevation(position, time), water_depth_, mwl_); + } + return GetWaterAcceleration(position_stretched, time, regular_wave_omega_, regular_wave_amplitude_, regular_wave_phase_, wavenumber_, water_depth_, mwl_); }; @@ -513,12 +539,7 @@ Eigen::Vector3d IrregularWaves::GetVelocity(const Eigen::Vector3d& position, dou // apply wave stretching (if enabled) auto position_stretched = position; if (params_.wave_stretching_) { - auto eta = GetEtaIrregular(position, time, spectrum_frequencies_, spectral_densities_, spectral_widths_, - wave_phases_, wavenumbers_); - // position relative to mean water level - auto z_pos = position.z() - mwl_; - // Wheeler stretching - position_stretched[2] = water_depth_ * (z_pos - eta) / (water_depth_ + eta); + position_stretched = GetWheelerStretchedPosition(position, GetElevation(position, time), water_depth_, mwl_); } return GetWaterVelocityIrregular(position_stretched, time, spectrum_frequencies_, spectral_densities_, @@ -529,12 +550,7 @@ Eigen::Vector3d IrregularWaves::GetAcceleration(const Eigen::Vector3d& position, // apply wave stretching (if enabled) auto position_stretched = position; if (params_.wave_stretching_) { - auto eta = GetEtaIrregular(position, time, spectrum_frequencies_, spectral_densities_, spectral_widths_, - wave_phases_, wavenumbers_); - // position relative to mean water level - auto z_pos = position.z() - mwl_; - // Wheeler stretching - position_stretched[2] = water_depth_ * (z_pos - eta) / (water_depth_ + eta); + position_stretched = GetWheelerStretchedPosition(position, GetElevation(position, time), water_depth_, mwl_); } return GetWaterAccelerationIrregular(position_stretched, time, spectrum_frequencies_, spectral_densities_,