Skip to content

Commit 42576be

Browse files
authored
Revert "Control optimal gains interpolation (#96) (#106)"
This reverts commit 21a305b.
1 parent 21a305b commit 42576be

6 files changed

Lines changed: 119 additions & 164 deletions

File tree

Controls/Declutching/optimalTimeCalc.m

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
% This script identifies the dynamics of the float in the respective wave
22
% conditions and determines the optimal proportional gain value for a
33
% passive controller (for regular waves)
4+
45
close all; clear all; clc;
56

6-
dof = 3; % Caluclate for heave motion
77
% Inputs (from wecSimInputFile)
88
simu = simulationClass();
9-
body(1) = bodyClass('../../_Common_Input_Files/Sphere/hydroData/sphere.h5');
10-
waves.height = 2.5; % Wave Height [m]
11-
waves.period = 9.6664; % Wave Period [s]
9+
body(1) = bodyClass('../hydroData/sphere.h5');
10+
waves.height = 1;
11+
waves.period = 3.5;
1212

1313
% Load hydrodynamic data for float from BEM
1414
hydro = readBEMIOH5(body.h5File{1}, 1, body.meanDrift);
@@ -19,62 +19,53 @@
1919
T = waves.period;
2020
omega = (1/T)*(2*pi);
2121

22-
% Extend the freq vector to include the wave frequency
23-
hydro.simulation_parameters.w_extended = sort([hydro.simulation_parameters.w omega]);
24-
omegaIndex = find(hydro.simulation_parameters.w_extended == omega, 1, 'first');
25-
2622
% Define excitation force based on wave conditions
27-
ampSpect = zeros(length(hydro.simulation_parameters.w_extended),1);
28-
ampSpect(omegaIndex) = A;
29-
Fe_re = squeeze(hydro.hydro_coeffs.excitation.re(dof, 1, :)) * simu.rho * simu.gravity;
30-
Fe_im = squeeze(hydro.hydro_coeffs.excitation.im(dof, 1, :)) * simu.rho * simu.gravity;
31-
32-
Fe_interp = interp1(hydro.simulation_parameters.w, Fe_re + 1j * Fe_im, hydro.simulation_parameters.w_extended, 'spline', 'extrap')';
33-
Fexc = ampSpect.*Fe_interp;
23+
ampSpect = zeros(length(hydro.simulation_parameters.w),1);
24+
[~,closestIndOmega] = min(abs(omega-hydro.simulation_parameters.w));
25+
ampSpect(closestIndOmega) = A;
26+
FeRao = squeeze(hydro.hydro_coeffs.excitation.re(3,:))'*simu.rho*simu.gravity + squeeze(hydro.hydro_coeffs.excitation.im(3,:))'*simu.rho*simu.gravity*1j;
27+
Fexc = ampSpect.*FeRao;
3428

3529
% Define the intrinsic mechanical impedance for the device
3630
mass = simu.rho*hydro.properties.volume;
37-
addedMass = squeeze(hydro.hydro_coeffs.added_mass.all(dof, dof, :)) * simu.rho;
38-
addedMass = interp1(hydro.simulation_parameters.w, addedMass, hydro.simulation_parameters.w_extended, 'spline', 'extrap')';
39-
40-
radiationDamping = squeeze(hydro.hydro_coeffs.radiation_damping.all(dof,dof,:)).*squeeze(hydro.simulation_parameters.w')*simu.rho;
41-
radiationDamping = interp1(hydro.simulation_parameters.w, radiationDamping, hydro.simulation_parameters.w_extended, 'spline', 'extrap')';
42-
43-
hydrostaticStiffness = hydro.hydro_coeffs.linear_restoring_stiffness(dof, dof) * simu.rho * simu.gravity;
44-
Gi = -((hydro.simulation_parameters.w_extended)'.^2 .* (mass+addedMass)) + 1j * hydro.simulation_parameters.w_extended'.*radiationDamping + hydrostaticStiffness;
45-
Zi = Gi./(1j*hydro.simulation_parameters.w_extended');
31+
addedMass = squeeze(hydro.hydro_coeffs.added_mass.all(3,3,:))*simu.rho;
32+
radiationDamping = squeeze(hydro.hydro_coeffs.radiation_damping.all(3,3,:)).*squeeze(hydro.simulation_parameters.w')*simu.rho;
33+
hydrostaticStiffness = hydro.hydro_coeffs.linear_restoring_stiffness(3,3)*simu.rho*simu.gravity;
34+
Gi = -((hydro.simulation_parameters.w)'.^2.*(mass+addedMass)) + 1j*hydro.simulation_parameters.w'.*radiationDamping + hydrostaticStiffness;
35+
Zi = Gi./(1j*hydro.simulation_parameters.w');
4636

4737
% Calculate magnitude and phase for bode plot
4838
Mag = 20*log10(abs(Zi));
4939
Phase = (angle(Zi))*(180/pi);
5040

51-
% Determine resonant frequency based on the phase of the impedance
52-
resonantFreq = interp1(Phase, hydro.simulation_parameters.w_extended, 0, 'spline','extrap');
53-
resonantPeriod = (2*pi)/resonantFreq;
41+
% Determine natural frequency based on the phase of the impedance
42+
[~,closestIndNat] = min(abs(imag(Zi)));
43+
natFreq = hydro.simulation_parameters.w(closestIndNat);
44+
natT = (2*pi)/natFreq;
5445

5546
% Create bode plot for impedance
5647
figure()
5748
subplot(2,1,1)
58-
semilogx((hydro.simulation_parameters.w_extended)/(2*pi),Mag)
49+
semilogx((hydro.simulation_parameters.w)/(2*pi),Mag)
5950
xlabel('freq (hz)')
6051
ylabel('mag (dB)')
6152
grid on
62-
xline(resonantFreq/(2*pi))
53+
xline(natFreq/(2*pi))
6354
xline(1/T,'--')
64-
legend('','Resonant Frequency','Wave Frequency','Location','southwest')
55+
legend('','Natural Frequency','Wave Frequency','Location','southwest')
6556

6657
subplot(2,1,2)
67-
semilogx((hydro.simulation_parameters.w_extended)/(2*pi),Phase)
58+
semilogx((hydro.simulation_parameters.w)/(2*pi),Phase)
6859
xlabel('freq (hz)')
6960
ylabel('phase (deg)')
7061
grid on
71-
xline(resonantFreq/(2*pi))
62+
xline(natFreq/(2*pi))
7263
xline(1/T,'--')
73-
legend('','Resonant Frequency','Wave Frequency','Location','northwest')
64+
legend('','Natural Frequency','Wave Frequency','Location','northwest')
7465

7566
% Determine optimal latching time
76-
optDeclutchTime = 0.5*(resonantPeriod - T)
77-
KpOpt = sqrt(radiationDamping(omegaIndex)^2 + ((hydrostaticStiffness/omega) - omega*(mass + addedMass(omegaIndex)))^2)
67+
optDeclutchTime = 0.5*(natT - T)
68+
KpOpt = sqrt(radiationDamping(closestIndOmega)^2 + ((hydrostaticStiffness/omega) - omega*(mass + addedMass(closestIndOmega)))^2)
7869

7970
% Calculate the maximum potential power
8071
P_max = -sum(abs(Fexc).^2./(8*real(Zi)))
Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
% This script identifies the dynamics of the float in the respective wave
2-
% conditions and determines the optimal proportional gain and latching time
3-
% value for a regular wave
2+
% conditions and determines the optimal proportional gain value for a
3+
% passive controller (for regular waves)
4+
45
close all; clear all; clc;
56

6-
dof = 3; % Caluclate for heave motion
77
% Inputs (from wecSimInputFile)
88
simu = simulationClass();
9-
body(1) = bodyClass('../../_Common_Input_Files/Sphere/hydroData/sphere.h5');
9+
body(1) = bodyClass('../hydroData/sphere.h5');
1010
waves.height = 2.5;
1111
waves.period = 9.6664;
1212

@@ -19,64 +19,56 @@
1919
T = waves.period;
2020
omega = (1/T)*(2*pi);
2121

22-
% Extend the freq vector to include the wave frequency
23-
hydro.simulation_parameters.w_extended = sort([hydro.simulation_parameters.w omega]);
24-
omegaIndex = find(hydro.simulation_parameters.w_extended == omega, 1, 'first');
25-
2622
% Define excitation force based on wave conditions
27-
ampSpect = zeros(length(hydro.simulation_parameters.w_extended),1);
28-
[~,closestIndOmega] = min(abs(omega-hydro.simulation_parameters.w_extended));
29-
ampSpect(omegaIndex) = A;
30-
Fe_re = squeeze(hydro.hydro_coeffs.excitation.re(dof, 1, :)) * simu.rho * simu.gravity;
31-
Fe_im = squeeze(hydro.hydro_coeffs.excitation.im(dof, 1, :)) * simu.rho * simu.gravity;
32-
33-
Fe_interp = interp1(hydro.simulation_parameters.w, Fe_re + 1j * Fe_im, hydro.simulation_parameters.w_extended, 'spline', 'extrap')';
34-
Fexc = ampSpect.*Fe_interp;
23+
ampSpect = zeros(length(hydro.simulation_parameters.w),1);
24+
[~,closestIndOmega] = min(abs(omega-hydro.simulation_parameters.w));
25+
ampSpect(closestIndOmega) = A;
26+
FeRao = squeeze(hydro.hydro_coeffs.excitation.re(3,:))'*simu.rho*simu.gravity + squeeze(hydro.hydro_coeffs.excitation.im(3,:))'*simu.rho*simu.gravity*1j;
27+
Fexc = ampSpect.*FeRao;
3528

3629
% Define the intrinsic mechanical impedance for the device
3730
mass = simu.rho*hydro.properties.volume;
38-
addedMass = squeeze(hydro.hydro_coeffs.added_mass.all(dof, dof, :)) * simu.rho;
39-
addedMass = interp1(hydro.simulation_parameters.w, addedMass, hydro.simulation_parameters.w_extended, 'spline', 'extrap')';
40-
41-
radiationDamping = squeeze(hydro.hydro_coeffs.radiation_damping.all(dof,dof,:)).*squeeze(hydro.simulation_parameters.w')*simu.rho;
42-
radiationDamping = interp1(hydro.simulation_parameters.w, radiationDamping, hydro.simulation_parameters.w_extended, 'spline', 'extrap')';
43-
44-
hydrostaticStiffness = hydro.hydro_coeffs.linear_restoring_stiffness(dof, dof) * simu.rho * simu.gravity;
45-
Gi = -((hydro.simulation_parameters.w_extended)'.^2 .* (mass+addedMass)) + 1j * hydro.simulation_parameters.w_extended'.*radiationDamping + hydrostaticStiffness;
46-
Zi = Gi./(1j*hydro.simulation_parameters.w_extended');
31+
addedMass = squeeze(hydro.hydro_coeffs.added_mass.all(3,3,:))*simu.rho;
32+
radiationDamping = squeeze(hydro.hydro_coeffs.radiation_damping.all(3,3,:)).*squeeze(hydro.simulation_parameters.w')*simu.rho;
33+
hydrostaticStiffness = hydro.hydro_coeffs.linear_restoring_stiffness(3,3)*simu.rho*simu.gravity;
34+
Gi = -((hydro.simulation_parameters.w)'.^2.*(mass+addedMass)) + 1j*hydro.simulation_parameters.w'.*radiationDamping + hydrostaticStiffness;
35+
Zi = Gi./(1j*hydro.simulation_parameters.w');
4736

4837
% Calculate magnitude and phase for bode plot
4938
Mag = 20*log10(abs(Zi));
5039
Phase = (angle(Zi))*(180/pi);
5140

52-
% Determine resonant frequency based on the phase of the impedance
53-
resonantFreq = interp1(Phase, hydro.simulation_parameters.w_extended, 0, 'spline','extrap');
54-
resonantPeriod = (2*pi)/resonantFreq;
41+
% Determine natural frequency based on the phase of the impedance
42+
[~,closestIndNat] = min(abs(imag(Zi)));
43+
natFreq = hydro.simulation_parameters.w(closestIndNat);
44+
natT = (2*pi)/natFreq;
5545

5646
% Create bode plot for impedance
5747
figure()
5848
subplot(2,1,1)
59-
semilogx((hydro.simulation_parameters.w_extended)/(2*pi),Mag)
49+
semilogx((hydro.simulation_parameters.w)/(2*pi),Mag)
6050
xlabel('freq (hz)')
6151
ylabel('mag (dB)')
6252
grid on
63-
xline(resonantFreq/(2*pi))
53+
xline(natFreq/(2*pi))
6454
xline(1/T,'--')
65-
legend('','Resonant Frequency','Wave Frequency','Location','southwest')
55+
legend('','Natural Frequency','Wave Frequency','Location','southwest')
6656

6757
subplot(2,1,2)
68-
semilogx((hydro.simulation_parameters.w_extended)/(2*pi),Phase)
58+
semilogx((hydro.simulation_parameters.w)/(2*pi),Phase)
6959
xlabel('freq (hz)')
7060
ylabel('phase (deg)')
7161
grid on
72-
xline(resonantFreq/(2*pi))
62+
xline(natFreq/(2*pi))
7363
xline(1/T,'--')
74-
legend('','Resonant Frequency','Wave Frequency','Location','northwest')
64+
legend('','Natural Frequency','Wave Frequency','Location','northwest')
7565

7666
% Determine optimal latching time
77-
optLatchTime = 0.5*(T - resonantPeriod)
78-
KpOpt = radiationDamping(omegaIndex)
79-
force = 80*(mass+addedMass(omegaIndex))
67+
optLatchTime = 0.5*(T - natT)
68+
KpOpt = radiationDamping(closestIndOmega)
69+
force = 80*(mass+addedMass(closestIndOmega))
8070

8171
% Calculate the maximum potential power
82-
P_max = -sum(abs(Fexc).^2./(8*real(Zi)))
72+
P_max = -sum(abs(Fexc).^2./(8*real(Zi)))
73+
74+
Lines changed: 30 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
% This script identifies the dynamics of the float in the respective wave
22
% conditions and determines the optimal proportional gain value for a
33
% passive controller (for regular waves)
4+
45
close all; clear all; clc;
56

6-
dof = 3; % Caluclate for heave motion
77
% Inputs (from wecSimInputFile)
88
simu = simulationClass();
9-
body(1) = bodyClass('../../_Common_Input_Files/Sphere/hydroData/sphere.h5');
9+
body(1) = bodyClass('../hydroData/sphere.h5');
1010
waves.height = 2.5;
1111
waves.period = 9.6664; % One of periods from BEM
1212

@@ -19,70 +19,57 @@
1919
T = waves.period;
2020
omega = (1/T)*(2*pi);
2121

22-
% Extend the freq vector to include the wave frequency
23-
hydro.simulation_parameters.w_extended = sort([hydro.simulation_parameters.w omega]);
24-
omegaIndex = find(hydro.simulation_parameters.w_extended == omega, 1, 'first');
25-
2622
% Define excitation force based on wave conditions
27-
ampSpect = zeros(length(hydro.simulation_parameters.w_extended),1);
28-
ampSpect(omegaIndex) = A;
29-
Fe_re = squeeze(hydro.hydro_coeffs.excitation.re(dof, 1, :)) * simu.rho * simu.gravity;
30-
Fe_im = squeeze(hydro.hydro_coeffs.excitation.im(dof, 1, :)) * simu.rho * simu.gravity;
31-
32-
Fe_interp = interp1(hydro.simulation_parameters.w, Fe_re + 1j * Fe_im, hydro.simulation_parameters.w_extended, 'spline', 'extrap')';
33-
Fexc = ampSpect.*Fe_interp;
23+
ampSpect = zeros(length(hydro.simulation_parameters.w),1);
24+
[~,closestIndOmega] = min(abs(omega-hydro.simulation_parameters.w));
25+
ampSpect(closestIndOmega) = A;
26+
FeRao = squeeze(hydro.hydro_coeffs.excitation.re(3,:))'*simu.rho*simu.gravity + squeeze(hydro.hydro_coeffs.excitation.im(3,:))'*simu.rho*simu.gravity*1j;
27+
Fexc = ampSpect.*FeRao;
3428

3529
% Define the intrinsic mechanical impedance for the device
36-
mass = simu.rho * hydro.properties.volume;
37-
addedMass = squeeze(hydro.hydro_coeffs.added_mass.all(dof, dof, :)) * simu.rho;
38-
addedMass = interp1(hydro.simulation_parameters.w, addedMass, hydro.simulation_parameters.w_extended, 'spline', 'extrap')';
39-
addedMass = squeeze(hydro.hydro_coeffs.added_mass.inf_freq(dof, dof, :)) * simu.rho;
40-
41-
radiationDamping = squeeze(hydro.hydro_coeffs.radiation_damping.all(dof,dof,:)).*squeeze(hydro.simulation_parameters.w')*simu.rho;
42-
radiationDamping = interp1(hydro.simulation_parameters.w, radiationDamping, hydro.simulation_parameters.w_extended, 'spline', 'extrap')';
43-
44-
hydrostaticStiffness = hydro.hydro_coeffs.linear_restoring_stiffness(dof, dof) * simu.rho * simu.gravity;
45-
Gi = -((hydro.simulation_parameters.w_extended)'.^2 .* (mass+addedMass)) + 1j * hydro.simulation_parameters.w_extended'.*radiationDamping + hydrostaticStiffness;
46-
Zi = Gi./(1j*hydro.simulation_parameters.w_extended');
30+
mass = simu.rho*hydro.properties.volume;
31+
addedMass = squeeze(hydro.hydro_coeffs.added_mass.all(3,3,:))*simu.rho;
32+
radiationDamping = squeeze(hydro.hydro_coeffs.radiation_damping.all(3,3,:)).*squeeze(hydro.simulation_parameters.w')*simu.rho;
33+
hydrostaticStiffness = hydro.hydro_coeffs.linear_restoring_stiffness(3,3)*simu.rho*simu.gravity;
34+
Gi = -((hydro.simulation_parameters.w)'.^2.*(mass+addedMass)) + 1j*hydro.simulation_parameters.w'.*radiationDamping + hydrostaticStiffness;
35+
Zi = Gi./(1j*hydro.simulation_parameters.w');
4736

4837
% Calculate magnitude and phase for bode plot
4938
Mag = 20*log10(abs(Zi));
5039
Phase = (angle(Zi))*(180/pi);
5140

52-
% Determine resonant frequency based on the phase of the impedance
53-
resonantFreq = interp1(Phase, hydro.simulation_parameters.w_extended, 0, 'spline','extrap');
54-
resonantPeriod = (2*pi)/resonantFreq;
41+
% Determine natural frequency based on the phase of the impedance
42+
[~,closestIndNat] = min(abs(imag(Zi)));
43+
natFreq = hydro.simulation_parameters.w(closestIndNat);
44+
T0 = (2*pi)/natFreq;
5545

5646
% Create bode plot for impedance
5747
figure()
5848
subplot(2,1,1)
59-
semilogx((hydro.simulation_parameters.w_extended)/(2*pi),Mag)
60-
xlabel('freq (hz)','interpreter','latex')
61-
ylabel('mag (dB)','interpreter','latex')
49+
semilogx((hydro.simulation_parameters.w)/(2*pi),Mag)
50+
xlabel('freq (hz)')
51+
ylabel('mag (dB)')
6252
grid on
63-
xline(resonantFreq/(2*pi))
53+
xline(natFreq/(2*pi))
6454
xline(1/T,'--')
65-
legend('','Resonant Frequency','Wave Frequency','Location','southwest','interpreter','latex')
55+
legend('','Natural Frequency','Wave Frequency','Location','southwest')
6656

6757
subplot(2,1,2)
68-
semilogx((hydro.simulation_parameters.w_extended)/(2*pi),Phase)
69-
xlabel('freq (hz)','interpreter','latex')
70-
ylabel('phase (deg)','interpreter','latex')
58+
semilogx((hydro.simulation_parameters.w)/(2*pi),Phase)
59+
xlabel('freq (hz)')
60+
ylabel('phase (deg)')
7161
grid on
72-
xline(resonantFreq/(2*pi))
62+
xline(natFreq/(2*pi))
7363
xline(1/T,'--')
74-
legend('','Resonant Frequency','Wave Frequency','Location','northwest','interpreter','latex')
64+
legend('','Natural Frequency','Wave Frequency','Location','northwest')
7565

7666
% Calculate the maximum potential power
77-
P_max = -sum(abs(Fexc).^2./(8*real(Zi)));
78-
fprintf('Maximum potential power P_max = %f\n', P_max);
67+
P_max = -sum(abs(Fexc).^2./(8*real(Zi)))
7968

8069
% Optimal proportional gain for passive control:
81-
KpOpt = sqrt(radiationDamping(omegaIndex)^2 + ((hydrostaticStiffness/omega) - omega*(mass + addedMass))^2);
70+
KpOpt = sqrt(radiationDamping(closestIndOmega)^2 + ((hydrostaticStiffness/omega) - omega*(mass + addedMass(closestIndOmega)))^2)
8271
Ki = 0;
83-
fprintf('Optimal proportional gain for passive control KpOpt = %f\n', KpOpt);
8472

8573
% Calculate expected power with optimal passive control
8674
Zpto = KpOpt + Ki/(1j*omega);
87-
P = -sum(0.5*real(Zpto).*((abs(Fexc)).^2./(abs(Zpto+Zi)).^2));
88-
fprintf('Expected power with optimal passive control P = %f\n', P);
75+
P = -sum(0.5*real(Zpto).*((abs(Fexc)).^2./(abs(Zpto+Zi)).^2))

Controls/Passive (P)/userDefinedFunctionsMCR.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
mcr.maxPower(imcr) = max(controllersOutput.power(startInd:endInd,3));
1818
mcr.maxForce(imcr) = max(controllersOutput.force(startInd:endInd,3));
1919

20-
if imcr == length(mcr.cases)
20+
if imcr == 9
2121
figure()
2222
plot(mcr.cases,mcr.meanPower)
2323
title('Mean Power vs. Proportional Gain')

0 commit comments

Comments
 (0)