MHKiT WEC-Sim Power Performance Example

This notebook demonstrates using the MHKiT wave module and WEC-Sim together to perform a resource characterization study in MHKiT, simulate representative cases with WEC-Sim, and visualize the results in MHKiT to estimate MAEP (Mean Annual Energy Production).
1. Characterize the available resource at a location
- See the PacWave example notebook
2. Write a WEC-Sim batch file for the given clusters
3. Simulate the device in WEC-Sim.
- Ensure that the spectra used in WEC-Sim is identical to the one used in MHKiT.
4. Load WEC-Sim batch results
5. Assess results and visualize quantities of interest
This example uses WEC-Sim to simulate the [Oscillating Surge Wave Energy Converter (OSWEC)](https://wec-sim.github.io/WEC-Sim/main/user/tutorials.html#oscillating-surge-wec-oswec), a flap-type device.

1. Characterize the available resource at a location

This example will use an abbreviated version of `PacWave_resource_characterization_example.ipynb`.
For full details on downloading, calculating, and visualizing the k-means clusters representation of the site's wave resouce, see that example.
We select the N=32 cluster as it's total energy flux is closet to the total energy flux of the site considering all wave conditions. We will load the PacWave example output, which can be easily saved after running the example with the command `results[32].to_csv("pacwave_cluster_32.csv")`. We will start this example by reading in that csv output and formatting it for WEC-Sim.
% Relative location and filename of simulated WEC-Sim data (run with mooring)
filename = './data/wave/pacwave_cluster_32.csv'
filename = './data/wave/pacwave_cluster_32.csv'
results = readtable(filename)
results = 32×6 table
 Var1TeHm0weightsTpJ
107.97451.25400.05899.29436.0311e+03
2110.79452.64140.035212.58103.7004e+04
326.90201.95310.05208.04431.2516e+04
4312.66767.31010.005114.76413.6745e+05
5412.89372.26230.016015.02763.6455e+04
6510.55764.75430.017312.30491.1678e+05
768.76672.73940.043610.21763.1826e+04
876.53741.30560.05077.61945.2724e+03
989.66631.34070.037111.26618.4436e+03
10912.78733.92040.016514.90361.0768e+05
111011.60591.82100.022313.52671.9446e+04
12117.58411.87870.05468.83931.2827e+04
131210.17546.13390.008811.85951.8819e+05
14139.31944.58740.018810.86179.5155e+04
15147.22901.25670.05778.42545.4490e+03
16155.64701.33910.03216.58154.7508e+03
17167.61602.63460.03658.87642.5340e+04
18179.46043.38110.033811.02615.2509e+04
191816.00043.04420.004318.64858.7447e+04
201910.55031.56360.030312.29641.2622e+04
212011.81742.98290.021713.77325.3748e+04
222112.10115.30570.014514.10391.7731e+05
232210.40003.58830.032312.12136.5405e+04
24239.13252.01160.048110.64401.7913e+04
25249.88032.46290.050611.51552.9157e+04
26258.32182.00310.05429.69911.6105e+04
27266.13141.79440.03547.14619.2960e+03
282711.43073.97990.025313.32259.0735e+04
292814.26382.78170.009416.62456.6183e+04
302913.74425.46520.007516.01882.4048e+05
31308.73531.27060.047110.18096.8213e+03
32318.30173.67680.02219.67575.4123e+04

2. Write a WEC-Sim batch file for the given clusters

WEC-Sim MCR (multiple condition run) files should contain a structure `mcr` that contains two variables: `header` and `cases`. Each column of `header` and `cases` denotes a variable and it's value respectively. Each row is distinct simulation. WEC-Sim defines waves using the significant wave height and peak period. We will isolate these values from the results of the cluster analysis and create a dictionary that is written to the `.mat` file.
mcr = struct();
mcr.header = {'waves.height','waves.period'};
mcr.cases = [results.Hm0 results.Tp]
mcr = struct with fields:
header: {'waves.height' 'waves.period'} cases: [32×2 double]
save('mcr_mhkit.mat', 'mcr');

3. Simulate the device in WEC-Sim

Now that the MCR file is created, we need to go simulate WEC performance in these wave conditions using WEC-Sim. To recreate the data used in the next step, use the created MCR file with WEC-Sim's OSWEC example. For an accurate comparison to the power calculated in the resource characterization, we should ensure that the WEC-Sim cases use irregular JONSWAP wave spectra as in the PacWave example.
For convenience in this demonstration, we enforce OSWEC model stability in the extreme wave conditions by arbitrarily applying a large PTO stiffness and damping in the wecSimInputFile.m:
% pto(1).stiffness = 1e5;
% pto(1).damping = 5e7;
To reduce the amount of extranenous data saved for this example, we limit the WEC-Sim output to the PTO's power output in the `userDefinedFunctions.m` script:
% if exist('imcr','var')
% if imcr == 1
% nmcr = size(mcr.cases,1);
% power = nan(1, nmcr);
% end
%
% iRampEnd = simu.rampTime./simu.dtOut + 1;
% power(imcr) = -mean(output.ptos(1).powerInternalMechanics(iRampEnd:end,5));
%
% if imcr == nmcr
% % % Save output
% save('mcr_mhkit_power.mat', 'power');
% end
% end
% bodies = output.bodies;

4. Load WEC-Sim batch results

Note that in this example we do not save the entire WEC-Sim `output` structure for each case. See the `wecsim_example.ipynb` for information on loading the WEC-Sim responseClass. Here, the output is one array of average power output that we will load and compare to the resource characterization.
Note that the power output [W] is significantly larger than the energy flux [W/m] due to the large width of the OSWEC.
% Relative location and filename of simulated WEC-Sim data (run with mooring)
filename = './data/wave/mcr_mhkit_power.mat';
% Load the WEC-Sim output data which contains the variable `power`.
load(filename)
results.Power = power'
results = 32×7 table
 Var1TeHm0weightsTpJPower
107.97451.25400.05899.29436.0311e+036.8613e+04
2110.79452.64140.035212.58103.7004e+043.8735e+05
326.90201.95310.05208.04431.2516e+041.9234e+05
4312.66767.31010.005114.76413.6745e+051.9512e+06
5412.89372.26230.016015.02763.6455e+043.1159e+05
6510.55764.75430.017312.30491.1678e+058.4103e+05
768.76672.73940.043610.21763.1826e+043.3986e+05
876.53741.30560.05077.61945.2724e+038.3326e+04
989.66631.34070.037111.26618.4436e+036.9516e+04
10912.78733.92040.016514.90361.0768e+055.0688e+05
111011.60591.82100.022313.52671.9446e+041.6020e+05
12117.58411.87870.05468.83931.2827e+042.1125e+05
131210.17546.13390.008811.85951.8819e+052.4020e+06
14139.31944.58740.018810.86179.5155e+041.0677e+06
15147.22901.25670.05778.42545.4490e+036.4143e+04
16155.64701.33910.03216.58154.7508e+037.3289e+04
17167.61602.63460.03658.87642.5340e+043.6720e+05
18179.46043.38110.033811.02615.2509e+044.0202e+05
191816.00043.04420.004318.64858.7447e+042.4145e+05
201910.55031.56360.030312.29641.2622e+041.3351e+05
212011.81742.98290.021713.77325.3748e+043.5522e+05
222112.10115.30570.014514.10391.7731e+051.3432e+06
232210.40003.58830.032312.12136.5405e+047.3683e+05
24239.13252.01160.048110.64401.7913e+041.9988e+05
25249.88032.46290.050611.51552.9157e+042.7157e+05
26258.32182.00310.05429.69911.6105e+042.3197e+05
27266.13141.79440.03547.14619.2960e+031.4780e+05
282711.43073.97990.025313.32259.0735e+049.3911e+05
292814.26382.78170.009416.62456.6183e+042.0003e+05
302913.74425.46520.007516.01882.4048e+058.6862e+05
31308.73531.27060.047110.18096.8213e+038.5504e+04
32318.30173.67680.02219.67575.4123e+047.5789e+05

5. Assess results and visualize quantities of interest

Now that we have loaded the OSWEC's modeled power, we can assess it's performance relative to the incoming wave and calculate the mean annual energy production (MAEP) using MHKiT.
results.CW = capture_length(results.Power, results.J)';
 
oswec_width = 18;
results.CWR = results.CW / oswec_width
results = 32×9 table
 Var1TeHm0weightsTpJPowerCWCWR
107.97451.25400.05899.29436.0311e+036.8613e+0411.37650.6320
2110.79452.64140.035212.58103.7004e+043.8735e+0510.46770.5815
326.90201.95310.05208.04431.2516e+041.9234e+0515.36730.8537
4312.66767.31010.005114.76413.6745e+051.9512e+065.31000.2950
5412.89372.26230.016015.02763.6455e+043.1159e+058.54710.4748
6510.55764.75430.017312.30491.1678e+058.4103e+057.20150.4001
768.76672.73940.043610.21763.1826e+043.3986e+0510.67870.5933
876.53741.30560.05077.61945.2724e+038.3326e+0415.80410.8780
989.66631.34070.037111.26618.4436e+036.9516e+048.23290.4574
10912.78733.92040.016514.90361.0768e+055.0688e+054.70730.2615
111011.60591.82100.022313.52671.9446e+041.6020e+058.23800.4577
12117.58411.87870.05468.83931.2827e+042.1125e+0516.46880.9149
131210.17546.13390.008811.85951.8819e+052.4020e+0612.76380.7091
14139.31944.58740.018810.86179.5155e+041.0677e+0611.22080.6234
15147.22901.25670.05778.42545.4490e+036.4143e+0411.77140.6540
16155.64701.33910.03216.58154.7508e+037.3289e+0415.42660.8570
17167.61602.63460.03658.87642.5340e+043.6720e+0514.49100.8051
18179.46043.38110.033811.02615.2509e+044.0202e+057.65630.4253
191816.00043.04420.004318.64858.7447e+042.4145e+052.76110.1534
201910.55031.56360.030312.29641.2622e+041.3351e+0510.57700.5876
212011.81742.98290.021713.77325.3748e+043.5522e+056.60900.3672
222112.10115.30570.014514.10391.7731e+051.3432e+067.57580.4209
232210.40003.58830.032312.12136.5405e+047.3683e+0511.26560.6259
24239.13252.01160.048110.64401.7913e+041.9988e+0511.15810.6199
25249.88032.46290.050611.51552.9157e+042.7157e+059.31410.5174
26258.32182.00310.05429.69911.6105e+042.3197e+0514.40370.8002
27266.13141.79440.03547.14619.2960e+031.4780e+0515.89990.8833
282711.43073.97990.025313.32259.0735e+049.3911e+0510.35010.5750
292814.26382.78170.009416.62456.6183e+042.0003e+053.02240.1679
302913.74425.46520.007516.01882.4048e+058.6862e+053.61210.2007
31308.73531.27060.047110.18096.8213e+038.5504e+0412.53480.6964
32318.30173.67680.02219.67575.4123e+047.5789e+0514.00310.7779
Calculate and display the mean annual energy production.
CW.values = results.CW;
J.values = results.J;
weights.values = results.weights;
MAEP = mean_annual_energy_production_matrix(CW, J, weights) / 1000 % kWh
MAEP = 2.8651e+06