Skip to content

Commit d1cd0ab

Browse files
committed
Consolidate IO module under src/hydro/io and include/hydroc/io
Moves all HDF5 and simulation export code into a dedicated IO module: - Added new public headers: include/hydroc/io/{h5_reader,h5_writer,simulation_export}.h - Moved implementations to src/hydro/io/ - Updated all includes and CMake entries - Removed obsolete top-level redirect headers (h5fileinfo.h, h5_writer.h, simulation_exporter.h) Public API and behaviour unchanged. Repository IO structure is now clean, consistent, and easier to navigate.
1 parent cee5719 commit d1cd0ab

17 files changed

Lines changed: 54 additions & 56 deletions

CMakeLists.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,15 +335,19 @@ endfunction()
335335

336336
# ── Main HydroChrono Library ──
337337
set(HYDROCHRONO_SOURCES
338-
src/h5fileinfo.cpp
338+
# IO module (consolidated under src/hydro/io/)
339+
src/hydro/io/h5_reader.cpp
340+
src/hydro/io/h5_writer.cpp
341+
src/hydro/io/simulation_export.cpp
342+
src/hydro/io/hydro_config_loader.cpp
343+
# Core library sources
339344
src/chloadaddedmass.cpp
340345
src/hydro_forces.cpp
341346
src/helper.cpp
342347
src/wave_types.cpp
343-
# src/simulation_logging.cpp # removed in streamlined logging
344348
src/hydro_yaml_parser.cpp
345349
src/setup_hydro_from_yaml.cpp
346-
src/hydro/io/hydro_config_loader.cpp
350+
# Hydro modules
347351
src/hydro/waves/wave_base.cpp
348352
src/hydro/waves/wave_utilities.cpp
349353
src/hydro/waves/regular_wave.cpp
@@ -359,8 +363,6 @@ set(HYDROCHRONO_SOURCES
359363
# logging consolidated: coordinator + CLI (logging.cpp), backend (logger_backend.cpp)
360364
src/utils/logger_backend.cpp
361365
src/utils/logging.cpp
362-
src/h5_writer.cpp
363-
src/simulation_exporter.cpp
364366
)
365367

366368
# Create the library target and configure it

include/hydroc/chloadaddedmass.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#include <chrono/core/ChMatrix.h>
1111
#include <chrono/physics/ChBody.h>
12-
#include <hydroc/h5fileinfo.h>
12+
#include <hydroc/io/h5_reader.h>
1313
#include <vector>
1414

1515
#include <chrono/physics/ChLoad.h>

include/hydroc/hydro_forces.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
#include <chrono/fea/ChMeshFileLoader.h>
7777

7878
// Hydroc library includes
79-
#include <hydroc/h5fileinfo.h>
79+
#include <hydroc/io/h5_reader.h>
8080
#include <hydroc/wave_types.h>
8181
// Note: hydro_types.h is included at the top to avoid header guard conflicts
8282

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
#ifndef H5FILEINFO_H
2-
#define H5FILEINFO_H
31
/*********************************************************************
4-
* @file h5fileinfo.h
2+
* @file h5_reader.h
53
*
6-
* @brief header file of HydroData main class and helper class \
7-
* H5FileInfo.
4+
* @brief HDF5 reader for hydrodynamic data (HydroData and H5FileInfo).
5+
*
6+
* This header provides the public API for reading BEMIO-formatted HDF5
7+
* hydrodynamic data files. HydroData holds the parsed coefficients and
8+
* H5FileInfo handles file loading.
89
*********************************************************************/
9-
// TODO: clean up include statements
10-
#pragma once
10+
#ifndef HYDROC_IO_H5_READER_H
11+
#define HYDROC_IO_H5_READER_H
1112

1213
#include <limits>
1314
#include <optional>
@@ -29,9 +30,7 @@ class H5File;
2930

3031
class H5FileInfo;
3132

32-
// TODO separate these 2 classes into 2 files? (and corresponding .cpp)
33-
34-
// contains "chunked" data from the h5 file, generated from H5FileInfor class
33+
// contains "chunked" data from the h5 file, generated from H5FileInfo class
3534
class HydroData {
3635
public:
3736
struct BodyInfo {
@@ -45,7 +44,6 @@ class HydroData {
4544
Eigen::MatrixXd lin_matrix;
4645
Eigen::MatrixXd inf_added_mass;
4746
Eigen::Tensor<double, 3> rirf_matrix;
48-
// Eigen::Tensor<double, 3> radiation_damping_matrix;
4947
};
5048
struct SimulationParameters {
5149
std::string h5_file_name;
@@ -59,15 +57,11 @@ class HydroData {
5957
Eigen::Tensor<double, 3> excitation_phase_matrix;
6058
};
6159
struct IrregularWaveInfo {
62-
// Eigen::Tensor<double,3> excitation_re_matrix;
63-
// Eigen::Vector3i re_dims;
64-
// Eigen::Tensor<double, 3> excitation_im_matrix;
65-
// Eigen::Vector3i im_dims;
6660
Eigen::VectorXd excitation_irf_time;
67-
Eigen::MatrixXd excitation_irf_matrix; // TODO needs to be tensor?
61+
Eigen::MatrixXd excitation_irf_matrix;
6862

6963
// see std::optional documentation for how to use
70-
std::optional<Eigen::MatrixXd> excitation_irf_resampled; // TODO needs to be tensor?
64+
std::optional<Eigen::MatrixXd> excitation_irf_resampled;
7165
std::optional<Eigen::MatrixXd> excitation_irf_time_resampled;
7266
};
7367

@@ -160,8 +154,8 @@ class HydroData {
160154
*/
161155
Eigen::VectorXd GetCBVector(int b) const { return body_data_[b].cb; }
162156

163-
double GetExcitationIRFVal(int b, int dof, int s) const; // TODO if this isn't used get rid of it
164-
Eigen::MatrixXd GetExcitationIRF(int b) const; // TODO if this isn't used get rid of it
157+
double GetExcitationIRFVal(int b, int dof, int s) const;
158+
Eigen::MatrixXd GetExcitationIRF(int b) const;
165159

166160
// things that are the same no matter the body, don't need body argument
167161
/**
@@ -225,11 +219,14 @@ class HydroData {
225219
std::vector<IrregularWaveInfo>& GetIrregularWaveInfos() { return irreg_wave_data_; }
226220
};
227221

228-
// TODO change name to LoadH5File or ReadH5File or H5Init or something similar to give better description of
229-
// functionality used only to initialize everything in HydroData from the h5 file
222+
/**
223+
* @brief HDF5 file reader for hydrodynamic data.
224+
*
225+
* Reads BEMIO-formatted HDF5 files and produces a HydroData object.
226+
*/
230227
class H5FileInfo {
231228
public:
232-
bool printed = false; // TODO remove this, dont use here
229+
bool printed = false;
233230

234231
/**
235232
* @brief prepares for h5 file reading, checks file exists.
@@ -257,7 +254,7 @@ class H5FileInfo {
257254
*
258255
* @return newly initialized HydroData object
259256
*/
260-
HydroData ReadH5Data(); // TODO: eventually pass user input struct here? instead of making it in function?
257+
HydroData ReadH5Data();
261258

262259
private:
263260
std::string h5_file_name_;
@@ -299,7 +296,7 @@ class H5FileInfo {
299296
* @param[in] data_name data name within file to extract value from
300297
* @param[out] var variable to be set from h5 info
301298
*/
302-
void Init3D(H5::H5File& file, std::string data_name, Eigen::Tensor<double, 3>& var /*, std::vector<int>& dims*/);
299+
void Init3D(H5::H5File& file, std::string data_name, Eigen::Tensor<double, 3>& var);
303300

304301
/**
305302
* @brief helper function for readH5Data() to remove the middle index of 3D data if that index is 1.
@@ -314,4 +311,4 @@ class H5FileInfo {
314311
Eigen::MatrixXd SqueezeMid(Eigen::Tensor<double, 3>& to_be_squeezed);
315312
};
316313

317-
#endif
314+
#endif // HYDROC_IO_H5_READER_H
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
#ifndef HYDROC_H5_WRITER_H
2-
#define HYDROC_H5_WRITER_H
3-
4-
/**
5-
* @file h5_writer.h
1+
/*********************************************************************
2+
* @file h5_writer.h
63
* @brief Lightweight RAII writer over the HDF5 C++ API (H5Cpp.h).
74
*
85
* Provides a compact, easy-to-use interface to write groups, attributes, and
@@ -13,7 +10,9 @@
1310
* @note Types: strings are written as variable-length UTF-8; numeric datasets use native double.
1411
* @note Errors: global HDF5 error printing is disabled; failures surface as HDF5 exceptions or std::runtime_error on open.
1512
* @note Thread-safety: not thread-safe; synchronize externally if shared across threads.
16-
*/
13+
*********************************************************************/
14+
#ifndef HYDROC_IO_H5_WRITER_H
15+
#define HYDROC_IO_H5_WRITER_H
1716

1817
#include <H5Cpp.h>
1918
#include <string>
@@ -148,4 +147,5 @@ class H5Writer {
148147

149148
} // namespace hydroc
150149

151-
#endif // HYDROC_H5_WRITER_H
150+
#endif // HYDROC_IO_H5_WRITER_H
151+
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @file simulation_exporter.h
2+
* @file simulation_export.h
33
* @brief Public interface for exporting HydroChrono simulations to HDF5.
44
*
55
* Provides a thin, high-level API to record inputs, model description, and
@@ -10,8 +10,8 @@
1010
* @note Encoding & units: strings are UTF-8; time in seconds, distances in meters,
1111
* angles in radians unless documented otherwise in attribute names.
1212
*/
13-
#ifndef HYDROC_SIMULATION_EXPORTER_H
14-
#define HYDROC_SIMULATION_EXPORTER_H
13+
#ifndef HYDROC_IO_SIMULATION_EXPORT_H
14+
#define HYDROC_IO_SIMULATION_EXPORT_H
1515

1616
#include <memory>
1717
#include <vector>
@@ -169,6 +169,5 @@ class SimulationExporter {
169169

170170
} // namespace hydroc
171171

172-
#endif // HYDROC_SIMULATION_EXPORTER_H
173-
172+
#endif // HYDROC_IO_SIMULATION_EXPORT_H
174173

src/hydro/force_components/hydrostatics_component.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*********************************************************************/
55

66
#include "hydrostatics_component.h"
7-
#include <hydroc/h5fileinfo.h>
7+
#include <hydroc/io/h5_reader.h>
88

99
#include <Eigen/Dense>
1010
#include <cassert>

src/hydro/force_components/radiation_component.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*********************************************************************/
55

66
#include "radiation_component.h"
7-
#include <hydroc/h5fileinfo.h>
7+
#include <hydroc/io/h5_reader.h>
88

99
#include <Eigen/Dense>
1010
#include <cassert>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*********************************************************************/
77
// TODO: this include statement list looks good
88
#include <H5Cpp.h>
9-
#include <hydroc/h5fileinfo.h>
9+
#include <hydroc/io/h5_reader.h>
1010
#include <filesystem> // std::filesystem::absolute
1111
#include <hydroc/logging.h>
1212

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* @note Future: chunking/compression and additional data types can be added if needed.
1111
*/
1212

13-
#include <hydroc/h5_writer.h>
13+
#include <hydroc/io/h5_writer.h>
1414

1515
#include <stdexcept>
1616
#include <sstream>

0 commit comments

Comments
 (0)