Skip to content

Commit b341418

Browse files
committed
Merge branch 'feature/chrono-fsi-interface'
2 parents 16522a2 + 4f742b2 commit b341418

13 files changed

Lines changed: 123 additions & 104 deletions

File tree

include/hydroc/core/hydro_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace hydrochrono::hydro {
2323
* Force vector [Fx, Fy, Fz, Mx, My, Mz] for surge, sway, heave,
2424
* roll, pitch, yaw degrees of freedom.
2525
*/
26-
using GeneralizedForce = Eigen::VectorXd;
26+
using GeneralizedForce = Eigen::VectorXd; //// RADU - why is this not an Eigen vector of fixed size 6, or better yet 2 vectors?
2727

2828
/**
2929
* @brief Forces for all bodies in the system.

include/hydroc/helper.h

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,20 @@
33

44
#pragma once
55

6-
#include <Eigen/Dense> // Need for the container function
76
#include <fstream>
87
#include <iostream>
9-
#include <hydroc/logging.h>
108
#include <string>
119
#include <filesystem> // C++17
1210

11+
#include <Eigen/Dense> // Need for the container function
12+
13+
#include <hydroc/logging.h>
14+
15+
//// RADU - why not use constants from Chrono?
1316
#ifndef M_PI
1417
#define M_PI 3.14159265358979323846
1518
#endif
1619

17-
/**@brief Returns last index of vector element below value.
18-
*
19-
* @param value Input value
20-
* @param ticks Array of ticks from which to find lower-bound index (assuming ascending order)
21-
*
22-
*/
23-
size_t get_lower_index(double value, const std::vector<double>& ticks);
24-
2520
/**@brief Base namespace for HydroChrono library
2621
*
2722
*/

include/hydroc/io/h5_reader.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class H5File;
3030

3131
class H5FileInfo;
3232

33+
//// RADU - these should not be in the global namespace!
34+
3335
// contains "chunked" data from the h5 file, generated from H5FileInfo class
3436
class HydroData {
3537
public:
@@ -78,9 +80,10 @@ class HydroData {
7880
std::vector<IrregularWaveInfo> irreg_wave_data_;
7981
friend H5FileInfo;
8082
void resize(int num_bodies);
81-
HydroData() = default;
8283

8384
public:
85+
HydroData() = default;
86+
8487
// getter function naming conventions: put Matrix, Vector, or Val at end to denote return type, always put body_num
8588
// argument first, body_num is always 0 indexed, one line return types can be defined here and not in cpp
8689

include/hydroc/logging.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
1313
*/
1414

15+
//// RADU - does this need to be public?
16+
1517
#pragma once
1618

1719
#include <cstddef>

include/hydroc/waves/irregular_wave.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ class IrregularWaves : public WaveBase {
5151
void AddH5Data(std::vector<HydroData::IrregularWaveInfo>& irreg_h5_data, HydroData::SimulationParameters& sim_data);
5252

5353
double GetElevation(const Eigen::Vector3d& position, double time) override;
54-
Eigen::Vector3d GetVelocity(const Eigen::Vector3d& position, double time) override;
55-
Eigen::Vector3d GetAcceleration(const Eigen::Vector3d& position, double time) override;
54+
Eigen::Vector3d GetVelocity(const Eigen::Vector3d& position, double time, double elevation) override;
55+
Eigen::Vector3d GetAcceleration(const Eigen::Vector3d& position, double time, double elevation) override;
5656

5757
private:
5858
IrregularWaveParams params_;

include/hydroc/waves/regular_wave.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,34 @@
1414
// Forward declaration for internal utilities (not exposed in public API)
1515
// Wave utilities are internal implementation details
1616

17+
struct RegularWaveParams {
18+
unsigned int num_bodies_;
19+
double regular_wave_amplitude_;
20+
double regular_wave_omega_;
21+
double regular_wave_phase_ = 0.0;
22+
bool wave_stretching_ = true;
23+
};
24+
1725
class RegularWave : public WaveBase {
1826
public:
1927
RegularWave();
2028
explicit RegularWave(unsigned int num_b);
29+
explicit RegularWave(const RegularWaveParams& params);
2130

2231
void Initialize() override;
2332
Eigen::VectorXd GetForceAtTime(double t) override;
2433
WaveMode GetWaveMode() override { return mode_; }
2534

35+
//// RADU - eliminate these and use a RegularWaveParams struct (consistent with IrregularWaves)
2636
double regular_wave_amplitude_;
2737
double regular_wave_omega_;
2838
double regular_wave_phase_ = 0.0;
29-
bool wave_stretching_ = true;
3039

3140
void AddH5Data(std::vector<HydroData::RegularWaveInfo>& reg_h5_data, HydroData::SimulationParameters& sim_data);
3241

3342
double GetElevation(const Eigen::Vector3d& position, double time) override;
34-
Eigen::Vector3d GetVelocity(const Eigen::Vector3d& position, double time) override;
35-
Eigen::Vector3d GetAcceleration(const Eigen::Vector3d& position, double time) override;
43+
Eigen::Vector3d GetVelocity(const Eigen::Vector3d& position, double time, double elevation) override;
44+
Eigen::Vector3d GetAcceleration(const Eigen::Vector3d& position, double time, double elevation) override;
3645

3746
private:
3847
unsigned int num_bodies_;

include/hydroc/waves/wave_base.h

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
#include <Eigen/Dense>
1010

11+
//// RADU - why is this not in some namespace?
12+
//// - should these classes be DLL-exported (e.g., to allow AddWave(NoWave))?
13+
//// if not, why is this a public headers?
14+
1115
enum class WaveMode {
1216
noWaveCIC = 0,
1317
regular = 1,
@@ -18,29 +22,38 @@ class WaveBase {
1822
public:
1923
virtual ~WaveBase() = default;
2024

21-
virtual void Initialize() = 0;
22-
virtual Eigen::VectorXd GetForceAtTime(double t) = 0;
23-
virtual WaveMode GetWaveMode() = 0;
24-
virtual double GetElevation(const Eigen::Vector3d& position, double time) = 0;
25-
virtual Eigen::Vector3d GetVelocity(const Eigen::Vector3d& position, double time) = 0;
26-
virtual Eigen::Vector3d GetAcceleration(const Eigen::Vector3d& position, double time) = 0;
25+
virtual void Initialize() = 0;
26+
virtual Eigen::VectorXd GetForceAtTime(double t) = 0;
27+
virtual WaveMode GetWaveMode() = 0;
28+
virtual double GetElevation(const Eigen::Vector3d& position, double time) = 0;
29+
virtual Eigen::Vector3d GetVelocity(const Eigen::Vector3d& position, double time, double elevation) = 0;
30+
virtual Eigen::Vector3d GetAcceleration(const Eigen::Vector3d& position, double time, double elevation) = 0;
31+
32+
Eigen::Vector3d GetVelocity(const Eigen::Vector3d& position, double time);
33+
Eigen::Vector3d GetAcceleration(const Eigen::Vector3d& position, double time);
2734

28-
double mwl_ = 0.0;
29-
double g_ = 9.81;
30-
double water_depth_ = 0.0;
35+
double mwl_ = 0.0;
36+
double g_ = 9.81;
37+
double water_depth_ = 0.0;
38+
bool wave_stretching_ = true;
39+
};
40+
41+
struct NoWaveParams {
42+
unsigned int num_bodies_;
3143
};
3244

3345
class NoWave : public WaveBase {
3446
public:
3547
NoWave();
3648
explicit NoWave(unsigned int num_b);
49+
explicit NoWave(const NoWaveParams& params);
3750

3851
void Initialize() override {}
3952
Eigen::VectorXd GetForceAtTime(double t) override;
4053
WaveMode GetWaveMode() override { return mode_; }
4154
double GetElevation(const Eigen::Vector3d&, double) override { return 0.0; }
42-
Eigen::Vector3d GetVelocity(const Eigen::Vector3d&, double) override { return Eigen::Vector3d(0.0, 0.0, 0.0); }
43-
Eigen::Vector3d GetAcceleration(const Eigen::Vector3d&, double) override { return Eigen::Vector3d(0.0, 0.0, 0.0); }
55+
Eigen::Vector3d GetVelocity(const Eigen::Vector3d&, double, double) override { return Eigen::Vector3d(0.0, 0.0, 0.0); }
56+
Eigen::Vector3d GetAcceleration(const Eigen::Vector3d&, double, double) override { return Eigen::Vector3d(0.0, 0.0, 0.0); }
4457

4558
private:
4659
unsigned int num_bodies_;

src/hydro/chrono/chrono_state_utils.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ void BuildSystemStateFromChronoBodies(
1818
for (const auto& body : bodies) {
1919
BodyState body_state;
2020

21+
//// RADU - why not simply do:
22+
////body_state.position = body->GetPos().eigen();
23+
////body_state.orientation_rpy = body->GetRot().GetCardanAnglesXYZ().eigen();
24+
////body_state.linear_velocity = body->GetPosDt().eigen();
25+
////body_state.angular_velocity = body->GetAngVelParent().eigen();
26+
2127
// Extract position and orientation
2228
const chrono::ChVector3d position_world = body->GetPos();
2329
const chrono::ChVector3d rotation_rpy = body->GetRot().GetCardanAnglesXYZ();

src/hydro/logging/logger_backend.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <direct.h>
1515
#elif defined(__APPLE__)
1616
#include <mach-o/dyld.h>
17+
#include <sys/stat.h>
18+
#include <unistd.h>
1719
#else
1820
#include <unistd.h>
1921
#include <limits.h>

src/hydro/utils/helper.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,22 +77,6 @@ bool hydroc::GetCLIArguments(int argc,
7777
return true;
7878
}
7979

80-
size_t get_lower_index(double value, const std::vector<double>& ticks) {
81-
auto it = std::upper_bound(ticks.begin(), ticks.end(), value);
82-
// get nearest-below index
83-
size_t idx = it - ticks.begin() - 1;
84-
// remove one if equal to value
85-
if (ticks[idx] == value) {
86-
idx -= 1;
87-
}
88-
if (idx <= 0 || idx >= ticks.size() - 1) {
89-
throw std::runtime_error("Could not find index for value " + std::to_string(value) + " in array with bounds (" +
90-
std::to_string(ticks.front()) + ", " + std::to_string(ticks.back()) + ").");
91-
}
92-
// return index
93-
return idx;
94-
}
95-
9680
using std::filesystem::path;
9781

9882
static path DATADIR{};

0 commit comments

Comments
 (0)