2011 Project report SO1

June 12, 2017 | Autor: Biao Liu | Categoría: Control Systems Engineering, Numerical Analysis, Control Systems
Share Embed


Descripción

Abstract:

In simulation of irrigation channels and rivers the water levels and flows are usually displayed by a 1-D plot, i.e. a single line. The aim of this project is to develop a simulator or a visualization tool for open water channels. The purpose is to illustrate the water flows of channels in a much more attractive and interactive manner, for e.g. an animated 3-D plot showing the flows of water in a channel. This will give an animated effect to the simulation results and to improve the visualization of the fascinating dynamics of the channels. This project will have a strong emphasis on software development.

Project team starts with researching on possible governing equations that could describe an open water channel then possible algorithm to work with such governing equations for 1-D plotting of the system. During the process of creating the system, the resulting program should be powerful enough to take care of physical conditions such as boundary conditions, submerge conditions induced by the implementation of sluice gates, different types of gates and off take lateral flow of the open water channel.

Another aspect of the project is to apply some degree of control on to each section of the entire channel by fixing the height of downstream gate and changing the position of upstream gate to control the water depth of each section. Therefore a closed loop system and different types of controller are necessary to be constructed.

And in order to generate a 3-D plot of the channel, a plotter is essential. The team tries to fully and clearly animate the physical situation by consider all possible visualization factors such as color, size and clarity.

Finally a user interface is built for user to manipulate the plot and simulate the channel with any parameters they interested in. A few useful functions are also included in the interface to help users to better record and analyze the stimulation they would like to run.

i

Content 1. Introduction………………………………………………………….….…………………………………...…..1 1.1 Background…………………………………………………………….….……………………………..….….1 1.2 Aim and advantage…………………………………………………….………………………………...……..1 1.3 Overview of the simulator……………………………………………………………………………...………1 2.Research………………………………………………….…………………………………………...…………..2 2.1 Model one dimensional flow with Saint Venant Equation………………………………………...…………2 2.1.1 The derivation of the continuity equation……………………………………………………......…………2 2.1.2 Derivation of the momentum equation………………………………………………...……………………3 2.1.3 The accuracy of the SaintVenant equations…………………………………………...……………………3 2.2 The solution of the Saint Venant equations………………………………………….....……...……………...4 2.2.1 Implicit finite-difference scheme…………………………………………………………….………………4 2.2.2 Preissmann Scheme…………………………………………………………………………………...……...4 2.3 Feedback control………………………………………………………………………………………..…..….5 2.3.1 Models for control design………………………………………..…………………………….…………….5 2.3.2 Controller design……………………………………………………………………...……………………...6 2.3.3 Controller configuration………………………………………………………………………..……………7 3 Development of the main program……………………………………………………………...…..…………..8 3.1 Use standard step method to generate an initial profile…………………………….……………………….8 3.1.1 Procedure for computing…………………………………………..………………………………………...9 3.1.2 Discussion……………………………………………………………………………………..........................9 3.2 Solution procedure for Preissmann Scheme………………………………………..………………………...9 3.3 Method to tackle multiple channels……………………………………..…………………………………...11 3.4 Undershot and overshot sluice gates with submerge condition…………………………………………….12 3.4.1 Undershot gates………………………………………………….………………………………………….12 3.4.2 Submerge condition……………………….………………………………………………………...………12 3.5 Off take lateral flow………………………………………………………………………………….…….…13 3.6 Implementation of PI and PIL controllers………………………………………………………………..…13 4 User interface and 3-D plotter………………………………………………………………………………….14 4.1 User interface………………………………………………………………………………………………….14 4.2 3-D plotter……………………………………………………………………………………..........................15 5. Simulation and test……………………………………………………………………………………………..16 5.1 Initial profile of a 3 cascaded channels………………………………………………………………………16 5.2 Step test…………….………………………………………………………………………………………….16 5.3 Step test with multiple channels and mixed types of gate…………………………………………….…….18 5.4 Simulation of off take/lateral flow…………………………………………………………………….……..19 6 Decentralized control scheme…………………………………………………………………………………..21 6.1 Lateral flow with controller…………………………………………………………………………………..21 6.1.1 Lateral flow opens for short period ……………………………………..……………………………...…21 ii

6.1.2 Lateral flow opens for all time………………………………..………………………………………...….22 6.1.3 Lateral flow at multiple sections in multiple channels……………………………………………………23 6.2 Test for PI controller………………………………………………………………………………………….27 6.3 Test for PIL controller..…………………………………………………………………………………….…28 6.4 Saturation test with PIL controller………………………………………………………………………..…29 7. Future improvement……………………………………………………………………………………………31 8. Conclusion………………………………………………………………………………………………………32 Reference……..……………………………………………………………………………………………………33 User guide………………………………………………………………………………………………………….34 Appendix…………………………………………………………………………………………………………..50

iii

1. Introduction: 1.1 Background Irrigation networks of open-water channels are used throughout the world to support agricultural activity. Management of the water resources has become an important issue, some may be interested in the dynamics of open water channels therefore a 3-D plot is required for better illustration and demonstration of a variety of simulated situations. This project focuses on the modeling and 3-D plotting of open-water channels from the perspective of large-scale irrigation network simulation.

1.2 Aim and advantage Hopefully the final product can be interactive and accurate at the same time. A graphical user interface with 3-D plotter is carried out as a platform to illustrate the functions of the whole program so that users can try it out personally interactively. Meanwhile, efforts have been made to ensure that the main program generate reliable accurate results. Since the project is heavily based on software design, the team also takes the efficiency of the code into consideration.

1.3 Overview of the simulator The project consists of 2 major programs and several small independent functions that return values needed to calculate the depth of water channel. "Mychannelbuilder.m" consists of the functions to plot the 3-D figure. "Preissmann.m" applies Preissmann Scheme to generate water depth. Together the whole software considers the problems such as different types of gate, submerge condition, off take flow, and multiple sections for large scale channel.

1

2. Research In this part of the report, the major topics the team studies on are discussed. 2.1 Model one dimensional flow with Saint Venant Equation Usually three conservation laws--mass, momentum, and energy are used to describe open water channel flow. In this project, two variables, the flow depth and velocity are chosen to define the flow conditions at a channel cross section. [1] Then study on the two Saint Venant equations is considered as the starting point in this project. 2.1.1 The derivation of the continuity equation

The following symbols are used in this derivation: A = the cross-sectional area of the section h = depth of flow at the section z = elevation of surface above a datum at the section V = mean velocity at the section Q = discharge at the section b = top width of flow surface of the section x = position of the section measured from the upstream t = time g = acceleration due to gravity r = mass density of the fluid ql = lateral flow rate Vx = component of lateral flow in the x direction = density of water Others symbols are defined in the text at the point when they are introduced. Assuming that there is no lateral flow, then

2

This has the partial derivative since Q is changing with both x and time t Now the volume of the water between the section 1 and 2 is increasing as a rate of [2]

As cross-sectional area A=bh then this is equivalent to

Since

are equal in magnitude but of opposite sign. So

2.1.2 Derivation of the momentum equation By applying Newton‟s 2nd law to our elemental length of channel we have [3]

It suggests that the rate of momentum change is equal to the resultant force acting on the control volume. The forces are pressure forces that act on the upstream and downstream , the component of weight of the water in x direction is

,

is channel bottom slope,

and frictional force between water and the channel sides and the channel bottom is

,

is the friction slope. Add these forces as the left hand side of the equation. Applying the mean value theorem [4], dividing term on both sides to Eqn (1) to get

2.1.3 The accuracy of the Saint Venant equations In Su Ki Ooi, M.P.M. Krutzen, E.Weyer (2003), the accuracy of the Saint Venant equations is examined. Water levels simulated using the Saint Venant equations with both physical and estimated parameters are compared against the measured water levels. The result has shown that the Saint Venant equations can adequately capture the dynamics of real open water channels.

3

2.2 The solution of the Saint Venant equations 2.2.1 Implicit finite-difference scheme The St Venant equations cannot be solved explicitly except by making some very large assumptions which are unrealistic for most situations. Therefore numerical techniques have to be used. In implicit finite-difference schemes, the spatial partial derivatives and/or the coefficients are replaced in terms of the values at the unknown time level. The unknown variables, therefore, appear implicitly in the algebraic equations, and the methods are called implicit methods. The algebraic equations for the entire system have to be solved simultaneously in these methods. [5] Implicit finite-difference schemes such as Beam and Warming scheme, Vasiliev scheme etc. Preissmann scheme is used to in this project. Some of the advantages of this choice are discussed in the next paragraph. 2.2.2 Preissmann Scheme Preissmann scheme has advantages which allows non-equidistant grids and computes discharge Q and elevation z at the same point. Thus the Preissmann type of implicit finite difference scheme was chosen in the mathematical model. The salient features of the Preissmann scheme are as follows: [6] (a) The Preissmann scheme is unconditionally stable as long as weighting coefficient > 0.5. Consequently, the time step is only a function of the required accuracy. The time step used can be chosen freely to be comparable with the particular physical phenomena under consideration. (b) The space intervals may be variable. This enables a more flexible schematization of the river, especially in the case of strongly varying cross sections. (c) Both unknown flow variables are computed at the same computational grid points. Stage/discharge rating curves and similar relationships may be introduced at the same locations with no particular difficulty. The partial derivatives and other coefficients are approximated as follows:

Where f is the flow variable, discharge Q or water depth y or area A or velocity V, and is a time weighting coefficient, 0< 1 name = load(filename); set(handles.Table1,'data',name); end guidata(hObject, handles);

function Qstep_Callback(hObject, eventdata, handles) % hObject

handle to Qstep (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of Qstep as text %

str2double(get(hObject,'String')) returns contents of Qstep as a double

% --- Executes during object creation, after setting all properties. function Qstep_CreateFcn(hObject, eventdata, handles) % hObject

handle to Qstep (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows. %

See ISPC and COMPUTER.

if

ispc

&&

isequal(get(hObject,'BackgroundColor'),

get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end guidata(hObject, handles);

function StepTime_Callback(hObject, eventdata, handles) % hObject

handle to StepTime (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of StepTime as text %

str2double(get(hObject,'String')) returns contents of StepTime as a double

69

% --- Executes during object creation, after setting all properties. function StepTime_CreateFcn(hObject, eventdata, handles) % hObject

handle to StepTime (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows. %

See ISPC and COMPUTER.

if

ispc

&&

isequal(get(hObject,'BackgroundColor'),

get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end guidata(hObject, handles); % --- Executes on button press in Pause_button. function Pause_button_Callback(hObject, ~, handles) % hObject

handle to Pause_button (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

structure with handles and user data (see GUIDATA)

pause(5); guidata(hObject, handles); % --- Executes on button press in Clear. function Clear_Callback(hObject, eventdata, handles) % hObject

handle to Clear (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

structure with handles and user data (see GUIDATA)

cla; set(handles.QIN,'string','2.5'); table = zeros(9,20); set(handles.Table1,'data',table); table = zeros(200,21); set(handles.qtable,'data',table); set(handles.num_chl,'string','0'); set(handles.num_time,'string','0'); set(handles.showtime,'string','0'); table = zeros(4,20); set(handles.controller_table,'data',table); guidata(hObject, handles); function showtime_Callback(hObject, eventdata, handles) % hObject

handle to showtime (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

structure with handles and user data (see GUIDATA) 70

% Hints: get(hObject,'String') returns contents of showtime as text %

str2double(get(hObject,'String')) returns contents of showtime as a double

% --- Executes during object creation, after setting all properties. function showtime_CreateFcn(hObject, eventdata, handles) % hObject

handle to showtime (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows. %

See ISPC and COMPUTER.

if

ispc

&&

isequal(get(hObject,'BackgroundColor'),

get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

% --- Executes when selected object is changed in uipanel8. function uipanel8_SelectionChangeFcn(hObject, eventdata, handles) % hObject

handle to the selected object in uipanel8

% eventdata structure with the following fields (see UIBUTTONGROUP) %

EventName: string 'SelectionChanged' (read only)

%

OldValue: handle of the previously selected object or empty if none was selected

%

NewValue: handle of the currently selected object

% handles

structure with handles and user data (see GUIDATA)

% -------------------------------------------------------------------function uipanel8_ButtonDownFcn(hObject, eventdata, handles) % hObject

handle to uipanel8 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

structure with handles and user data (see GUIDATA)

function edit8_Callback(hObject, eventdata, handles) % hObject

handle to edit8 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit8 as text %

str2double(get(hObject,'String')) returns contents of edit8 as a double

71

% --- Executes during object creation, after setting all properties. function edit8_CreateFcn(hObject, eventdata, handles) % hObject

handle to edit8 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows. %

See ISPC and COMPUTER.

if

ispc

&&

isequal(get(hObject,'BackgroundColor'),

get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

function stestM_time_Callback(hObject, eventdata, handles) % hObject

handle to stestM_time (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of stestM_time as text %

str2double(get(hObject,'String')) returns contents of stestM_time as a double

% --- Executes during object creation, after setting all properties. function stestM_time_CreateFcn(hObject, eventdata, handles) % hObject

handle to stestM_time (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows. %

See ISPC and COMPUTER.

if

ispc

&&

isequal(get(hObject,'BackgroundColor'),

get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

% --- Executes on button press in gbutton. function gbutton_Callback(hObject, eventdata, handles) % hObject

handle to gbutton (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

structure with handles and user data (see GUIDATA)

72

% --- Executes on button press in gbuttonfix. function gbuttonfix_Callback(hObject, eventdata, handles) % hObject

handle to gbuttonfix (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

structure with handles and user data (see GUIDATA)

% --- Executes on button press in qbutton. function qbutton_Callback(hObject, eventdata, handles) % hObject

handle to qbutton (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

structure with handles and user data (see GUIDATA)

filename = uigetfile('.txt'); [i j] = size(filename); if j > 1 name = load(filename); set(handles.qtable,'data',name); set(handles.QIN,'string',name(1,2)); end guidata(hObject, handles);

function num_chl_Callback(hObject, eventdata, handles) % hObject

handle to num_chl (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of num_chl as text %

str2double(get(hObject,'String')) returns contents of num_chl as a double

% --- Executes during object creation, after setting all properties. function num_chl_CreateFcn(hObject, eventdata, handles) % hObject

handle to num_chl (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows. %

See ISPC and COMPUTER.

if

ispc

&&

isequal(get(hObject,'BackgroundColor'),

get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

73

function num_time_Callback(hObject, eventdata, handles) % hObject

handle to num_time (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of num_time as text %

str2double(get(hObject,'String')) returns contents of num_time as a double

% --- Executes during object creation, after setting all properties. function num_time_CreateFcn(hObject, eventdata, handles) % hObject

handle to num_time (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows. %

See ISPC and COMPUTER.

if

ispc

&&

isequal(get(hObject,'BackgroundColor'),

get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

% --- Executes on button press in save_button. function save_button_Callback(hObject, eventdata, handles) % hObject

handle to save_button (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

structure with handles and user data (see GUIDATA)

checky = get(handles.savey, 'Value'); if checky == 1 data = getappdata(0,'YMa'); [m,n] = size(data); path = uiputfile('.txt','Save flow depth Y as'); [i j] = size(path); if j > 1 fid = fopen(path,'W'); for i = 1:m for j = 1:n fprintf(fid,'%10f ',data(i,j)); end fprintf(fid,'\n'); end fclose(fid); 74

end end checkq = get(handles.saveq, 'Value'); if checkq == 1 data = getappdata(0,'QMa'); [m,n] = size(data); path = uiputfile('.txt','Save discharge Q as'); [i j] = size(path); if j > 1 fid = fopen(path,'W'); for i = 1:m for j = 1:n fprintf(fid,'%10f ',data(i,j)); end fprintf(fid,'\n'); end fclose(fid); end end %msgbox('Flow depth saved as "Ymatrix.txt" in the current directory'); %save(path,'data'); guidata(hObject, handles);

% --- Executes on button press in exit_button. function exit_button_Callback(hObject, eventdata, handles) % hObject

handle to exit_button (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

structure with handles and user data (see GUIDATA)

close all; clc;

function offtakeplace_Callback(hObject, eventdata, handles) % hObject

handle to offtakeplace (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of offtakeplace as text %

str2double(get(hObject,'String')) returns contents of offtakeplace as a double

% --- Executes during object creation, after setting all properties. function offtakeplace_CreateFcn(hObject, eventdata, handles) 75

% hObject

handle to offtakeplace (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows. %

See ISPC and COMPUTER.

if

ispc

&&

isequal(get(hObject,'BackgroundColor'),

get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

function offtakerate_Callback(hObject, eventdata, handles) % hObject

handle to offtakerate (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of offtakerate as text %

str2double(get(hObject,'String')) returns contents of offtakerate as a double

% --- Executes during object creation, after setting all properties. function offtakerate_CreateFcn(hObject, eventdata, handles) % hObject

handle to offtakerate (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows. %

See ISPC and COMPUTER.

if

ispc

&&

isequal(get(hObject,'BackgroundColor'),

get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

function steptime_Callback(hObject, eventdata, handles) % hObject

handle to steptime (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of steptime as text %

str2double(get(hObject,'String')) returns contents of steptime as a double

76

% --- Executes during object creation, after setting all properties. function steptime_CreateFcn(hObject, eventdata, handles) % hObject

handle to steptime (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows. %

See ISPC and COMPUTER.

if

ispc

&&

isequal(get(hObject,'BackgroundColor'),

get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

function stepby_Callback(hObject, eventdata, handles) % hObject

handle to stepby (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of stepby as text %

str2double(get(hObject,'String')) returns contents of stepby as a double

% --- Executes during object creation, after setting all properties. function stepby_CreateFcn(hObject, eventdata, handles) % hObject

handle to stepby (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows. %

See ISPC and COMPUTER.

if

ispc

&&

isequal(get(hObject,'BackgroundColor'),

get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

function offtake_turnontime_Callback(hObject, eventdata, handles) % hObject

handle to offtake_turnontime (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

structure with handles and user data (see GUIDATA)

77

% Hints: get(hObject,'String') returns contents of offtake_turnontime as text %

str2double(get(hObject,'String')) returns contents of offtake_turnontime as a double

% --- Executes during object creation, after setting all properties. function offtake_turnontime_CreateFcn(hObject, eventdata, handles) % hObject

handle to offtake_turnontime (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows. %

See ISPC and COMPUTER.

if

ispc

&&

isequal(get(hObject,'BackgroundColor'),

get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

% --- Executes on button press in pushbutton12. function pushbutton12_Callback(hObject, eventdata, handles) % hObject

handle to pushbutton12 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

structure with handles and user data (see GUIDATA)

set(handles.uipanel1,'Visible','on'); %set(handles.uipanel2,'Visible','on'); %set(handles.uipanel3,'Visible','on'); set(handles.graph_panel,'Visible','off'); %set(handles.axis,'Visible','off');

% --- Executes on button press in pushbutton14. function pushbutton14_Callback(hObject, eventdata, handles) % hObject

handle to pushbutton14 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

structure with handles and user data (see GUIDATA)

set(handles.uipanel1,'Visible','off'); %set(handles.uipanel2,'Visible','off'); %set(handles.uipanel3,'Visible','off'); set(handles.graph_panel,'Visible','on'); %set(handels.axis,'Visible','on'); guidata(hObject, handles);

78

% --- Executes on button press in load_ot. function load_ot_Callback(hObject, eventdata, handles) % hObject

handle to load_ot (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

structure with handles and user data (see GUIDATA)

filename = uigetfile('.txt'); [i j] = size(filename); if j > 1 file = load(filename); setappdata(0,'ot_data',file); end guidata(hObject, handles);

% --- Executes on key press with focus on controller_table and none of its controls. function controller_table_KeyPressFcn(hObject, eventdata, handles) % hObject

handle to controller_table (see GCBO)

% eventdata structure with the following fields (see UITABLE) %

Key: name of the key that was pressed, in lower case

%

Character: character interpretation of the key(s) that was pressed

%

Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed

% handles

structure with handles and user data (see GUIDATA)

% --- Executes on button press in show_ot. function show_ot_Callback(hObject, eventdata, handles) % hObject

handle to show_ot (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

structure with handles and user data (see GUIDATA)

ot = getappdata(0,'ot_data'); figure; colnames = {'Channel NO', 'ON Time', 'OFF Time', 'Section Number', 'Rate', 'Section Number', 'Rate', '...'}; table = uitable('ColumnName', colnames, 'Position', [20 20 500 380]); set(table,'Data',ot); guidata(hObject, handles); % --- Executes on button press in ot_format. function ot_format_Callback(hObject, eventdata, handles) % hObject

handle to ot_format (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

structure with handles and user data (see GUIDATA)

figure; rownames = {'1', '2', '3', '...'}; colnames = {'Channel NO', 'ON Time', 'OFF Time', 'Section Number', 'Rate', 'Section Number', 79

'Rate', '...'}; uitable('ColumnName', colnames, 'RowName', rownames, 'Position', [20 20 500 350]); % --- Executes on button press in load_controller. function load_controller_Callback(hObject, eventdata, handles) % hObject

handle to load_controller (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

structure with handles and user data (see GUIDATA)

filename = uigetfile('.txt'); [i j] = size(filename); if j > 1 file = load(filename); set(handles.controller_table,'Data',file); end guidata(hObject, handles);

function ctrl_on_user_Callback(hObject, eventdata, handles) % hObject

handle to ctrl_on_user (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of ctrl_on_user as text %

str2double(get(hObject,'String')) returns contents of ctrl_on_user as a double

% --- Executes during object creation, after setting all properties. function ctrl_on_user_CreateFcn(hObject, eventdata, handles) % hObject

handle to ctrl_on_user (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows. %

See ISPC and COMPUTER.

if

ispc

&&

isequal(get(hObject,'BackgroundColor'),

get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

% --- Executes on button press in plot_window. function plot_window_Callback(hObject, eventdata, handles) % hObject

handle to plot_window (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB 80

% handles

structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of plot_window

% --- Executes on button press in savey. function savey_Callback(hObject, eventdata, handles) % hObject

handle to savey (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of savey

% --- Executes on button press in saveq. function saveq_Callback(hObject, eventdata, handles) % hObject

handle to saveq (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of saveq

% --- Executes on button press in pushbutton26. function pushbutton26_Callback(hObject, eventdata, handles) % hObject

handle to pushbutton26 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles

structure with handles and user data (see GUIDATA)

pause;

81

%######################################################################### %Feed back controller function to determine the required input discharge %Filename: PI_controller.m %######################################################################## function

[discharge]

=

PI_controller(Ki,Ti_c,sampling,g_constant,Q_0,y_0,y_1,y_set,gatetype,Yud) % y_initial and Q_initial happen at k % y_current and u and discharge happen at k+1 % u and discharge happen at k+1 if gatetype == 1 u = Q_0/g_constant+sampling*Ki/Ti_c*((y_set-y_0))-(y_set-y_0)*Ki+(y_set-y_1)*Ki; discharge = g_constant*u; else u

=

Q_0/g_constant/(Yud)^(1/2)

+

sampling*Ki/Ti_c*((y_set-y_0))-(y_set-y_0)*Ki+(y_set-y_1)*Ki; discharge = u*g_constant*(Yud)^(1/2); end

%######################################################################### %Feed back controller function to determine the required input discharge %Filename: PIL_controller.m %######################################################################## function

[discharge]

=

PIL_controller(Ki,Ti_c,Ti_f,sampling,g_constant,Q_0,Q_1,y_0,y_1,y_set_p,y_set_c,gatetype)

%Q_0 y_0 happen at k %Q_1 y_1 happen at k+1 %u and discharge happen at k+2 if gatetype == 1 u

=

(Q_0/g_constant*Ti_c*(sampling-Ti_f)+Q_1/g_constant*Ti_c*(2*Ti_f-sampling)+(y_set_c-y_1)* sampling*Ti_c*Ki+(y_set_p-y_0)*((sampling^2)*Ki-sampling*Ki*Ti_c))/Ti_c/Ti_f; discharge = g_constant*u; else u

=

(Q_0/g_constant*Ti_c*(sampling-Ti_f)+Q_1/g_constant*Ti_c*(2*Ti_f-sampling)+(y_set_c-y_1)* sampling*Ti_c*Ki+(y_set_p-y_0)*((sampling^2)*Ki-sampling*Ki*Ti_c))/Ti_c/Ti_f; discharge = g_constant*u; end

82

%######################################################################## %Function to plot the channel, including 2 walls and the datum. %Filename: plot_channel.m %######################################################################## function [x,TOT_SEC,ELE] = plot_channel(NCHL,CHL,NSEC,SO,BO,S) %plot datum W = 4; G_dif = 0.0001; %########################################################################## %G_dif: a variavle to indicates the jump over the gate. This happens %because in our program, we are assuming the gate is a surface with a very %small thickness (almost 0), but there are two flow depth at two sides of the %gate, in order to display the gate and the jump in the flow depth, we have %to represent them as multiple points with very small change in X, where X %is the horizontal distance along the channel from upstream to downstream. %########################################################################## TOT_SEC = 0; i = 1; DAM = 4; BO(1) = round(BO(1)); while i = 1 if i == NCHL RO_ELE = 0; x1 = x(JJ):0.0001:x(JJ)+0.0001; else RO_ELE = RO_ELE + CHL(i+1)*SO(i+1); JJ = JJ - NSEC(i+1); x1 = x(JJ):0.0001:x(JJ)+0.0001; end %draw fronnt cover1 (The light blue trapezion at left hand side of the gate) x5 = x(JJ):0.0001:x(JJ)+.0001; y5 = [-2/(1/S(i)) (BO(1)-W)/2-1 (BO(1)-W)/2]; [x5 y5] = meshgrid(x5,y5); z5 = zeros(3,2); z5(1,1) = DAM+RO_ELE; z5(1,2) = DAM+RO_ELE; z5(2,1) = RO_ELE; z5(2,2) = DAM+RO_ELE; z5(3,1) = RO_ELE; z5(3,2) = DAM+RO_ELE; cover1 = surf(x5,y5,z5); set(cover1,'FaceAlpha',0.5); set(cover1,'FaceColor',[0.3 0.3 0.9]); set(cover1,'EdgeColor',[0.3 0.3 0.9]); drawnow; %draw the front cover2(The light blue trapezion at right hand side of the gate) x6 = x(JJ):0.0001:x(JJ)+.0001; y6 = [W+(BO(1)-W)/2 W+(BO(1)-W)/2+1 W+2/(1/S(i))+(BO(1)-W)/2+1]; [x6 y6] = meshgrid(x6,y6); z6 = zeros(3,2); z6(1,1) = RO_ELE; z6(1,2) = DAM+RO_ELE; z6(2,1) = RO_ELE; z6(2,2) = DAM+RO_ELE; z6(3,1) = DAM+RO_ELE; z6(3,2) = DAM+RO_ELE; 85

cover2 = surf(x6,y6,z6); set(cover2,'FaceAlpha',0.5); set(cover2,'FaceColor',[0.3 0.3 0.9]); set(cover2,'EdgeColor',[0.3 0.3 0.9]); drawnow; i = i - 1; end %plot the channel sides i = NCHL; JJ = TOT_SEC; RO_ELE = 0; x2_m = []; y2_m = []; z2_m = []; x3_m = []; y3_m = []; z3_m = []; while i >= 1 z2 = zeros(3,NSEC(i)); z3 = zeros(3,NSEC(i)); if i == NCHL RO_ELE = 0; else RO_ELE = CHL(i+1) * SO(i+1) + RO_ELE; end J = 0; DYDX = CHL(i)/NSEC(i)*SO(i); %elevation per section while J Dgate %######################################################################## %account for the submerge condition, using trial and error to find %out the downstream water level %head = difference between the downstream flow depth and gate height %YD = downstream flow depth %######################################################################## YD = find_YD(Cout,Dgate,Ydd,Q); end elseif gtype == 2 %######################################################################## %undershot gate is used, downstream water level is calculated by 88

%making the assumption that the water level at the right %hand side (Ydd) of the last gate (if it is a undershot gate) is the %same as the gate opening. %######################################################################## YD = (Q/(Cout*Dgate))^2 + Ydd; end X = 0:-CHL/NSEC:-CHL; Y = 1:NSEC+1; V = 1:NSEC+1; Y(1) = YD; Q2 = Q*Q; ALQ = VH_coef*Q2/(2*G); ALQ2 = 2*ALQ; QN2 = (MN*Q)^2; Y1=YD; Z1 = ZD; DPDY = 2*(1+S^2)^0.5; A1=Y1*(BO+S*Y1); P1=BO+2*Y1*(1+S^2)^0.5; R1=A1/P1; SF1=QN2/(A1*A1*R1^1.3333); p = 2; while p
Lihat lebih banyak...

Comentarios

Copyright © 2017 DATOSPDF Inc.