close all
clear all


a = 1;
D = 2*a;
rho = 1025;
g = 9.81;


drafts = [4 2 1 .6 .4 .2];  % 0.1];

for i = 1:length(drafts)

  d = drafts(i);
  
  V = pi*d*a^2;
  
  filename = ['t_cyl_d' num2str(d)]

  FD_coefs{i} = Readwdra3dResults([filename '.out']);
    
  
  w_nd = FD_coefs{i}.w*sqrt(D/g);  %The same for all drafts so no need to index
  w_nd_smooth = w_nd(1):(w_nd(end)-w_nd(1))/100:w_nd(end);

  am_nd(i,:) = real(FD_coefs{i}.F{3,3})/(rho*V);
  am_nd_smooth(i,:) = interp1(w_nd,am_nd(i,:),w_nd_smooth,'PCHIP');
  
  dmp_nd(i,:) = imag(FD_coefs{i}.F{3,3})./(rho*V*FD_coefs{i}.w);
  dmp_nd_smooth(i,:) = interp1(w_nd,dmp_nd(i,:),w_nd_smooth,'PCHIP');
  
  
  
  roll_am_nd(i,:) = real(FD_coefs{i}.F{5,5})/(rho*V*D^2);
  roll_am_nd_smooth(i,:) = interp1(w_nd,roll_am_nd(i,:),w_nd_smooth,'PCHIP');
  
  roll_dmp_nd(i,:) = imag(FD_coefs{i}.F{5,5})./(rho*V*D^2*FD_coefs{i}.w);
  roll_dmp_nd_smooth(i,:) = interp1(w_nd,roll_dmp_nd(i,:),w_nd_smooth,'PCHIP');
 
  
  
  exct_nd(i,:) = abs(FD_coefs{i}.F{7,3})./(rho*V);
  exct_nd_smooth(i,:) = interp1(w_nd,exct_nd(i,:),w_nd_smooth,'PCHIP');
  
  roll_exct_nd(i,:) = abs(FD_coefs{i}.F{7,5})./(rho*V*D*(FD_coefs{i}.w).^2);
  roll_exct_nd_smooth(i,:) = interp1(w_nd,roll_exct_nd(i,:),w_nd_smooth,'PCHIP');
  
  leg_str{i} = ['$d/D = ' num2str(d/D) ' $ \hspace{.1in}'];
  
end


figure('Position',[1000 402 950 1096],'PaperOrientation','portrait','PaperPositionMode','auto');
subplot(3,1,1)
plot(w_nd_smooth,am_nd_smooth);
%hold on
%plot(w_nd,am_nd,'x');
lh = legend(leg_str);
set(lh,'Interpreter','Latex');
alh = xlabel('Non-dimensional Frequency $\left( \omega \sqrt{\frac{D}{g}} \right)$');
set(alh,'Interpreter','Latex');
alh = ylabel('Added-Mass $\left( \frac{a_{33}}{\rho \bigtriangledown} \right)$');
set(alh,'Interpreter','Latex');
%th = title('Heave Added Mass for Cylindrical Buoy');
%set(th,'Interpreter','Latex');
grid on
xlim([0 5]);

subplot(3,1,2)
plot(w_nd_smooth,dmp_nd_smooth);
%hold on
%plot(w_nd,dmp_nd,'x')
lh = legend(leg_str);
set(lh,'Interpreter','Latex');
alh = xlabel('Non-dimensional Frequency $\left( \omega \sqrt{\frac{D}{g}} \right)$');
set(alh,'Interpreter','Latex');
alh = ylabel('Damping $\left( \frac{b_{33}}{\rho \omega \bigtriangledown} \right)$');
set(alh,'Interpreter','Latex');
%th = title('Heave Damping for Cylindrical Buoy');
%set(th,'Interpreter','Latex');
grid on
xlim([0 5]);

subplot(3,1,3)
plot(w_nd_smooth,exct_nd_smooth);
%hold on
%plot(w_nd,exct_nd,'x');
lh = legend(leg_str);
set(lh,'Interpreter','Latex');

alh = xlabel('Non-dimensional Frequency $\left( \omega \sqrt{\frac{D}{g}} \right)$');
set(alh,'Interpreter','Latex');
alh = ylabel('Exciting Force Magnitude $\left( \frac{| X_{33} |}{\rho \bigtriangledown} \right)$');
set(alh,'Interpreter','Latex');
%th = title('Heave Exciting Force Magnitude for Cylindrical Buoy');
%set(th,'Interpreter','Latex');
grid on
xlim([0 5]);


print('-dpdf','CylindricalBuoy_HeaveHydroDynamics');


figure('Position',[1000 402 950 1096],'PaperOrientation','portrait','PaperPositionMode','auto');
subplot(3,1,1)
plot(w_nd_smooth,roll_am_nd_smooth);
%hold on
%plot(w_nd,roll_am_nd,'x');
lh = legend(leg_str);
set(lh,'Interpreter','Latex');
alh = xlabel('Non-dimensional Frequency $\left( \omega \sqrt{\frac{D}{g}} \right)$');
set(alh,'Interpreter','Latex');
alh = ylabel('Added-Mass $\left( \frac{a_{55}}{\rho D^2 \bigtriangledown} \right)$');
set(alh,'Interpreter','Latex');
%th = title('Roll Added Mass for Cylindrical Buoy');
%set(th,'Interpreter','Latex');
grid on
xlim([0 5]);

subplot(3,1,2)
plot(w_nd_smooth,roll_dmp_nd_smooth);
%hold on
%plot(w_nd,roll_dmp_nd,'x')
lh = legend(leg_str);
set(lh,'Interpreter','Latex');
alh = xlabel('Non-dimensional Frequency $\left( \omega \sqrt{\frac{D}{g}} \right)$');
set(alh,'Interpreter','Latex');
alh = ylabel('Non-dimensional Damping $\left( \frac{b_{55}}{\rho \omega D^2 \bigtriangledown} \right)$');
set(alh,'Interpreter','Latex');
%th = title('Roll Damping for Cylindrical Buoy');
%set(th,'Interpreter','Latex');
grid on
xlim([0 5]);

subplot(3,1,3)
plot(w_nd_smooth,roll_exct_nd_smooth);
%hold on
%plot(w_nd,roll_exct_nd,'x')
lh = legend(leg_str);
set(lh,'Interpreter','Latex');
alh = xlabel('Non-dimensional Frequency $\left( \omega \sqrt{\frac{D}{g}} \right)$');
set(alh,'Interpreter','Latex');
alh = ylabel('Exciting Force Magnitude $\left( \frac{| X_{55} |}{\rho \omega^2 D \bigtriangledown} \right)$');
set(alh,'Interpreter','Latex');
%th = title('Roll Exciting Force Magnitude for Cylindrical Buoy');
%set(th,'Interpreter','Latex');
grid on
xlim([0 5]);

print('-dpdf','CylindricalBuoy_RollHydroDynamics');

