Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring classes and properties - part 4 #26

Merged
merged 5 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,11 @@ $ cat .gitignore
!**/mooring/lines.txt
**/vtk/*
savedData*.mat
WECCCOMP/**/SS*.mat
WECCCOMP/**/SS*.fig
Passive_Yaw/**/IrrYaw.mat
Passive_Yaw/**/figYawIrr.fig
yaw*.mat
**/SS*.mat
**/SS*.fig
**/**/IrrYaw.mat
**/**/figYawIrr.fig


# BEM
*.1
Expand Down
Binary file modified Multiple_Condition_Runs/RM3_MCROPT3/mcrExample.mat
Binary file not shown.
8 changes: 4 additions & 4 deletions Passive_Yaw/PassiveYawRegression/runLoadPassiveYawIrr.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
IrrYaw.Pos_new=output.bodies(1).position(:,6);
IrrYaw.Force_new=output.bodies(1).forceTotal(:,6);
% Spectrum
IrrYaw.Sp.WEC_Sim_new.m0 = spectralMoment(waves.w,waves.S,0);
IrrYaw.Sp.WEC_Sim_new.m2 = spectralMoment(waves.w,waves.S,2);
IrrYaw.Sp.WEC_Sim_new.m0 = calcSpectralMoment(waves.w,waves.S,0);
IrrYaw.Sp.WEC_Sim_new.m2 = calcSpectralMoment(waves.w,waves.S,2);

%% Load Data
irrCICouput_new=output; % Keeps the new run in the workspace
Expand All @@ -25,8 +25,8 @@
IrrYaw.Pos_org=output.bodies(1).position(:,6);
IrrYaw.Force_org=output.bodies(1).forceTotal(:,6);
% Spectrum
IrrYaw.Sp.WEC_Sim_org.m0 = spectralMoment(waves.w,waves.S,0);
IrrYaw.Sp.WEC_Sim_org.m2 = spectralMoment(waves.w,waves.S,2);
IrrYaw.Sp.WEC_Sim_org.m0 = calcSpectralMoment(waves.w,waves.S,0);
IrrYaw.Sp.WEC_Sim_org.m2 = calcSpectralMoment(waves.w,waves.S,2);

%% Quantify Maximum Difference Between Saved and Current WEC-Sim RunsReg
[IrrYaw.Pos_diff ,IrrYaw.Pos_i]=max(abs(IrrYaw.Pos_new-IrrYaw.Pos_org));
Expand Down
68 changes: 68 additions & 0 deletions WECCCOMP/WECCCOMP/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
$ cat .gitignore

# File Types
*~
*.acn
*.acr
*.alg
*.asv
*.autosave
*.aux
*.avi
*.bak
*.bat
*.bbl
*.blg
*.c
*.DS_Store
*.dvi
*.exp
*.fig
*.glg
*.glo
*.gls
*.idx
*.ilg
*.ind
*.ist
*.lib
*.lof
*.log
*.lot
*.maf
*.mak
*.map
*.mex
*.mex64
*.mex*
*.mol
*.mtc
*.mtc0
*.mtc1
*.mtc3
*.o
*.obj
*.png
*.r2015b
*.slx.r*
*.slxc
*.sublime-workspace
*.sublime-project
*.synctex
*.synctex.gz
*.synctex.gz(busy)
*.toc
*.vtp
*.zip

# MATLAB
**/output/
**/slprj/
*build_exception*
*.mat
!WECCCOMP_ss.mat

# Other
.DS_Store
view_html.sh
*vis-temp*
15 changes: 15 additions & 0 deletions WECCCOMP/WECCCOMP/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# WECCCOMP – WEC Control Competition

**Author:** Kelley Ruehl (Sandia), Nathan Tom (NREL), Yi-Hsiang Yu (NREL) and Francesco Ferri (Aalborg)

**WEC-Sim Version:** v4.2 (or newer)

**Matlab Version:** 2019b (or newer), and Statistics and Machine Learning Toolbox for [prctile](
https://www.mathworks.com/help/stats/prctile.html) function.

**WEC-Sim Model**
Numerical model for the WEC Control Competition (WECCCOMP) using WEC-Sim to model the WaveStar.

**Questions?**
* Post all WEC-Sim modeling questions to the [WEC-Sim online forum](https://github.com/WEC-Sim/WEC-Sim/issues).
* Post all WECCCOMP control competition questions to the [WECCCOMP online forum](http://www.eeng.nuim.ie/coer/control-competition-forum-login/).
Binary file added WECCCOMP/WECCCOMP/WECCCOMP-info-sheet_V6.pdf
Binary file not shown.
Binary file not shown.
Binary file added WECCCOMP/WECCCOMP/WaveStar.slx
Binary file not shown.
23 changes: 23 additions & 0 deletions WECCCOMP/WECCCOMP/controller_init.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
% init file for the WecSim model of the Wavestart arm

mc = 0;
cc = 0;
kc = 0;

McSat = inf;
xPcTs = 0.001;

a_CAB_neutral = 1.170165;
L_AB = 0.412;
L_AC = 0.2;
L_BC_neutral = 0.381408;
r_Acc = 0.464; % "Moment arm" for accelerometer

Theta0 = 23.4881/180*pi; % Inclination of accelerometer at neutral (rad)
grav = 9.82;
AccCalib = grav./(951.4/1000);
Acc0 = 3.5523; % Voltage at zero (horizontal arm and accelerometers)

fix = 30;
LPfreq.vel = fix; % Low Pass cut off freq in Hz
HPfreq.vel = fix; % High pass cut off freq in velocity filter (Hz)
64 changes: 64 additions & 0 deletions WECCCOMP/WECCCOMP/userDefinedFunctions.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
%% Script for plotting response and calculating power
% https://github.com/WEC-Sim/WECCCOMP

close all
clear power power_eff

%% Plot waves
waves.plotElevation(simu.rampTime);
hold on
plot([25 25],[1.5*min(waves.waveAmpTime(:,2)),1.5*max(waves.waveAmpTime(:,2))])
legend('\eta','rampTime','powerCalcTime')
try
waves.plotSpectrum();
catch
end
xlim([0 inf])

%% Plot RY response for Float
output.plotResponse(1,5);
xlim([0 inf])

%% Plot RY forces for Float
plotForces(output,1,5)
xlim([0 inf])

%% Calculate and Plot Power
time = output.ptos.time;
ii = find(time==25);
time = time(ii:end);
% force = -output.ptos.forceActuation(ii:end,3);
% vel = output.ptos.velocity(ii:end,3);
% power = force.*vel;
power = output.ptos(1).powerInternalMechanics(ii:end,3);
eff = 0.7;
for i = 1:length(power)
if power(i)>= 0
power_eff(i) = power(i)*eff;
else
power_eff(i) = power(i)/eff;
end
end
figure
plot(time,power,time,power_eff)
xlim([25 inf])
xlabel('Time (s)')
ylabel('Power (W)')
title(['body' num2str(1) ' (' output.bodies(1).name ') Power'])
legend('power','power w/eff')


%% Calculate Evaluation Criteria (EC)
pto_force = output.ptos(1).forceInternalMechanics(ii:end,3);
pto_displacement = output.ptos(1).position(ii:end,3);

f_98 = prctile(abs(pto_force),98);
f_max = 60;
z_98 = prctile(abs(pto_displacement),98);
z_max = 0.08;
power_average = mean(power_eff);
power_abs_average = mean(abs(power_eff));
P98 = prctile(abs(power_eff),98);

EC = power_average/(2 + f_98/f_max + z_98/z_max - power_abs_average/P98);

67 changes: 67 additions & 0 deletions WECCCOMP/WECCCOMP/userDefinedFunctionsMCR.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
%% Example of user input MATLAB file for MCR post processing
% https://github.com/WEC-Sim/WECCCOMP

%% Save/Store/Plot Data

%Save Power Plot
figname = sprintf('SS%01d.fig', imcr);
savefig (figname)

%Save Data
filename = sprintf('SS%01d.mat', imcr);
save(filename, 'mcr','output','waves','EC');

%Store Data
mcr.power_average(imcr) = power_average;
mcr.pto_damping(imcr) = pto(1).damping;
mcr.EC(imcr) = EC;

%% Close previous results
close all

%% Scripts for last MCR case

if imcr == length(mcr.cases)

%% Load/Store Results
H = mcr.cases(:,1);
T = mcr.cases(:,2);
gamma = mcr.cases(:,3)';
c = mcr.pto_damping';
P = mcr.power_average';
EC = mcr.EC';

%% Plot Power Matrix
figure
mat = [mcr.power_average(4) mcr.power_average(5) mcr.power_average(6);... % Create Power Matrix
mcr.power_average(1) mcr.power_average(2) mcr.power_average(3)];
imagesc(mat); % Create a colored plot of the matrix values
colormap parula
caxis([min(P) max(P)])

textStrings = num2str(mat(:),'%0.2f'); % Create strings from the matrix values
textStrings = strtrim(cellstr(textStrings)); % Remove any space padding
[x,y] = meshgrid(1:3,1:2); % Create x and y coordinates for the strings
hStrings = text(x(:),y(:),textStrings(:),... % Plot the strings
'HorizontalAlignment','center');
midValue = mean(get(gca,'CLim')); % Get the middle value of the color range
textColors = repmat(mat(:) < midValue,1,3); % Choose white or black for the text color
set(hStrings,{'Color'},num2cell(textColors,2)); % Change the text colors
c_bar = colorbar;
c_bar.Label.String = 'Power (Watts)';
set(gca,'XTick',1:3,... % Change the axes tick marks
'XTickLabel',{'[0.0208, 0.9880]','[0.0625, 1.4120]','[0.1042,1.8360]'},... % and tick labels
'YTick',1:2,...
'YTickLabel',{'3.3','1'},...
'TickLength',[0 0]);
xlabel('[ Tp (s), Hs (m) ]')
ylabel('gamma')
title(['Power Matrix for Damping = ' num2str(c(1)) ' [N/m/s]'])

%% Plot Evaluation Criteria
figure
bar(EC)
xlabel('Sea State')
ylabel('Evaluation Criteria (EC)')

end
Loading