Assumptions
Assumptions
1. Valve Sizing Cv: Eq (2) is used to size the valve, determining Cv_max. The valve has
linear characteristics, so Cv(u) = u * Cv_max, where u is the control signal (0 to 1).
2. Flow Equation (1) Interpretation: f = K * Cv(u) * sqrt(h_i - h_j + y).
o K: Given flow constant (0.239).
o Cv(u): The actual valve coefficient at opening u. This is u * Cv_max.
o h_i: Level in the upstream tank.
o h_j: Level in the downstream tank. For flow out of the final tank (like f2 from
FC24 or f4 from FC26), h_j can be considered 0 if discharging to a fixed level
datum (e.g., atmospheric pressure at the outlet pipe elevation).
o y: Difference in height. Figure 2 indicates y=1m. For flow between tanks (e.g.,
f1), this is the static head difference aiding flow if tank 1's outlet is y above tank
2's inlet. For flow from the last tank (e.g., f2), if its outlet is y above the discharge
datum, then y contributes to the head. The diagram suggests y=1m is a general
elevation advantage for the outlets.
o We will use max(0, term) for the sqrt(term) to prevent errors if the head term
becomes negative, implying zero flow in such cases.
• K = 0.239 (flow constant for connecting pipe, units will be sqrt(bar)/sqrt(m) for
consistency)
• D = 14.27 m (tank diameter)
• Tank Area A = π * (D/2)² = π * (14.27/2)² ≈ π * (7.135)² ≈ 159.93 m²
• Average flowrate f_avg = 500 L/s = 0.5 m³/s = 0.5 * 3600 m³/hr = 1800 m³/hr
• Pressure drop for valve sizing ΔP = 20 kPa = 0.2 bar
• Specific gravity SG = 1 (water)
• Static head y = 1 m
• FC23 level h1 = 3.5 m (maintained, implies steady state for this calculation).
• FC24 level h2 = 3 m (desired height).
• At steady state, inflow to FC23 equals outflow f1. This outflow must be the average flow
rate if h1 is maintained for average conditions. So, f1 = f_avg = 1800 m³/hr.
• Flow f1 is from FC23 to FC24: f1 = K_eff * u1 * sqrt(max(0, h1 - h2 + y))
1800 = 2232.36 * u1 * sqrt(max(0, 3.5 - 3 + 1))
1800 = 2232.36 * u1 * sqrt(0.5 + 1)
1800 = 2232.36 * u1 * sqrt(1.5)
1800 = 2232.36 * u1 * 1.2247
1800 ≈ 2733.98 * u1
u1 = 1800 / 2733.98 ≈ 0.6584
So, V₁ opening u1 ≈ 0.6584 (or 65.84%).
Equations:
u2(t) will be determined by the PI controller in Question 2. f_in(t) comes from Flow.csv.
% Constants
A = 159.93;
K_eff = 2232.36;
y_const = 1.0;
u1_fixed = 0.6584;
h2_setpoint = 3.0;
u2_bias = 0.4032;
% ODE function
function dXdt = tank_odes(t, X, Kp, Ki, u1_fixed, K_eff, A, y_const,
h2_setpoint, u2_bias, time_csv, f_in_csv)
h1 = X(1);
h2 = X(2);
integral_e2 = X(3); % Integral of error for h2 controller
% Interpolate f_in(t)
f_in_t = interp1(time_csv, f_in_csv, t, 'linear', 'extrap');
% Calculate f1
head1 = h1 - h2 + y_const;
if head1 < 0, head1 = 0; end % Prevent sqrt of negative
f1 = K_eff * u1_fixed * sqrt(head1);
% PI Controller for u2
e2 = h2_setpoint - h2;
u2_output = u2_bias + Kp * e2 + Ki * integral_e2;
d_integral_e2_dt = e2;
if (u2_output > 1 && e2 > 0) || (u2_output < 0 && e2 < 0)
d_integral_e2_dt = 0; % Basic anti-windup: stop integrating if
saturated and error pushes further
end
u2 = u2_saturated;
% Calculate f2
head2 = h2 + y_const;
if head2 < 0, head2 = 0; end
f2 = K_eff * u2 * sqrt(head2);
% ODEs
dh1dt = (1/A) * (f_in_t - f1);
dh2dt = (1/A) * (f1 - f2);
% Initial conditions
X0 = [3.5; 3.0; 0]; % h1(0), h2(0), integral_e2(0)
% Simulation time span (e.g., from Flow.csv)
% t_span = [min(time_csv) max(time_csv)];
% Solve ODE
% [t_sol, X_sol] = ode45(@(t,X) tank_odes(t, X, Kp, Ki, u1_fixed, K_eff, A,
y_const, h2_setpoint, u2_bias, time_csv, f_in_csv), t_span, X0);
Modified ODE function state vector: X = [h1; h2; integral_e2; h3; h4; integral_e4]
Initial conditions: h1(0)=3.5, h2(0)=3.0, int_e2(0)=0, h3(0)=3.5, h4(0)=3.0, int_e4(0)=0.
Simulate with the same f_in(t) from Flow.csv.
This guide provides a structured approach to solving the assignment. The main challenge will be
implementing the simulation correctly in Matlab (or your chosen software) and tuning the PI
controllers. Good luck!