Sei sulla pagina 1di 30

BUDAPEST UNIVERSITY OF TECHNOLOGY AND ECONOMICS

DEPARTMENT OF HYDRODYNAMIC SYSTEMS


MECHANICAL ENGINEERING AND MODELING (MSC)
2010/2011 SPRING SEMESTER



UNSTEADY FLOW IN PIPE NETWORKS




Open Channel Flow with
Variable Bottom Slope



Documentation





Name: Lszl ARANY (H8QF9G)
Tams BAKONYI (PCDSEN)


Supervisor: Csaba HS, PhD



Date: 10. 05. 2011
2
I. INTRODUCTION


The main task of this project was to simulate an open channel flow with variable bottom
slope by using the method of characteristics (MoC) with the help of MATLAB. The final
simulation has been reached throughout two main simulation steps.
Firstly, a simpler wave pool problem had been simulated in order to introduce the
operating of the basic equations of method of characteristics and its boundary conditions and
the usability of MATLAB in these kinds of problems.
In the second step, the final simulation of the open channel flow having variable bottom
slope had been done as an additional extension of the previous program code with some
variations in it. The detailed explanation of the simulations can be seen later.

II. METHOD OF CHARACTERISTICS

Two equations governing the flow are the continuity and the equation of motion.
Continuity equation can be written as follows:
0 =
c
c
+
c
c
+
c
c
x
v
y
x
y
v
t
y
, (1)
in which y [m] corresponds to the height of the water level at the a actual position;
v [m/s] corresponds to the velocity of the flow.
Equation of motion has this form:
v v
D x
z
g a
x
y
g
x
v
v
t
v
x

c
c
=
c
c
+
c
c
+
c
c
2

, (2)
in which on the RHS the three source terms (denoted by S) are shown that are arising from
the acceleration, variable bottom slope and the flow friction, respectively.
The third important connection shows the relationship between the actual height of water
level (y) and the velocity of the pressure wave (c [m/s]):

g
c
y
2
= = y g c . (3)
After substituting the previous equation (3) into (1) and multiplying by g the following
equation is given:
3
0
2
2 2
=
c
c
+
c
c
+
c
c
x
v
c
x
c
v
t
c
. (4)
Having used this expression
t
c
c
t
c
c
c
=
c
c
2
2
and divided by c the following equation is given:
0 2 2 =
c
c
+
c
c
+
c
c
x
v
c
x
c
v
t
c
. (5)
In the next step the continuity equation is multiplied by
c
g
and the equation of motion is
added to it:
( ) S
x
v
c
x
c
v
x
c
c
x
v
v c v
t
=
c
c
+
c
c
+
c
c
+
c
c
+ +
c
c
2 2 2 . (6)
By rearranging the terms the two final equations are given:
( ) ( ) ( ) S c v
x
c v c v
t
= +
c
c
+ + +
c
c
2 2 , (7)
( ) ( ) ( ) S c v
x
c v c v
t
=
c
c
+
c
c
2 2 . (8)
In which:
c v 2 + = o , (9)
c v 2 = | . (10)
Further valid notations are:
( )
c
c
+ +
c
c
=
+
x
c v
t Dt
D
, (11)
( )
c
c
+
c
c
=

x
c v
t Dt
D
. (12)
With the help of the notations used in (9-12) the following equations can be written in this
form:

S
Dt
D
=
+
o
, (13)
S
Dt
D
=

|
. (14)



4
According to the main equations of method of characteristics (13 and 14) the following
relationships and the relating figures (Fig. 1-3) are shown below.

Fig. 1: Method of characteristics







Fig. 2: Context of o and |








Fig. 3: Desired and given parameters







R
i
L
i
j
S
t
=
A

+
| |
1
L
i
L
i
j
S
t
=
A

+
o o
1
5
The foundation of method of characteristics assumes that there are lines from grid-points
on which the values of certain quantities (here the velocity v and c) are changing by means of
a known context. In this case the changing of o and | are given, which only depend on v
and c based on (9, 10).
The expressions refer to changing of ( ) c v, o and ( ) c v, | are illustrated in Figure 2. It can
be observed that the change of the value of ( ) c v, o (or ( ) c v, | ) during one step ( ) t A on a
given line is equal to the source terms (S) given in the starting point of the given line. The
given line can be defined by its slope (m).
In Figure 1 it can be seen that each grid-point at the known time level can have two slopes
having the expressions:
Slopes from left denoted by red:
c v t
x
dt
dx
m
L
+
=
A
A
= =
1
. (15)
Slopes from left denoted by purple:
c v t
x
dt
dx
m
R

=
A
A
= =
1
. (16)
Thus, in each grid point and in each time step two variables are looked for:
- The actual velocity:
(

s
m
v ;
- The actual height of water level | | ( ) m y , which is expressed by the pressure wave
velocity
|
|
.
|

\
|
(

s
m
c using Eq. (3): | | m y
s
m
g
s
m
c
(

=
(

2
.
Thus, if the value of v and c are known in a certain grid-point at the known time level, the
two slopes starting from this grid-point are also known because the slopes depend on only v
and c in the point.
However, our desired points (where the values of v and c should be known in the next
numerical step) are given by their positions according to the numerical square-grid. In Figure
1 this desired point is the grid-point having the coordinates ( ) 1 , + i j .
The first main task of the method of characteristics is to find the point from which the
starting right-handed (or so left-handed) slope accurately intersects the desired point in the
unknown time level. In Figure 1-3 point Left denoted by L is the point that has the left
handed-slope accurately intersecting the desired point ( ) 1 , + i j . In Figure 1-3 point Right
denoted by R is the point that has the right handed-slope that accurately intersecting the
desired point ( ) 1 , + i j . The x position of the point L and R (in Fig. 3 denoted by
L
X and
R
X )
6
have to be determined for every inner space grid-point. Grid-points lying on the side boundary
of the calculation zone will be discussed later.
The slopes are only known at the known time step (step i in the Figure 1-3) because at
this time level the values of v and c are known in each grid point and thus we know all of the
slopes because the slopes only depend on v and c (Eqs.(15) and (16)). However, if we know
the values of v and c in each grid point at a certain time level (so if we know all the slopes
also), we can approximate the values of v and c in every x position between the grid points
also, with the help of simple linear interpolation. This approximation using linear
interpolation between the grid points gives quite accurate results and good stability properties.
On the whole, we are looking for the x coordinates of point L(eft) and R(ight) ( )
R L
x x and
whose slopes are intersecting each other accurately in the desired point at the next time
level, here it is the point ( ) 1 , + i j .
In MATLAB there is a helpful command for this position-seeking action called
interp1().

Explanation of MATLAB command interp1(, , )
The command interp1(x1, x2, x3) requires three variables in itself. The necessary
parameters for understanding are depicted in Figure 4 and 5 shown below.

Fig. 4: Explanation of command interp1()
7

Fig. 5: Explanation of command interp1()(2)
In Figure 4 and 5,
+
j
x denotes the x coordinate of the o lines started from
j
x after t A .
The following equation can be written:
( ) t c v x x
j j j j
A + + =
+
. (17)
In Figure 4 and 5,

j
x denotes the x coordinate of the | lines started from
j
x after t A .
The following equation can be written:
( ) t c v x x
j j j j
A + =

. (18)
We are seeking
R L
x x and , with the help of interp1 we can give it by this command:
First case: )) ( , , ( interp1 i x x x x
j j L
+
= . (comm1)
The first variable required by the command is defined by Eq. (17) and (18) for both the
left-handed and right-handed slopes. In this case this is denoted by
+
j
x .
The second variable is the x-coordinate of the actual known grid point. In this case this is
denoted by
j
x .
The third variable is the next desired point where the characteristic line ( ) o should arrive
at. In this case this is denoted by ) (i x and means the point ( ) 1 , + i j .

8
Second case: )) ( , , ( interp1 i x x x x
j j R

= . (comm2)
The first variable required by the command is defined by Eq. (17) and (18) for both the left-
handed and right-handed slopes. In this case this is denoted by

j
x .
The second variable is the x-coordinate of the actual known grid point. In this case this is
denoted by
j
x .
The third variable is the next desired point where the characteristic line ( ) | should arrive
at. In this case this is denoted by ) (i x and means the point ( ) 1 , + i j .
Thus, by means of command interp1() the sought x-coordinates of the points L(eft) and
R(ight) can be defined. If
R L
x x and are known the values of v and c at these
R L
x x and
coordinates can also be defined by using linear interpolation from the encircling known grid
point. This interpolations can be also performed by the interp1() command as follows:
) , , ( interp1
L j j L
x v x v = , (comm3)
) , , ( interp1
L j j L
x c x c = , (comm4)
) , , ( interp1
R j j R
x v x v = , (comm5)
) , , ( interp1
R j j R
x c x c = . (comm6)
Having known the values of
L
v ,
L
c ,
R
v and
R
c (and thus the slopes also), an equation
system can be derived for the desired point where the slopes intersect each other to determine
the sought variables
1 + i
j
v ,
1 + i
j
c (at the next time step).
Since the characteristic line o starting from point L(eft) and the characteristic line |
starting from point R(ight) intersect each other in point ( ) 1 , + i j , the following equation
system is given to determine
1 + i
j
v and
1 + i
j
c .
Equation of o (see Fig. 2):

L
i
L
i
j
S
t
=
A

+
o o
1
. (19)
Equation of | (see Fig. 2):

R
i
L
i
j
S
t
=
A

+
| |
1
. (20)
From Eqs. (19) and (20) the following system has this form:

L
i
L
i
j
S t A + =
+
o o
1
;
.
1
R
i
R
i
j
S t A + =
+
| | (21)
9
Considering Eqs. (9) and (10) and the source term is assumed to be
v v
D dx
dz
g S =
2

,(because the acceleration term in the source term is not present in this
problem) the system (21) changes its form as follows:

|
.
|

\
|
A + + = +
+ + i
L
i
L
L
i
L
i
L
i
j
i
j
v v
D dx
dz
g t c v c v
2
2 2
1 1

; (22)

|
.
|

\
|
A + =
+ + i
R
i
R
R
i
R
i
R
i
j
i
j
v v
D dx
dz
g t c v c v
2
2 2
1 1

. (23)
From Eqs. (22) and (23) it can be observed that we have only two unknowns:
1 + i
j
v and
1 + i
j
c .
The sum of the Eq.(22) and (23) gives an expression for
1 + i
j
v :
|
.
|

\
|
A + +
|
.
|

\
|
A + + =
+ i
R
i
R
R
i
R
i
R
i
L
i
L
L
i
L
i
L
i
j
v v
D dx
dz
g t c v v v
D dx
dz
g t c v v
2
2
2
2 2
1

;
|
.
|

\
|
A + + + =
+ i
R
i
R
i
L
i
L
R L
i
R
i
L
i
R
i
L
i
j
v v
D
v v
D dx
dz
g
dx
dz
g t c c v v v
2 2
2 2 2
1

;
)
`

|
.
|

\
|
A + + + =
+ i
R
i
R
i
L
i
L
R L
i
R
i
L
i
R
i
L
i
j
v v
D
v v
D dx
dz
g
dx
dz
g t c c v v v
2 2
2 2
2
1
1

(24)

After subtracting Eq.(23) from (22) an expression for
1 + i
j
c can be obtained:
|
.
|

\
|
A +
|
.
|

\
|
A + + = +
+ + i
R
i
R
R
i
R
i
R
i
L
i
L
L
i
L
i
L
i
j
i
j
v v
D dx
dz
g t c v v v
D dx
dz
g t c v c c
2
2
2
2 2 2
1 1

|
.
|

\
|
+ + A + + + =
+ i
R
i
R
i
L
i
L
R L
i
R
i
L
i
R
i
L
i
j
v v
D
v v
D dx
dz
g
dx
dz
g t c c v v c
2 2
2 2 4
1


)
`

|
.
|

\
|
+ + A + + + =
+ i
R
i
R
i
L
i
L
R L
i
R
i
L
i
R
i
L
i
j
v v
D
v v
D dx
dz
g
dx
dz
g t c c v v c
2 2
2 2
4
1
1

(25)

The water level height at point ( ) 1 , + i j can be directly expressed from
1 + i
j
c based on
Eq.(3):
2
1
2 2
2 2
16
1
)
`

|
.
|

\
|
+ + A + + +

=
+ i
R
i
R
i
L
i
L
R L
i
R
i
L
i
R
i
L
i
j
v v
D
v v
D dx
dz
g
dx
dz
g t c c v v
g
y

(26)
10
Boundary conditions
At the boundaries the calculation of the variables is changed a bit. At the boundary of
computational domain one of the sought variables are directly known by means of the type of
boundary condition. In our case, by the apropos of the wave pool and the variable bottom
slope problems two different types of boundary condition were arisen (known water level
height and known velocity at the boundary).
1.) Known water level height at the front boundary (
1
y is known in every time step)
If the water level height is known, the velocity of pressure waves (
1
c ) is also known due
to Eq.(3).

Fig. 6: Front boundary condition with given water level height
In this case, we are only interested in the characteristic lines of | and the interpolation
into the point R(ight). Since
1
c is given in every time step, the calculation is reduced only for
1
v in every time step.
Here, the following equation can be written to express
1
1
+ i
v :

R
i
R
i
S t A + =
+
| |
1
1
;
|
.
|

\
|
A + =
+ + i
R
i
R
R
i
R
i
R
i i
v v
D dx
dz
g t c v c v
2
2 2
1
1
1
1

;
|
.
|

\
|
A + =
+ + i
R
i
R
R
i
R
i
R
i i
v v
D dx
dz
g t c v y g v
2
2 2
1
1
1
1

|
.
|

\
|
A + + =
+ + i
R
i
R
R
i i
R
i
R
i
v v
D dx
dz
g t y g c v v
2
2 2
1
1
1
1

. (27)

1
1
+ i
y is known in every time step!
11
2.) Known water level height at the end boundary (
N
y is known in every time step)
If the water level height is known, the velocity of pressure waves (
N
c ) is also known due
to Eq.(3).
















Fig. 7: End boundary condition with given water level height
In this case, we are only interested in the characteristic lines of o and the interpolation
into the point L(eft). Since
N
c is given in every time step, the calculation is reduced only for
N
v in every time step.
Here, the following equation can be written to express
1 + i
N
v :

L
i
L
i
N
S t A + =
+
o o
1
;
|
.
|

\
|
A + + = +
+ + i
L
i
L
L
i
L
i
L
i
N
i
N
v v
D dx
dz
g t c v c v
2
2 2
1 1

;
|
.
|

\
|
A + + =
+ + i
L
i
L
L
i
N
i
L
i
L
i
N
v v
D dx
dz
g t c c v v
2
2 2
1 1

|
.
|

\
|
A + + =
+ + i
L
i
L
L
i
N
i
L
i
L
i
N
v v
D dx
dz
g t y g c v v
2
2 2
1 1

. (28)
1 + i
N
y is known in every time step!

12
3.) Known velocity at the front boundary (
1
v is known in every time step)
If the velocity is known, the parameter looked for is the pressure wave velocity
1
c (and
the water level height
1
y ) at the boundary.

Fig. 8: Front boundary condition with given velocity

The equations are the same like in the previous cases, but here the sought variable is the
1
1
+ i
y throughout
1
1
+ i
c .

R
i
R
i
S t A + =
+
| |
1
1
;
|
.
|

\
|
A + =
+ + i
R
i
R
R
i
R
i
R
i i
v v
D dx
dz
g t c v c v
2
2 2
1
1
1
1

;
;
2
2 2
1
1
1
1
|
.
|

\
|
A + =
+ + i
R
i
R
R
i i
R
i
R
i
v v
D dx
dz
g t v c v c


;
2
2
2
1
1
1
1
1
)
`

|
.
|

\
|
A + + =
+ + i
R
i
R
R
i i
R
i
R
i
v v
D dx
dz
g t v c v c


.
2
2
4
1
2
1
1
1
1
)
`

|
.
|

\
|
A + +

=
+ + i
R
i
R
R
i i
R
i
R
i
v v
D dx
dz
g t v c v
g
y

(28)
1
1
+ i
v is known in every time step!

13
4.) Known velocity at the end boundary (
N
v is known in every time step)
If the velocity is known, the parameter looked for is the pressure wave velocity
N
c (and
the water level height
N
y ) at the boundary.

Fig. 9: End boundary condition with given velocity
The equations are the same like in the previous cases, but here the sought variable is the
1 + i
N
y throughout
1 + i
N
c .

L
i
L
i
N
S t A + =
+
o o
1
;
|
.
|

\
|
A + + = +
+ + i
L
i
L
L
i
L
i
L
i
N
i
N
v v
D dx
dz
g t c v c v
2
2 2
1 1

;

|
.
|

\
|
A + + =
+ + i
L
i
L
L
i
N
i
L
i
L
i
N
v v
D dx
dz
g t v c v c
2
2 2
1 1

;

)
`

|
.
|

\
|
A + + =
+ + i
L
i
L
L
i
N
i
L
i
L
i
N
v v
D dx
dz
g t v c v c
2
2
2
1
1 1

;

2
1 1
2
2
4
1
)
`

|
.
|

\
|
A + +

=
+ + i
L
i
L
L
i
N
i
L
i
L
i
N
v v
D dx
dz
g t v c v
g
y

. (29)
1 + i
N
v is known in every time step!
14

III. WAVE POOL PROBLEM

The problem is illustrated in Figure 10.

Fig. 10: Schematic figure of the wave pool
Given a wave pool with its dimensions:
Length: m L 10 = ,
Width: m B 10 = ,
Initial water level height on both boundaries: m y y y
N
1
1 0
= = = .
The number of grid points is denoted by N.
Consequently, the distance between the grid points:

1
=
N
L
dx . (30)
In this problem, there is no variable bottom slope; no acceleration and no flow
friction are assumed, so the source term (denoted by S) is completely zero.
Due to the previous assumption the equations derived in Chapter II could be significantly
simplified here.
The main simplification can be noticed from Eqs.(19) and (20). The simplified equations
show that the value of c v 2 + = o and c v 2 = | are constants along the characteristic lines.

i
L
i
j
i
L
i
j
L
i
L
i
j
t
S
t
o o
o o o o
= =
A

=
A

+
+ +
1
1 1
0 (31)

i
R
i
j
i
R
i
j
R
i
R
i
j
t
S
t
| |
| | | |
= =
A

=
A

+
+ +
1
1 1
0 (32)
Henceforward, for the sake of simplicity: o is denoted by
1
K :
1
K = o (33)
| is denoted by
2
K :
2
K = | (34)
15
Innerspace points:
The innerspace points (N=2N-1) are calculated by the method of characteristics
introduced in Chapter II. However, in this problem we have more simplified equations than in
Chapter II due to the absent of source terms. X-coordinates of the actual L(eft) and the R(ight)
points are approximated by the command interp1(), and the actual variable values at these
points (
L
v ,
L
c ,
R
v and
R
c ) are also interpolated by means of interp1()(see later in the
program code). But, in this case the value of
1
K and
2
K are constant along the slopes.
Thus, for the next desired point, where the slopes starting from L(eft) and R(ight) intersect
each other, the following equation system is given:

1 1
1
2 2
+ +
+ = = +
i
j
i
j
i
L
i
L
c v K c v , (35)

1 1
2
2 2
+ +
= =
i
j
i
j
i
R
i
R
c v K c v . (36)
Since, the values of
1
K and
2
K are known at the time level i , adding and subtracting of
Eqs. (35) and (36) gives an expression for
1 + i
j
v ,
1 + i
j
c and
1 + i
j
y :

2
2 1 1
K K
v
i
j
+
=
+
, (37)

4
2 1 1
K K
c
i
j

=
+
, (38)

( )
g
K K
y
i
j

=
+
16
2
2 1 1
. (39)
Boundary conditions:
Front boundary: At the front boundary we have a wave excitation that means a given
water level height in every time step. The excitation is harmonic, and is expressed by the
following equation (Figure 10). Index 1 is referring to the first grid point.
) sin(
0 1
t wa y y + = e (40)
Here, only the velocity is needed to calculate at the front boundary. Figure 6 relates to this
boundary condition (see Chapter II).
The equations are:

1
1
1
1 2
2 2
+ +
= =
i i i
R
i
R
c v K c v , (41)

1
1
1 1
y g c c
i i
= =
+
. (42)
From (41) and (42) the new velocity can be obtained as follows:

1 2
1
1
2 y g K v
i
+ =
+
(43)
16
End boundary: At the front boundary we have static wall on which the velocity is always
zero. Thus, we have a velocity boundary condition, regarding to Figure 9. Index N is referring
to the last grid point.
0 =
N
v (44)
Here, only the water level is needed to calculate at the end boundary.
The equations are:

1 1
1
2 2
+ +
+ = = +
i
N
i
N
i
L
i
L
c v K c v , (45)
0
1
= =
+ i
N
i
N
v v . (46)
From (45) and (46) the new velocity can be obtained as follows:

2
1 1
K
c
i
N
=
+
, (46)

g
K
y
i
N

=
+
4
2
1 1
. (47)
Having known the equations (37),(39), (40), (43), (44) and (47) we can calculate the
desired y and v values for all the points (innerspace points and the two boundaries) for the
next time step.

IV. WAVE POOL PROBLEM MATLAB CODE
WITH EXPLANATION

The program has five major parts. In the first part the general information, initial
conditions and constant parameters are given. The second part of the program, called Main
loop, consists of the plotting and the definitions of functions using the method of
characteristics for the innerspace and boundary points. The third part describes the accurate
and necessary equations for the calculation of the new values of v and y for the innerspace
points. These values will be recalled in the Main loop. The 4
th
part describes the accurate and
necessary equations for the calculation of the new values of v and y for at the front boundary.
The 5
th
part of the program describes the accurate and necessary equations for the calculation
of the new values of v and y for at the end boundary. These boundary values will be also
recalled in the Main loop.


17
Explanation of MATLAB command linspace(0, L, N)
It divides the distance between 0 and L into N equal parts and stores the point coordinates in a
vector.
function hullammedence %name of the function
clear all, clc, clf

global dt
global wa

% PARS, definition of the constants characterising the problem
pars.L=10; % wave pool length
pars.B=10; %wave pool width
pars.N=31; %number of grid points
pars.g=9.81; %gravity
omega=2; %frequency of the wave excitation
xgrid=linspace(0,pars.L,pars.N); % dividing of the bottom of wave pool (see former
for the command explanation)
wa=0.2; % amplitude of the excitation

% Simulation time
tmax=50; % simulation time in sec
dt=0.05;% setting of the time step
t=0; % beginning of the simulation
PauseTime=0.0001;


% Initial Conditions
y0=1; % initial water level
v0=0; % initial water velocity
y=y0*ones(1,pars.N); % initial water level vector
v=v0*ones(1,pars.N); % initial velocity vector
ynew=y; % new water level vector
vnew=v; % new velocity vector

% Main loop
while t<tmax

% Plotting of the water level height
figure(1)
subplot(2,1,1), plot(xgrid, ynew,'r-*');
grid on, ylabel('y [m]')
title(['t=',num2str(t),'s'])
axis([0 10 0 2])

% Plotting of the velocity and the pressure wave velocity
subplot(2,1,2), plot(xgrid, vnew,'b*-',xgrid,(pars.g*ynew).^0.5,'r--');
grid on, xlabel('x [m]'), ylabel('v [m/s]')
pause(PauseTime);
18

% Assigns values to y(2)...y(N-1) and v(2)...v(N-2), Function of method of
characteristics function for the innerspace points, It will be accurately defined later.
[ynew,vnew]=moc_step(y,v,dt,pars,ynew,vnew);

% Front Boundary Condition
yf=y0+wa*sin(omega*t); % function of wave excitation (see Eq.(40))
vf=BC_front(y,v,yf,pars); %Function of method of characteristics for the Front
Boundary Condition, It will be accurately defined later.
ynew(1)=yf; % Recalling of the new y value at the first grid point
vnew(1)=vf; % Recalling of the new v value at the first grid point

% End Boundary Condition
vv=0; % Defining that the velocity is always zero here (see Eq.(44))
ye=BC_end(y,v,vv,pars); %Function of method of characteristics for the End
Boundary Condition, It will be accurately defined later.
disp('ye=');
disp(ye);
ynew(pars.N)=ye; % Recalling of the new y value at the last grid point
vnew(pars.N)=vv; % Recalling of the new v value at the first grid point (always
zero)

% Close step
y=ynew;
v=vnew;
t=t+dt; %go to the next time step

end

end

function [ynew,vnew]=moc_step(y,v,dt,pars,ynew,vnew) % definition of the function
of method of characteristics for the innerspace points
N=pars.N;
g=pars.g;
dx=pars.L/(pars.N-1);

for i=2:(N-1) % for only the innerspace points N=2N-1
x=linspace(0,pars.L,pars.N); %resolution of the x-axis
c=(g*y).^0.5; % defining the connection between the pressure wave velocity and
the water height level (see Eq.(3))
x_alpha=x+(v+c)*dt; %see Eq.(17)
x_beta=x+(v-c)*dt; %see Eq.(18)
xi=x(i); % the x-coordinate of the i-th grid point will be xi

% The position of the slopes running in
x_innen_alpha=interp1(x_alpha,x,xi); %linear interpolation of x-coordinate of the
L(eft) point, see (comm1)
x_innen_beta=interp1(x_beta,x,xi); %linear interpolation of x-coordinate of the
R(ight) point, see (comm2)
19
% Calculation of v(alpha), c(alpha), v(beta), c(beta), linear interpolation to the
L(eft) and the R(ight) points
cia=interp1(x,c,x_innen_alpha); %see (comm4)
via=interp1(x,v,x_innen_alpha); %see (comm3)
cib=interp1(x,c,x_innen_beta); %see (comm6)
vib=interp1(x,v,x_innen_beta); %see (comm5)

% Computing the constant k values
k1=via+2*cia; % definition of K1 see Eq.(35)
k2=vib-2*cib; % definition of K2 see Eq.(36)

% Calculation of the new y and v values
vnew(i)=(k1+k2)/2; % see Eq.(37)
ynew(i)=(k1-k2)^2/(16*g); % see Eq.(39)

end
end

function vf=BC_front(y,v,yy,pars) % definition of the function of method of
characteristics for the Front Boundary Condition

global dt

% Variables at the front
m1f=0;
m2f=0;
Xf=0;
Kf=0;
N=pars.N; %number of grid points
g=pars.g;
dx=pars.L/(pars.N-1);
x=linspace(0,pars.L,pars.N); %resolution
c=(g*y).^0.5; %see Eq.(3)

x_beta=x+(v-c)*dt; % equation for the x-position of the appropriate R(ight) point ,see
Eq.(18)
x_innen_beta=interp1(x_beta,x,0); %linear interpolation of x-coordinate of the R(ight)
point where the x-coordinate of the desired point is zero (third variable in the
command), see (comm2)

% linear interpolation to the R(ight) point (pressure wave velocity and the velocity)
ci=interp1(x,c,x_innen_beta); %see(comm6)
vi=interp1(x,v,x_innen_beta); %see(comm5)

% v and c at the determined position
VXf=vi; %another notation
CXf=ci; %another notation

% The constant K value at the front
Kf=VXf-2*CXf; %see Eq.(41)
20
% Return value of the function
vf=Kf+2*sqrt(g*yy); %see Eq.(43)
end

function ye=BC_end(y,v,vv,pars) % definition of the function of method of
characteristics for the End Boundary Condition
global dt
% Variables at the end
N=pars.N;
g=pars.g;
dx=pars.L/(pars.N-1);
L=pars.L;
x=linspace(0,pars.L,pars.N);
c=(g*y).^0.5; %see Eq.(3)

xi=L; % defining the position, we are at the position L, so at the end of the wave
pool

x_alpha=x+(v+c)*dt; % equation for the x-position of the appropriate L(eft) point
,see Eq.(17)
x_innen_alpha=interp1(x_alpha,x,xi); %linear interpolation of x-coordinate of the
L(eft) point where the x-coordinate of the desired point is xi defined as L (third
variable in the command), see (comm1)

% linear interpolation to the L(eft) point (pressure wave velocity and the velocity)
ci=interp1(x,c,x_innen_alpha); %see(comm4)
vi=interp1(x,v,x_innen_alpha); %see(comm3)

% v and c at the determined position
VXe=vi; %another notation
CXe=ci; %another notation

% The constant K value at the end
Ke=VXe+2*CXe; %see Eq.(45)

% Return value of the function
ye=Ke^2/(4*g); %see Eq.(47)

end

21
V. VARIABLE BOTTOM SLOPE PROBLEM

The problem is illustrated in Figure 11. Constant water level heights are given at both
boundaries (can be different water levels) and the initial water level can be seen in Figure 11.
After the first time step the initial water level will change and waves will propagate for the
left-hand side and the right-hand side. The variable bottom slope is approximated as a ( ) x
2
sin
function.

Fig. 11: Open channel flow with variable bottom slope
In this problem, we consider the source term (S) that consists of the flow friction term and
the term arising from the variable bottom slope. Thus, we need the same equations derived in
Chapter II.
The dimensions of the pool remain the same like in the case of the wave pool.
The governing equations are:
|
.
|

\
|
=
A

=
A

+ +
i
L
i
L
L
i
L
i
j
L
i
L
i
j
v v
D dx
dz
g
t
S
t 2

1 1

o o o o
; (48)
|
.
|

\
|
=
A

=
A

+ +
i
R
i
R
R
i
R
i
j
R
i
R
i
j
v v
D dx
dz
g
t
S
t 2

1 1

| | | |
. (49)

In this kind of problems, the flow friction part ( )
f
S in the source term are usually
approximated by the Mannings friction rule.

22
The Mannings friction rule says:

3 / 4 2
2
2
h
f
R A
n Q Q
v v
D
S


= =

, (50)
In which: v A Q = - Volume flow rate
(

s
m
3
; (51)
01 . 0 = n - Mannings constant; (52)
B
g
c
B y A = =
2
- Actual cross-section | |
2
m (53)

P
A
R
h
= - Hydraulic radius | | m (54)

g
c
B y B P
2
2 2 + = + = - Wetted perimeter for rectangular channel | | m (55)
The other source term arisen due to the bottom slope is denoted by
l
S and defined as a
( ) x H
2
sin function, where H means the amplitude of the function.
Thus the whole source term (S) has this form:

3 / 4 2
2
h
f l
R A
n Q Q
dx
dz
g S S S


= + = . (56)
In this program the variable bottom slope is generated between the coordinates L0 and
L0+LS with the maximum height of H with this function (Fig.11). This function satisfies the
requirements.

( )
2
0
sin ) (
|
.
|

\
|
=
LS
L x
H x z t (57)
From Eq.(57):

( ) ( )
LS LS
L x
LS
L x
H
dx
dz
g S
l
t
t t
|
.
|

\
|

|
.
|

\
|
= =
0
cos
0
sin 2 (58)
For the sake of stability a control cycle is applied in the program code for the time step
selection. The aim of this selection is to control the Courant-number to be smaller than one.
Thus, the flow doesnt traverse spatially more than one complete grid (with the dimension dx)
during one time step. This criterion is very important from the point of view of stability.
For the time step it can be written:
c v
t
dx
+ =
A
. (59)
23
From Eq.(59) the selection criterion for the time step can be derived with a safety factor C
as follows:
C
y g v
dx
C
c v
dx
t
+
=
+
= A (60)
Innerspace points: The equations for the new v and y values are the same as derived in
Chapter II., but having applied the Mannings friction rule the following equations can be
obtained:

|
|
.
|

\
|


A + + + =
+
3 / 4 2
2
3 / 4 2
2
1
2 2
2
1
hR R
R R
hL L
L L
R L
i
R
i
L
i
R
i
L
i
j
R A
n Q Q
R A
n Q Q
dx
dz
g
dx
dz
g t c c v v v (61)

(62)


Boundary conditions:
Front boundary: At the front boundary we have a constant water level height in every
time step. Here, only the velocity is needed to calculate at the front boundary. Figure 6 relates
to this boundary condition (see Chapter II).
The following equation is valid in this case:
|
|
.
|

\
|


A + + =
+ +
3 / 4 2
2
1
1
1
1
2 2
hR R
R R
R
i i
R
i
R
i
R A
n Q Q
dx
dz
g t y g c v v . (63)

1
1
+ i
y is known in every time step!

End boundary: At the end boundary we have a constant water level height in every time
step. Here, only the velocity is needed to calculate at the end boundary. Figure 7 relates to this
boundary condition (see Chapter II).
The following equation is valid in this case:
|
|
.
|

\
|


A + + =
+ +
3 / 4 2
2
1 1
2 2
hL L
L L
L
i
N
i
L
i
L
i
N
R A
n Q Q
dx
dz
g t y g c v v . (64)
1 + i
N
y is known in every time step!



2
3 / 4 2
2
3 / 4 2
2
1
2 2
16
1

|
|
.
|

\
|


+ A + + +

=
+
hR R
R R
hL L
L L
R L
i
R
i
L
i
R
i
L
i
j
R A
n Q Q
R A
n Q Q
dx
dz
g
dx
dz
g t c c v v
g
y
24
VI. VARIABLE BOTTOM SLOPE PROBLEM
MATLAB CODE WITH EXPLANATION

The program has almost the same structure like the previous one. The time step selection
is added into the Main loop and the additional source terms appear in the code.

function hullammedence
clear all, clc, clf
%definition of the global parameters
global dt % time step
global wa % amplitude of excitation
global bottom % bottom curve
global dzodx % dz/dx vector

% PARS
pars.L=10; % structure
pars.B=10; % width of the tank
pars.N=40; % spatial resolution
pars.dx=pars.L/(pars.N-1); % distance between two nodes
pars.g=9.81; % gravitational constant
pars.manning=0.01; % Mannings constant
omega=5; % frequency of excitation
wa=0.7; % amplitude of excitation
xgrid=linspace(0,pars.L,pars.N); % x coordinate vector


%Parameters of the bottom slope
pars.L0=2; % Vector element at which the sine square begins
pars.LS=7; % Width of the sine square (in elements)
pars.H=0.5; % Height of the sine square (in meters)
% Initial Conditions
y1=5; % water level at the front
y2=5; %water level at the end
v0=0; % initial water velocity

% Generating the bottom slope
bottom=zeros(1,pars.N); % The initial bottom height is set to zero
dzodx=zeros(1,pars.N); % The initial bottom slope derivative is set to zero

L0=pars.L0;
LS=pars.LS;
H=pars.H;

for i=1:length(bottom)
xxx=xgrid(i);
if xxx>L0 && xxx<L0+LS; % see Fig. 11
25
bottom(i)=H*(sin(pi*(xxx-L0)/LS))^2; % bottom sine square generated, see
Eq.(57)
dzodx(i) =H*2*sin(pi*(xxx-L0)/LS)*cos(pi*(xxx-L0)/LS)*pi/LS; % bottom slope
derivative generated, see Eq.(58)
%fprintf('\n x=%5.3f, sin(...)=%5.3f',xxx,sin(pi*(xxx-L0)/LS));
end
end

% Simulation time
tmax=50; %total simulation time
t=0;
C=0.9; % safety factor (0..1) for time step selection , see Eq.(60)

for d=0:pars.N-1;
y(d+1)=y1-d*pars.dx/pars.L*(y1-y2);
disp(d*pars.dx/pars.L*(y1-y2));
end

v=v0*ones(1,pars.N); % initial velocity vector
y=y+bottom; % initial water level
ynew=y; % new water level vector
vnew=v; % new velocity vector

% Main loop
while t<tmax

% Timestep selection
dt=C*pars.dx/max((pars.g*y).^0.5+abs(v)); % see Eq.(60)

% Plot
figure(1)
subplot(3,1,1), plot(xgrid, y,'r-+',xgrid,bottom,'k-');%,xgrid,dzodx,'k--');
grid on, ylabel('y [m]')
title(['t=',num2str(round(t)),'s'])
axis([0 pars.L 0 6])

subplot(3,1,2), plot(xgrid, vnew,'b-',xgrid,(pars.g*ynew).^0.5,'r--');
grid on, xlabel('x [m]'), ylabel('v [m/s]')
axis([0 pars.L -5 7])

subplot(3,1,3), plot(xgrid,ynew.*vnew,'-')
grid on, xlabel('x [m]'), ylabel('Q [m^3/s/m]')
axis([0 pars.L -1 15])

%subplot(4,1,4), plot(xgrid,bottom,'b-',xgrid,dzodx,'r-')
%grid on, xlabel('x [m]'), ylabel('h [m]')

% Front Boundary Condition
yf=y1; % assignment of the first grid point to the front boundary
26
vf=BC_front(y,v,yf,pars); %Function of method of characteristics for the Front
Boundary Condition, It will be accurately defined later.
ynew(1)=yf; % Recalling of the new y value at the first grid point
vnew(1)=vf; % Recalling of the new v value at the first grid point

% Assigns values to y(2)...y(N-1) and v(2)...v(N-2)
[ynew,vnew]=moc_step(y,v,dt,pars,ynew,vnew); % definition of the function of
method of characteristics for the innerspace points

% End Boundary Condition
ye=y2; % definition of the end water level height given by y2
ve=BC_end(y,v,ye,pars); %Function of method of characteristics for the End
Boundary Condition, It will be accurately defined later.
ynew(pars.N)=ye; % Recalling of the new y value at the last grid point
vnew(pars.N)=ve; % Recalling of the new v value at the last grid point

% Close step
y=ynew;
v=vnew;
t=t+dt; %go to the next time step

%fprintf('\nOverall energy: %5.3e',sum(y+v.^2/2/pars.g));

z=abs(v)-(pars.g*y).^0.5; %if the velocity is higher than the sound velocity, the flow
is supersonic
if (max(z)>0)
error('Szuperszonikus aramlas, ilyet nem tudok.');
end

end

end

function [ynew,vnew]=moc_step(y,v,dt,pars,ynew,vnew) % definition of the function
of method of characteristics for the innerspace points
% defining the constant parameters
N=pars.N;
g=pars.g;
B=pars.B;
m=pars.manning;
dx=pars.L/(pars.N-1);
H=pars.H;
L0=pars.L0;
LS=pars.LS;

for i=2:(N-1) % for only the innerspace points N=2N-1

x=linspace(0,pars.L,pars.N); %resolution of the x-axis
c=(g*y).^0.5; % defining the connection between the pressure wave velocity and
the water height level (see Eq.(3))
27

x_alpha=x+(v+c)*dt; %see Eq.(17)
x_beta=x+(v-c)*dt; %see Eq.(18)
xi=x(i); % the x-coordinate of the i-th grid point will be xi

% The position of the slopes running in
x_innen_alpha=interp1(x_alpha,x,xi); linear interpolation of x-coordinate of the
L(eft) point, see (comm1)
x_innen_beta=interp1(x_beta,x,xi); %linear interpolation of x-coordinate of the
R(ight) point, see (comm2)

% Calculation of v(alpha), c(alpha), v(beta), c(beta)
cl=interp1(x,c,x_innen_alpha); %see (comm4)(left)
vl=interp1(x,v,x_innen_alpha); %see (comm3)(left)
cr=interp1(x,c,x_innen_beta); %see (comm6)(right)
vr=interp1(x,v,x_innen_beta); %see (comm5)(right)


% Bottom slope source terms
if x_innen_beta>L0 && x_innen_beta<L0+LS; % position of the variable bottom
surface, see Fig. 11 (right)
Sr= -g*H*2*sin(pi*(x_innen_beta-L0)/LS)*cos(pi*(x_innen_beta-L0)/LS)*pi/LS; %
definition of source term relates to variable bottom slope by Eq.(58) if there is any
variable bottom slope
else
Sr=0; %if there is no variable bottom at the certain position this source term is
zero
end

if x_innen_alpha>L0 && x_innen_alpha<L0+LS; % position of the variable bottom
surface, see Fig. 11 (left)
Sl=-g*H*2*sin(pi*(x_innen_alpha-L0)/LS)*cos(pi*(x_innen_alpha-L0)/LS)*pi/LS;
% definition of source term relates to variable bottom slope by Eq.(58) if there is any
variable bottom slope
else
Sl=0; %if there is no variable bottom at the certain position this source term is
zero
end

% Friction source terms
Al=cl^2/g*B; % flow cross-section from left Eq.(53)
Ar=cr^2/g*B; % flow cross-section from left Eq.(53)
Pl=B+2*cl^2/g; %wetted perimeter for rectangular channel from left Eq.(55)
Pr=B+2*cr^2/g; %wetted perimeter for rectangular channel from right Eq.(55)
Ql=Al*vl; %volume flow rate (left) Eq.(51)
Qr=Ar*vr; %volume flow rate (right) Eq.(51)
Rhl=Al/Pl; %hydraulic radius (left) Eq.(54)
Rhr=Ar/Pr; %hydraulic radius (right) Eq.(54)
Sfl=-Ql*abs(Ql)*m^2/(Al^2*Rhl^(4/3)); %Mannings friction rule (left) Eq.(50)
Sfr=-Qr*abs(Qr)*m^2/(Ar^2*Rhr^(4/3)); %Mannings friction rule (right) Eq.(50)
28


% Calculation of the new y and v values
vnew(i)=1/2*(vl+vr+2*cl-2*cr+dt*(Sl+Sr+Sfl+Sfr)); % see Eq.(61)
ynew(i)=1/(16*g)*(vl-vr+2*cl+2*cr+dt*(Sl-Sr+Sfl-Sfr))^2; % see Eq.(62)


end
end

function vf=BC_front(y,v,yy,pars) % definition of the function of method of
characteristics for the Front Boundary Condition

global dt

% Variables at the front
N=pars.N;
g=pars.g;
dx=pars.L/(pars.N-1);
B=pars.B;
m=pars.manning;
L0=pars.L0;
LS=pars.LS;
H=pars.H;

x=linspace(0,pars.L,pars.N); %resolution
c=(g*y).^0.5; %see Eq.(3)

% Interpolation
x_beta=x+(v-c)*dt; % equation for the x-position of the appropriate R(ight) point ,see
Eq.(18)
x_innen_beta=interp1(x_beta,x,0); %linear interpolation of x-coordinate of the R(ight)
point where the x-coordinate of the desired point is zero (third variable in the
command), see (comm2)

% linear interpolation to the R(ight) point (pressure wave velocity and the velocity)
cr=interp1(x,c,x_innen_beta); %see(comm6)
vr=interp1(x,v,x_innen_beta); %see(comm5)

%Source term at the front
if x_innen_beta>L0 && x_innen_beta<L0+LS; % position of the variable bottom
surface, see Fig. 11 (right)
Sr= -g*H*2*sin(pi*(x_innen_beta-L0)/LS)*cos(pi*(x_innen_beta-L0)/LS)*pi/LS;
%see Eq.(58)(right)
else
Sr=0; %no bottom slope, no this kind of source term
end

Ar=cr^2/g*B; % flow cross-section from right Eq.(53)

29
Pr=B+2*cr^2/g; %wetted perimeter for rectangular channel from right Eq.(55)
Qr=Ar*vr; %volume flow rate (right) Eq.(51)
Rhr=Ar/Pr; %hydraulic radius (right) Eq.(54)
Sfr=-Qr*abs(Qr)*m^2/(Ar^2*Rhr^(4/3)); %Mannings friction rule (right) Eq.(50)

% Return value of the function, the calculation of the new velocity at the front
boundary
vf=2*sqrt(yy*g)+vr-2*cr+dt*(Sr+Sfr); %see Eq.(63)

end

function ve=BC_end(y,v,ye,pars) % definition of the function of method of
characteristics for the End Boundary Condition

global dt

% Variables at the end
N=pars.N;
g=pars.g;
dx=pars.L/(pars.N-1);
L=pars.L;
B=pars.B;
m=pars.manning;
L0=pars.L0;
LS=pars.LS;
H=pars.H;

x=linspace(0,pars.L,pars.N); %resolution
c=(g*y).^0.5; %see Eq.(3)

% Interpolation
xi=L; % defining the position, we are at the position L, so at the end of the pool
x_alpha=x+(v+c)*dt; % equation for the x-position of the appropriate L(eft) point ,see
Eq.(17)
x_innen_alpha=interp1(x_alpha,x,xi); %linear interpolation of x-coordinate of the
L(eft) point where the x-coordinate of the desired point is xi defined as L (third
variable in the command), see (comm1)
%linear interpolation to the L(eft) point (pressure wave velocity and the velocity)
cl=interp1(x,c,x_innen_alpha); %see(comm4)
vl=interp1(x,v,x_innen_alpha); %see(comm3)

%Source term at the front
if x_innen_alpha>L0 && x_innen_alpha<L0+LS; % position of the variable bottom
surface, see Fig. 11 (left)
Sl= -g*H*2*sin(pi*(x_innen_alpha-L0)/LS)*cos(pi*(x_innen_alpha-L0)/LS)*pi/LS;
%see Eq.(58)(left)
else
Sl=0; %if there is no bottom slope, no this kind of source term
end

30
% Friction source terms
Al=cl^2/g*B; % flow cross-section from left Eq.(53)
Pl=B+2*cl^2/g; %wetted perimeter for rectangular channel from left Eq.(55)
Ql=Al*vl; %volume flow rate (left) Eq.(51)
Rhl=Al/Pl; %hydraulic radius (left) Eq.(54)
Sfl=-Ql*abs(Ql)*m^2/(Al^2*Rhl^(4/3)); %Mannings friction rule (left) Eq.(50)

% Return value of the function, the calculation of the new velocity at the end
boundary
ve=vl+2*cl-2*sqrt(g*ye)+dt*(Sl+Sfl); %see Eq.(64)

end

Potrebbero piacerti anche