Skip to content

Commit 336d30d

Browse files
committed
Update hydro APIs for added-mass fix and VSG visualization
1 parent 44cccaf commit 336d30d

4 files changed

Lines changed: 26 additions & 6 deletions

File tree

include/hydroc/waves/irregular_wave.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ class IrregularWaves : public WaveBase {
5151
Eigen::Vector3d GetVelocity(const Eigen::Vector3d& position, double time, double elevation) override;
5252
Eigen::Vector3d GetAcceleration(const Eigen::Vector3d& position, double time, double elevation) override;
5353

54+
/// Return the surface slope (∂η/∂x, ∂η/∂y) at a given position and time.
55+
/// Used for computing surface normals in visualization.
56+
Eigen::Vector2d GetElevationGradientXY(const Eigen::Vector3d& position, double time) const;
57+
58+
/// Compute elevation using only the first max_components wave components.
59+
/// Used for faster visualization rendering when full accuracy is not required.
60+
/// @param max_components Maximum number of frequency components to use (0 or negative = use all)
61+
double GetElevationForVisualization(const Eigen::Vector3d& position, double time, int max_components) const;
62+
5463
private:
5564
IrregularWaveParams params_;
5665
std::vector<double> spectrum_;

include/hydroc/waves/regular_wave.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ class RegularWave : public WaveBase {
4343
Eigen::Vector3d GetVelocity(const Eigen::Vector3d& position, double time, double elevation) override;
4444
Eigen::Vector3d GetAcceleration(const Eigen::Vector3d& position, double time, double elevation) override;
4545

46+
/// Return the surface slope (∂η/∂x, ∂η/∂y) at a given position and time.
47+
/// Used for computing surface normals in visualization.
48+
Eigen::Vector2d GetElevationGradientXY(const Eigen::Vector3d& position, double time) const;
49+
4650
private:
4751
unsigned int num_bodies_ = 0;
4852
const WaveMode mode_ = WaveMode::regular;

src/hydro/hydro_system.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include <chrono/physics/ChSystemSMC.h>
3434
#include <chrono/physics/ChLoadHydrodynamics.h>
3535
#include <chrono/solver/ChIterativeSolverLS.h>
36-
#include <chrono/solver/ChSolverPMINRES.h>
3736
#include <chrono/timestepper/ChTimestepper.h>
3837
#include <chrono/timestepper/ChTimestepperHHT.h>
3938
#include <chrono/fea/ChMeshFileLoader.h>
@@ -278,11 +277,13 @@ HydroSystem::HydroSystem(std::vector<std::shared_ptr<ChBody>> user_bodies,
278277
force_per_body_.emplace_back(bodies_[b], this);
279278
}
280279

281-
// Handle added mass info (applied via a Chrono ChLoadHydrodynamics)
280+
// Handle added mass info (applied via Chrono's ChLoadHydrodynamics).
281+
// ChBodyAddedMassBlocks is a std::vector<ChBodyAddedMassBlock>; each entry
282+
// pairs a body with its 6×6N row of the infinite-frequency added mass matrix.
282283
const auto& body_info = file_info_.GetBodyInfos();
283284
ChBodyAddedMassBlocks body_blocks;
284-
for (size_t i = 0; i < num_bodies_; i++) {
285-
body_blocks.insert(std::pair(bodies_[i], body_info[i].inf_added_mass));
285+
for (int i = 0; i < num_bodies_; i++) {
286+
body_blocks.push_back({bodies_[i], body_info[i].inf_added_mass});
286287
}
287288
if (num_bodies_ > 0) {
288289
auto hydro_load = chrono_types::make_shared<ChLoadHydrodynamics>(body_blocks);

src/hydro/runner/run_from_yaml.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,20 @@ std::shared_ptr<chrono::ChSystem> InitializeChronoSystem(const std::string& mode
204204
hydroc::debug::LogDebug("Creating Chrono YAML parser");
205205
auto parser = chrono::parsers::ChParserMbsYAML();
206206

207+
// Load simulation settings (solver, integrator, visualization, etc.)
207208
hydroc::debug::LogDebug(std::string("Loading simulation file: ") + sim_file);
208-
parser.LoadSimulationFile(sim_file);
209+
auto sim_yaml = YAML::LoadFile(sim_file);
210+
parser.LoadSimData(sim_yaml);
211+
if (sim_yaml["solver"])
212+
parser.LoadSolverData(sim_yaml);
209213

210214
hydroc::debug::LogDebug("Creating system");
211215
auto system = parser.CreateSystem();
212216

217+
// Load MBS model (bodies, joints, etc.)
213218
hydroc::debug::LogDebug(std::string("Loading model file: ") + model_file);
214-
parser.LoadModelFile(model_file);
219+
auto model_yaml = YAML::LoadFile(model_file);
220+
parser.LoadModelData(model_yaml);
215221

216222
hydroc::debug::LogDebug("Analyzing mesh files referenced in YAML model");
217223
std::filesystem::path model_dir = std::filesystem::path(model_file).parent_path();

0 commit comments

Comments
 (0)