Appix B 1) Directional Spectrum Matlab code to produce Directional Spectrums based on data from Scripps Buoys DATA RETRIEVED FROM: Scripps Coastal Data Information Program http://cdip.ucsd.edu/ --->Historic--->Interactive products ---> Interactive data---->spectral data the data must be an ascii file with no text By Rodrigo Arrea, 11/6/09 ------------------------------------------------------------------------------------------------ Load numerical data load 200710220454.txt data=x200710220454; Figure out the y axis limit in the non-directional graphs, so that the limit is always the same and the spectrums can be compared limy=1.1*ceil(max(data(:,3))); Extract the useful data [s,v]=size(data); Each spectral data file has 64 frequencies, in case of consecutive data... n=s/64; for q=1:n; lf=(q-1)*64+1; hf=64*q; spec=data(lf:hf,1:9); Divide the data into variables f=spec(1:64,1); d=spec(1:64,2); E=spec(1:64,3); a1=spec(1:64,5); b1=spec(1:64,6); a2=spec(1:64,7); b2=spec(1:64,8); Calculate R1 R2 Theta1 and Theta2 r1=sqrt(a1.^2+b1.^2); r2=sqrt(a2.^2+b2.^2); theta1=atan2(b1,a1); theta2=0.5*atan2(b2,a2); Change radians into degrees for u=1:64; a=theta1(u,1); b=theta2(u,1); theta1(u,1)=a*180/pi; theta2(u,1)=b*180/pi; Avoid negative angles if theta1(u)<=0 theta1(u)=theta1(u) + 360; if theta2(u)<=0 theta2(u)=theta2(u)+360; Calculate directional energy dir=(0:3:360); S=zeros(64,121); X=zeros(64,121); Y=zeros(64,121); alpha=zeros(size(dir)); The angles are changed to nautical convention for i=1:121; if dir(1,i)<=90 alpha(1,i)=90-dir(1,i); elseif 90<dir(1,i)<=360
alpha(1,i)=450-dir(1,i); S(1:64,i)=1/pi.*(0.5+r1.*cosd(dir(1,i)-theta1)+r2.*cosd((dir(1,i)-theta2)....*2)); Nautical convention is used to graph for i=1:121; X(1:64,i)=f.*cosd(alpha(1,i)); Y(1:64,i)=f.*sind(alpha(1,i)); Significant wave height, peak period, Mean direction m0=0; for p=1:63 m0=d(p,1)*(e(p,1)+e(p+1,1))/2+m0; Hs=4*sqrt(m0); [y,v]=max(e); Tp=1/f(v,1); Graph's grid g1=0.05; xg1=-g1:0.01:g1; g2=0.1; xg2=-g2:.01:g2; g3=0.2; xg3=-g3:.01:g3; g4=0.4; xg4=-g4:.01:g4; g5=0.58; xg5=-g5:.01:g5; T1=1/g1; T2=1/g2; T3=1/g3; T4=1/g4; T5=1/g5; yg5=zeros(size(xg5)); color axis cmax=max(max(s))*1.02; ------PLOTS---------------- close all scrsz = get(0,'screensize'); figure('position',[scrsz(1) scrsz(2) scrsz(3) scrsz(4)]) subplot(2,3,[1 2 4 5]); set(gcf,'color','white') hold on h_plot=pcolor(x,y,s); caxis([0.4 cmax]) set(gcf,'defaultaxesfontsize',18) ('location','northoutside') set(h_plot,'facecolor','interp','facealpha',1); shading flat axis equal tight off hold on Period gridlines (round) line(xg1,real(sqrt(g1^2-xg1.^2)),'linewidth',2,'linestyle','--','color','k') line(xg1,-real(sqrt(g1^2-xg1.^2)),'linewidth',2,'linestyle','--','color','k') line(xg2,real(sqrt(g2^2-xg2.^2)),'linewidth',2,'linestyle','--','color','k') line(xg2,-real(sqrt(g2^2-xg2.^2)),'linewidth',2,'linestyle','--','color','k') line(xg3,real(sqrt(g3^2-xg3.^2)),'linewidth',2,'linestyle','--','color','k') line(xg3,-real(sqrt(g3^2-xg3.^2)),'linewidth',2,'linestyle','--','color','k') line(xg4,real(sqrt(g4^2-xg4.^2)),'linewidth',2,'linestyle','--','color','k') line(xg4,-real(sqrt(g4^2-xg4.^2)),'linewidth',2,'linestyle','--','color','k') line(xg5,real(sqrt(g5^2-xg5.^2)),'linewidth',2,'linestyle','--','color','k') line(xg5,-real(sqrt(g5^2-xg5.^2)),'linewidth',2,'linestyle','--','color','k') text(0,g1,[num2str(t1),' s'],'horizontalalignment','center',... 'Fontsize',16,'Color','w','fontweight','bold') text(0,g2,[num2str(t2),' s'],'horizontalalignment','center',... 'Fontsize',16,'Color','w','fontweight','bold') text(0,g3,[num2str(t3),' s'],'horizontalalignment','center',... 'Fontsize',16,'Color','w','fontweight','bold') text(0,g4,[num2str(t4),' s'],'horizontalalignment','center',...
'Fontsize',16,'Color','w','fontweight','bold') text(0,g5,['t=',num2str(t5),' s'],'horizontalalignment',... 'center','fontsize',16,'verticalalignment','top','color','w',... 'fontweight','bold') Direction gridlines line(yg5,xg5,'linewidth',1,'linestyle',':','color','k') line(xg5,yg5,'linewidth',1,'linestyle',':','color','k') z=(-g5*sind(45):0.01:g5*sind(45)); line(z,z,'linewidth',1,'linestyle',':','color','k') line(-z,z,'linewidth',1,'linestyle',':','color','k') text(0,g5,'0\circ','horizontalalignment','center','verticalalignment','bottom',... text(g5,0,' 90\circ','horizontalAlignment','left','verticalalignment','middle',... text(0,-g5,'180\circ','horizontalalignment','center','verticalalignment','top',... text(-g5,0,'270\circ ','horizontalalignment','right','verticalalignment','middle',... Energy Spectrum subplot(2,3,3);plot(f,e,'linewidth',2); xlim([0 0.58]) ylim([0 limy]) xlabel('wave frequency, Hz ','FontSize',18) ylabel('energy, m^2/hz','fontsize',18) title({['measured Spectrum'];['Hs=',num2str(Hs),' & Tp=',num2str(Tp)]},'FontSize',20) Pierson Moskowitz Spectrum A=5/16*Hs^2*f(v,1)^4; B=5*f(v,1)^4/4; SPM=zeros(64,1); for i=1:64; SPM(i,1)=30*60*A*exp(-B/f(i,1)^4)/f(i,1)^2; JONSWAP Spectrum SJ=zeros(64,1); gam=2.7; sig1=0.07; sig2=0.09; sig=zeros(64,1); for i=1:64; if f(i,1)<=f(v,1) sig(i,1)=sig1; elseif f(i,1)>f(v,1) sig(i,1)=sig2; SJ(i,1)=SPM(i,1)*gam^exp(-(f(i,1)-f(v,1))^2/(2*(sig(i,1))^2*(f(v,1))^2)); subplot(2,3,6);plot(f,spm,f,sj,'linewidth',2); xlim([0 0.58]) ylim([0 limy]) xlabel('wave frequency, Hz ','FontSize',18) ylabel('energy, m^2/hz','fontsize',18) leg('spm',['sj, gamma= ',num2str(gam)],'location',[.8.3.1.1]) leg('boxoff') title({['spm = Pierson-Moskowitz '];['SJ = JONSWAP spectrum ']},'Fontsize',20) 2) Theoretical Transmission Coefficient I) For swell waves MATlab code for calculating theoretical trasmission coefficients of wave filters following the following assumptions: -Linear Wave Theory -Seas behave as deep-water waves, and swell as shallow-water waves. -Horizontal particle displacement amplitude is proportional to kinematic wave energy -All the wave energy above the draft is blocked and all the wave
energy below is transmitted By Rodrigo Arrea, 11/6/09 ------------------------------------------------------------------------------------- Swell Conditions: T=10:15, and H=0.1:1 Ts=(10:0.2:15); [m1 n1]=size(ts); Hs=(0.1:0.05:1); [m2 n2]=size(hs); Hs=Hs'; d=0:-0.1:-10; [m3 n3]=size(d); Ld=1.56.*Ts.^2; deep water equation Ls=zeros(1,n1); for p=1:100 Ls(i)=Ld(i)*tanh(2*pi*10/Ls(i)); ks=2*pi./ls; as=2;does not affect the transmission coefficient compute a matrix with the horizontal disp. amplitudes for all wave periods and depths Hs(k,i)=as*cosh(ks(i)*(d(k)+10))/(sinh(ks(i)*10)); Get the total 'Energy' of the entire thing, by integrating the displacement over the depth Es=zeros(1,n1); for i=1:n1 Es(i)=Es(i)+Hs(k,i)*0.1; Find the amount of energy blocked by different drafts dr=(-0.1:-0.1:-2.0); [m4 n4]=size(dr); Bs=zeros(20,n1); for z=1:n4; y=z+1; for k=1:y; Bs(z,i)=Bs(z,i)+Hs(k,i)*0.1; Calculate the transmission coefficient Cts=zeros(20,n1); for z=1:20; Cts(z,i)=(Es(i)-Bs(z,i))/Es(i); set(gcf,'color','white','defaultaxesfontsize',18) pcolor(cts) set(gca,'ydir','reverse') xlabel('wave Period, [sec]') ylabel('wave Filter Draft, [m]')
II) For wind-waves MATlab code for calculating theoretical trasmission coefficients of wave filters following the following assumptions: -Linear Wave Theory -Seas behave as deep-water waves, and swell as shallow-water waves. -Horizontal particle displacement amplitude is proportional to kinematic wave energy -All the wave energy above the draft is blocked and all the wave energy below is transmitted By Rodrigo Arrea, 11/6/09 ----------------------------------------------------------------------------------------- SEAS (chop) Tc=(0.5:0.1:3.5); [m1 n1]=size(tc); Hc=(0.1:0.05:1); [m2 n2]=size(hc); Hc=Hc'; d=0:-0.1:-10; [m3 n3]=size(d); Lc=1.56.*Tc.^2; kc=2*pi./lc; ac=1.3; compute a matrix with the horizontal disp. amplitudes for all wave periods and depths Hc(k,i)=ac*exp(kc(i)*d(k)); Get the total 'Energy' of the entire thing, by integrating the displacement over the depth Ec=zeros(1,n1); for i=1:n1 Ec(i)=Ec(i)+Hc(k,i)*0.1; Find the amount of energy blocked by different drafts dr=(-0.1:-0.1:-2.0); [m4 n4]=size(dr); Bc=zeros(20,n1); for z=1:n4; y=z+1; for k=1:y; Bc(z,i)=Bc(z,i)+Hc(k,i)*0.1; Calculate the transmission coefficient Ctc=zeros(20,n1); for z=1:20; Ctc(z,i)=(Ec(i)-Bc(z,i))/Ec(i); set(gcf,'color','white','defaultaxesfontsize',18) pcolor(ctc) set(gca,'ydir','reverse') xlabel('wave Period, [sec] ') ylabel('wave Filter Draft, [m] ')
3) Wind-waves forecast Source code to calculate the forecasted wave height and period due to a constant wind and deping on different fetches. Gives two figures one with the wave height and the other with the wave period By Rodrigo Arrea, 11/06/09 Wind speed U10=(0.05:0.05:20); Fetch Length X=(20:20:20000); Drag Coefficient CD=0.001*(1.1+0.035.*U10); Gravity g=9.81; friction velocity u=sqrt(u10.^2.*cd); wave height [m n]=size(u10); [v b]=size(x); H=zeros(b,n); for i=1:n; for j=1:b; H(j,i)=u(i)^2/g*0.0413*sqrt(g*X(j)/u(i)^2); wave period T=zeros(b,n); for i=1:n; for j=1:b; T(j,i)=u(i)/g*0.651*(g*X(j)/u(i)^2)^(1/3); close all ---PLOTS--- figure scrsz = get(0,'screensize'); set(gcf,'color','white','defaultaxesfontsize',20,'position',... [scrsz(1) scrsz(2) scrsz(3) scrsz(4)]) pcolor(h); xlabel('u_1_0, wind speed at 10 meters above water level [m/s] ') ylabel('x, Fetch Length [km] ') title('predicted wind-wave height in meters ') figure scrsz = get(0,'screensize'); set(gcf,'color','white','defaultaxesfontsize',20,'position',... [scrsz(1) scrsz(2) scrsz(3) scrsz(4)]) pcolor(t); xlabel('u_1_0, wind speed at 10 meters above water level [m/s] ') ylabel('x, Fetch Length [km] ') title('predicted wind-wave period in seconds ')