-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTwo_layer_dambreak.m
187 lines (161 loc) · 5.74 KB
/
Two_layer_dambreak.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
%**************************************************************************
% The extension of the Stoker's (1957) analytical solution
% to dam-break flows of two layers of identical density
%
% The governing equations are availabe through:
% Chen et al. (2007): https://doi.org/10.1080/00221686.2007.9521739
%
% Code generated by: Payam Sarkhosh
% Research assistant at Prof. Yee-Chung Jin's Lab
% University of Regina, Saskatchewan, Canada
% Spring 2022
%**************************************************************************
clc
clear all
clf
%******************************* inputs ***********************************
disp('*******************************************************************')
disp('******* Please enter the following inputs, and press ENTER ********')
disp('*******************************************************************')
disp(' ')
h0 = input('initial total water depth: h0 (m) >> ');
hd = input('initial sub-layer water depth: h1 (m) >> ');
Lc = input('channel length: Lc (m) >> ');
Lr = input('reservoir length: Lr (m) >> ');
T = input('total simulation time T (s) >> ');
n=2000; %Number of space intervals
m=T*100; %Number of time intervals
%**************************************************************************
dx=Lc/n; %space step
dt=T/m; %Time step
g=9.81; %Gravitational acceleration
x=zeros(n,1); %X vector
u=zeros(n,1); %Flow velocity vector
h=zeros(n,1); %Flow depth vector
h1=zeros(n,1); %Sub-layer depth vector
h0_s = hd; %Initial sub-layer depth vector
x_UBC=-Lr;
x_DBC=Lc-Lr;
x0=0;
xA_s=x0;
xA=x0;
%************************ Plotting initial condition plot *****************
x1=-Lr;
x2=0;
xDam2=linspace(x1,x2,n);
Dam2=h0+1e-50*xDam2;
x1=x0+1e-10;
xDam1=linspace(x0,x1,n);
Dam1=h0*(xDam1-x0)/1e-10;
%*************************** Mesh generation ******************************
x(1)=x_UBC;
for i=1:n-1
x(i+1)=x_UBC+i*dx;
if abs(x(i)-x0)<0.5*dx
i_0=i;
end
end
x(n)=Lc-Lr;
h(1)=h0;
h1(1)=h0_s;
%****************** defenition of constant values**************************
x2_end=-1e-20;
hA=1e+20;
x2_s_end=-1e-20;
Cup=(g*h0)^0.5; % wave speed at upstreamstream
Cdown=(g*hd)^0.5; % wave speed at downstream
for k=1:m
Time=k*dt;
%**************** Newton-Raphson iteration ***************************
f_CB=1; df_CB=1; CB=10*h0;
while abs(f_CB/CB)>1e-10
f_CB= CB*hd - hd*(((8*CB^2)/Cdown^2 + 1)^(1/2) - 1)*(CB/2 - Cup...
+((g*hd*(((8*CB^2)/Cdown^2 + 1)^(1/2) - 1))/2)^(1/2)) ;
df_CB= hd -hd*((2*CB*g*hd)/(Cdown^2*((8*CB^2)/Cdown^2 + 1)^(1/2)...
*((g*hd*(((8*CB^2)/Cdown^2 + 1)^(1/2) - 1))/2)^(1/2)) + 1/2)...
*(((8*CB^2)/Cdown^2 + 1)^(1/2) - 1) - (8*CB*hd*(CB/2 - Cup...
+ ((g*hd*(((8*CB^2)/Cdown^2 + 1)^(1/2) - 1))/2)^(1/2)))/...
(Cdown^2*((8*CB^2)/Cdown^2 + 1)^(1/2)) ;
CB=CB-f_CB/df_CB;
end
%*************** Newton-Raphson iteration end *************************
hA=0.5*hd*((1+8*CB^2.0/Cdown^2.0)^0.5-1);
if hd==0
CB=0; hA=0;
end
X2_end=CB*Time;
uA=2*Cup-2*(g*hA)^0.5;
X2_s_end=uA*Time;
for i=2:n
h(i)=(2*(g*h0)^0.5-x(i)/Time)^2.0/9/g;
u(i)=2*(x(i)/Time+(g*h0)^0.5)/3;
h1(i) = h(i)*h0_s/h0;
h(1)=h(2);
u(1)=u(2);
h1(1)=h1(2);
%******************************************************************
if h(i)>=h0
i_A=i;
h(i)=h0;
u(i)=0;
h1(i)=h0_s;
end
if hA==0 && h(i)>h(i-1)
h(i)=0;
u(i)=0;
h1(i)=0;
end
if hA>0
if x(i)<=X2_end && h(i)<=hA
i_B=i;
h(i)=hA;
u(i)=uA;
h1(i) = h(i)*h0_s/h0;
if x(i)>=X2_s_end
h1(i)=h(i);
end
elseif x(i)>X2_end
h(i)=hd;
u(i)=0;
h1(i)=h(i);
end
end
end
subplot(2,1,1)
plot(xDam2,Dam2,'--k','LineWidth',1), hold on
plot(xDam1,Dam1,'--k','LineWidth',1)
plot(x,h,'b','LineWidth',3)
plot(x,h1,'--b','LineWidth',3)
xlim([x_UBC x_DBC])
ylim([0 1.1*h0])
y_label=ylabel('water depth (m)');
set(y_label,'position',get(y_label,'position')-[0.2 0 0]);
set(gca,'FontSize',14)
Time=Time+0.0001;
title({"Stoker's (1957) solution to simulate"
"ideal dam-break problem with two layers of identical density"
['t = ',num2str(Time,'%.2f'),' s']},'FontSize',15)
Time=Time-0.0001;
hold off
subplot(2,1,2)
brown = [0.5, 0, 0];
plot(x,u,'Color',brown,'LineWidth',3)
xlim([x_UBC x_DBC])
ylim([0 (g*h0)^0.5+uA])
x_label=xlabel('x (m)');
set(x_label,'position',get(x_label,'position')+[0.15 -0.1 0]);
y_label=ylabel('velocity (m/s)');
set(y_label,'position',get(y_label,'position')-[0.2 0 0]);
set(gca,'FontSize',14)
fig=figure(1);
if(Time == T)
disp(' ')
disp(['******* Outputs at t = ',num2str(Time),' s **********'])
T2 = table(x,h,u,h1);
format short
disp(T2);
disp(['******* Outputs at t = ',num2str(Time),' s **********'])
end
format long
hold off
end