Skip to content

Feature: Part 1 Wave Module Native Code Conversion - #196

Merged
simmsa merged 114 commits into
MHKiT-Software:developfrom
simmsa:feat_convert_wave_module_to_native_matlab
Sep 30, 2026
Merged

simmsa merged 114 commits into
MHKiT-Software:developfrom
simmsa:feat_convert_wave_module_to_native_matlab

Conversation

@simmsa

@simmsa simmsa commented Mar 4, 2026 •

Copy link
Copy Markdown
Contributor

This PR converts numeric MHKiT-Python wave module functions into native MATLAB functions.

Overall the intent is to maintain the same API, and helper functions for common operations and leverage native matlab functionality, and fill in gaps where necessary.

Tasks:

  • Write native MATLAB implementations of wave functions (no Python dependency)
    • read_NDBC_file: Rewrite to native MATLAB
    • swan_read_block: Rewrite to native MATLAB
    • capture_length: Rewrite to native MATLAB
    • capture_length_matrix: Rewrite to native MATLAB
    • capture_width: Rewrite to native MATLAB, deprecate capture width
    • capture_width_matrix: Rewrite to native MATLAB, deprecate capture width matrix
    • mean_annual_energy_production_matrix: Rewrite to native MATLAB
    • mean_annual_energy_production_timeseries: Rewrite to native MATLAB
    • power_matrix: Rewrite to native MATLAB
    • wave_energy_flux_matrix: Rewrite to native MATLAB
    • wec_reference_power_matrix: Return a DOE reference model WEC power matrix (new)
    • reference_model_power_matrix: Load DOE reference model power matrix data (new)
    • plot_wave_joint_probability_distribution: Dedicated JPD plotting function (new)
    • average_crest_period: Rewrite to native MATLAB
    • average_wave_period: Rewrite to native MATLAB
    • average_zero_crossing_period: Rewrite to native MATLAB
    • depth_regime: Rewrite to native MATLAB
    • energy_flux: Rewrite to native MATLAB
    • energy_period_to_peak_period: Define as native MATLAB (new)
    • peak_period: Rewrite to native MATLAB
    • spectral_bandwidth: Rewrite to native MATLAB
    • spectral_width: Rewrite to native MATLAB
    • wave_celerity: Rewrite to native MATLAB
    • wave_length: Rewrite to native MATLAB
    • wave_number: Rewrite to native MATLAB
  • Examples
    • wave_example: Use native functions and DOE reference models, and reorder sections
    • cdip_example: Rerender with native MATLAB and 1 year of cached CDIP 277 data
    • wecsim_power_performance_example: Use capture width in place of capture length
  • Tests
    • Wave_TestElevationSpectrum: Hold elevation spectrum tests moved out of resource tests (new)
    • Wave_TestContours: Hold contour tests moved from Wave_TestResourceMetrics
    • Wave_TestIO: Mark hindcast tests as assume-fail
    • Wave_TestIOcdip: Check CDIP metadata within a time window
    • Wave_TestPerformance: Test capture width and seeded annual energy production
    • Wave_TestResourceMetrics: Add joint probability plot tests and use MATLAB logicals
    • Wave_TestResourceSpectrum: Add seeded surface elevation and zero-frequency spectrum tests
    • Utils_TestBinnedStatistic2d: Test 2D binned statistics (new)
    • Utils_TestDefineBins: Test bin size correctness (new)
    • Utils_TestMhkitUtils: Hold mhkit_* helper tests (new)
    • Utils_TestGenUtils: Move helper tests out and skip a flaky NDBC variable
    • Examples_TestMatlabOnly: Add the wave and WEC-Sim examples
    • runMatlabOnlyTests: Add native wave tests to the MATLAB-only suite
  • Utilities
    • mhkit_binned_statistic_2d: Compute a 2D binned statistic on a bin grid (new)
    • mhkit_define_bins_1d: Compute bin centers and edges for one axis (new)
    • mhkit_define_bins_2d: Define a 2D bin grid (new)
    • mhkit_frequency_to_column_names: Convert frequencies to valid table column names (new)
    • mhkit_standardize_spectrum_input: Convert any supported spectrum input to plain arrays (new)
    • mhkit_restore_spectrum_output: Return results in the caller's original spectrum format (new)
    • mhkit_standardize_user_input_to_column_vectors: Convert vector inputs to column vectors (new)
    • mhkit_restore_column_vectors_to_user_input: Restore the caller's original vector orientation (new)
    • mhkit_verify_is_column_vector: Check that a value is a column vector (new)
    • mhkit_colormap: Return an RGB colormap by name (new)
    • mhkit_plot_matrix: Plot a binned matrix, one colored cell per bin (new)

@simmsa simmsa added this to the 1.1 milestone Jul 13, 2026
@akeeste akeeste self-assigned this Aug 31, 2026
@akeeste

akeeste commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Still in draft but ready for @akeeste review. Should be only a few lines per function that are most relevant

This separates out MATLAB native and python calling functions into
separate test files
This separates out MATLAB native and new MATLAB only utility functions
into one test file that can be tested separately on actions
This adds per variable reads and auto retries and more deterministic
error messages
@simmsa
simmsa marked this pull request as ready for review September 29, 2026 16:04
@simmsa

simmsa commented Sep 29, 2026

Copy link
Copy Markdown
Contributor Author

@akeeste, apologies for the delay here.

This is ready for review.

The two test failures are expected, those are running the older python tests.

There are new tests that are passing for the native MATLAB functions and examples:

image

@simmsa
simmsa merged commit 1e53ca2 into MHKiT-Software:develop Sep 30, 2026
25 of 30 checks passed
This was referenced Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants