- % WAVE SIMULATION
- Hs=15; %significant wave height
- Tz=15; % zero upcrossing time
- g=9.81;
- d=500; %water depth
- f=linspace(0.01,.2,100); % frequency
- f0=((1/(2*pi))*sqrt(0.161*g/Hs));% peak frequency
- q=f/f0;
- Sf=(5*Hs^2/(16*f0))./q.^5.*exp(q.^-4.*-1.25); %energy density for unidirectional random wave
- w=2*pi*f;
- %Sf=(Tz*Hs^2/(8*(pi^2))*((Tz*f).^-5).*exp((-1/pi)*((Tz*f)).^-4));
- s=1;% spreading factor
- Ns=(gamma(s))/((sqrt(pi))*(gamma(s+0.5)));%normalising factor
- gg=1;
- thet0=0;
- for thet=(-pi:pi/36:pi);% direction
- if abs(thet-thet0) <=(pi/2)
- hh=Ns.*((cos(thet)).^2);
- else
- hh=0;
- end
- disp(hh);
- G(gg)=hh;
- the(gg)=thet;
- gg=gg+1;
- end
- th=(the*180/pi)';
- SSf=(Sf'*G);%energy density for multidirectional random wave
- figure(1)
- surf(th,f,SSf)
- xlabel('theta(deg)')
- ylabel('f(Hz)')
- zlabel('Sf')
- figure(1)
- grid on
- title('Plot of Wave Spectrum')
- x=0;
- y=0;
- deltaf=0.001;
- deltath=pi/18;
- eta=zeros(length(f),length(the)); %wave elevation
- u1=zeros(length(f),length(the)); % hoizontal water particle velocity in x direction
- v1=zeros(length(f),length(the)); % hoizontal water particle velocity in y direction
- w1=zeros(length(f),length(the)); % vertical water particle velocity
- ua1=zeros(length(f),length(the));% hoizontal water particle acceleration in x direction
- va1=zeros(length(f),length(the));% hoizontal water particle acceleration in y direction
- wa1=zeros(length(f),length(the));% vertcal water particle acceleration
- Fx=zeros(length(f),length(the));% force in x direction
- Fy=zeros(length(f),length(the));% force in y direction
- Fz=zeros(length(f),length(the));% force in z direction
- Mx=zeros(length(f),length(the));% moment in x direction
- My=zeros(length(f),length(the));% moment in y direction
- Mz=zeros(length(f),length(the));% moment in z direction
- m=1;
- T = 0;
- for x=(1:1:100);
- for y = (1:100);
- eta(x,y)=0;
- u1(x,y)=0;
- v1(x,y)=0;
- w1(x,y)=0;
- ua1(x,y)=0;
- va1(x,y)=0;
- wa1(x,y)=0;
- for j=1:(length(f)-1); % loop for frequecy run
- n=1;
- for i=1:(length(the)-1);% loop for direction run
- Sn(j,i)=(SSf(j,i)+SSf((j),(i+1)))/2;% energy densty
- Aa(j,i)=sqrt(2*Sn(j,i)*deltaf*deltath);% amplitude
- Ff(j)=(f(j)+f((j+1)))/2;
- Tpp(j)=1/Ff(j);
- phi(j,i)=rand*2*pi;%phase shift
- Lo(j)=1.56.*Tpp(j).^2;%initial wave length
- L(j)=(g.*(Tpp(j).^2)/(2*pi)).*tanh(2*pi*d./Lo(j));%wave length
- Lo(j)=L(j);
- kj(j)=(2*pi)./L(j);% wave number
- eta(x,y) = eta(x,y) + Aa(j,i)*(cos((kj(j)*x*cos(the(i)))+(kj(j)*y*sin(the(i)))-(2*pi*Ff(j)*T)+(phi(j,i))));
- u1(x,y)=u1(x,y) +((2*pi)*Aa(j,i)*2*pi*Ff(j)*cosh(kj(j)*(y))*cos(thet0)*(cos((kj(j)*x*cos(the(i)))+(kj(j)*y*sin(the(i)))-(2*pi*Ff(j)*T)+(phi(j,i))))/sinh(kj(j)*(d+eta(j,i))));
- v1(x,y)=v1(x,y) +((2*pi)*Aa(j,i)*2*pi*Ff(j)*cosh(kj(j)*(y))*sin(thet0)*(cos((kj(j)*x*cos(the(i)))+(kj(j)*y*sin(the(i)))-(2*pi*Ff(j)*T)+(phi(j,i))))/sinh(kj(j)*(d+eta(j,i))));
- w1(x,y)=w1(x,y) +((2*pi)*Aa(j,i)*2*pi*Ff(j)*sinh(kj(j)*(y))*(sin((kj(j)*x*cos(the(i)))+(kj(j)*y*sin(the(i)))-(2*pi*Ff(j)*T)+(phi(j,i))))/sinh(kj(j)*(d+eta(j,i))));
- ua1(x,y)=ua1(x,y) +((4*(pi^2))*Aa(j,i)*(2*pi*Ff(j))^2*cosh(kj(j)*(y))*cos(thet0)*(sin((kj(j)*x*cos(the(i)))+(kj(j)*y*sin(the(i)))-(2*pi*Ff(j)*T)+(phi(j,i))))/sinh(kj(j)*(d+eta(j,i))));
- va1(x,y)=va1(x,y) +((4*(pi^2))*Aa(j,i)*(2*pi*Ff(j))^2*cosh(kj(j)*(y))*sin(thet0)*(sin((kj(j)*x*cos(the(i)))+(kj(j)*y*sin(the(i)))-(2*pi*Ff(j)*T)+(phi(j,i))))/sinh(kj(j)*(d+eta(j,i))));
- wa1(x,y)=wa1(x,y) +((4*(pi^2))*Aa(j,i)*(2*pi*Ff(j))^2*sinh(kj(j)*(y))*(sin((kj(j)*x*cos(the(i)))+(kj(j)*y*sin(the(i)))-(2*pi*Ff(j)*T)+(phi(j,i))))/sinh(kj(j)*(d+eta(j,i))));
- Fx(j+1,i+1)=((Vol*rho*Cm*ua1(j,i))+(0.5*Cd*rho*((4*D*dl)+(2*pl*ph))*u1(j,i)*abs(u1(j,i))));
- Fy(j+1,i+1)=((Vol*rho*Cm*va1(j,i))+(0.5*Cd*rho*((4*D*dl)+(2*pl*ph))*v1(j,i)*abs(v1(j,i))));
- Fz(j+1,i+1)=((Vol*rho*Cm*wa1(j,i))+(0.5*Cd*rho*((4*D*dl)+(2*pl*ph))*w1(j,i)*abs(w1(j,i))));
- Mx(j+1,i+1)=Fx(j+1,i+1)*(d+z);
- My(j+1,i+1)=Fy(j+1,i+1)*(d+z);
- Mz(j+1,i+1)=0;
- n=n+1;
- % U(m,n)=u1(j+1,i+1);
- % V(m,n)=v1(j+1,i+1);
- % W(m,n)=w1(j+1,i+1);
- % Ua(m,n)=ua1(j+1,i+1);
- % Va(m,n)=va1(j+1,i+1);
- % Wa(m,n)=wa1(j+1,i+1);
- FX(m,n)=Fx(j+1,i+1);
- FY(m,n)=Fy(j+1,i+1);
- FZ(m,n)=Fz(j+1,i+1);
- MX(m,n)=Mx(j+1,i+1);
- MY(m,n)=My(j+1,i+1);
- MZ(m,n)=Mz(j+1,i+1);
- end
- end
- t(m)=T;
- F=[FX FY FZ MX MY MZ];
- E(x,y) = eta(x,y);
- U(x,y) = sum(sum(u1));
- V(x,y) = sum(sum(v1));
- W(x,y) = sum(sum(w1));
- Ua(x,y) = sum(sum(ua1));
- Va(x,y) = sum(sum(va1));
- Wa(x,y) = sum(sum(wa1));
- m=m+1;
- end
- end
- F=F';
- x=[1:100];
- y=[1:100];
- figure(2)
- surf(x,y,E)
- xlabel('Theta(deg)')
- ylabel('Time(sec)')
- zlabel('Surface elevation(m)')
- grid on
- title('Random elevation of surface wave')
- x=[1:100];
- y=[1:100];
- figure(3)
- surf(x,y,U)
- xlabel('Theta(deg)')
- ylabel('Time(sec)')
- zlabel('Horizontal velocity X(m)')
- grid on
- title('Time history of Horizontal velocity, X')
- x=[1:100];
- y=[1:100];
- figure(4)
- surf(x,y,V)
- xlabel('Theta(deg)')
- ylabel('Time(sec)')
- zlabel('Horizontal velocity Y(m)')
- grid on
- title('Time history of Horizontal velocity, Y')
- x=[1:100];
- y=[1:100];
- figure(5)
- surf(x,y,W)
- xlabel('Theta(deg)')
- ylabel('Time(sec)')
- zlabel('Vertical velocity(m)')
- grid on
- title('Time history of Vertical velocity')
- x=[1:100];
- y=[1:100];
- figure(6)
- surf(x,y,Ua)
- xlabel('Theta(deg)')
- ylabel('Time(sec)')
- zlabel('Horizontal acceleration, X(m)')
- grid on
- title('Time history of Horizontal acceleration, X')
- x=[1:100];
- y=[1:100];
- figure(7)
- surf(x,y,Va)
- xlabel('Theta(deg)')
- ylabel('Time(sec)')
- zlabel('Horizontal acceleration, Y(m)')
- grid on
- title('Time history of Horizontal acceleration, Y')
- x=[1:100];
- y=[1:100];
- figure(8)
- surf(x,y,Wa)
- xlabel('Theta(deg)')
- ylabel('Time(sec)')
- zlabel('Vertical acceleration(m)')
- grid on
- title('Time history of Vertical acceleration')