|
1 | 1 | % This script identifies the dynamics of the float in the respective wave |
2 | 2 | % conditions and determines the optimal proportional gain value for a |
3 | 3 | % passive controller (for regular waves) |
| 4 | + |
4 | 5 | close all; clear all; clc; |
5 | 6 |
|
6 | | -dof = 3; % Caluclate for heave motion |
7 | 7 | % Inputs (from wecSimInputFile) |
8 | 8 | simu = simulationClass(); |
9 | | -body(1) = bodyClass('../../_Common_Input_Files/Sphere/hydroData/sphere.h5'); |
| 9 | +body(1) = bodyClass('../hydroData/sphere.h5'); |
10 | 10 | waves.height = 2.5; |
11 | 11 | waves.period = 9.6664; % One of periods from BEM |
12 | 12 |
|
|
19 | 19 | T = waves.period; |
20 | 20 | omega = (1/T)*(2*pi); |
21 | 21 |
|
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 | | - |
26 | 22 | % 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; |
34 | 28 |
|
35 | 29 | % 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'); |
47 | 36 |
|
48 | 37 | % Calculate magnitude and phase for bode plot |
49 | 38 | Mag = 20*log10(abs(Zi)); |
50 | 39 | Phase = (angle(Zi))*(180/pi); |
51 | 40 |
|
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; |
55 | 45 |
|
56 | 46 | % Create bode plot for impedance |
57 | 47 | figure() |
58 | 48 | 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)') |
62 | 52 | grid on |
63 | | -xline(resonantFreq/(2*pi)) |
| 53 | +xline(natFreq/(2*pi)) |
64 | 54 | xline(1/T,'--') |
65 | | -legend('','Resonant Frequency','Wave Frequency','Location','southwest','interpreter','latex') |
| 55 | +legend('','Natural Frequency','Wave Frequency','Location','southwest') |
66 | 56 |
|
67 | 57 | 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)') |
71 | 61 | grid on |
72 | | -xline(resonantFreq/(2*pi)) |
| 62 | +xline(natFreq/(2*pi)) |
73 | 63 | xline(1/T,'--') |
74 | | -legend('','Resonant Frequency','Wave Frequency','Location','northwest','interpreter','latex') |
| 64 | +legend('','Natural Frequency','Wave Frequency','Location','northwest') |
75 | 65 |
|
76 | 66 | % 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))) |
79 | 68 |
|
80 | 69 | % 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) |
82 | 71 | Ki = 0; |
83 | | -fprintf('Optimal proportional gain for passive control KpOpt = %f\n', KpOpt); |
84 | 72 |
|
85 | 73 | % Calculate expected power with optimal passive control |
86 | 74 | 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)) |
0 commit comments