You are on page 1of 24

SKAA 3413

COMPUTER PROGRAMMING

GROUP PROJECT
RECTANGULAR CHANNEL CONSTRICTION

STUDENT/
MATRIC NO.

MOHD AZLAN BIN AMIR NORDIN


SX130554KAWS04
MOHD HASNAN BIN HASSAN
SX130580KAWS04
MOHD ZAMY SHAM BIN MOHD ZIN
SX130577KAWS04
MUHAMMAD ASYRAF BIN MASRI
SX130588KAWS04
NOORSHAFIY BIN AZMEY
SX130600KAWS04

SESI - SEM

2014/2015 1

SECTION

03

LECTURER

DR. PONSELVI JEEVARAGAGAM

ii

TABLE OF CONTENTS

CHAPTER
1

TITLE

PAGE

INTRODUCTION

1.1

Background of Problem

1.2

Objectives of Program

1.3

Benefits of Program

PROGRAM ALGORITHM

2.1

Analysis Method

2.2

Pseudo Code

2.3

Flow Chart

PROGRAM STRUCTURE

3.1

GUI Setting

3.2

Script

TEST PLAN

11

4.1

Input Validation

11

4.2

Test 1 - Wier

12

4.3

Test 2 - Constriction

14

4.4

Test 3 - Weir & Constriction

15

REFERENCES
APPENDICES
Appendix 1 - Work Program
Appendix 2 - Test Plan Calculation

16

CHAPTER 1

1.1

INTRODUCTION

Background of Problem

The water will flow uniformly in an open channel if there is no obstruction to


the flow. The possible obstruction for the flow is either broad crested weir or
constriction or both.

Weir is a structure that is placed at the channel invert that will increase the
invert level while constriction
constriction is the reduction of the channel width. Obstruction will
modify the hydraulic profile and energy line of the flow.

Figure 1.1 Channel constriction.

Figure 1.2 Broad crested weir.

1.2

Objectives of Program

The program will analyse the flow of water in a rectangular open channel
trough the obstruction. The hydraulic profile of the flow will depends on:
1.

State of flow before the obstruction (subcritical/supercritical).

2.

Height of weir, h.

3.

Width of constriction, B2.

The objectives of the program are:


1.

To determine the water depth at the obstruction (yy2), upstream of the


obstruction (y
( 1) and downstream of the obstruction (y
( 3).

1.3

2.

To illustrate the hydraulic profile of the flow.

3.

To write the output to text file Result.txt.

Benefits of Program

The benefits of the program are:


1.

Quickly calculate values of E, y, and yc from upstream section to


downstream section.

2.

Quickly plot the elevation of hydraulic profile of the flow.

3.

User friendly by application of GUI.


GUI

CHAPTER 2

2.1

PROGRAM ALGORITHM

Analysis Method

The program is using the concept of specific energy as a method of analysis


as shown in equation below:

q2
E = y+
2 gy 2

The values of E are equal from upstream to downstream of control structure


and must satisfy the Emin for each section. If E0 > Emin2 + h, the value of E1 and E2 are
equal to the value of E0 and value of y1 and y3 are equal with value of y0. The value
of E2 = E0 h and y2 to be calculated from equation below:

y2 +

q22
= E0 h
2 gy22

If E0 < Emin2 + h, the value of E2 is equal to the value of Emin2 and value of y2
are equal with value of yc2. The value of E1, E3 = Emin2 + h and the value of y1 and y3
are to be calculated from equation below:

y+

q2
= Emin 2 + h
2 gy 2

4
2.2

Pseudo Code

The algorithm of the program is listed below:

1.

User input Q , y0 , B , B2 and h

2.

Validate input until Q , y0 , B , B2 > 0 , B2 < B and h 0

3.

q = Q B , yc = 3 q 2 g , Emin = 1.5 yc

4.

q2 = Q B2 , yc 2 = 3 q22 g , Emin 2 = 1.5 yc 2

5.

E0 = y0 +

6.

If E0 > Emin 2 + h

q2
2 gy0

a. E1 = E3 = E0
b. y1 = y3 = y0
c. E2 = E0 h
d. Determine y2 by solving equation 2 gy23 2 gE2 y22 + q22 = 0 where

yc 2 < y2 < y0 if y0 > yc 2 or y0 < y2 < yc 2 if y0 < yc 2


7.

If E0 < Emin 2 + h
a. E2 = Emin 2
b.

y2 = yc 2

c. E1 = E3 = Emin 2 + h
d. Solving equation 2 gy 3 2 gE1 y 2 + q 2 = 0 to determine y1 and y3
where y1 > y0 and y3 < yc
8.

Plot graph to display E , y , and yc for section 0 to section 3

9.

Write output Result.txt as format below


Location
E(m)
y(m)
yc(m)
-------------------------------------------------(0)Normal
E0
y0
yc0
(1)Upstream
E1
y1
yc1
(2)Structure
E2
y2
yc2
(3)Downstream
E3
y3
yc3

5
2.3

Flow Chart

Main Program (PRJ_Main.m)


Start

Input
Q, y0 , B, B2 , h

B2 B
Q, y0 , B, B2 > 0

No

h0
Yes
2
q = Q B , yc = 3 q g , Emin = 1.5 yc
q2 = Q B2
, y = 3 q 2 g , Emin 2 = 1.5 yc 2
c2

E0 = y0 +

Yes

q2
2 gy0

E0 > Emin 2 + h

UDF_Uncontrol

No

UDF_Control

E0 , E1 , E2 , E3
y0 , y1 , y2 , y3
yc 0 , yc1 , yc 2 , yc 3

Plot hydraulic profile


Write Result.txt

End

6
UDF_Uncontrol.m:

E1 = E3 = E0
y1 = y3 = y0

E2 = E0 h
Solve 2 gy23 2 gE2 y22 + q22 = 0

Yes

y0 > yc 2

No

yc 2 < y2 < y0

y0 < y2 < yc 2

UDF_Control.m:

E2 = Emin 2
y2 = yc 2

E1 = E3 = Emin 2 + h
Solve 2 gy 3 2 gE1 y 2 + q 2 = 0
y1 > y0
y3 < yc

CHAPTER 3

3.1

PROGRAM STRUCTURE

GUI Setting

(1)

(2)

(3)

(4)

(5)

(6)

(7)

(8)

(9)

(10)

Marker

Tag

Marker

Tag

(1)

txtQ

(6)

txtVal

(2)

txty0

(7)

FigGraph

(3)

txtB

(8)

btnRUN

(4)

txtB2

(9)

btnCLEAR

(5)

txth

(10)

btnEND

8
3.2

Script

btnRUN script
% --- Executes on button press in btnRUN.
function btnRUN_Callback(hObject, eventdata, handles)
% hObject
handle to btnRUN (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles
structure with handles and user data (see GUIDATA)
Q=str2double(get(handles.txtQ,'string'));
y0=str2double(get(handles.txty0,'string'));
B=str2double(get(handles.txtB,'string'));
B2=str2double(get(handles.txtB2,'string'));
h=str2double(get(handles.txth,'string'));
if isnan(Q)||isnan(y0)||isnan(B)||isnan(B2)||isnan(h)||...
(Q<=0||y0<=0||B<=0||B2<=0||h<0)==1
set(handles.txtVal,'string',...
'All inputs must be a positive number.',...
'ForegroundColor','r')
axes(handles.FigGraph),cla reset,axis off
axes(handles.FigAns),cla reset,axis off
elseif B2>B
set(handles.txtVal,'string',...
'B2 must be smaller than or equal to B.',...
'ForegroundColor','r')
axes(handles.FigGraph),cla reset,axis off
axes(handles.FigAns),cla reset,axis off
else set(handles.txtVal,'string','')
Inp.Q=Q;
Inp.y0=y0;
Inp.B=B;
Inp.B2=B2;
Inp.h=h;
%Calculation
g=9.81;
q=Q/B;
yc=(q^2/9.81)^(1/3);
Emin=1.5*yc;
E0=y0+q^2/2/g/y0^2;
q2=Q/B2;
yc2=(q2^2/9.81)^(1/3);
Emin2=1.5*yc2;
if E0>Emin2+h
[Out]=UDF_Uncontrol(E0,y0,yc2,h,q2);
else
[Out]=UDF_Control(q,E0,y0,h,Emin2,yc2);
end
%List location and yc
Out(1).Loc='(0)Normal
';
Out(2).Loc='(1)Upstream ';
Out(3).Loc='(2)Structure ';
Out(4).Loc='(3)Downstream';
Out(1).yc=yc;
Out(2).yc=yc;
Out(3).yc=yc2;
Out(4).yc=yc;

9
%Table for plot
Tbl(1,:)=0:7;
Tbl(2,1:2)=Out(1).E;
Tbl(2,3:4)=Out(2).E;
Tbl(2,5:6)=Out(3).E+h;
Tbl(2,7:8)=Out(4).E;
Tbl(3,1:2)=Out(1).y;
Tbl(3,3:4)=Out(2).y;
Tbl(3,5:6)=Out(3).y+h;
Tbl(3,7:8)=Out(4).y;
Tbl(4,1:2)=Out(1).yc;
Tbl(4,3:4)=Out(2).yc;
Tbl(4,5:6)=Out(3).yc+h;
Tbl(4,7:8)=Out(4).yc;
%Plot profile
axes(handles.FigGraph),cla reset,axis off,hold on
area(Tbl(1,:),Tbl(3,:),'FaceColor','c')
area([3.5 4 5 5.5],[0 h h 0],'FaceColor','y')
plot(Tbl(1,:),Tbl(2,:),'k','LineStyle','--')
plot(Tbl(1,:),Tbl(4,:),'r','LineStyle','-.')
text(0.5,Out(1).E,'\nablaE','HorizontalAlignment','c',...
'VerticalAlignment','base')
text(0.5,Out(1).y,'\nablay','HorizontalAlignment','c',...
'VerticalAlignment','base')
text(0.5,Out(1).yc,'\nablay_{c}','HorizontalAlignment','c',...
'VerticalAlignment','base')
if h>0
text(4.5,h,sprintf('h=%.2fm',h),'HorizontalAlignment',...
'c','VerticalAlignment','bottom')
end,hold off
%Display result
axes(handles.FigAns),cla reset,axis off,hold on
xlim([0 7])
text(0.5,0,sprintf('E_{0}=%.3fm\ny_{0}=%.3fm\ny_{c}=%.3fm',...
Out(1).E,Out(1).y,Out(1).yc),'HorizontalAlignment','c',...
'VerticalAlignment','bottom')
text(2.5,0,sprintf('E_{1}=%.3fm\ny_{1}=%.3fm\ny_{c}=%.3fm',...
Out(2).E,Out(2).y,Out(2).yc),'HorizontalAlignment','c',...
'VerticalAlignment','bottom')
text(4.5,0,sprintf('E_{2}=%.3fm\ny_{2}=%.3fm\ny_{c2}=%.3fm',...
Out(3).E,Out(3).y,Out(3).yc),'HorizontalAlignment','c',...
'VerticalAlignment','bottom')
text(6.5,0,sprintf('E_{3}=%.3fm\ny_{3}=%.3fm\ny_{c}=%.3fm',...
Out(4).E,Out(4).y,Out(4).yc),'HorizontalAlignment','c',...
'VerticalAlignment','bottom'),hold off
%Write result
fid=fopen('Results.txt','w');
fprintf(fid,'%s%.3fm\n%s%.3fm\n%s%.3fm\n%s%.3fm\n%s%.3fm\n',...
'Q = ',Inp.Q,'y0 = ',Inp.y0,'B = ',Inp.B,'B2 = ',...
Inp.B2,'h = ',Inp.h)
fprintf(fid,'\n Location
E(m)
y(m)
yc(m)\n')
fprintf(fid,'---------------------------------------------\n')
for i=1:4
fprintf(fid,' %s%10.3f%10.3f%10.3f\n',Out(i).Loc,...
Out(i).E,Out(i).y,Out(i).yc)
end
fclose(fid)
end

10
btnCLEAR script
% --- Executes on button press in btnCLEAR.
function btnCLEAR_Callback(hObject, eventdata, handles)
% hObject
handle to btnCLEAR (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles
structure with handles and user data (see GUIDATA)
set(handles.txtQ,'string','')
set(handles.txty0,'string','')
set(handles.txtB,'string','')
set(handles.txtB2,'string','')
set(handles.txth,'string','')
set(handles.txtVal,'string','')
axes(handles.FigGraph)
cla reset
set(handles.FigGraph,'Visible','off')
axes(handles.FigAns)
cla reset
set(handles.FigAns,'Visible','off')

btnEND script
% --- Executes on button press in btnEND.
function btnEND_Callback(hObject, eventdata, handles)
% hObject
handle to btnEND (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles
structure with handles and user data (see GUIDATA)
delete(handles.PRJ_Main)

CHAPTER 4

TEST PLAN

Testing for this program was made using exercise from Hydraulics Lecture
Notes by Mr. Amat Sairin Demun.

4.1

Input Validation

The program requires all inputs are positive number. A notification will
appear if any of the input is not a positive number as shown below.

12
The program also requires the value of B2 is less than or equal to the value of

B. If the value of B2 is greater than B a notification will appear as shown below.

4.2

Test 1 - Wier

Q=

AR 2 3 S A5 3 S
= 23
n
P n

A5 3 Qn 9.8 0.015
=
=
= 5.197
P2 3
S
0.0008

( By0 )

53

( B + 2 y0 )

23

( 2.6 y0 )

53

( 2.6 + 2 y0 )

23

= 5.197 y0 = 2.270m

13

Location
E(m)
y(m)
yc(m)
--------------------------------------------(0)Normal
2.411
2.270
1.131
(1)Upstream
2.411
2.270
1.131
(2)Structure
1.911
1.642
1.131
(3)Downstream
2.411
2.270
1.131

Location
E(m)
y(m)
yc(m)
--------------------------------------------(0)Normal
2.411
2.270
1.131
(1)Upstream
2.617
2.501
1.131
(2)Structure
1.697
1.131
1.131
(3)Downstream
2.617
0.599
1.131

14
4.3

Test 2 - Constriction

( 2.6 y0 )

53

( 2.6 + 2 y0 )

23

9.8 0.016
= 1.109 y0 = 0.715m
0.02

15
4.4

Test 3 - Weir & Constriction

Location
E(m)
y(m)
yc(m)
--------------------------------------------(0)Normal
2.715
0.450
0.972
(1)Upstream
8.794
8.788
0.972
(2)Structure
3.794
2.529
2.529
(3)Downstream
8.794
0.231
0.972

REFERENCES

Amat Sairin Demun (2010). Hydraulics Lecture Notes. (3rd Edition). Skudai: UTM.

Mohamad Hidayat Jamal (2014). Lecture Module for SKAA 2513 Hydraulics.
Unpublished, UTM.

Ponselvi Jeevaragagam (2014). Lecture Module for SKAA 3413 Computer


Programming. Unpublished, UTM.

APPENDIX 1
Work Program

PROGRAM FOR RECTANGULAR CHANNEL CONSTRICTION


Work Program

November
No.

Works Description

Action by

Choosing the problem:


Weir & constriction

Plan the program, pseudo


code, flowchart, algorithm

Shafiy/Hasnan

Draft the program, GUI

Hasnan/Zamy

Develop the program, script

Asyraf/Azlan

Test the program

Prepare the report, compile


the program

Submission

Everyone

Everyone
Zamy/Shafiy

Week
10

Week
11

December
Week
12

Week
13

Week
14

January
Week
15

Week
16

Week
17

Week
18

APPENDIX 2
Test Plan Calculation

You might also like