Skip to content

Commit 7b12d0d

Browse files
committed
Deduplicate radiation convolution types via public header
1 parent e0b8821 commit 7b12d0d

6 files changed

Lines changed: 92 additions & 88 deletions

File tree

include/hydroc/hydro_forces.h

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@
8484
// Public hydroc includes (for SystemState)
8585
#include <hydroc/core/system_state.h>
8686

87+
// Radiation types (canonical definitions - single source of truth)
88+
#include <hydroc/radiation/radiation_types.h>
89+
8790
namespace hydrochrono::hydro {
8891
// Forward declarations
8992
class HydrostaticsComponent;
@@ -299,42 +302,26 @@ class TestHydro {
299302
*/
300303
double GetRIRFval(int row, int col, int st);
301304

302-
// Convolution mode selection
303-
enum class RadiationConvolutionMode {
304-
Baseline,
305-
TaperedDirect
306-
};
305+
// ─────────────────────────────────────────────────────────────────────────
306+
// Radiation Convolution Configuration
307+
// ─────────────────────────────────────────────────────────────────────────
308+
// These types are defined in the radiation module (single source of truth):
309+
// - hydrochrono::hydro::RadiationConvolutionMode (enum)
310+
// - hydrochrono::hydro::TaperedDirectOptions (struct)
311+
// See: src/hydro/force_components/radiation_component.h
312+
// src/hydro/radiation/radiation_rirf_processing.h
307313

308314
/**
309315
* @brief Set the radiation convolution mode. Default is Baseline.
316+
* @param mode RadiationConvolutionMode::Baseline or ::TaperedDirect
310317
*/
311-
void SetRadiationConvolutionMode(RadiationConvolutionMode mode) {
312-
convolution_mode_ = mode;
313-
InvalidateRadiationComponent(); // Invalidate component to recreate with new settings
314-
}
315-
316-
struct TaperedDirectOptions {
317-
// smoothing: "sg" (Savitzky–Golay) or "moving_average"
318-
std::string smoothing = "sg";
319-
int window_length = 5; // odd, >= 3
320-
321-
// RIRF truncation
322-
double rirf_end_time = -1.0; // end RIRF at this time (seconds), -1.0 = use full length
323-
324-
// Simple taper control - sensible defaults for improved stability
325-
double taper_start_percent = 0.8; // start taper at 80% (taper last 20%)
326-
double taper_end_percent = 1.0; // end taper at 100% of total time series
327-
double taper_final_amplitude = 0.0; // final amplitude as fraction of original (0.0 = zero, 1.0 = no change)
328-
bool export_plot_csv = false; // dump before/after CSV summaries (false by default)
329-
};
318+
void SetRadiationConvolutionMode(hydrochrono::hydro::RadiationConvolutionMode mode);
330319

331320
/**
332321
* @brief Set options for TaperedDirect preprocessing.
322+
* @param opts TaperedDirectOptions struct with smoothing, tapering, and export settings
333323
*/
334-
void SetTaperedDirectOptions(const TaperedDirectOptions& opts) {
335-
tapered_opts_ = opts;
336-
InvalidateRadiationComponent(); // Invalidate component to recreate with new settings
337-
}
324+
void SetTaperedDirectOptions(const hydrochrono::hydro::TaperedDirectOptions& opts);
338325

339326
/**
340327
* @brief Set the directory where diagnostics (e.g., CSVs) should be written.
@@ -441,10 +428,11 @@ class TestHydro {
441428
bool profiling_enabled_ = false;
442429

443430
// Convolution kernel preprocessing (optional)
444-
RadiationConvolutionMode convolution_mode_ = RadiationConvolutionMode::Baseline;
431+
// Uses canonical types from radiation module (single source of truth)
432+
hydrochrono::hydro::RadiationConvolutionMode convolution_mode_;
445433
bool rirf_processed_ready_ = false;
446434
std::vector<Eigen::Tensor<double, 3>> rirf_processed_; // per body [dof x col x step]
447-
TaperedDirectOptions tapered_opts_;
435+
hydrochrono::hydro::TaperedDirectOptions tapered_opts_;
448436
std::string diagnostics_output_dir_;
449437

450438
void EnsureProcessedRIRF();
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*********************************************************************
2+
* @file radiation_types.h
3+
* @brief Public types for radiation damping configuration.
4+
*********************************************************************/
5+
6+
#ifndef HYDROC_RADIATION_TYPES_H
7+
#define HYDROC_RADIATION_TYPES_H
8+
9+
#include <string>
10+
11+
namespace hydrochrono::hydro {
12+
13+
/**
14+
* @brief Convolution mode for radiation damping.
15+
*/
16+
enum class RadiationConvolutionMode {
17+
Baseline,
18+
TaperedDirect
19+
};
20+
21+
/**
22+
* @brief Options for TaperedDirect RIRF preprocessing.
23+
*/
24+
struct TaperedDirectOptions {
25+
// smoothing: "sg" (Savitzky–Golay) or "moving_average"
26+
std::string smoothing = "sg";
27+
int window_length = 5; // odd, >= 3
28+
29+
// RIRF truncation
30+
double rirf_end_time = -1.0; // end RIRF at this time (seconds), -1.0 = use full length
31+
32+
// Simple taper control - sensible defaults for improved stability
33+
double taper_start_percent = 0.8; // start taper at 80% (taper last 20%)
34+
double taper_end_percent = 1.0; // end taper at 100% of total time series
35+
double taper_final_amplitude = 0.0; // final amplitude as fraction of original (0.0 = zero, 1.0 = no change)
36+
bool export_plot_csv = false; // dump before/after CSV summaries (false by default)
37+
};
38+
39+
} // namespace hydrochrono::hydro
40+
41+
#endif // HYDROC_RADIATION_TYPES_H
42+

src/hydro/config/setup_from_yaml.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
#include <hydroc/waves/regular_wave.h>
4040
#include <hydroc/waves/irregular_wave.h>
4141
#include <hydroc/logging.h> // For Logger
42+
#include "../radiation/radiation_rirf_processing.h" // For TaperedDirectOptions (canonical type)
43+
#include "../force_components/radiation_component.h" // For RadiationConvolutionMode (canonical type)
4244
#include <filesystem>
4345
#include <iostream>
4446
#include <stdexcept>
@@ -201,9 +203,9 @@ std::unique_ptr<TestHydro> SetupHydroFromYAML(
201203
std::transform(mode.begin(), mode.end(), mode.begin(), ::tolower);
202204
hydroc::debug::LogDebug("Lowercase mode: '" + mode + "'");
203205
if (mode == "tapereddirect") {
204-
test_hydro->SetRadiationConvolutionMode(TestHydro::RadiationConvolutionMode::TaperedDirect);
206+
test_hydro->SetRadiationConvolutionMode(hydrochrono::hydro::RadiationConvolutionMode::TaperedDirect);
205207
hydroc::debug::LogDebug("Radiation convolution mode: TaperedDirect");
206-
TestHydro::TaperedDirectOptions opts;
208+
hydrochrono::hydro::TaperedDirectOptions opts;
207209
opts.smoothing = !hydro_data.td_smoothing.empty() ? hydro_data.td_smoothing : opts.smoothing;
208210
opts.window_length = std::max(3, hydro_data.td_window_length != 0 ? hydro_data.td_window_length : opts.window_length);
209211
if (opts.window_length % 2 == 0) opts.window_length += 1; // enforce odd
@@ -232,7 +234,7 @@ std::unique_ptr<TestHydro> SetupHydroFromYAML(
232234
hydroc::cli::LogInfo(hydroc::cli::CreateAlignedLine("", "Conv Export CSV", (opts.export_plot_csv ? "true" : "false")));
233235
}
234236
} else {
235-
test_hydro->SetRadiationConvolutionMode(TestHydro::RadiationConvolutionMode::Baseline);
237+
test_hydro->SetRadiationConvolutionMode(hydrochrono::hydro::RadiationConvolutionMode::Baseline);
236238
hydroc::debug::LogDebug("Radiation convolution mode: Baseline");
237239
hydroc::cli::LogInfo(hydroc::cli::CreateAlignedLine("", "Convolution Mode", "Baseline"));
238240
}

src/hydro/force_components/radiation_component.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <hydroc/core/force_component.h>
1010
#include <hydroc/core/system_state.h>
11+
#include <hydroc/radiation/radiation_types.h>
1112
#include "../radiation/radiation_rirf_convolution.h"
1213
#include "../radiation/radiation_rirf_processing.h"
1314
#include <Eigen/Dense>
@@ -18,14 +19,6 @@ class HydroData;
1819

1920
namespace hydrochrono::hydro {
2021

21-
/**
22-
* @brief Convolution mode for radiation damping.
23-
*/
24-
enum class RadiationConvolutionMode {
25-
Baseline,
26-
TaperedDirect
27-
};
28-
2922
/**
3023
* @brief Radiation damping force component (RIRF convolution).
3124
*

src/hydro/hydro_forces.cpp

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,9 @@ TestHydro::TestHydro(std::vector<std::shared_ptr<ChBody>> user_bodies,
248248
num_bodies_(bodies_.size()),
249249
file_info_(H5FileInfo(h5_file_name, num_bodies_).ReadH5Data()),
250250
hydro_system_(nullptr),
251-
chrono_coupler_(nullptr) {
251+
chrono_coupler_(nullptr),
252+
convolution_mode_(hydrochrono::hydro::RadiationConvolutionMode::Baseline),
253+
tapered_opts_() {
252254
prev_time = -1;
253255

254256
// Set up time vector
@@ -417,15 +419,7 @@ void TestHydro::EnsureProcessedRIRF() {
417419

418420
const int steps = file_info_.GetRIRFDims(2);
419421

420-
// Convert TaperedDirectOptions to hydrochrono::hydro::TaperedDirectOptions
421-
hydrochrono::hydro::TaperedDirectOptions opts;
422-
opts.smoothing = tapered_opts_.smoothing;
423-
opts.window_length = tapered_opts_.window_length;
424-
opts.rirf_end_time = tapered_opts_.rirf_end_time;
425-
opts.taper_start_percent = tapered_opts_.taper_start_percent;
426-
opts.taper_end_percent = tapered_opts_.taper_end_percent;
427-
opts.taper_final_amplitude = tapered_opts_.taper_final_amplitude;
428-
opts.export_plot_csv = tapered_opts_.export_plot_csv;
422+
// tapered_opts_ is now the canonical type (single source of truth) - no conversion needed
429423

430424
// Create lambda to get RIRF values from file_info_
431425
auto get_rirf_val = [this](int body, int row_dof, int col, int step) -> double {
@@ -434,7 +428,7 @@ void TestHydro::EnsureProcessedRIRF() {
434428

435429
// Process RIRF kernels using the dedicated module
436430
rirf_processed_ = hydrochrono::hydro::ProcessRirfKernels(
437-
num_bodies_, steps, rirf_time_vector, get_rirf_val, opts, diagnostics_output_dir_);
431+
num_bodies_, steps, rirf_time_vector, get_rirf_val, tapered_opts_, diagnostics_output_dir_);
438432

439433
rirf_processed_ready_ = true;
440434
}
@@ -443,6 +437,20 @@ void TestHydro::InvalidateRadiationComponent() {
443437
radiation_component_.reset();
444438
}
445439

440+
// ─────────────────────────────────────────────────────────────────────────
441+
// Radiation configuration setters
442+
// ─────────────────────────────────────────────────────────────────────────
443+
444+
void TestHydro::SetRadiationConvolutionMode(hydrochrono::hydro::RadiationConvolutionMode mode) {
445+
convolution_mode_ = mode;
446+
InvalidateRadiationComponent(); // Invalidate component to recreate with new settings
447+
}
448+
449+
void TestHydro::SetTaperedDirectOptions(const hydrochrono::hydro::TaperedDirectOptions& opts) {
450+
tapered_opts_ = opts;
451+
InvalidateRadiationComponent(); // Invalidate component to recreate with new settings
452+
}
453+
446454
void TestHydro::EnsureRadiationComponent() {
447455
if (radiation_component_) {
448456
return; // Already created
@@ -493,27 +501,11 @@ std::unique_ptr<hydrochrono::hydro::RadiationComponent> TestHydro::CreateRadiati
493501

494502
const int rirf_steps = file_info_.GetRIRFDims(2);
495503

496-
// Convert TestHydro::RadiationConvolutionMode to hydrochrono::hydro::RadiationConvolutionMode
497-
hydrochrono::hydro::RadiationConvolutionMode component_mode;
498-
if (convolution_mode_ == RadiationConvolutionMode::TaperedDirect) {
499-
component_mode = hydrochrono::hydro::RadiationConvolutionMode::TaperedDirect;
500-
} else {
501-
component_mode = hydrochrono::hydro::RadiationConvolutionMode::Baseline;
502-
}
503-
504-
// Convert TestHydro::TaperedDirectOptions to hydrochrono::hydro::TaperedDirectOptions
505-
hydrochrono::hydro::TaperedDirectOptions component_opts;
506-
component_opts.smoothing = tapered_opts_.smoothing;
507-
component_opts.window_length = tapered_opts_.window_length;
508-
component_opts.rirf_end_time = tapered_opts_.rirf_end_time;
509-
component_opts.taper_start_percent = tapered_opts_.taper_start_percent;
510-
component_opts.taper_end_percent = tapered_opts_.taper_end_percent;
511-
component_opts.taper_final_amplitude = tapered_opts_.taper_final_amplitude;
512-
component_opts.export_plot_csv = tapered_opts_.export_plot_csv;
513-
504+
// convolution_mode_ and tapered_opts_ are now the canonical types from
505+
// hydrochrono::hydro namespace - no conversion needed (single source of truth)
514506
return std::make_unique<hydrochrono::hydro::RadiationComponent>(
515507
file_info_, num_bodies_, rirf_steps, rirf_time_vector, rirf_width_vector,
516-
component_mode, component_opts, diagnostics_output_dir_);
508+
convolution_mode_, tapered_opts_, diagnostics_output_dir_);
517509
}
518510

519511
// ------------------------------------------------------------
@@ -627,7 +619,7 @@ double TestHydro::GetRIRFval(int row, int col, int st) {
627619
int col_dof = col % kDofPerBody;
628620
int row_dof = row % kDofPerBody;
629621

630-
if (convolution_mode_ == RadiationConvolutionMode::TaperedDirect) {
622+
if (convolution_mode_ == hydrochrono::hydro::RadiationConvolutionMode::TaperedDirect) {
631623
EnsureProcessedRIRF();
632624
// processed tensor is scaled by rho already
633625
const auto& tensor = rirf_processed_[body_index];

src/hydro/radiation/radiation_rirf_processing.h

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,10 @@
1111
#include <string>
1212
#include <vector>
1313

14-
namespace hydrochrono::hydro {
14+
// Include canonical TaperedDirectOptions from public header
15+
#include <hydroc/radiation/radiation_types.h>
1516

16-
// Options for TaperedDirect RIRF preprocessing
17-
struct TaperedDirectOptions {
18-
// smoothing: "sg" (Savitzky–Golay) or "moving_average"
19-
std::string smoothing = "sg";
20-
int window_length = 5; // odd, >= 3
21-
22-
// RIRF truncation
23-
double rirf_end_time = -1.0; // end RIRF at this time (seconds), -1.0 = use full length
24-
25-
// Simple taper control - sensible defaults for improved stability
26-
double taper_start_percent = 0.8; // start taper at 80% (taper last 20%)
27-
double taper_end_percent = 1.0; // end taper at 100% of total time series
28-
double taper_final_amplitude = 0.0; // final amplitude as fraction of original (0.0 = zero, 1.0 = no change)
29-
bool export_plot_csv = false; // dump before/after CSV summaries (false by default)
30-
};
17+
namespace hydrochrono::hydro {
3118

3219
/**
3320
* @brief Preprocess RIRF kernels for TaperedDirect mode.

0 commit comments

Comments
 (0)