You are on page 1of 23

CM: 1079

Team No. 3

ES205
Analysis and Design of Engineering Systems
Prof. Cornwell
Spring 2018-19

Report on experimental findings:


Tank draining system parameter identification

April 26, 2019

Josh Krsek
Albert Li
Ryan Tarr

Rose-Hulman Institute of Technology


Terre Haute, IN 47803
Abstract
The purpose of this experiment was to identify the discharge coefficients of each individual tank and
validate our individual tank models using the double tank draining system. We determined the optimal
discharge coefficient value for each tank that resulted in the lowest standard error of estimate between
the mathematical models and experimental data. We validated our individual tank models by
substituting the optimal discharge coefficients, 0.663 and 0.600 for the upper and lower tanks
respectively, into a two-tank model and comparing this model to experimental data. The two-tank model
matched the experimental data to within approximately 9% in terms of the upper tank drain time and
approximately 4% in terms of lower tank drain time with the model response trailing the experimental
data in both cases. We conclude that the mathematical models we developed accurately represent the
response of individual tank draining systems.

2
Table of Contents
Introduction ............................................................................................................................................. .5

Experimental Test Procedure.................................................................................................................. .5

Method of Analysis ................................................................................................................................. .6

Results and Discussion............................................................................................................................ .8

Conclusions and Recommendations ...................................................................................................... 14

Appendix A ............................................................................................................................................. 15

Appendix B .............................................................................................................................................. 16

Appendix C .............................................................................................................................................. 19

List of Figures
Figure 1 – Schematic of dual tank draining system. ............................................................................ .5

Figure 2 – Comparison of the initial model using 𝐶𝑑 = 0.7 , model using optimized 𝐶𝑑 = 0.663, and
experimental data of the upper tank experiment. .............................................................. .9

Figure 3 – Comparison of the initial model using 𝐶𝑑 = 0.7 , model using optimized 𝐶𝑑 = 0.600, and
experimental data of the lower tank experiment. ............................................................... 9

Figure 4 – Comparison of the model response using the discharge coefficients found from the single tank
tests and experimental data of the double tank experiment. ............................................. 10

Figure 5 – Comparison of the upper tank model response using the updated optimized discharge
coefficient 𝐶𝑑 = 0.693 and the experimental data of the double tank experiment. ......... 11

Figure 6 – Comparison of the model response using the lower tank discharge coefficient found from the
single tank test, upper tank discharge coefficient from the updated test, and experimental data
of the double tank experiment. ............................................................................................ 12

Figure B1 – Calibration data and regression line for the upper tank. .................................................. 17

Figure B2 – Calibration data and regression line for the lower tank. .................................................. 17

Figure C1 – Simulink diagram used for the simulation of the double tank model. ............................ 23

3
List of Tables
Table 1 – Original and optimized discharge coefficients with corresponding SEE values for both tanks.
................................................................................................................................................. .9

Table 2 – Optimized discharge coefficients for the upper tank found using the single tank and double
tank draining data along with their percent difference. ...................................................... 11

Table 3 – Observed characteristics of the predicted and measured response of the two-tank system.
................................................................................................................................................. 13

Table 4 – SEE value for both individual tanks in the two-tank system. ............................................. 13

Table A1 –Station 7 measured physical dimensions of the tanks ......................................................... 15

Table A2 –Station 7 measured areas of tanks and orifices. ................................................................... 15

Table B1 –Calibration data for the conversion of transducer voltage to water height. ....................... 16

Nomenclature
𝐴 – Cross-sectional area of a rectangular tank
𝐴𝑖 – Cross-sectional area of tank 𝑖
𝐴𝑜 – Area of orifice
𝐴𝑜𝑖 – Area of orifice of tank 𝑖
𝐶𝑑 – Discharge coefficient of orifice
𝐶𝑑𝑖 – Discharge coefficient of orifice of tank 𝑖
𝑔 – Acceleration of gravity
ℎ – Height of fluid measured from the bottom of the tank
ℎ𝑖 – Height of the fluid in tank 𝑖 measured from the bottom of the tank
ℎ𝑜 – Distance from the bottom of the tank to the exit of the orifice
ℎ𝑖𝑜 – Distance from the bottom of tank 𝑖 to the exit of the orifice
𝑖 = 1,2 – Subscript index (1 = upper tank, 2 = lower tank)
𝑚𝑠𝑦𝑠 – Mass of a system
𝑚̇𝑖𝑛 – Mass flowrate into a system
𝑚̇𝑜𝑢𝑡 – Mass flowrate out of a system
𝑄𝑖 – Volumetric flowrate out of tank 𝑖
𝑄𝑖𝑛 – Volumetric flowrate into the system
𝑄𝑜𝑢𝑡 – Volumetric flowrate out of the system
𝑡 – Time

4
Introduction
The purpose of this experiment was to identify the discharge coefficients of each individual tank and
validate our individual tank models using the double tank draining system. The discharge coefficients
were optimized by minimized the SEE of the water level heights obtained from experiment and our
Simulink model. To validate the optimized discharge coefficients, we compared the height of the water
level of each tank in our refined predictive model which used the optimal discharge coefficients with the
height of the water level from the experimental data of the double tank draining system. In this report,
we will discuss the experimental procedure, the method of analysis, and then results and discussion.

Experimental Test Procedure


In this section, we will discuss the procedure we used to collect all tank draining data. A double tank
draining system was initially filled with different amount of water in the upper tank and the lower tank.
The dimensions of the upper tank and the lower tank were measured using a measuring tape. These
measurements can be found in Appendix A. Figure 1 shows the general experimental apparatus
arrangement of the dual tank draining system.

in

Figure 1. Schematic of dual tank draining system.

Attached to each tank was a pressure transducer to measure the water pressure at the bottom of each
tank. Both sensors produced voltage signals (in Volts). To relate the voltage to water height in each tank,
we collected different water height readings with corresponding voltage data and established two
calibration equations for the two sensors. The upper tank was filled up until the water level was
approximately 9 inches above the bottom of the tank. The sensor voltage data displayed in a program
called TankCalibrate was recorded by hand. The water was drained such that the water level was
decreased by 1 inch after every measurement until we reached 1 inch of water in the tank. The same
process was repeated for the lower tank to relate sensor voltage to water level data. The table of the

5
heights of the water level in the upper tank and the lower tank with corresponding sensor voltage
readings and the correlation equations of both sensors can be found in Appendix B.

In the single tank draining experiments, the upper tank was filled to approximately 9 inches of water and
the sensor data was collected using a program called TankData. The upper tank was drained until the
1
water was about inch above the entrance to the orifice. The original data was trimmed to remove the
4
noise at the beginning of the data set. The same procedure was repeated for the lower tank.

In the double tank draining experiment, the upper tank was refilled to about 8 inches of water, and the
lower tank was refilled to approximately 4 inches of water. We started the data collection using TankData
when both outflow valves were opened at the same time. After the lower tank stopped draining for about
5 seconds, the data collection was ended.

Method of Analysis
In this section, we will derive the equations of motion for all tank draining experiments and outline the
process used to determine the optimal discharge coefficients. We began by modeling the draining of a
single tank and then solving the differential equation to determine the height of the fluid in the tank as a
function of time. Using this model, we then determined the optimal discharge coefficients by finding
their values such that the error between the model and data would be minimized. Finally, we used these
discharge coefficients in a double-tank draining system and compared the model response to data as a
way to validate our results.

Modeling the draining of a tank

The general conservation of mass principle is


𝑑
(𝑚 ) = ∑ 𝑚̇𝑖𝑛 − ∑ 𝑚̇𝑜𝑢𝑡 (1)
𝑑𝑡 𝑠𝑦𝑠
We will use this principle to arrive at the differential equation of motion for each tank.

Single tank draining

Assuming the density of water is constant, the geometry of the tank is a rectangular prism, and knowing
there is one outlet (an orifice) and no inlet, we can simplify the conservation of mass principle to arrive at
𝑑ℎ
𝐴 = −𝑄𝑜𝑢𝑡 (2)
𝑑𝑡

We model the flowrate out of the system as

𝑄𝑜𝑢𝑡 = 𝐶𝑑 𝐴𝑜 √2𝑔(ℎ + ℎ𝑜 ) (3)


From Eq (2) and (3), we have

6
𝑑ℎ
𝐴 + 𝐶𝑑 𝐴𝑜 √2𝑔(ℎ + ℎ𝑜 ) = 0
𝑑𝑡 (4)

We solve Eq (4) to arrive at the model response


2
𝐶𝑑 𝐴𝑜 √2𝑔
ℎ(𝑡) = [√ℎ(0) + ℎ𝑜 + 𝑡] − ℎ𝑜
2𝐴 (5)

Eq (5) is used as the model for the single tank experiments for both tank 1 and tank 2.

Determining the optimal coefficient of discharge

At this point, all physical dimensions in Eq (5) are known, making 𝐶𝑑 the only unknown. We want our
model to closely represent our data—we can do this by determining the value of 𝐶𝑑 that allows our model
to fit the data the best it can. First, we set 𝐶𝑑 = 0.7 to create a fully defined initial model. From here, we
use the command fminsearch in Matlab in order to determine the optimal value for 𝐶𝑑 such that the
Standard Error of Estimate (SEE) is minimized. The SEE gives us a quantitative value for the “goodness
of fit” between the model and the data. It is given as

∑𝑛 [ℎ(𝑡𝑖 )𝑚𝑜𝑑𝑒𝑙 − ℎ(𝑡𝑖 )𝑑𝑎𝑡𝑎 ]2


𝑆𝐸𝐸 = √ 𝑖=1
𝑛−2 (6)

where 𝑛 is the number of data points over the time span 𝑡 = [0, 𝑡1 , … , 𝑡𝑛−1 ] and the differences between
data and model are computed at the same time values, 𝑡𝑖 . Using this method for both single tank
experiments, we arrive at the optimal values for 𝐶𝑑1 and 𝐶𝑑2.

Double tank draining

Tank 1

Using conservation of mass, the same assumptions from the single tank draining section, and knowing
there is one inlet (an orifice) and one outlet, we begin with
𝑑ℎ1
𝐴1 = 𝑄𝑖𝑛 − 𝑄1 (7)
𝑑𝑡

The flowrate out of the system is given by Eq (3). The tank 1 equation of motion is
𝑑ℎ1
𝐴1 + 𝐶𝑑1 𝐴𝑜1 √2𝑔(ℎ1 + ℎ1𝑜 ) = 𝑄𝑖𝑛
𝑑𝑡
(8)

7
Tank 2

Similar to tank 1, we start with


𝑑ℎ2
𝐴2 = 𝑄1 − 𝑄2 (9)
𝑑𝑡
The flowrate out of the system is given by Eq (3). The flowrate into the system is simply given as the
flowrate out of tank 1 which can be given by Eq (3). The tank 2 equation of motion is
𝑑ℎ2
𝐴2 + 𝐶𝑑2 𝐴𝑜2 √2𝑔(ℎ2 + ℎ2𝑜 ) − 𝐶𝑑1 𝐴𝑜1 √2𝑔(ℎ1 + ℎ1𝑜 ) = 0
𝑑𝑡
(10)

From Eq (8) and (10), we formed a Simulink diagram, which can be viewed in Appendix C. We then
plugged the measured physical dimensions and optimal discharge coefficients into the model and ran the
simulation in Matlab to arrive at our model results for a double tank system. The model results were
compared to the experimental data for the double tank system as a way to validate our discharge
coefficient values for each tank.

Results and Discussion


In this section, we will discuss the results from our experiment and make analytical comparisons between
our model and data. The initial and optimized discharge coefficients with their corresponding SEE values
are shown in Table 1. A comparison of the initial model, optimized model, and experimental data is
shown in Figure 2 for the upper tank experiment and Figure 3 for the lower tank experiment.

Table 1. Original and optimized discharge coefficients with corresponding SEE values for both tanks.

Upper tank Lower tank

Discharge coefficient, Discharge


Case SEE (in) SEE (in)
𝐶d coefficient, 𝐶d

Initial model 0.7 0.247 0.7 0.825

Optimized model 0.663 0.105 0.600 0.201

8
Figure 2. Comparison of the initial model using 𝐶𝑑 = 0.7 , model using optimized 𝐶𝑑 =
0.663, and experimental data of the upper tank experiment.

Figure 3. Comparison of the initial model using 𝐶𝑑 = 0.7 , model using optimized 𝐶𝑑 =
0.600, and experimental data of the lower tank experiment.

In both cases, the single upper and single lower tank draining experiments, the data points tend to lie
above the model response curve when the tank first begins to drain and below the curve when the tank is
almost finished draining. This means that for both the upper and lower tanks, the fluid height was

9
decreasing slower than the model initially and then faster than the model once the fluid height reached
about 1 ½ inches. The difference in change in fluid height may be due to us ignoring the tapered shape of
the tanks. We modeled the tanks as rectangular prisms with a width equal to the average width of the
actual tank. Because the widths of the actual tanks decrease as the fluid height decreases, the surface
areas decrease. Assuming the flow rate out is constant, this causes the rate of which the fluid height
decreases to increase and causes our model to become misaligned with the data.

A comparison of the model response using the discharge coefficients found from the single tank tests and
the experimental data of the double tank experiment is shown in Figure 4. We noticed that in the double
tank experiment, the upper tank model (tank 1) deviated significantly from the upper tank draining data.
This deviation was alarming because the upper tank has no inflow and is simply draining similar to how
it was in the single tank experiment which we used to determine the upper tank discharge coefficient.
Since the model matches the data well for the upper tank draining by itself, we expect the upper tank
model to match the data well for the double tank system.

Figure 4. Comparison of the model response using the discharge coefficients found from
the single tank tests and experimental data of the double tank experiment.

In order to develop a more accurate model for the double tank draining system, we computed the
discharge coefficient for the upper tank that resulted in the lowest SEE value between the model and data
of the upper tank in the double tank system. Table 2 shows the initial optimized and updated discharge
coefficients. A comparison of the upper tank data and model using the new optimized discharge
coefficient for the double tank system is shown in Figure 5.

10
Table 2. Optimized discharge coefficients for the upper tank found using the single tank and double tank
draining data along with their percent difference.

Initial (optimized Updated (optimized


Percent difference
from single tank) from double tank)

Upper tank discharge


0.663 0.693 4.33 %
coefficient, 𝐶d

Figure 5. Comparison of the upper tank model response using the updated optimized
discharge coefficient 𝐶𝑑 = 0.693 and the experimental data of the double tank
experiment.

The new discharge coefficient matches the upper tank data for the two-tank experiment better than the
optimized discharge coefficient found from the single tank draining experiment. We would expect the
optimized discharge coefficient to fit both the single and double tank experiments; however, this was not
the case. We suspect the difference in discharge coefficients between experiments may be due to the
variability in how far the valve was opened. For instance, we may have opened the upper tank valve
slightly more or less in the two-tank experiment than in the single upper tank experiment. This would
cause a change in the effective area of the orifice and result in different discharge coefficients. The new
discharge coefficient for the upper tank was used in the comparison of the updated model and
experimental data for the double tank system is shown in Figure 6.

11
Figure 6. Comparison of the model response using the lower tank discharge coefficient
found from the single tank test, upper tank discharge coefficient from the
updated test, and experimental data of the double tank experiment.

The upper tank (tank 1) model fits the data well as we would expect since we selected the discharge
coefficient which minimized the SEE value between the model and the data. However, once the upper
tank stops draining, it has outliers at around 35 and 42 seconds which cause the measure fluid height to
spike down. The drift in the empty tank data may be attributed to inaccuracies in the pressure transducer.

The lower tank (tank 2) model seems to fit the data the best possible for the first approximately 30
seconds where the upper tank is draining in to the lower tank. The high variability in the lower tank fluid
height during the first 30 seconds is most likely due to the water flowing in to the lower tank. The water
flowing in to the tank causes the fluid to move inside the tank which causes variations in the pressure
readings of the pressure transducer on the bottom of the tank. Because the height of the fluid is
determined from the pressure reading, variations in the pressure results in variations in fluid height. This
issue is especially prevalent in our experiment because both tanks had large nozzles which attributed to
larger flow rates.

After the upper tank stops draining in to the lower tank, the lower tank model appears to drain at a
slower rate than the experiment. This could possibly be because the actual tank is tapered, but the model
assumes a square tank with a width equal to the average width between the top and bottom of the actual
tank. This means that the actual tank has a smaller cross-sectional area than the model during the last half
of its draining time. Assuming the model and actual tank have equal flow rates, the smaller cross-
sectional area would correspond to a faster decrease in height.

12
Table 3 shows observed characteristics of the two-tank system and Table 4 shows the SEE values for both
tanks when comparing the model to the experimental data.

Table 3. Observed characteristics of the predicted and measured response of the two-tank system.

Time for upper tank Time for lower tank to Time for lower tank to
to empty (s) drain to 3 in. level (s) drain to 1 in. level (s)

Predicted response 29 38 50

Measured response 32 37 48

Percent difference 9.38 % 2.70 % 4.17 %

Table 4. SEE value for both individual tanks in the two-tank system.

SEE for upper tank (in) SEE for lower tank (in)

0.0856 0.300

The values shown in Table 3 are simply read off the plot of the two-tank data and therefore do not imply
high precision; however, the values do allow for comparisons between the model and the data. For
example, the time it takes for the upper take to empty appears to be less for the predicted response
(model) than for the measured response (experimental data). However, it is difficult to read the exact
time of which the measured response stops draining because it seems to curve in to a steady state value
instead of having a sharp corner like the predicted response. The time it takes for the lower tank fluid
height to reach levels of three and one inch is greater for the predicted response than the measured
response. The time gap between the predicted and measured response increases as the fluid height goes
from three inches to one inch. This means that the fluid height decreases faster when it is at a lower
height. This is caused by us neglecting the tapered attribute of the tank as we previously discussed.

The SEE value between the predicted and measured response for the upper tank is quite low at 0.0856.
The SEE value for the lower tank is slightly higher at 0.300 but is still within a reasonable range of what
we consider to be an accurate model. The low SEE values of the individual tanks for the two-tank system
make us conclude that the predicted response is a reasonable representation of the measured response. In
order to better quantify this comparison between the predicted and measured responses, we could
compute a new SEE which sums the SEE values of each individual tank. If we need to find the optimal
model for the two-tank system, we could adjust parameters to minimize that summed SEE.

13
Conclusions and Recommendations
The purpose of this experiment was to develop mathematical models which accurately represent the fluid
response of two individual tanks. We were able to conclude that the model containing values from the
individual tank models, 0.663 and 0.600 respectively, accurately represented the drain time of the upper
tank in the two-tank draining experiment to within approximately 9%. The time it took for the lower tank
to drain to fluid heights of three and one inch differed from the two-tank model by approximately 3%
and 4% respectively. Because the two-tank model and experimental data disagree by less than 10%, and
by even less than 5% for some parameters, we consider the model to be a reasonable representation of the
two-tank system. Therefore, we concluded that the individual tank models developed in this experiment
are, with only slight error, accurate representations of the actual tanks.

In order to improve our experimental results, we would recommend ensuring that the valves are fully
opened for all trials. For our experiment, we faced an issue of the upper tank discharge coefficient
differing between trials. This issue may have been alleviated if wide open valves were ensured for both
trials. Additionally, we recommend including the taper of the tank in our model instead of simply using
the average width of the tank.

14
Appendix A – Physical system parameter measurements
The physical parameters, directly measured with a ruler, of both the upper and lower tanks are shown in
Table A1. The tank and orifice areas calculated from those measured quantities are shown in Table A2.

Table A1. Station 7 measured physical dimensions of the tanks.

Tank width Tank depth Orifice Outlet height Nut height


Tank
(in) (in) diameter (in) (in) (in)

Upper 7-1/16 3-3/8 3/8 3-1/2 1/2

Lower 7-1/16 3-3/8 3/8 3-1/2 1/2

Table A2. Station 7 calculated areas of tanks and orifices.

Tank Area Orifice Area


Tank
(in )
2 (in2)

Upper 23.84 0.110

Lower 23.84 0.110

15
Appendix B – Calibration of tank pressure transducer
The pressure transducer voltage for corresponding heights measured in the calibration experiments of
both tanks is shown in Table B1. A plot of the transducer voltage data as a function of fluid height as well
as a line of best fit and its corresponding equation is shown for the upper tank in Figure B1 and for the
lower tank in Figure B2.

Table B1. Calibration data for the conversion of transducer voltage to water height.

Upper tank Lower Tank

Water height from bottom Pressure transducer Water height from Pressure transducer
(inches) output (Volts) bottom (inches) output (Volts)

9 2.38 9 2.31

8 2.25 8 2.20

7 2.14 7 2.10

6 2.02 6 1.99

5 1.91 5 1.86

4 1.78 4 1.76

3 1.67 3 1.64

2 1.56 2 1.53

1 1.44 1 1.42

16
Figure B1. Calibration data and regression line for the upper tank.

Figure B2. Calibration data and regression line for the lower tank.
.

17
Appendix C – MATLAB code and Simulink diagram
The MATLAB code shown below was used to compute the calibration equations and calibration
comparison plots.
clc
close all
clear variables

% Calibration Data & Equation

% Upper Tank
h_up_cal = [9 8 7 6 5 4 3 2 1]; % height of fluid (in)
V_up_cal = [2.38 2.25 2.14 2.02 1.91 1.78 1.67 1.56 1.44]; % voltage reading
(V)
% Determining best fit line
fit_up_cal = polyfit(h_up_cal, V_up_cal,1);
m_up = fit_up_cal(1);
b_up = fit_up_cal(2);
V_up = m_up*h_up_cal + b_up;
% Plotting data and best fit line
figure (1)
plot(h_up_cal, V_up_cal, 'o', h_up_cal, V_up, '-')
xlabel('Height of fluid in tank (from bottom), (in)')
ylabel('Transducer voltage reading (V)')
legend('Calibration data', 'Calibration equation')
eqn_up = sprintf('V = %.4f h + %.4f', m_up, b_up);
text(3, 2, eqn_up, 'FontSize', 9);

% Lower Tank
h_low_cal = [9 8 7 6 5 4 3 2 1]; % height of fluid (in)
V_low_cal = [2.31 2.20 2.10 1.99 1.86 1.76 1.64 1.53 1.42]; % voltage reading
(V)
% Determining best fit line
fit_low_cal = polyfit(h_low_cal, V_low_cal,1);
m_low = fit_low_cal(1);
b_low = fit_low_cal(2);
V_low = m_low*h_low_cal + b_low;
% Plotting data and best fit line
figure (2)
plot(h_low_cal, V_low_cal, 'o', h_low_cal, V_low, '-')
xlabel('Height of fluid in tank (from bottom), (in)')
ylabel('Transducer voltage reading (V)')
legend('Calibration data', 'Calibration equation')
eqn_low = sprintf('V = %.4f h + %.4f', m_low, b_low);
text(3, 2, eqn_low, 'FontSize', 9);

The MATLAB code shown below was used for the single-tank modeling and the simulation of the
double-tank model.

clc
clear variables
close all

%% data

data1=xlsread('uppertank_9in');

18
tdata1=data1(:,1);
vdata1=data1(:,2);
hdata1=(vdata1-1.3214)/0.1168;

save data1 tdata1 hdata1

data2=xlsread('lowertank_9in');
tdata2=data2(:,1);
vdata2=data2(:,3);
hdata2=(vdata2-1.3078)/0.1120;

save data2 tdata2 hdata2

data=xlsread('upperandlower_8in_4in');
tdata=data(:,1);
vdata1_2tank=data(:,2);
vdata2_2tank=data(:,3);
hdata1_2tank=(vdata1_2tank-1.3214)/0.1168;
hdata2_2tank=(vdata2_2tank-1.3078)/0.1120;

data3=xlsread('uppertank_redo');
tdata3=data3(:,1);
vdata3=data3(:,2);
hdata3=(vdata3-1.3214)/0.1168;

save data3 tdata3 hdata3


%% determining optimal discharge coefficient

% tank 1

g=32.2*12; % accel of grav (in/s^2)


ho_1=3.5; % distance from orifice exit to bottom of tank 1
hi_1=hdata1(1); % initial height tank 1 (in)
Ao_1=0.1104; % orifice area of tank 1 (in^2)
A_1=23.836; % tank 1 area (in^2)

Cd_1=0.7; % tank 1 discharge coefficient

hm_1=((sqrt(hi_1+ho_1)-(Cd_1*Ao_1*sqrt(2*g)*tdata1/(2*A_1))).^2)-ho_1; %
height of tank 1 model

plot(tdata1,hm_1,'k',tdata1,hdata1,'k--')

% tank 2

ho_2=3.5; % distance from orifice exit to bottom of tank 2


hi_2=hdata2(1); % initial height tank 2 (in)
Ao_2=0.1104; % orifice area of tank 2 (in^2)
A_2=23.836; % tank 2 area (in^2)

Cd_2=0.7; % tank 2 discharge coefficient

hm_2=((sqrt(hi_2+ho_2)-(Cd_2*Ao_2*sqrt(2*g)*tdata2/(2*A_2))).^2)-ho_2; %
height of tank 2 model

figure
plot(tdata2,hm_2,'k',tdata2,hdata2,'k--')

% SEE stuff

19
% tank 1

SEE1_i=sqrt((sum((hm_1-hdata1).^2))/(length(tdata1)-2));

Cd0_1=0.7;

options=optimset(@fminsearch);
options=optimset(options,'Display','iter');
coeffs=fminsearch(@lab5_perf_index_1,Cd0_1,options);

Cd1_optim=coeffs(1);

hm_1_optim=((sqrt(hi_1+ho_1)-(Cd1_optim*Ao_1*sqrt(2*g)*tdata1/(2*A_1))).^2)-
ho_1; % height of tank 1 model

SEE1_f=sqrt((sum((hm_1_optim-hdata1).^2))/(length(tdata1)-2));

% tank 1 redo

Cd1_redo=0.7
hi_1_redo=hdata3(1); % initial height tank 1 (in)
hm_1_redo=((sqrt(hi_1_redo+ho_1)-
(Cd1_redo*Ao_1*sqrt(2*g)*tdata3/(2*A_1))).^2)-ho_1; % height of tank 1 model

Cd0_redo=0.7

options=optimset(@fminsearch);
options=optimset(options,'Display','iter');
coeffs=fminsearch(@lab5_perf_index_redo1,Cd0_redo,options);

Cd1_redo=coeffs(1);

hm_1_optim_redo=((sqrt(hi_1_redo+ho_1)-
(Cd1_redo*Ao_1*sqrt(2*g)*tdata3/(2*A_1))).^2)-ho_1; % height of tank 1 model

SEE1_f_redo=sqrt((sum((hm_1_optim_redo-hdata3).^2))/(length(tdata3)-2));

figure
plot(tdata3,hm_1_optim_redo,'k-',tdata3,hdata3,'b.')
xlabel('Time, (s)');
ylabel('Height of fluid in tank (from bottom), (in)')
legend('Initial model, Cd = 0.7','Optimized model, Cd = 0.693','Data')

% tank 2

SEE2_i=sqrt((sum((hm_2-hdata2).^2))/(length(tdata2)-2));

Cd0_2=0.7;

options=optimset(@fminsearch);
options=optimset(options,'Display','iter');
coeffs=fminsearch(@lab5_perf_index_2,Cd0_2,options);

Cd2_optim=coeffs(1);

hm_2_optim=((sqrt(hi_2+ho_2)-(Cd2_optim*Ao_2*sqrt(2*g)*tdata2/(2*A_2))).^2)-
ho_2; % height of tank 2 model

SEE2_f=sqrt((sum((hm_2_optim-hdata2).^2))/(length(tdata2)-2));
%% comparing initial model, optimized model, and data

20
% tank 1

figure
plot(tdata1,hm_1,'k--',tdata1,hm_1_optim,'k-',tdata1,hdata1,'b.')
xlabel('Time, (s)');
ylabel('Height of fluid in tank (from bottom), (in)')
legend('Initial model, Cd = 0.7','Optimized model, Cd = 0.663','Data')

% tank 2

figure
plot(tdata2,hm_2,'k--',tdata2,hm_2_optim,'k-',tdata2,hdata2,'b.')
xlabel('Time, (s)');
ylabel('Height of fluid in tank (from bottom), (in)')
legend('Initial model, Cd = 0.7','Optimized model, Cd = 0.6','Data')

%% two tank system

Qi=0; % flowrate into tank 1


A1=23.836; % area of tank 1 (in^2)
A2=23.836; % area of tank 2 (in^2)
do1=0.375; % diameter of tank 1 orifice (in)
do2=0.375; % diameter of tank 2 orifice (in)
h1o=3.5; % height of orifice 1 exit to bottom of tank 1 (in)
h2o=3.5; % height of orifice 2 exit to bottom of tank 2 (in)
h1b=hdata1_2tank(length(hdata1_2tank)); % height from bottom of tank 1 to top
of orifice 1 (in)

h2b=hdata2_2tank(length(hdata2_2tank)); % height from bottom of tank 2 to top


of orifice 2 (in)
Cd1=Cd1_redo; % discharge coefficient for tank 1
Cd2=Cd2_optim; % discharge coefficient for tank 2
h1_0=hdata1_2tank(1); % initial height of water in tank 1 (in)
h2_0=hdata2_2tank(1); % initial height of water in tank 2 (in)

maxstep=0.001; % max step time


tol=1e-6; % relative and absolute tolerance
tf=tdata(length(tdata)); % final time (s)
g=32.2*12; % acceleration of gravity (in/s^2)

n1=h1b; % threshold for switching tank 1 flowrate off


n2=h2b; % threshold for switching tank 2 flowrate off

Ao1=0.25*pi*do1^2; % area of tank 1 orifice (in^2)


Ao2=0.25*pi*do2^2; % area of tank 2 orifice (in^2)

% plot

sim('prelab_5_sim');

figure
plot(t,h1,'b-',t,h2,'r-',tdata,hdata1_2tank,'b.',tdata,hdata2_2tank,'r.');
xlabel('Time, (s)');
ylabel('Height of fluid in tanks (from bottom), (in)')
legend('Tank 1 model','Tank 2 model','Tank 1 data','Tank 2 data')

% computing SEE for double tank

% tank 1

21
SEE1_2tank=sqrt(sum((h1-hdata1_2tank).^2)/(length(tdata)-2));

% tank 2

SEE2_2tank=sqrt(sum((h2-hdata2_2tank).^2)/(length(tdata)-2));

%% initial plot

Cd1=Cd1_optim; % setting the Cd value to the optimized value from the single
tank model

sim('prelab_5_sim');

figure
plot(t,h1,'b-',t,h2,'r-',tdata,hdata1_2tank,'b.',tdata,hdata2_2tank,'r.');
xlabel('Time, (s)');
ylabel('Height of fluid in tanks (from bottom), (in)')
legend('Tank 1 model','Tank 2 model','Tank 1 data','Tank 2 data')

The MATLAB code below is the function used to determine the optimal 𝐶𝑑 for the upper tank.

function SEE1 = lab5_perf_index_1(Cd_1)

g=32.2*12; % accel of grav (in/s^2)


ho_1=3.5; % distance from orifice entrance to bottom of tank 1
hi_1=9; % initial height tank 1 (in)
Ao_1=0.1104; % orifice area of tank 1 (in^2)
A_1=23.836; % tank 1 area (in^2)

load data1

hm_1=((sqrt(hi_1+ho_1)-(Cd_1*Ao_1*sqrt(2*g)*tdata1/(2*A_1))).^2)-ho_1; %
height of tank 1 model

SEE1=sqrt((sum((hm_1-hdata1).^2))/(length(tdata1)-2));

The MATLAB code below is the function used to determine the optimal 𝐶𝑑 for the lower tank.

function SEE2 = lab5_perf_index_2(Cd_2)

g=32.2*12; % accel of grav (in/s^2)


ho_2=3.5; % distance from orifice entrance to bottom of tank 2
hi_2=9; % initial height tank 2 (in)
Ao_2=0.1104; % orifice area of tank 2 (in^2)
A_2=23.836; % tank 2 area (in^2)

load data2

hm_2=((sqrt(hi_2+ho_2)-(Cd_2*Ao_2*sqrt(2*g)*tdata2/(2*A_2))).^2)-ho_2; %
height of tank 2 model

SEE2=sqrt((sum((hm_2-hdata2).^2))/(length(tdata2)-2));

22
The MATLAB code below is the function used to determine the new optimal 𝐶𝑑 for the upper tank by
comparing it the single-tank model to part of the two-tank experiment data.

function SEE_redo = lab5_perf_index_redo1(Cd1_redo)

g=32.2*12; % accel of grav (in/s^2)


ho_1=3.5; % distance from orifice entrance to bottom of tank 1

Ao_1=0.1104; % orifice area of tank 1 (in^2)


A_1=23.836; % tank 1 area (in^2)

load data3

hi_1_redo=hdata3(1); % initial height tank 1 (in)

hm_1_redo=((sqrt(hi_1_redo+ho_1)-
(Cd1_redo*Ao_1*sqrt(2*g)*tdata3/(2*A_1))).^2)-ho_1; % height of tank 1 model

SEE_redo=sqrt((sum((hm_1_redo-hdata3).^2))/(length(tdata3)-2));

Figure C1 shows the Simulink diagram which we used to model the double tank draining system.

Figure C1. Simulink diagram used for the simulation of the double tank model.

23

You might also like