Tank Level Simulator

Interactive closed-loop level control with a control valve on the inlet and a load-dependent outlet. Tune the PID controller, change the downstream demand, and watch the level track the setpoint.

Process Animation

Speed:
Water (process variable) Setpoint Inlet valve (control) Outlet valve (load) Outlet flow

Level Response Plot

Level (m) Setpoint (m) Inlet flow (m³/s) Outlet flow (m³/s) Valve opening (%) Disturbance / demand

Level L

m

Inlet Qin

m³/s

Outlet Qout

m³/s

Inlet valve u

% open

Outlet valve uv

% open

Error

m

Sim time

s

Tank Geometry

Physical resistance on the outlet. Close to throttle the drain, open to drain faster. Acts as a load disturbance.

Inlet Control Valve

PID & Disturbance

Simulates pump / supply issues. 1.0 = nominal, 0.5 = degraded, 0 = pump dead.

Process Equations

Mass balance on the tank:

$$A \frac{dL}{dt} = Q_{in} - Q_{out}$$

A = cross-section, L = level, Qin = inlet flow, Qout = outlet flow.

Torricelli's law (outlet):

$$Q_{out} = u_v \cdot a \sqrt{2 g L}$$

Outflow depends on level and on the bottom outlet valve opening uv ∈ [0, 1]. Closing uv chokes the drain — a physical load disturbance the controller must reject.

Valve dynamics (1st-order lag):

$$\tau_v \frac{dQ_{in}}{dt} + Q_{in} = C_v \cdot u \cdot \sqrt{\Delta P}$$

u = PID output (0..1, valve fraction open). ΔP is assumed constant.

PID Controller

Control law (parallel form):

$$u(t) = K_p\, e(t) + K_i \int_0^t e(\tau)\, d\tau - K_d \frac{dL}{dt}$$

Derivative-on-measurement (avoids derivative kick on setpoint changes). Anti-windup via output clamping and integrator freezing.

Open-loop dynamics:

$$\frac{L(s)}{Q_{in}(s)} = \frac{1}{A s + \frac{a g}{\sqrt{2 g L_0}}}$$

Linearised about operating point L0 — first-order, non-integrating. Tuning rule of thumb: Kp ≈ A·τ / (L·τ_v) for 1st-order-plus-dead-time.