Skip to content

Commit 01d0b24

Browse files
committed
make RadiationComponent the sole owner of radiation history and force computation
Remove all legacy radiation history buffers and convolution objects from TestHydro (velocity_history_, time_history_, radiation_convolution_). These structures duplicated the internal state already maintained by RadiationComponent and are no longer needed.
1 parent 403d334 commit 01d0b24

2 files changed

Lines changed: 14 additions & 66 deletions

File tree

include/hydroc/hydro_forces.h

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484

8585
namespace hydrochrono::hydro {
8686
// Forward declarations
87-
class RadiationRirfConvolution;
8887
class HydrostaticsComponent;
8988
class RadiationComponent;
9089
class ExcitationComponent;
@@ -378,9 +377,7 @@ class TestHydro {
378377
Eigen::VectorXd rirf_time_vector; // Assumed consistent for each body
379378
Eigen::VectorXd rirf_width_vector;
380379

381-
// Properties for velocity history management and time tracking
382-
std::vector<std::vector<std::vector<double>>> velocity_history_;
383-
std::vector<double> time_history_;
380+
// Time tracking for force caching
384381
double prev_time;
385382

386383
// Cached SystemState: built once per time step and reused by all force computations
@@ -391,26 +388,6 @@ class TestHydro {
391388
std::shared_ptr<ChLoadContainer> my_loadcontainer;
392389
std::shared_ptr<ChLoadAddedMass> my_loadbodyinertia;
393390

394-
/**
395-
* @brief Fetches the velocity history for a specific DOF, body, and timestep.
396-
*
397-
* @param step The timestep index, ranging from [0,1,...,1000].
398-
* @param c The combined index for the body and DOF, where the order is first by body then by DOF.
399-
*
400-
* @return Velocity history for the specified DOF and body at the given timestep.
401-
*/
402-
double GetVelHistoryVal(int step, int c) const;
403-
404-
/**
405-
* @brief Updates the velocity history for a given timestep, body, and DOF.
406-
*
407-
* @param val The new value to set.
408-
* @param step The timestep index, ranging from [0,1,...,1000].
409-
* @param b_num The body number (1-based), indicating which body's data to update.
410-
* @param index The DOF index, ranging from [0,1,...,5].
411-
*/
412-
double SetVelHistory(double val, int step, int b_num, int index);
413-
414391
/**
415392
* @brief Returns the cached SystemState for the given time.
416393
*
@@ -426,9 +403,6 @@ class TestHydro {
426403
// Hydrodynamics profiling data (accumulated over run)
427404
HydroProfileStats profile_stats_;
428405

429-
// Radiation damping convolution module
430-
std::unique_ptr<hydrochrono::hydro::RadiationRirfConvolution> radiation_convolution_;
431-
432406
// Hydrostatics force component
433407
std::unique_ptr<hydrochrono::hydro::HydrostaticsComponent> hydrostatics_component_;
434408

src/hydro_forces.cpp

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
* - Reads HDF5 hydrodynamic data via H5FileInfo (equilibrium, stiffness, RIRF kernels)
2020
* - Uses WaveBase hierarchy for wave excitation forces
2121
* - Applies forces to Chrono bodies through ChForce/ChLoadAddedMass
22-
* - Maintains velocity history buffers for radiation convolution
22+
* - RadiationComponent maintains velocity history for radiation convolution
2323
*
2424
* KEY ASSUMPTIONS:
2525
* - All bodies share the same H5 file (multibody data in single file)
2626
* - Bodies are 1-indexed in ForceFunc6d interface (legacy)
2727
* - 6 DOF per body (surge, sway, heave, roll, pitch, yaw)
2828
* - Forces computed once per time step, cached via prev_time check
29-
* - Radiation history stored per-body in velocity_history_ vector
29+
* - RadiationComponent is the single source of truth for radiation history/forces
3030
*
3131
* KNOWN LIMITATIONS:
3232
* - Monolithic design: all force components mixed in one class
@@ -36,11 +36,10 @@
3636
*
3737
* DEBUG INSTRUMENTATION:
3838
* To enable debug output, compile with -DHYDROCHRONO_DEBUG.
39-
* This will print force components, history sizes, and timing info.
39+
* This will print force components and timing info.
4040
* Baseline outputs to record:
4141
* - Total force vector per time step (total_force_)
4242
* - Individual components (hydrostatic, radiation, waves)
43-
* - Velocity history size and time span
4443
* - RIRF kernel access patterns
4544
*********************************************************************/
4645

@@ -58,7 +57,6 @@
5857
#include "hydro/core/hydro_system.h"
5958
#include "hydro/chrono/chrono_hydro_coupler.h"
6059
#include "hydro/radiation/radiation_rirf_processing.h"
61-
#include "hydro/radiation/radiation_rirf_convolution.h"
6260

6361
#include <chrono/physics/ChLoad.h>
6462
#include <unsupported/Eigen/Splines>
@@ -261,17 +259,7 @@ TestHydro::TestHydro(std::vector<std::shared_ptr<ChBody>> user_bodies,
261259
// Total degrees of freedom (multibody: 6 DOF per body)
262260
int total_dofs = kDofPerBody * num_bodies_;
263261

264-
// Initialize radiation convolution module
265-
const int rirf_steps = file_info_.GetRIRFDims(2);
266-
radiation_convolution_ = std::make_unique<hydrochrono::hydro::RadiationRirfConvolution>(
267-
num_bodies_, rirf_steps, rirf_time_vector, rirf_width_vector);
268-
269-
// Initialize vectors (legacy: kept for compatibility, but radiation_convolution_ owns the history)
270-
time_history_.clear();
271-
velocity_history_.clear();
272-
for (int b = 0; b < num_bodies_; ++b) {
273-
velocity_history_.push_back(std::vector<std::vector<double>>(0));
274-
}
262+
// Initialize force vectors
275263
force_hydrostatic_.assign(total_dofs, 0.0);
276264
force_radiation_damping_.assign(total_dofs, 0.0);
277265
total_force_.assign(total_dofs, 0.0);
@@ -609,13 +597,13 @@ void TestHydro::CompareWithHydroSystem(double time, int total_dofs) {
609597
}
610598

611599
// Main radiation convolution computation.
612-
// Delegates to RadiationComponent for force computation.
600+
// RadiationComponent is the single source of truth for radiation history and forces.
601+
// It internally manages velocity history and performs RIRF convolution.
613602
std::vector<double> TestHydro::ComputeForceRadiationDampingConv() {
614603
auto __t0 = std::chrono::steady_clock::now();
615-
const int rirf_steps = file_info_.GetRIRFDims(2);
616604
const int total_dofs = kDofPerBody * num_bodies_;
617605

618-
assert(total_dofs > 0 && rirf_steps > 0);
606+
assert(total_dofs > 0);
619607

620608
// Ensure radiation component exists with current settings
621609
EnsureRadiationComponent();
@@ -625,37 +613,23 @@ std::vector<double> TestHydro::ComputeForceRadiationDampingConv() {
625613
const hydrochrono::hydro::SystemState& system_state = GetCachedSystemState(simulation_time);
626614

627615
#ifdef HYDROCHRONO_DEBUG
616+
const int rirf_steps = file_info_.GetRIRFDims(2);
628617
std::cout << "[HYDRO_DEBUG] Radiation conv: time=" << simulation_time
629618
<< ", rirf_steps=" << rirf_steps << std::endl;
630619
#endif
631620

632-
// Compute forces using the radiation component
621+
// RadiationComponent::Compute() handles:
622+
// - Recording current velocities into its internal history
623+
// - Performing RIRF convolution over the velocity history
624+
// - Returning the radiation damping forces
633625
hydrochrono::hydro::BodyForces body_forces(num_bodies_);
634626
for (int b = 0; b < num_bodies_; ++b) {
635627
body_forces[b].resize(kDofPerBody);
636628
body_forces[b].setZero();
637629
}
638630
radiation_component_->Compute(system_state, simulation_time, body_forces);
639631

640-
// Also update legacy history buffers for compatibility (used by GetRIRFval and other legacy code)
641-
// Extract velocities for legacy buffer update
642-
std::vector<std::vector<double>> body_velocities(num_bodies_);
643-
for (int b = 0; b < num_bodies_; ++b) {
644-
const auto& body_state = system_state.bodies[b];
645-
body_velocities[b] = {
646-
body_state.linear_velocity[0], body_state.linear_velocity[1], body_state.linear_velocity[2],
647-
body_state.angular_velocity[0], body_state.angular_velocity[1], body_state.angular_velocity[2]
648-
};
649-
}
650-
time_history_.insert(time_history_.begin(), simulation_time);
651-
for (int b = 0; b < num_bodies_; ++b) {
652-
velocity_history_[b].insert(velocity_history_[b].begin(), body_velocities[b]);
653-
}
654-
655-
// Also update legacy radiation_convolution_ for compatibility
656-
radiation_convolution_->RecordVelocities(simulation_time, body_velocities);
657-
658-
// Convert BodyForces back to legacy flat 6N vector format
632+
// Convert BodyForces to legacy flat 6N vector format
659633
force_radiation_damping_.assign(kDofPerBody * num_bodies_, 0.0);
660634
for (int b = 0; b < num_bodies_; ++b) {
661635
const int body_offset = kDofPerBody * b;

0 commit comments

Comments
 (0)