Skip to content

Commit 6747be1

Browse files
committed
Initialize variables
1 parent 8fed63f commit 6747be1

8 files changed

Lines changed: 36 additions & 26 deletions

File tree

include/hydroc/core/system_state.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ namespace hydrochrono::hydro {
2626
* and angular velocity for one body in the system.
2727
*/
2828
struct BodyState {
29-
Eigen::Vector3d position; // Position in world frame (x, y, z)
30-
Eigen::Vector3d orientation_rpy; // Orientation as roll-pitch-yaw angles (radians)
31-
Eigen::Vector3d linear_velocity; // Linear velocity in world frame (m/s)
32-
Eigen::Vector3d angular_velocity; // Angular velocity in parent frame (rad/s)
29+
Eigen::Vector3d position = Eigen::Vector3d::Zero(); // Position in world frame (x, y, z)
30+
Eigen::Vector3d orientation_rpy = Eigen::Vector3d::Zero(); // Orientation as roll-pitch-yaw angles (radians)
31+
Eigen::Vector3d linear_velocity = Eigen::Vector3d::Zero(); // Linear velocity in world frame (m/s)
32+
Eigen::Vector3d angular_velocity = Eigen::Vector3d::Zero(); // Angular velocity in parent frame (rad/s)
3333
};
3434

3535
/**

include/hydroc/hydro_system.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ class ComponentFunc : public chrono::ChFunction {
115115
virtual double GetVal(double x) const override;
116116

117117
private:
118-
ForceFunc6d* base_; ///< Pointer to the full 6D force on the body.
119-
int index_; ///< Index representing force degree of freedom on the body.
118+
ForceFunc6d* base_ = nullptr; ///< Pointer to the full 6D force on the body.
119+
int index_ = 0; ///< Index representing force degree of freedom on the body.
120120
};
121121

122122
/**
@@ -176,13 +176,13 @@ class ForceFunc6d {
176176

177177
/// Body index in the system (1-indexed, parsed from Chrono body name "bodyN").
178178
/// This matches Chrono's body naming convention where bodies are named body1, body2, etc.
179-
int b_num_;
179+
int b_num_ = 0;
180180

181181
ComponentFunc forces_[kDofPerBody]; ///< Forces for each degree of freedom.
182182
std::shared_ptr<ComponentFunc> force_ptrs_[kDofPerBody]; ///< Pointers to the forces.
183183
std::shared_ptr<chrono::ChForce> chrono_force_; ///< Chrono force for the body.
184184
std::shared_ptr<chrono::ChForce> chrono_torque_; ///< Chrono torque for the body.
185-
HydroSystem* all_hydro_forces_; ///< Pointer to HydroSystem for calculations.
185+
HydroSystem* all_hydro_forces_ = nullptr; ///< Pointer to HydroSystem for calculations.
186186
};
187187

188188
// Forward declaration of ChLoadAddedMass (defined in added_mass.h, included in .cpp)
@@ -425,6 +425,12 @@ class HydroSystem {
425425

426426
// Time tracking for force caching
427427
double prev_time;
428+
429+
// Debug counter for printing first few timesteps
430+
int debug_call_count_ = 0;
431+
432+
// Track if we've already reported NaN (to avoid spamming)
433+
bool nan_reported_ = false;
428434

429435
// Cached SystemState: built once per time step and reused by all force computations
430436
hydrochrono::hydro::SystemState cached_state_;

include/hydroc/io/h5_reader.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ class HydroData {
3535
public:
3636
struct BodyInfo {
3737
std::string body_name;
38-
int body_num;
39-
double disp_vol;
38+
int body_num = 0;
39+
double disp_vol = 0.0;
4040
Eigen::VectorXd rirf_time_vector;
41-
double rirf_timestep;
41+
double rirf_timestep = 0.0;
4242
Eigen::VectorXd cg;
4343
Eigen::VectorXd cb;
4444
Eigen::MatrixXd lin_matrix;
@@ -47,9 +47,9 @@ class HydroData {
4747
};
4848
struct SimulationParameters {
4949
std::string h5_file_name;
50-
double rho;
51-
double g;
52-
double water_depth;
50+
double rho = 0.0;
51+
double g = 0.0;
52+
double water_depth = 0.0;
5353
};
5454
struct RegularWaveInfo {
5555
Eigen::VectorXd freq_list;

include/hydroc/waves/irregular_wave.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
#include <vector>
1414

1515
struct IrregularWaveParams {
16-
unsigned int num_bodies_;
17-
double simulation_dt_;
18-
double simulation_duration_;
16+
unsigned int num_bodies_ = 0;
17+
double simulation_dt_ = 0.0;
18+
double simulation_duration_ = 0.0;
1919
double ramp_duration_ = 0.0;
2020
std::string eta_file_path_;
2121
double wave_height_ = 0.0;
@@ -60,7 +60,7 @@ class IrregularWaves : public WaveBase {
6060
std::vector<double> time_data_;
6161
std::vector<double> free_surface_elevation_sampled_;
6262
std::vector<double> free_surface_time_sampled_;
63-
bool spectrumCreated_;
63+
bool spectrumCreated_ = false;
6464

6565
const WaveMode mode_ = WaveMode::irregular;
6666
std::vector<HydroData::IrregularWaveInfo> wave_info_;

include/hydroc/waves/regular_wave.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ class RegularWave : public WaveBase {
3535
Eigen::Vector3d GetAcceleration(const Eigen::Vector3d& position, double time) override;
3636

3737
private:
38-
unsigned int num_bodies_;
38+
unsigned int num_bodies_ = 0;
3939
const WaveMode mode_ = WaveMode::regular;
4040
std::vector<HydroData::RegularWaveInfo> wave_info_;
4141
Eigen::VectorXd excitation_force_mag_;
4242
Eigen::VectorXd excitation_force_phase_;
4343
Eigen::VectorXd force_;
44-
double wavenumber_;
44+
double wavenumber_ = 0.0;
4545

4646
double GetOmegaDelta() const;
4747
double GetExcitationMagInterp(int b, int i, int j, double freq_index_des) const;

include/hydroc/waves/wave_base.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class NoWave : public WaveBase {
4343
Eigen::Vector3d GetAcceleration(const Eigen::Vector3d&, double) override { return Eigen::Vector3d(0.0, 0.0, 0.0); }
4444

4545
private:
46-
unsigned int num_bodies_;
46+
unsigned int num_bodies_ = 0;
4747
const WaveMode mode_ = WaveMode::noWaveCIC;
4848
};
4949

src/hydro/force_components/radiation_component.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class RadiationComponent : public IHydroForceComponent {
8080
Eigen::VectorXd rirf_width_vector_;
8181

8282
// Processed RIRF tensors (for TaperedDirect mode)
83-
bool rirf_processed_ready_;
83+
bool rirf_processed_ready_ = false;
8484
std::vector<Eigen::Tensor<double, 3>> rirf_processed_;
8585

8686
static constexpr int kDofPerBody = 6;

src/hydro/radiation/radiation_rirf_convolution.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,10 @@ std::vector<double> RadiationRirfConvolution::ComputeForces(
170170
// Multibody loop: process each body's velocity history
171171
for (int body_index = 0; body_index < num_bodies_; ++body_index) {
172172
const auto& velocity_history_body = velocity_history_[body_index];
173-
if (velocity_history_body.size() <= history_index_local) {
174-
continue; // inconsistent; should not happen in normal flow
173+
// InterpolateVelocity6D accesses [history_index_local] and [history_index_local + 1]
174+
// so we need at least history_index_local + 2 elements
175+
if (velocity_history_body.size() < history_index_local + 2) {
176+
continue; // not enough history entries for interpolation
175177
}
176178

177179
double interpolated_velocity_dof[kDofPerBody];
@@ -231,8 +233,10 @@ std::vector<double> RadiationRirfConvolution::ComputeForces(
231233
// Multibody loop: process each body's velocity history
232234
for (int body_index = 0; body_index < num_bodies_; ++body_index) {
233235
const auto& velocity_history_body = velocity_history_[body_index];
234-
if (velocity_history_body.size() <= history_index) {
235-
continue; // skip if inconsistent; should not happen in normal flow
236+
// InterpolateVelocity6D accesses [history_index] and [history_index + 1]
237+
// so we need at least history_index + 2 elements
238+
if (velocity_history_body.size() < history_index + 2) {
239+
continue; // not enough history entries for interpolation
236240
}
237241

238242
double interpolated_velocity_dof[kDofPerBody];

0 commit comments

Comments
 (0)