Professional Documents
Culture Documents
Week 4
Week 4
• Linear advection
• Riemann problem
• Inviscid Burgers’ equation
• Finite volume method
CIV 6745
Computational Method in Water Engineering
• Week 4: Finite volume method to solve the shallow water equations
1- The Shallow Water equations (SWE)
2- General Riemann problem solution
3- Finite Volume (shock-capturing) method
4- MATLAB Finite Volume code
5- More “approximate” approach to estimate the local Riemann
Problem solution
6- Coursework
Recommended reading
• Toro E F. Riemann Solvers and Numerical Methods for Fluid Dynamics:
A Practical Introduction. Third Edition. Springer-Verlag Berlin
Heidelberg, 2009, 721 pages.
Mass conservation 𝜕𝑡 ℎ + 𝜕𝑥 𝑞 = 0 h q
𝑞2 ℎ2
Momentum conservation 𝜕𝑡 𝑞 + 𝜕𝑥 +𝑔 = 𝑔ℎ(𝑆0 − 𝑆𝑓 )
ℎ 2
Mass conservation 𝜕𝑡 ℎ + 𝜕𝑥 𝑞 = 0 h q
𝑞2 ℎ2
Momentum conservation 𝜕𝑡 𝑞 + 𝜕𝑥 + 𝑔 = 𝑔ℎ(𝑆0 − 𝑆𝑓 )
ℎ 2
We will assume a water flow in a “flat” and “frictionless” channel in order to have 𝑆0 =
𝑆𝑓 = 0 for simplicity.
1- The Shallow Water equations (SWE)
1.2 Conservative matrix form – two PDEs in a form of a system of
equations. Denoting by:
𝑞 0
ℎ
𝐔 = ; 𝐅=𝐅 𝐔 = 𝑞2 ℎ2 ; 𝐒 = 𝐒(𝐔) = 𝑔ℎ(𝑆 − 𝑆 )
𝑞 +𝑔 0 𝑓
ℎ 2
𝜕𝑡 𝐔 + 𝜕𝑥 𝐅(𝐔) = 0
1- The Shallow Water equations (SWE)
1.2 Conservative matrix form – two PDEs in a form of a system of
equations. Denoting by:
𝑞 0
ℎ
𝐔 = ; 𝐅=𝐅 𝐔 = 𝑞2 ℎ2 ; 𝐒 = 𝐒(𝐔) = 𝑔ℎ(𝑆 − 𝑆 )
𝑞 +𝑔 0 𝑓
ℎ 2
Flow vector,
or the vector Flux vector Source terms
of unknowns vector
(assumed to
be zero)
𝜕𝑡 𝐔 + 𝜕𝑥 𝐅(𝐔) = 0
1- The Shallow Water equations (SWE)
1.3 Quasi-linear form – as for the scalar case, we can the following quasi-linear form for the
system case:
𝜕𝑡 𝐔 + 𝐀 𝐔 𝜕𝑥 𝐔 = 0
𝑞2 ℎ2 𝑞2 ℎ2
𝜕𝑓1 𝜕(𝑞) 𝜕𝑓1 𝜕(𝑞) 𝜕𝑓2 𝜕 ℎ +𝑔 2 𝜕𝑓2 𝜕 ℎ +𝑔 2
With = = 0; = = 1; = = 𝑔ℎ − 𝑢2 ; = = 2𝑢
𝜕𝑢1 𝜕ℎ 𝜕𝑢2 𝜕𝑞 𝜕𝑢1 𝜕ℎ 𝜕𝑢2 𝜕𝑞
1- The Shallow Water equations (SWE)
1.3 Quasi-linear form – as for the scalar case, we can the
following quasi-linear form for the system case:
𝜕𝑡 𝐔 + 𝐀 𝐔 𝜕𝑥 𝐔 = 0
𝜕𝐅 0 1
𝐀 𝐔 = = 2
𝜕𝐔 𝑐 − 𝑢2 2𝑢
λ1 = 𝑢 + 𝑐 and λ2 = 𝑢 − 𝑐
𝑢𝐿 = 0
ℎ𝑅
𝑢𝑅 = 0
1- The Shallow Water equations (SWE)
1.5 The dam-break problem – consider a 1D horizontal channel (frictionless).
Assume two sections are separated by a vertical gate.
The fluid in each section is a uniform (constant) depth and at rest (zero velocity);
thus at 𝑡 = 0𝑠,
ℎ𝐿 𝑥 < 0
ℎ 𝑥, 0 = ቊ
ℎ𝑅 𝑥 > 0
Assume that the gate/dam is removed (at t = 0s) instantenously (at high speed).
Two wave emerge:
1- The Shallow Water equations (SWE)
Depression
Shock
1- The Shallow Water equations (SWE)
• Left travelling wave reducing the depth of water (gradually) as it propagates into
the fluid at rest
Rarefaction/depression wave
• Right travelling wave increasing the depth of water as it propagates through the
fluid at rest
Shock/bore wave
This idealized situation (i.e. flat + frictionless dam-break case) can be exactly solved
by the shallow water equations (i.e. one particular scenario from the general
Riemann problem solution).
1- The Shallow Water equations (SWE)
𝑡
𝑥
ℎ𝐿
ℎ𝑚 𝑞𝑚
ℎ𝑅 𝑞𝐿 𝑞𝑅
𝑥 𝑥
ℎ𝐿
Note: 𝑡 = 10𝑠
1- The mathematics of this exact ℎ𝑚
solution is complex and quite out of
ℎ𝑅
scope. Therefore, you will be provided
this exact solution as a MATLAB code
that does the job for you. For example,
for the previous case, it outputs the
following. 𝐔𝑚
𝐔𝐿
𝐔𝑅
2- You will have to use these depth (h)
and discharge (h*u = q) to later validate
your numerical solution to the dam-
break problem.
𝑞𝑚
𝑞𝐿 𝑞𝑅
2- General Riemann problem solution
2.1 Background – Consider discontinuous initial water states, as seen in the dam-
break problem. Generally, 4 wave combinations could form, one of which is the
rarefaction-shock scenario associated with the dam-break problem.
2- General Riemann problem solution
𝑡 = 0𝑠
𝑡 = 10𝑠
+5 𝑥 < 0
ℎ 𝑥, 0 = 10 𝑚 𝑢 𝑥, 0 = ቊ Shock-shock
−5 𝑥 > 0
𝑡 = 0𝑠 𝑡 = 10𝑠
2- General Riemann problem solution
𝑡 = 10𝑠
−5 𝑥 < 0 Rarefaction-
ℎ 𝑥, 0 = 10 𝑚 𝑢 𝑥, 0 = ቊ
+5 𝑥 > 0 rarefaction
𝑡 = 10𝑠
2- General Riemann problem solution
𝑡 = 10𝑠
ℎ𝐿 = 5 𝑥 < 0
ℎ 𝑥, 0 = ቊ Shock-rarefaction
ℎ𝑅 = 10 𝑥 > 0
𝑡 = 10𝑠
2- General Riemann problem solution
2.2 What do you need to know – these four combinations of wave patterns arising
from the (discontinuous) initial condition (or IVP):
𝐔𝐿 𝑥 < 0 ℎ
𝐔 𝑥, 0 = ቊ 𝑤𝑖𝑡ℎ 𝐔 = = 𝑓𝑙𝑜𝑤 𝑣𝑒𝑐𝑡𝑜𝑟
𝐔𝑅 𝑥 > 0 𝑞
1- Are very important to understand the LOCAL wave patterns involved in the the
finite volume method for solving the shallow water equations (or shallow water
flows, more generally).
[x,h,u] = Exact_Solution_SWE(hl,ul,hr,ur,x0,xmin,xmax,N,T);
pause(0.05)
T = T + dt;
%
if T-Time >= 0
Don’t touch! T=T-dt;
dt=Time-T;
T=T+dt;
[x,h,u] = Exact_Solution_SWE(hl,ul,hr,ur,x0,xmin,xmax,N,T);
end
end
U
UL 𝐔𝐿𝑅 𝐔𝐿𝑅 = 𝐔RPS (𝑥 = 0, 𝑡)
UR
Exact solution of the GENERAL
x Riemann problem evaluated
0 (LOCALLY) at 𝑥 = 0.
𝐔 𝑥<0 ℎ
𝐔 𝑥, 0 = ቊ 𝐿 with 𝐔 = = 𝑓𝑙𝑜𝑤 𝑣𝑒𝑐𝑡𝑜𝑟
𝐔𝑅 𝑥 > 0 𝑞
2- General Riemann problem solution
2.3 Local Riemann Problem Solution (RPS)
3- Open a new m-script and past it there, with the interest of only keeping [h_m,u_m] as output
arguments.
Scroll
down
Select and copy
Fit it to purpose:
Rename it as
“Loc_RPS” and
have two output
arguments
“[h_m,u_m]”
As for the scalar case, you will also
need it for the flux estimation between
two discontinuous states between two
computational cells
𝑞
ℎ
𝜕𝑡 𝐔 + 𝜕𝑥 𝐅 𝐔 = 0, Where 𝐔 = and 𝐅 = 𝐅 𝐔 = 𝑞2 ℎ2
𝑞 + 𝑔
ℎ 2
𝑡2
𝑡1
… …
𝐼𝑖 𝑥
𝐔(𝑥, 𝑡)
𝐔𝑖
𝐔𝑖−1
𝐔𝑖+1
𝐔𝑖−2
𝐔𝑖+2
…
…
𝐼𝑖−1 𝐼𝑖 𝐼𝑖+1
𝑥
𝑡 + ∆𝑡
𝑡
… …
𝐼𝑖 𝑥
𝐔(𝑥, 𝑡)
𝐔𝑖
𝐔𝑖−1
𝐔𝑖+1
𝐔𝑖−2
𝐔𝑖+2
…
…
𝐼𝑖−1 𝐼𝑖 𝐼𝑖+1
𝑥
𝑡 + ∆𝑡 𝑅𝑃𝑆
𝑅𝑃𝑆
𝐔𝑖− 𝐔𝑖+1 Τ2
1 Τ2
𝑡
… …
𝐼𝑖 𝑥
𝐔(𝑥, 𝑡)
𝐔𝑖
𝐔𝑖−1
𝐔𝑖+1
𝐔𝑖−2
𝐔𝑖+2
… 𝑅𝑃𝑆
…
𝐅𝑖− 𝑅𝑃𝑆
1 Τ2 𝐅𝑖+1 Τ2
𝐼𝑖−1 𝐼𝑖 𝐼𝑖+1
𝑥
𝑡 + ∆𝑡 𝑅𝑃𝑆
𝑅𝑃𝑆
𝐔𝑖− 𝐔𝑖+1 Τ2
1 Τ2
𝑡
… …
𝐼𝑖 𝑥
𝐔(𝑥, 𝑡 + ∆𝑡)
𝐔𝑖
𝐔𝑖−1
𝐔𝑖+1
𝐔𝑖−2
𝐔𝑖+2
…
…
𝐼𝑖−1 𝐼𝑖 𝐼𝑖+1
𝑥
𝑡2
𝑡1
… ∆𝑡 RPS … (𝑡)
(𝑡+∆𝑡) (𝑡) RPS
𝐔𝑖 = 𝐔𝑖 − 𝐅𝑖+1Τ2 − 𝐅𝑖−1Τ2
𝐼 𝑖 𝑥
∆𝑥
Over each cell 𝐼𝑖 you should:
𝑡 RPS
(1) Solve the Local Riemann problems 𝐔𝐿𝑅 𝐔𝑖+1 , 𝐔𝑖𝑡 to evaluate 𝐅𝑖+1/2
𝑡 𝑡1 RPS
(2) Solve the Local Riemann problems 𝐔𝐿𝑅 𝐔𝑖 , 𝐔𝑖−1 to evaluate 𝐅𝑖−1/2
(3) Update your solution {𝐔𝑖 }𝑖 to time 𝑡 + ∆𝑡 as:
∆𝑡 RPS RPS (𝑡)
𝐔𝑖𝑡+∆𝑡 = 𝐔𝑖𝑡 − 𝐅𝑖+1Τ2 − 𝐅𝑖− 1Τ2
∆𝑥
(4) Repeat the process until my solution reaches my chosen end time…
3- Finite Volume (shock-capturing) method
𝑡
𝐔𝒎 𝐔𝒎
𝑥𝑖+1Τ2 𝑥
3- Finite Volume (shock-capturing) method
3.3 Numerical flux estimation
We are going to deal with this computationally:
2- Set u_L = 𝑢𝑖 = 𝑞𝑖 /ℎ𝑖 and u_R = 𝑢𝑖+1 = 𝑞𝑖+1 /ℎ𝑖+1 . Also h_L = ℎ𝑖 and h_R = ℎ𝑖+1
Call the function as: [h_LR,u_LR]= Loc_RPS(h_L,u_L,h_R,u_R)
3- Evaluate the Flux 𝐅 for the vector U_LR = [h_LR,u_LR], i.e. 𝐅i+1/2 = 𝐅(𝐔𝐋𝐑 )
10 m
5m
-200 0 + 200
4- MATLAB Finite Volume code
4.1.1 Recall the function “Generate_1D_Mesh” and modify it to be vectorial
function [x_interface,x,dx, U_now] = Generate_1D_Mesh(x_min,x_max,N)
% Interface points
for i = 1:N+1
x_interface(i) = x_min + (i-1)*dx; % simple but important
end
% Cell centers
for i = 1:N
x(i) = 0.5*(x_interface(i)+x_interface(i+1));
U_now(:,i) = Initial_Condition(x(i));
end
4- MATLAB Finite Volume code
4.1.2 Recall the function “Initial_Condition” and modify it to be vectorial
function U0 = Initial_Condition(x)
x0 = 0;
U0 = [h0; q0];
4- MATLAB Finite Volume code
4.1.3 Make a flux function relative to the case of the shallow water equations
function F_out = Flux_SWE(U_in)
global g % be careful that “g” is initiated earlier
% This is the F(U) function aimed to evaluate the Flux as function of the
% state variables "h" and "q".
% Input: U_in = [h_in; q_in]
% Output: F_out in terms of the relationship: F = [q; q^2/h + g*h^2/2]
h_in = U_in(1,:);
q_in = U_in(2,:);
f1_out = q_in;
f2_out = q_in^2/h_in + (g/2)*h_in^2;
% 4- Time step, time now and desired output time must be invovled:
dt = 0.05;
t_now = 0; Changed to 0.05
T_out = 10; % changed
Changed to 10s
%
F_out = Flux_SWE(U_LR);
Vectorial PS. Once F_out is evaluated, you can overwrite the same
temporary variable! Good practice to save memory…
% flux evaluation at xi-1/2 Same but with different Left and right
U_L = U_now(:,i-1); states
U_R = U_now(:,i);
% Depth
h_L = U_L(1,:);
h_R = U_R(1,:);
% Veloctiy
q_L = U_L(2,:);
q_R = U_R(2,:);
%
u_L = q_L/h_L;
u_R = q_R/h_R;
%
[h_LR,u_LR]= Loc_RPS(h_L,u_L,h_R,u_R); U_LR = [h_LR; h_LR*u_LR];
%
F_in = Flux_SWE(U_LR);
% Update step:
U_future(:,i) = U_now(:,i) - dt/dx*(F_out - F_in);
end
% Boundaries treatment
U_future(:,1) = U_future(:,2);
U_future(:,N) = U_future(:,N-1);
• Some are approximate Riemann state solvers as we have seen, i.e. 𝐅i+1/2 =
𝐅(𝐔i+1/2 (0)) with 𝐔𝐢+𝟏/𝟐 (x/t) is the approximate solution.
• Some others approximate the flux Riemann solvers directly, i.e. 𝐅i+1/2 is the
direct flux approximated.
In any case, the approximation is EXPLICIT. That is, given the input states 𝐔𝐿 and
𝐔R , 𝐅LR is directly and simply calculated by these states (no need to iterate)
5- More “approximate” approach to estimate
the local Riemann Problem solution
5.3 Example of the Local Lax Friedrich approximate Riemann solver
1
𝐅LR = 𝐅 LLF 𝐔L , 𝐔R = 𝐅 𝐔L + 𝐅 𝐔R − 𝑎𝑚𝑎𝑥 𝐔R − 𝐔L
2
𝑤𝑖𝑡ℎ
𝑎𝑚𝑎𝑥 = max |𝑢𝐿 − 𝑐𝐿 , |𝑢𝑅 − 𝑐𝑅 , |𝑢𝐿 + 𝑐𝐿 , |𝑢𝑅 + 𝑐𝑅
function F = Flux_LLF(hl,ul,hr,ur)
global g
%
cl = (g*hl)^0.5;
cr = (g*hr)^0.5;
%
a_max = max([abs(ul-cl),abs(ur-cr),abs(ul+cl),abs(ur+cr)]);
%
Ur = [hr;hr*ur];
Ul =[hl;hl*ul];
% Comment here
% [h_LR,u_LR]= Loc_RPS(h_L,u_L,h_R,u_R); U_LR = [h_LR; h_LR*u_LR];
% Comment here
% F_out = Flux_SWE(U_LR);
F_out = Flux_LLF(h_L,u_L,h_R,u_R);
% flux evaluation at xi-1/2
U_L = U_now(:,i-1);
U_R = U_now(:,i);
% Depth
h_L = U_L(1,:);
h_R = U_R(1,:);
% Veloctiy
q_L = U_L(2,:);
q_R = U_R(2,:);
%
u_L = q_L/h_L;
u_R = q_R/h_R;
F_in = Flux_LLF(h_L,u_L,h_R,u_R);
% Update step:
U_future(:,i) = U_now(:,i) - dt/dx*(F_out - F_in);
end
Then you compare them!
6- Coursework
6.1 Dam-break problem
6.1.1 Extract and save the exact solution of the dam-break problem at 𝑡 =
10𝑠 for the initial conditions:
10 𝑚 𝑥<0
ℎ 𝑥, 𝑡 = 0 = ቊ and 𝑞 𝑥, 0 = 0 𝑚2 /𝑠
5𝑚 𝑥>0
6- Coursework
6.1 Dam-break problem
10 𝑚 𝑥<0
ℎ 𝑥, 𝑡 = 0 = ቊ and 𝑞 𝑥, 0 = 0 𝑚2 /𝑠
1𝑚 𝑥>0
6- Coursework
6.1 Dam-break problem
6.1.3 Create you own Finite Volume MATLAB code solving the shallow water
equations. Use this code to get an approximate numerical solution to the
dam-break problems defined in 6.1.1.
Ps. Use only the Local Lax Friedrich approximate Riemann flux.
6- Coursework
6.1 Dam-break problem
6.1.4 Compare the outcomes (at 𝑡 = 10𝑠) of the numerical solutions with
the exact solution.
You are expected to construct a structured, well-documented MATLAB code and to write
up a short memo explaining your methods/selections for coding it. Use can use Equations
and Figures as necessary and provide a copy of your code(s) as an appendix. There is no
particular format to follow, just make sure your explanations are clear and well presented.
Your coursework should be submitted to MOLE before the deadline (05 Mar. noon)
including a PDF report and your source codes. Please follow this format in naming your
folder: “Kesserwani_CW4”.