Surface gravity water waves 147
% T = Wave period [s];
% Dx = Spatial step [m];
% Dt = Time step [s];
% nx = Number of computational steps;
% nt = Number of time steps;
clc; clear all; close all;
% Input data;
g=9.81;
ho=5;
a=1;
T=8;
xf=3;
Dx=2;
Dt=0.1;
nx=200;
nt=3200;
r=g*(Dt/Dx)^2/2;
nx2=nx/2;
% Option for variable bed friction;
for i=1:nx
fb(i)=0.001;
end
for i=1:nx
z(i)=0;
zo(i)=0;
zm(i)=0;
h(i)=ho;
bed(i)=0;
end
% Definition of size and location of the submerged
breakwater;
for i=nx2-5:nx2+5
h(i)=ho/xf;
bed(i)=-h(i)+ho;
end
c=sqrt(g*h(1));
L=c*T;
zr1=0;
% Main program;
for k=1:nt
% Open sea boundary conditions;
zr2=z(2)-a*sin(2*pi*((k-1)*Dt/T-Dx/L));
zr1=zr1+Dt/Dx*c*(zr2-zr1);
zn(1)=a*sin(2*pi*k*Dt/T)+zr1;
% Solution of main domain;
for i=2:nx-1
tt=r*((h(i+1)+h(i))*(z(i+1)-z(i))-(h(i)+h(i-1))*
(z(i)-z(i-1)));
zn(i)=2*z(i)-zo(i)+tt-Dt*fb(i)*(z(i)-zo(i));
end
% T = Wave period [s];
% Dx = Spatial step [m];
% Dt = Time step [s];
% nx = Number of computational steps;
% nt = Number of time steps;
clc; clear all; close all;
% Input data;
g=9.81;
ho=5;
a=1;
T=8;
xf=3;
Dx=2;
Dt=0.1;
nx=200;
nt=3200;
r=g*(Dt/Dx)^2/2;
nx2=nx/2;
% Option for variable bed friction;
for i=1:nx
fb(i)=0.001;
end
for i=1:nx
z(i)=0;
zo(i)=0;
zm(i)=0;
h(i)=ho;
bed(i)=0;
end
% Definition of size and location of the submerged
breakwater;
for i=nx2-5:nx2+5
h(i)=ho/xf;
bed(i)=-h(i)+ho;
end
c=sqrt(g*h(1));
L=c*T;
zr1=0;
% Main program;
for k=1:nt
% Open sea boundary conditions;
zr2=z(2)-a*sin(2*pi*((k-1)*Dt/T-Dx/L));
zr1=zr1+Dt/Dx*c*(zr2-zr1);
zn(1)=a*sin(2*pi*k*Dt/T)+zr1;
% Solution of main domain;
for i=2:nx-1
tt=r*((h(i+1)+h(i))*(z(i+1)-z(i))-(h(i)+h(i-1))*
(z(i)-z(i-1)));
zn(i)=2*z(i)-zo(i)+tt-Dt*fb(i)*(z(i)-zo(i));
end
