Skip to content

Commit b9e07bf

Browse files
authored
Merge pull request #175 from akeeste/wecsim_example_2
WEC-Sim Power performance example
2 parents 7e5ab9d + 7daa268 commit b9e07bf

8 files changed

Lines changed: 370 additions & 16 deletions
447 Bytes
Binary file not shown.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
,Te,Hm0,weights,Tp,J
2+
0,7.974491297618696,1.2539695860020375,0.05886124580653463,9.294278901653492,6031.115427233068
3+
1,10.79453302186441,2.6414034469857426,0.03521606218803187,12.581040818023789,37004.325097576424
4+
2,6.901978594273449,1.9531216543907912,0.05200095798403432,8.044264095889801,12516.214518733921
5+
3,12.66762764506827,7.310116435425513,0.00506999304134946,14.764134784461854,367451.94558109366
6+
4,12.893701222644763,2.262294477484095,0.016045936894736042,15.027623802616274,36455.136139003094
7+
5,10.557620939325757,4.754296605622727,0.017311356620466345,12.30491950970368,116784.36178931354
8+
6,8.766663943128838,2.73937982438113,0.04364638972455223,10.217557043273704,31825.667988697423
9+
7,6.53740270831686,1.3055783411566657,0.05074593316072677,7.619350475893777,5272.441394386226
10+
8,9.666290858496115,1.340694087456887,0.03707009242331086,11.266073261650485,8443.64982080737
11+
9,12.787307070448522,3.9203973577543567,0.016464374526706786,14.903621294229048,107680.98651108926
12+
10,11.605879274797648,1.8210155555767638,0.022322848153721837,13.52666582144248,19446.169168239652
13+
11,7.584081846459788,1.8787353416133314,0.05462400212242149,8.839256231305114,12827.143860504848
14+
12,10.175410691413894,6.133932424424177,0.008836092568956415,11.859453020295915,188189.68918703857
15+
13,9.31935707393927,4.587432323814967,0.018817182816956667,10.861721531397752,95155.06836750833
16+
14,7.228995507990213,1.2566906096446477,0.05769191323850427,8.425402689965283,5449.034308785218
17+
15,5.646966933450414,1.3391066651568038,0.03211811510063545,6.581546542483,4750.825174993035
18+
16,7.615979550190041,2.634620209981552,0.03649712691597074,8.876433042179535,25339.645267361964
19+
17,9.460406027609398,3.381146758779285,0.03382351193072047,11.026114251293006,52508.67094062201
20+
18,16.000440812915354,3.044223392703431,0.00429464920004312,18.64853241598526,87446.89573211693
21+
19,10.55034307463129,1.5636343648164452,0.03026542177097602,12.296437149919917,12622.321615858824
22+
20,11.817436231011273,2.9829231066038613,0.021717088244806053,13.77323570047934,53748.08982906377
23+
21,12.10112174926391,5.305727115709343,0.014539688517578586,14.10387150263859,177305.22043219427
24+
22,10.400034982693642,3.5882967612571264,0.03231245358261764,12.121252893582334,65405.27202789767
25+
23,9.132539594795865,2.0115676174654173,0.04813020643130128,10.643985541720124,17913.12934373824
26+
24,9.880295706786633,2.4629082845730914,0.05063441840994648,11.515496161755983,29157.316024586242
27+
25,8.321803224944599,2.0030803613144172,0.054171203145458285,9.699071357744288,16104.920042215257
28+
26,6.131352093023454,1.794448837319034,0.03542910867558095,7.146098010516846,9295.960215551484
29+
27,11.430726526098171,3.9798910657304747,0.025330550582418253,13.322525088692508,90734.82138245075
30+
28,14.263809369877091,2.781733273746191,0.009358726934992883,16.624486445078194,66183.17957100201
31+
29,13.744160648067846,5.465225456257929,0.007517584283470983,16.01883525415833,240475.8375064763
32+
30,8.735251181801084,1.270630004139555,0.047066226355940106,10.180945433334598,6821.344536640248
33+
31,8.301748078970448,3.6767674099266174,0.02206953864653263,9.675697061737118,54122.886646054554

examples/wecsim_example.html

Lines changed: 26 additions & 10 deletions
Large diffs are not rendered by default.

examples/wecsim_example.m

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
% Mooring, MoorDyn, and PTOSim classes.
2323

2424
% Relative location and filename of simulated WEC-Sim data (run with mooring)
25-
filename = './examples/data/RM3MooringMatrix_matlabWorkspace.mat'
25+
filename = './data/RM3MooringMatrix_matlabWorkspace.mat'
2626
load(filename, 'output');
2727

2828
%% 2. WEC-Sim Simulated Data
@@ -150,10 +150,19 @@
150150
xlim([0, 4]);
151151

152152
%%
153-
% Calculate Peak Wave Period (Tp) and Significant Wave Height (Hm0)
153+
% Calculate Wave Statistics using MHKiT wave module functions
154154

155-
Tp = peak_period(ws_spectrum);
156155
Hm0 = significant_wave_height(ws_spectrum);
157-
158-
fprintf('Peak Wave Period (Tp) = %.4f s\n', Tp);
159-
fprintf('Significant Wave Height (Hm0) = %.4f m\n', Hm0);
156+
Tp = peak_period(ws_spectrum);
157+
Te = energy_period(ws_spectrum);
158+
159+
wave_statistics_data = {
160+
% Parameter, Value, Units
161+
'Significant Wave Height, Hm0', Hm0, 'm';
162+
'Peak Wave Period, Tp', Tp, 's';
163+
'Energy Period, Te', Te, 's';
164+
};
165+
166+
wave_statistics_table = cell2table(wave_statistics_data, 'VariableNames', {'Parameter', 'Value', 'Units'});
167+
wave_statistics_table.Value = round(wave_statistics_table.Value, 4);
168+
wave_statistics_table

examples/wecsim_example.mlx

-19.9 KB
Binary file not shown.

examples/wecsim_power_performance_example.html

Lines changed: 180 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
%% MHKiT WEC-Sim Power Performance Example
2+
% This notebook demonstrates using the MHKiT wave module and WEC-Sim together
3+
% to perform a resource characterization study in MHKiT, simulate representative
4+
% cases with WEC-Sim, and visualize the results in MHKiT to estimate MAEP (Mean
5+
% Annual Energy Production).
6+
%
7+
% 1. Characterize the available resource at a location
8+
%
9+
% - See the PacWave example notebook
10+
%
11+
% 2. Write a WEC-Sim batch file for the given clusters
12+
%
13+
% 3. Simulate the device _in WEC-Sim_.
14+
%
15+
% - Ensure that the spectra used in WEC-Sim is identical to the one used in
16+
% MHKiT.
17+
%
18+
% 4. Load WEC-Sim batch results
19+
%
20+
% 5. Assess results and visualize quantities of interest
21+
%
22+
% This example uses WEC-Sim to simulate the [Oscillating Surge Wave Energy Converter
23+
% (OSWEC)](https://wec-sim.github.io/WEC-Sim/main/user/tutorials.html#oscillating-surge-wec-oswec),
24+
% a flap-type device.
25+
%% 1. Characterize the available resource at a location
26+
% This example will use an abbreviated version of `PacWave_resource_characterization_example.ipynb`.
27+
%
28+
% For full details on downloading, calculating, and visualizing the k-means
29+
% clusters representation of the site's wave resouce, see that example.
30+
%
31+
% We select the N=32 cluster as it's total energy flux is closet to the total
32+
% energy flux of the site considering all wave conditions. We will load the PacWave
33+
% example output, which can be easily saved after running the example with the
34+
% command `results[32].to_csv("pacwave_cluster_32.csv")`. We will start this example
35+
% by reading in that csv output and formatting it for WEC-Sim.
36+
37+
% Relative location and filename of simulated WEC-Sim data (run with mooring)
38+
filename = './data/wave/pacwave_cluster_32.csv'
39+
results = readtable(filename)
40+
%% 2. Write a WEC-Sim batch file for the given clusters
41+
% WEC-Sim MCR (multiple condition run) files should contain a structure `mcr`
42+
% that contains two variables: `header` and `cases`. Each column of `header` and
43+
% `cases` denotes a variable and it's value respectively. Each row is distinct
44+
% simulation. WEC-Sim defines waves using the significant wave height and peak
45+
% period. We will isolate these values from the results of the cluster analysis
46+
% and create a dictionary that is written to the `.mat` file.
47+
48+
mcr = struct();
49+
mcr.header = {'waves.height','waves.period'};
50+
mcr.cases = [results.Hm0 results.Tp]
51+
save('mcr_mhkit.mat', 'mcr');
52+
%% 3. Simulate the device _in WEC-Sim_
53+
% Now that the MCR file is created, we need to go simulate WEC performance in
54+
% these wave conditions using WEC-Sim. To recreate the data used in the next step,
55+
% use the created MCR file with WEC-Sim's OSWEC example. For an accurate comparison
56+
% to the power calculated in the resource characterization, we should ensure that
57+
% the WEC-Sim cases use irregular JONSWAP wave spectra as in the PacWave example.
58+
%
59+
%
60+
%
61+
% For convenience in this demonstration, we enforce OSWEC model stability in
62+
% the extreme wave conditions by arbitrarily applying a large PTO stiffness and
63+
% damping in the wecSimInputFile.m:
64+
65+
% pto(1).stiffness = 1e5;
66+
% pto(1).damping = 5e7;
67+
%%
68+
% To reduce the amount of extranenous data saved for this example, we limit
69+
% the WEC-Sim output to the PTO's power output in the `userDefinedFunctions.m`
70+
% script:
71+
72+
% if exist('imcr','var')
73+
% if imcr == 1
74+
% nmcr = size(mcr.cases,1);
75+
% power = nan(1, nmcr);
76+
% end
77+
%
78+
% iRampEnd = simu.rampTime./simu.dtOut + 1;
79+
% power(imcr) = -mean(output.ptos(1).powerInternalMechanics(iRampEnd:end,5));
80+
%
81+
% if imcr == nmcr
82+
% % % Save output
83+
% save('mcr_mhkit_power.mat', 'power');
84+
% end
85+
% end
86+
% bodies = output.bodies;
87+
%% 4. Load WEC-Sim batch results
88+
% Note that in this example we do not save the entire WEC-Sim `output` structure
89+
% for each case. See the `wecsim_example.ipynb` for information on loading the
90+
% WEC-Sim responseClass. Here, the output is one array of average power output
91+
% that we will load and compare to the resource characterization.
92+
%
93+
% Note that the power output [W] is significantly larger than the energy flux
94+
% [W/m] due to the large width of the OSWEC.
95+
96+
% Relative location and filename of simulated WEC-Sim data (run with mooring)
97+
filename = './data/wave/mcr_mhkit_power.mat';
98+
% Load the WEC-Sim output data which contains the variable `power`.
99+
load(filename)
100+
results.Power = power'
101+
%% 5. Assess results and visualize quantities of interest
102+
% Now that we have loaded the OSWEC's modeled power, we can assess it's performance
103+
% relative to the incoming wave and calculate the mean annual energy production
104+
% (MAEP) using MHKiT.
105+
106+
results.CW = capture_length(results.Power, results.J)';
107+
108+
oswec_width = 18;
109+
results.CWR = results.CW / oswec_width
110+
%%
111+
% Calculate and display the mean annual energy production.
112+
113+
CW.values = results.CW;
114+
J.values = results.J;
115+
weights.values = results.weights;
116+
MAEP = mean_annual_energy_production_matrix(CW, J, weights) / 1000 % kWh
7.21 KB
Binary file not shown.

0 commit comments

Comments
 (0)