Skip to content

Commit 73d43c8

Browse files
committed
Add sphere/OSWEC state-space comparison diagnostics
- Add sphere_decay_ss_comparison: conv vs SS, 60s heave decay - Add oswec_decay_ss_comparison: conv vs SS, 180s pitch decay - Add unified plot_model_comparison.py (3-panel verification figure) - Include kernel fit, time series, and performance scaling plots
1 parent 318137e commit 73d43c8

7 files changed

Lines changed: 1357 additions & 721 deletions

tests/manual/CMakeLists.txt

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
# Manual/Diagnostic Tests for HydroChrono
22
# =========================================
33
#
4-
# These are NOT automated tests - they are diagnostic tools for visual
5-
# verification and debugging. They output data files that can be plotted
6-
# using the accompanying Python scripts.
4+
# These are visual verification tools for comparing convolution vs state-space
5+
# radiation damping. They output data files that can be plotted using the
6+
# accompanying Python script.
77
#
8-
# Build: cmake --build build --target radiation_ss_visual_check
9-
# Run: ./radiation_ss_visual_check
10-
# Plot: python plot_radiation_ss.py
8+
# Usage:
9+
# cmake --build build --config Release --target sphere_decay_ss_comparison
10+
# cd build/bin/tests/manual && ./sphere_decay_ss_comparison
11+
# python plot_model_comparison.py sphere --save
12+
#
13+
# cmake --build build --config Release --target oswec_decay_ss_comparison
14+
# cd build/bin/tests/manual && ./oswec_decay_ss_comparison
15+
# python plot_model_comparison.py oswec --save
1116
#
1217
# Output structure:
1318
# build/bin/tests/manual/
14-
# radiation_ss_visual_check.exe
15-
# plot_radiation_ss.py
19+
# sphere_decay_ss_comparison.exe
20+
# oswec_decay_ss_comparison.exe
21+
# plot_model_comparison.py
1622
# output/
17-
# radiation_ss_*.csv
18-
# plot_*.png
23+
# sphere_ss_verification.png
24+
# oswec_ss_verification.png
25+
# *_kernel_fit.csv, *_performance.csv, *_convolution.csv, *_state_space.csv
1926

2027
# Output to tests/manual/ subdirectory
2128
set(MANUAL_TEST_OUTPUT_DIR ${HYDROCHRONO_TEST_OUTPUT_DIR}/manual)
@@ -28,28 +35,50 @@ if(CMAKE_CONFIGURATION_TYPES)
2835
endif()
2936

3037
# =============================================================================
31-
# State-Space Radiation Model Visual Verification
38+
# Sphere Decay Comparison: Convolution vs State-Space
3239
# =============================================================================
33-
add_executable(radiation_ss_visual_check
34-
radiation_ss_visual_check.cpp
35-
../../src/hydro/radiation/radiation_ss_model.cpp
40+
add_executable(sphere_decay_ss_comparison
41+
sphere_decay_ss_comparison.cpp
3642
)
3743

38-
target_include_directories(radiation_ss_visual_check
44+
target_include_directories(sphere_decay_ss_comparison
3945
PRIVATE
40-
../../src
41-
../../include
46+
${CHRONO_INCLUDE_DIR}
47+
${CMAKE_SOURCE_DIR}/src
48+
${CMAKE_SOURCE_DIR}/include
4249
)
4350

44-
target_link_libraries(radiation_ss_visual_check
51+
target_link_libraries(sphere_decay_ss_comparison
4552
PRIVATE
53+
HydroChrono
54+
${CHRONO_LIBS}
4655
Eigen3::Eigen
4756
)
4857

49-
# Copy the Python plotting script to the build output directory
58+
# =============================================================================
59+
# OSWEC Decay Comparison: Convolution vs State-Space (2-body system)
60+
# =============================================================================
61+
add_executable(oswec_decay_ss_comparison
62+
oswec_decay_ss_comparison.cpp
63+
)
64+
65+
target_include_directories(oswec_decay_ss_comparison
66+
PRIVATE
67+
${CHRONO_INCLUDE_DIR}
68+
${CMAKE_SOURCE_DIR}/src
69+
${CMAKE_SOURCE_DIR}/include
70+
)
71+
72+
target_link_libraries(oswec_decay_ss_comparison
73+
PRIVATE
74+
HydroChrono
75+
${CHRONO_LIBS}
76+
Eigen3::Eigen
77+
)
78+
79+
# Copy the unified plotting script to the build output directory
5080
configure_file(
51-
${CMAKE_CURRENT_SOURCE_DIR}/plot_radiation_ss.py
52-
${MANUAL_TEST_OUTPUT_DIR}/plot_radiation_ss.py
81+
${CMAKE_CURRENT_SOURCE_DIR}/plot_model_comparison.py
82+
${MANUAL_TEST_OUTPUT_DIR}/plot_model_comparison.py
5383
COPYONLY
5484
)
55-

tests/manual/README.md

Lines changed: 93 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,130 @@
1-
# Manual/Diagnostic Tests
1+
# Manual Diagnostic Tests
22

3-
This directory contains diagnostic tools for **visual verification** of HydroChrono components. These are NOT automated tests - they generate data files that you can plot and inspect.
3+
This directory contains diagnostic tools for **visual verification** of the state-space radiation damping implementation in HydroChrono. These are NOT automated tests - they generate comparison figures showing convolution vs state-space methods.
44

5-
## Available Diagnostics
5+
## Quick Start
6+
7+
```bash
8+
# Build
9+
cmake --build build --config Release --target sphere_decay_ss_comparison
610

7-
### RadiationStateSpaceModel Verification
11+
# Run (generates CSV data files)
12+
cd build/bin/tests/manual
13+
./sphere_decay_ss_comparison
814

9-
**Executable:** `radiation_ss_visual_check`
10-
**Python script:** `plot_radiation_ss.py`
15+
# Plot (generates verification figure)
16+
python plot_model_comparison.py sphere --save
17+
```
1118

12-
Verifies the state-space radiation model by comparing numerical results against analytical solutions.
19+
---
1320

14-
#### Scenarios covered:
21+
## Available Diagnostics
1522

16-
1. **Constant velocity response** - Single mode, constant velocity input
17-
- Verifies exponential approach to steady state
18-
- Checks force = H × z relationship
23+
### Sphere Decay Test
1924

20-
2. **Step velocity response** - Velocity step change
21-
- Shows the "memory" effect of radiation damping
22-
- Tests transient response to input changes
25+
Single-body heave decay simulation comparing convolution and state-space radiation.
2326

24-
3. **Multiple modes** - Superposition of slow and fast modes
25-
- Verifies that mode contributions add correctly
26-
- Shows different time constants interacting
27+
```bash
28+
cmake --build build --config Release --target sphere_decay_ss_comparison
29+
./sphere_decay_ss_comparison
30+
python plot_model_comparison.py sphere --save
31+
```
2732

28-
4. **Time step sensitivity** - Same scenario with dt = 0.01, 0.1, 0.5, 1.0 s
29-
- Demonstrates unconditional stability of the exact integrator
30-
- Even very large time steps give reasonable results
33+
**Output**: `output/sphere_ss_verification.png`
3134

32-
## Usage
35+
### OSWEC Decay Test
3336

34-
### 1. Build the diagnostic
37+
Two-body pitch decay simulation (flap + base) with increased fitting parameters for complex coupled kernels.
3538

3639
```bash
37-
cmake --build build --target radiation_ss_visual_check
40+
cmake --build build --config Release --target oswec_decay_ss_comparison
41+
./oswec_decay_ss_comparison
42+
python plot_model_comparison.py oswec --save
3843
```
3944

40-
### 2. Run it (generates CSV files)
45+
**Output**: `output/oswec_ss_verification.png`
4146

42-
```bash
43-
# From the manual tests directory (recommended):
44-
cd build/bin/tests/manual
45-
./radiation_ss_visual_check
47+
---
4648

47-
# This creates output/ subdirectory with CSV files:
48-
# output/radiation_ss_constant_v.csv
49-
# output/radiation_ss_step_v.csv
50-
# ...
49+
## Output Files
5150

52-
# Or specify a custom output directory:
53-
./radiation_ss_visual_check my_output_dir
54-
```
51+
### Data Files (CSV)
5552

56-
### 3. Plot the results
53+
| File | Description |
54+
|------|-------------|
55+
| `{model}_kernel_fit.csv` | RIRF kernel vs state-space fit for key DOF |
56+
| `{model}_convolution.csv` | Time series from convolution method |
57+
| `{model}_state_space.csv` | Time series from state-space method |
58+
| `{model}_performance.csv` | Computation time scaling data |
5759

58-
```bash
59-
# From the manual tests directory:
60-
cd build/bin/tests/manual
61-
python plot_radiation_ss.py
60+
### Figures (PNG)
6261

63-
# This reads from output/ and displays plots
62+
Each verification figure (`{model}_ss_verification.png`) contains:
6463

65-
# Save plots to PNG files:
66-
python plot_radiation_ss.py --save
64+
1. **Top row**: Kernel fit quality (RIRF vs SS fit for key DOF)
65+
2. **Middle row**: Time series comparison (convolution vs state-space)
66+
3. **Bottom row**: Performance scaling (total time, per-step cost, speedup)
6767

68-
# Or specify a custom data directory:
69-
python plot_radiation_ss.py my_output_dir --save
70-
```
68+
---
7169

7270
## Directory Structure
7371

74-
After running, you'll have:
7572
```
76-
build/bin/tests/
77-
├── unit/
78-
│ ├── test_radiation_ss_model.exe
79-
│ └── test_hydro_yaml_parser.exe
80-
├── manual/
81-
│ ├── radiation_ss_visual_check.exe
82-
│ ├── plot_radiation_ss.py
83-
│ └── output/
84-
│ ├── radiation_ss_constant_v.csv
85-
│ ├── radiation_ss_step_v.csv
86-
│ ├── radiation_ss_multi_mode.csv
87-
│ ├── radiation_ss_dt_sensitivity.csv
88-
│ ├── plot_constant_velocity.png (if --save)
89-
│ ├── plot_step_velocity.png
90-
│ ├── plot_multi_mode.png
91-
│ └── plot_dt_sensitivity.png
92-
└── regression/
93-
└── ...
73+
tests/manual/
74+
├── sphere_decay_ss_comparison.cpp # Sphere heave decay test
75+
├── oswec_decay_ss_comparison.cpp # OSWEC pitch decay test
76+
├── plot_model_comparison.py # Unified plotting script
77+
├── CMakeLists.txt
78+
└── README.md
79+
80+
build/bin/tests/manual/
81+
├── sphere_decay_ss_comparison.exe
82+
├── oswec_decay_ss_comparison.exe
83+
├── plot_model_comparison.py
84+
└── output/
85+
├── sphere_ss_verification.png
86+
├── oswec_ss_verification.png
87+
└── *.csv (data files)
9488
```
9589

96-
## Requirements
90+
---
91+
92+
## What These Diagnostics Show
93+
94+
### Kernel Fit Quality
95+
96+
Shows how accurately the Hankel-SVD fitter approximates the RIRF kernel:
97+
- Blue line: Actual RIRF from BEM data
98+
- Red dashed: State-space reconstruction
99+
- Good fit: Lines overlap, R² close to 1.0
100+
101+
### Time Series Comparison
102+
103+
Verifies the state-space model produces forces equivalent to direct convolution:
104+
- Blue: Convolution-based simulation
105+
- Red dashed: State-space simulation
106+
- Key metric: Maximum position/angle difference
107+
108+
### Performance Scaling
97109

98-
The plotting script requires:
99-
- Python 3.6+
100-
- matplotlib
101-
- pandas
110+
Demonstrates the computational advantage of state-space:
111+
- **Convolution**: O(N) per step - time grows with simulation length
112+
- **State-space**: O(1) per step - constant time regardless of history
113+
- Speedup factor grows with simulation duration (typically 10-20× for long simulations)
102114

103-
Install with:
115+
---
116+
117+
## Requirements
118+
119+
Python dependencies:
104120
```bash
105-
pip install matplotlib pandas
121+
pip install matplotlib pandas numpy
106122
```
107123

108-
## Output Files
109-
110-
| File | Description |
111-
|------|-------------|
112-
| `radiation_ss_constant_v.csv` | Constant velocity response data |
113-
| `radiation_ss_step_v.csv` | Step velocity response data |
114-
| `radiation_ss_multi_mode.csv` | Multiple modes superposition data |
115-
| `radiation_ss_dt_sensitivity.csv` | Time step sensitivity data |
124+
---
116125

117-
## Why Visual Checks?
126+
## Notes
118127

119-
Unit tests verify *numerical correctness* - the numbers match expected values within tolerance. But visual checks help to build intuition about how the model behaves, spot unexpected patterns and communicate results to others effectively.
128+
- The sphere test uses default fitting parameters (`max_order=10`, `max_hankel_size=200`)
129+
- The OSWEC test uses increased parameters (`max_order=15`, `max_hankel_size=500`) due to more complex coupled dynamics
130+
- Both tests use the `RadiationStateSpaceComponent` integrated with `HydroSystem`

0 commit comments

Comments
 (0)