|
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 | | - |
5 | 4 | close all; clear all; clc; |
6 | 5 |
|
| 6 | +dof = 3; % Caluclate for heave motion |
7 | 7 | % Inputs (from wecSimInputFile) |
8 | 8 | simu = simulationClass(); |
9 | | -body(1) = bodyClass('../hydroData/sphere.h5'); |
| 9 | +body(1) = bodyClass('../../_Common_Input_Files/Sphere/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 | + |
22 | 26 | % Define excitation force based on wave conditions |
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; |
| 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; |
28 | 34 |
|
29 | 35 | % Define the intrinsic mechanical impedance for the device |
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'); |
| 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'); |
36 | 47 |
|
37 | 48 | % Calculate magnitude and phase for bode plot |
38 | 49 | Mag = 20*log10(abs(Zi)); |
39 | 50 | Phase = (angle(Zi))*(180/pi); |
40 | 51 |
|
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; |
| 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; |
45 | 55 |
|
46 | 56 | % Create bode plot for impedance |
47 | 57 | figure() |
48 | 58 | subplot(2,1,1) |
49 | | -semilogx((hydro.simulation_parameters.w)/(2*pi),Mag) |
50 | | -xlabel('freq (hz)') |
51 | | -ylabel('mag (dB)') |
| 59 | +semilogx((hydro.simulation_parameters.w_extended)/(2*pi),Mag) |
| 60 | +xlabel('freq (hz)','interpreter','latex') |
| 61 | +ylabel('mag (dB)','interpreter','latex') |
52 | 62 | grid on |
53 | | -xline(natFreq/(2*pi)) |
| 63 | +xline(resonantFreq/(2*pi)) |
54 | 64 | xline(1/T,'--') |
55 | | -legend('','Natural Frequency','Wave Frequency','Location','southwest') |
| 65 | +legend('','Resonant Frequency','Wave Frequency','Location','southwest','interpreter','latex') |
56 | 66 |
|
57 | 67 | subplot(2,1,2) |
58 | | -semilogx((hydro.simulation_parameters.w)/(2*pi),Phase) |
59 | | -xlabel('freq (hz)') |
60 | | -ylabel('phase (deg)') |
| 68 | +semilogx((hydro.simulation_parameters.w_extended)/(2*pi),Phase) |
| 69 | +xlabel('freq (hz)','interpreter','latex') |
| 70 | +ylabel('phase (deg)','interpreter','latex') |
61 | 71 | grid on |
62 | | -xline(natFreq/(2*pi)) |
| 72 | +xline(resonantFreq/(2*pi)) |
63 | 73 | xline(1/T,'--') |
64 | | -legend('','Natural Frequency','Wave Frequency','Location','northwest') |
| 74 | +legend('','Resonant Frequency','Wave Frequency','Location','northwest','interpreter','latex') |
65 | 75 |
|
66 | 76 | % Calculate the maximum potential power |
67 | | -P_max = -sum(abs(Fexc).^2./(8*real(Zi))) |
| 77 | +P_max = -sum(abs(Fexc).^2./(8*real(Zi))); |
| 78 | +fprintf('Maximum potential power P_max = %f\n', P_max); |
68 | 79 |
|
69 | 80 | % Optimal proportional gain for passive control: |
70 | | -KpOpt = sqrt(radiationDamping(closestIndOmega)^2 + ((hydrostaticStiffness/omega) - omega*(mass + addedMass(closestIndOmega)))^2) |
| 81 | +KpOpt = sqrt(radiationDamping(omegaIndex)^2 + ((hydrostaticStiffness/omega) - omega*(mass + addedMass))^2); |
71 | 82 | Ki = 0; |
| 83 | +fprintf('Optimal proportional gain for passive control KpOpt = %f\n', KpOpt); |
72 | 84 |
|
73 | 85 | % Calculate expected power with optimal passive control |
74 | 86 | Zpto = KpOpt + Ki/(1j*omega); |
75 | | -P = -sum(0.5*real(Zpto).*((abs(Fexc)).^2./(abs(Zpto+Zi)).^2)) |
| 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); |
0 commit comments