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 (control) Outlet (load)

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

Valve u

% open

Error

m

Sim time

s

Tank Geometry

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} = a \sqrt{2 g L}$$

Outflow depends on level only — as L rises the discharge rate increases.

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.