Skip to content

Commit af272a1

Browse files
jleonqujtgrasbkmruehl
authored
Irregular CIC test for OSWEC (WEC-Sim#1484)
* Irregular CIC test for OSWEC - needs more work * Update OSWEC tests * changing fig size and legend defaults --------- Co-authored-by: jtgrasb <87095491+jtgrasb@users.noreply.github.com> Co-authored-by: Ruehl <kmruehl@sandia.gov>
1 parent 448b115 commit af272a1

10 files changed

Lines changed: 307 additions & 13 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ examples/**/**/*.png
8181
!/tests/**/**/regularSS_org.mat
8282
!/tests/**/**/irregularSS_org.mat
8383
!/tests/**/**/irregularCIC_org.mat
84+
!/tests/**/**/irregularSpread_OSWEC_org.mat
8485
!/tests/**/**/RegYaw_org.mat
8586
!/tests/**/**/IrrYaw_org.mat
8687

Binary file not shown.
Binary file not shown.
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2+
% Copyright 2014 the National Renewable Energy Laboratory and Sandia Corporation
3+
%
4+
% Licensed under the Apache License, Version 2.0 (the "License");
5+
% you may not use this file except in compliance with the License.
6+
% You may obtain a copy of the License at
7+
%
8+
% http://www.apache.org/licenses/LICENSE-2.0
9+
%
10+
% Unless required by applicable law or agreed to in writing, software
11+
% distributed under the License is distributed on an "AS IS" BASIS,
12+
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
% See the License for the specific language governing permissions and
14+
% limitations under the License.
15+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16+
17+
%% Run the WEC-Sim OSWEC Test Case for pitch DOF w/PTO
18+
% This script will run the OSWEC in WEC-Sim for irregular waves with Hs=2.5[m]
19+
% and Tp=8[s] and a default wave spread. The OSWEC WEC model has 2 bodies,
20+
% restricted to pitch motion only, and has PTO damping=12[kNm-s/rad].
21+
22+
locdir=pwd;
23+
%% Run Simulation
24+
wecSim; % Run Simulation
25+
26+
%% Post-Process Data
27+
% Body 1
28+
B1.WEC_Sim_new.time=output.bodies(1).time;
29+
Pshift1=output.bodies(1).position(1,5);
30+
B1.WEC_Sim_new.pitch=output.bodies(1).position(:,5)-Pshift1;
31+
%Body 2
32+
B2.WEC_Sim_new.time=output.bodies(2).time;
33+
Pshift2=output.bodies(2).position(1,5);
34+
B2.WEC_Sim_new.pitch=output.bodies(2).position(:,5)-Pshift2;
35+
% Relative Motion
36+
Rel.WEC_Sim_new.time=B1.WEC_Sim_new.time;
37+
Rel.WEC_Sim_new.pitch=B1.WEC_Sim_new.pitch-B2.WEC_Sim_new.pitch;
38+
% Spectrum
39+
Sp.WEC_Sim_new.m0 = calcSpectralMoment(waves.omega,waves.spectrum,0);
40+
Sp.WEC_Sim_new.m2 = calcSpectralMoment(waves.omega,waves.spectrum,2);
41+
42+
%% Load Data
43+
irrSpreadouput_new=output; % Keeps the new run in the workspace
44+
load('irregularSpread_OSWEC_org.mat') % Load Previous WEC-Sim Data
45+
46+
%% Post-Process Data
47+
% Body 1
48+
B1.WEC_Sim_org.time=output.bodies(1).time;
49+
Pshift1=output.bodies(1).position(1,5);
50+
B1.WEC_Sim_org.pitch=output.bodies(1).position(:,5)-Pshift1;
51+
%Body 2
52+
B2.WEC_Sim_org.time=output.bodies(2).time;
53+
Pshift2=output.bodies(2).position(1,5);
54+
B2.WEC_Sim_org.pitch=output.bodies(2).position(:,5)-Pshift2;
55+
% Relative Motion
56+
Rel.WEC_Sim_org.time=B1.WEC_Sim_org.time;
57+
Rel.WEC_Sim_org.pitch=B1.WEC_Sim_org.pitch-B2.WEC_Sim_org.pitch;
58+
% Spectrum
59+
Sp.WEC_Sim_org.m0 = calcSpectralMoment(waves.omega,waves.spectrum,0);
60+
Sp.WEC_Sim_org.m2 = calcSpectralMoment(waves.omega,waves.spectrum,2);
61+
62+
clear Pshift1 Pshift2
63+
64+
%% Quantify Maximum Difference Between Saved and Current WEC-Sim Runs
65+
[irregularSpread_OSWEC.B1_P_max ,irregularSpread_OSWEC.B1_P_I]=max(abs(B1.WEC_Sim_org.pitch-B1.WEC_Sim_new.pitch));
66+
[irregularSpread_OSWEC.B2_P_max ,irregularSpread_OSWEC.B2_P_I]=max(abs(B2.WEC_Sim_org.pitch-B2.WEC_Sim_new.pitch));
67+
[irregularSpread_OSWEC.Rel_P_max,irregularSpread_OSWEC.Rel_P_I]=max(abs(Rel.WEC_Sim_org.pitch-Rel.WEC_Sim_new.pitch));
68+
69+
irregularSpread_OSWEC.B1 = B1;
70+
irregularSpread_OSWEC.B2 = B2;
71+
irregularSpread_OSWEC.Rel = Rel;
72+
irregularSpread_OSWEC.Sp = Sp;
73+
74+
save('irregularSpread_OSWEC','irregularSpread_OSWEC')
75+
76+
%% Plot Old vs. New Comparison
77+
if testCase.openCompare==1
78+
cd ../..
79+
plotOldNewOSWEC(B1,B2,Rel,[irregularSpread_OSWEC.B1_P_max ,irregularSpread_OSWEC.B1_P_I],...
80+
[irregularSpread_OSWEC.B2_P_max ,irregularSpread_OSWEC.B2_P_I],...
81+
[irregularSpread_OSWEC.Rel_P_max,irregularSpread_OSWEC.Rel_P_I],'irregularSpreadOSWEC');
82+
cd(locdir)
83+
end
84+
%% Clear output and .slx directory
85+
86+
try
87+
rmdir('output','s')
88+
rmdir('slprj','s')
89+
delete('OSWEC.slx.autosave', 'OSWEC_sfun.mexmaci64')
90+
catch
91+
end
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
%% Simulation Data
2+
simu = simulationClass(); % Initialize Simulation Class
3+
simu.simMechanicsFile = 'OSWEC.slx'; % Specify Simulink Model File
4+
simu.explorer = 'off'; % Turn SimMechanics Explorer (on/off)
5+
simu.startTime = 0; % Simulation Start Time [s]
6+
simu.rampTime = 100; % Wave Ramp Time [s]
7+
simu.endTime = 200; % Simulation End Time [s]
8+
simu.solver = 'ode4'; % simu.solver = 'ode4' for fixed step & simu.solver = 'ode45' for variable step
9+
simu.dt = 0.1; % Simulation Time-Step [s]
10+
simu.cicEndTime = 30; % Specify CI Time [s]
11+
12+
%% Wave Information
13+
14+
% Irregular Waves using PM Spectrum with Directionality
15+
waves = waveClass('irregular'); % Initialize Wave Class and Specify Type
16+
waves.height = 2.5; % Significant Wave Height [m]
17+
waves.period = 8; % Peak Period [s]
18+
waves.spectrumType = 'PM'; % Specify Spectrum Type
19+
waves.direction = [0,30,90]; % Wave Directionality [deg]
20+
waves.spread = [0.1,0.2,0.7]; % Wave Directional Spreading [%]
21+
waves.phaseSeed = 1;
22+
23+
%% Body Data
24+
% Flap
25+
body(1) = bodyClass('../../../../examples/OSWEC/hydroData/oswec.h5'); % Initialize bodyClass for Flap
26+
body(1).geometryFile = '../../../../examples/OSWEC/geometry/flap.stl'; % Geometry File
27+
body(1).mass = 127000; % User-Defined mass [kg]
28+
body(1).inertia = [1.85e6 1.85e6 1.85e6]; % Moment of Inertia [kg-m^2]
29+
30+
% Base
31+
body(2) = bodyClass('../../../../examples/OSWEC/hydroData/oswec.h5'); % Initialize bodyClass for Base
32+
body(2).geometryFile = '../../../../examples/OSWEC/geometry/base.stl'; % Geometry File
33+
body(2).mass = 999; % Placeholder mass for a fixed body
34+
body(2).inertia = [999 999 999]; % Placeholder inertia for a fixed body
35+
36+
%% PTO and Constraint Parameters
37+
% Fixed
38+
constraint(1)= constraintClass('Constraint1'); % Initialize ConstraintClass for Constraint1
39+
constraint(1).location = [0 0 -10]; % Constraint Location [m]
40+
41+
% Rotational PTO
42+
pto(1) = ptoClass('PTO1'); % Initialize ptoClass for PTO1
43+
pto(1).stiffness = 0; % PTO Stiffness Coeff [Nm/rad]
44+
pto(1).damping = 12000; % PTO Damping Coeff [Nsm/rad]
45+
pto(1).location = [0 0 -8.9]; % PTO Location [m]

tests/RegressionTests/IrregularWaves/printPlotIrregular.m

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
load('./irregularSS/irregularSS.mat') % Load WEC-Sim Run Data
2323

2424
%% Plot Heave Comparisons
25-
h=figure('units','normalized','outerposition',[0 0 1 1]);
25+
h=figure('units','normalized');
2626
% First Row = All simulations, all times
2727
% Second Row = All simulations, t=350-400s
2828

@@ -87,8 +87,7 @@
8787
xlim([0 200])
8888
ylim([-2 2])
8989
l=legend('"irregular"','"irregular" with State Space');
90-
set(l,'Position',[0.765 0.86 0.07 0.05],'Units','normalized',...
91-
'FontSize',12);
90+
set(l,'Units','normalized','FontSize',12);
9291

9392
subplot(2,3,6)
9493
m = plot(irregularCIC.Rel.WEC_Sim_new.time(find( irregularCIC.Rel.WEC_Sim_new.time==startTime):end),...

tests/RegressionTests/RegularWaves/printPlotRegular.m

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
load('./regularSS/regularSS.mat')
2424

2525
%% Plot Heave Comparisons
26-
h=figure('units','normalized','outerposition',[0 0 1 1]);
26+
h=figure('units','normalized');
2727
% First Row = All simulations, all times
2828
% Second Row = All simulations, t=350-400s
2929

@@ -95,8 +95,7 @@
9595
xlim([0 150])
9696
ylim([-2 2])
9797
l=legend('"regular"','"regularCIC"','"regularCIC" with State Space');
98-
set(l,'Position',[0.765 0.84 0.07 0.07],'Units','normalized',...
99-
'FontSize',12);
98+
set(l,'Units','normalized','FontSize',12);
10099

101100
subplot(2,3,6)
102101
m=plot( regular.Rel.WEC_Sim_new.time(find( regular.Rel.WEC_Sim_new.time==startTime):end),...

tests/RegressionTests/plotOldNew.m

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
% titstr: Title string to be displayed
3030

3131
function plotOldNew(B1,B2,Rel,InfoDiffB1, InfoDiffB2, InfoDiffRel,titstr)
32-
h=figure('units','normalized','outerposition',[0 0 1 1]);
32+
h=figure('units','normalized');
3333
% figure;
3434
subplot(2,3,1)
3535
%First Column: Body 1 Heave
@@ -105,8 +105,7 @@ function plotOldNew(B1,B2,Rel,InfoDiffB1, InfoDiffB2, InfoDiffRel,titstr)
105105
xlim([0 200])
106106
ylim([-2 2])
107107
l=legend('WEC-Sim Org','WEC-Sim New');
108-
set(l,'Position',[0.92 0.90 0.07 0.07],'Units','normalized',...
109-
'FontSize',12);
108+
set(l,'Units','normalized','FontSize',12);
110109

111110
subplot(2,3,6)
112111
m=plot(Rel.WEC_Sim_org.time(find(Rel.WEC_Sim_org.time==startTime):end),...
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2+
% Copyright 2014 the National Renewable Energy Laboratory and Sandia Corporation
3+
%
4+
% Licensed under the Apache License, Version 2.0 (the "License");
5+
% you may not use this file except in compliance with the License.
6+
% You may obtain a copy of the License at
7+
%
8+
% http://www.apache.org/licenses/LICENSE-2.0
9+
%
10+
% Unless required by applicable law or agreed to in writing, software
11+
% distributed under the License is distributed on an "AS IS" BASIS,
12+
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
% See the License for the specific language governing permissions and
14+
% limitations under the License.
15+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16+
17+
%% Plot Old vs. New Output Comparison
18+
% This script is called to plot the heave motion of body 1, 2, and relative
19+
% motion between them for the new simulation and the stored run for the
20+
% OSWEC.
21+
22+
% INPUTS:
23+
% B1: Body 1 data structure
24+
% B2: Body 2 data structure
25+
% Rel: Relative motion data structure
26+
% InfoDiffB1: A 2-element vector specifying (1) the max difference
27+
% (max(abs(old-new))) of body 1 pitch, and (2) the time at which it occurs.
28+
% InfoDiffB2: Same for body 2
29+
% InfoDiffRel: Same for relative body motions
30+
% titstr: Title string to be displayed
31+
32+
function plotOldNewOSWEC(B1,B2,Rel,InfoDiffB1, InfoDiffB2, InfoDiffRel,titstr)
33+
h=figure('units','normalized');
34+
% figure;
35+
subplot(2,3,1)
36+
%First Column: Body 1 Pitch
37+
startTime = 100;
38+
subplot(2,3,1)
39+
n=plot(B1.WEC_Sim_org.time,B1.WEC_Sim_org.pitch,'r:',...
40+
B1.WEC_Sim_new.time,B1.WEC_Sim_new.pitch,'k-');
41+
xlabel('time(s)')
42+
ylabel('Pitch(rad)')
43+
title(strcat(titstr,'Flap Pitch DOF 12PTO'))
44+
str1=['Max Diff = ' num2str(InfoDiffB1(1)) ' rad'];
45+
str2=['at time = ' num2str(B1.WEC_Sim_org.time(InfoDiffB1(2))) 's'];
46+
a=text(10,1.5,str1);set(a,'FontSize',12)
47+
a=text(10,1.2,str2);set(a,'FontSize',12)
48+
b=get(n(1),'LineWidth')+1;
49+
set(n(1),'LineWidth',b)
50+
xlim([0 200])
51+
ylim([-0.3 0.3])
52+
53+
subplot(2,3,4)
54+
m=plot(B1.WEC_Sim_org.time(find(B1.WEC_Sim_org.time==startTime):end),...
55+
B1.WEC_Sim_org.pitch(find(B1.WEC_Sim_org.time==startTime):end),'r:',...
56+
B1.WEC_Sim_new.time(find(B1.WEC_Sim_new.time==startTime):end),...
57+
B1.WEC_Sim_new.pitch(find(B1.WEC_Sim_new.time==startTime):end),'k-');
58+
a=get(m(1),'LineWidth')+1;
59+
set(m(1),'LineWidth',a)
60+
xlabel('time(s)')
61+
ylabel('Pitch(rad)')
62+
xlim([100 200])
63+
ylim([-0.3 0.3])
64+
65+
%Second Column: Body 2 Pitch
66+
subplot(2,3,2)
67+
n=plot(B2.WEC_Sim_org.time,B2.WEC_Sim_org.pitch,'r:',...
68+
B2.WEC_Sim_new.time,B2.WEC_Sim_new.pitch,'k-');
69+
xlabel('time(s)')
70+
ylabel('Pitch(rad)')
71+
title(strcat(titstr, 'Base Pitch DOF 12PTO'))
72+
str1=['Max Diff = ' num2str(InfoDiffB2(1)) ' m'];
73+
str2=['at time = ' num2str(B1.WEC_Sim_org.time(InfoDiffB2(2))) 's'];
74+
a=text(10,0.18,str1);set(a,'FontSize',12)
75+
a=text(10,0.15,str2);set(a,'FontSize',12)
76+
b=get(n(1),'LineWidth')+1;
77+
set(n(1),'LineWidth',b)
78+
xlim([0 200])
79+
ylim([-0.1 0.1])
80+
81+
subplot(2,3,5)
82+
m=plot(B2.WEC_Sim_org.time(find(B2.WEC_Sim_org.time==startTime):end),...
83+
B2.WEC_Sim_org.pitch(find(B2.WEC_Sim_org.time==startTime):end),'r:',...
84+
B2.WEC_Sim_new.time(find(B2.WEC_Sim_new.time==startTime):end),...
85+
B2.WEC_Sim_new.pitch(find(B2.WEC_Sim_new.time==startTime):end),'k-');
86+
a=get(m(1),'LineWidth')+1;
87+
set(m(1),'LineWidth',a)
88+
xlabel('time(s)')
89+
ylabel('Pitch(rad)')
90+
xlim([100 200])
91+
ylim([-0.1 0.1])
92+
93+
%Third Column: Relative Pitch
94+
subplot(2,3,3)
95+
n=plot(Rel.WEC_Sim_org.time,Rel.WEC_Sim_org.pitch,'r:',...
96+
Rel.WEC_Sim_new.time,Rel.WEC_Sim_new.pitch,'k-');
97+
xlabel('time(s)')
98+
ylabel('Pitch(rad)')
99+
title(strcat(titstr, ' Relative Pitch DOF 12PTO'))
100+
str1=['Max Diff = ' num2str(InfoDiffRel(1)) ' m'];
101+
str2=['at time = ' num2str(Rel.WEC_Sim_org.time(InfoDiffRel(2))) 's'];
102+
a=text(10,1.5,str1);set(a,'FontSize',12)
103+
a=text(10,1.2,str2);set(a,'FontSize',12)
104+
b=get(n(1),'LineWidth')+1;
105+
set(n(1),'LineWidth',b)
106+
xlim([0 200])
107+
ylim([-0.3 0.3])
108+
l=legend('WEC-Sim Org','WEC-Sim New');
109+
set(l,'Units','normalized','FontSize',12);
110+
111+
subplot(2,3,6)
112+
m=plot(Rel.WEC_Sim_org.time(find(Rel.WEC_Sim_org.time==startTime):end),...
113+
Rel.WEC_Sim_org.pitch(find(Rel.WEC_Sim_org.time==startTime):end),'r:',...
114+
Rel.WEC_Sim_new.time(find(Rel.WEC_Sim_new.time==startTime):end),...
115+
Rel.WEC_Sim_new.pitch(find(Rel.WEC_Sim_new.time==startTime):end),'k-');
116+
a=get(m(1),'LineWidth')+1;
117+
set(m(1),'LineWidth',a)
118+
xlabel('time(s)')
119+
ylabel('Pitch(rad)')
120+
xlim([100 200])
121+
ylim([-0.3 0.3])
122+
123+
end

0 commit comments

Comments
 (0)