Example: MHKiT-MATLAB WEC-Sim
This example loads simulated data from a WEC-Sim run for a two-body point absorber (Reference Model 3) and demonstrates the application of the MHKiT Wave Module to interact with the simulated data. The analysis is broken down into three parts: load WEC-Sim data, interact with the WEC-Sim data, and apply the MHKiT wave module.
- Load WEC-Sim Simulated Data
- Analyze WEC-Sim Simulated Data (e.g. Wave Class, Body Class, PTO Class, Constraint Class, and Mooring Class Data)
- Apply MHKiT Wave Module
1. Load WEC-Sim Simulated Data
WEC-Sim saves output data as a MATLAB structure, generated by WEC-Sim’s Response Class. The WEC-Sim structure contains data for: wave, bodies, ptos, constraints, mooring, moordyn, and ptosim
Here we will load the WEC-Sim RM3 data run with a mooring matrix.
filename = './data/RM3MooringMatrix_matlabWorkspace.mat'
2. Analyze WEC-Sim Simulated Data
This section will analyze the WEC-Sim RM3 data using the WEC-Sim structure.
Wave Class Data
Data from WEC-Sim’s Wave Class includes information about the wave input, including the the wave type, and wave elevation as a function of time.
% Store WEC-Sim output from the Wave Class to a new variable, called `wave_data`
ylabel("Wave Surface Elevation [m]")
Body Class Data
Data from WEC-Sim’s Body Class includes information about each body, including the body’s position, velocity, acceleration, forces acting on the body, and the body’s name. For the RM3 example there will be 2 boides a float and a spar.
% Store WEC-Sim output from the Body Class as 'bodies'
% Store Body Class data for Body 1 as `body1`.
Plot heave position data for Body 1
The RM3 device creates power in the heave direction (DOF 3). Let us consider the float's (body 1) position as a function of time by plotting body1.position(:,3).
ylabel("Heave Position [m]")
% Calculate the maximum and minimum heave position of Body 1
fprintf("Body 1 max heave position = %4.5f [m]", max(body1.position(:,3)))
fprintf("Body 1 max heave position = %4.5f [m]", min(body1.position(:,3)))
Plot Body 1 position data for all DOFs
As an example we could plot multiple postion DOFs by calling a plot on only the position data.
ylabel("Position [m or rad]")
3. Apply MHKiT Wave Module
In the example below we will calculate a spectrum from the wecsim wave elevation timeseries data using the MHKiT elevation_spectrum function.
% Use the MHKiT Wave Module to calculate the wave spectrum from the WEC-Sim Wave Class Data
nnft=1000 % Number of bins in the Fast Fourier Transform
ws_spectrum = elevation_spectrum(wave_data.elevation, sample_rate, nnft,wave_data.time)
% Plot calculated wave spectrum
spect_plot = plot_spectrum(ws_spectrum);
% Calculate Peak Wave Period (Tp) and Significant Wave Height (Hm0)
Tp = peak_period(ws_spectrum)
Hm0 = significant_wave_height(ws_spectrum)