Bernoulli Equation Simulator

JJ Ben-Joseph headshot JJ Ben-Joseph

1. Why pair Bernoulli's equation with animation?

Bernoulli's principle links pressure, velocity, and elevation along a streamline, asserting that their energy contributions trade off to keep the total constant. Textbook problems ask for the unknown pressure at a nozzle exit or the speed at a pipe constriction, but without a picture the flow seems static. In reality a fluid parcel accelerates or slows, gaining kinetic energy while surrendering pressure or climbing against gravity. The simulator above turns the algebra into a moving story: a circle representing a parcel slides through a pipe that widens or narrows according to the specified velocities. Three striped bars track how much of the parcel's mechanical energy resides in pressure, kinetic, or potential form. As the parcel approaches a throat, the kinetic bar swells while the pressure bar shrinks, and if the pipe rises, the green potential bar grows. This visualization helps students and engineers connect the terms in Bernoulli's equation to tangible changes in flow. Because everything runs locally in your browser, you can experiment with extreme cases, pause the motion, or export a CSV without installing software.

2. Variables, units, and assumptions

The calculator requires fluid density ρ , initial pressure P 1 , initial velocity v 1 , initial elevation h 1 , final velocity v 2 , and final elevation h 2 . All inputs must be finite SI values; the script rejects negative densities or nonnumeric entries. Gravity is taken as g = 9.81 m/s². The flow is assumed steady, inviscid, incompressible, and along a single streamline with no pump or turbine adding or removing energy. A fixed time step Δt controls the animation; it is clamped between 0.001 and 0.1 seconds for visual clarity. To depict the pipe geometry, the code infers an upstream cross-sectional area of one square unit; continuity then sets the downstream area by A 2 = v 1 v 2 . Heights change linearly along the pipe. These simplifications keep the visualization intuitive while preserving Bernoulli's core energy balance.

3. Governing equations

Bernoulli's equation for points 1 and 2 reads

P 1 + 1 2 ρ v 1 2 + ρ g h 1 = P 2 + 1 2 ρ v 2 2 + ρ g h 2 .

Solving for the unknown pressure gives

P 2 = P 1 + 1 2 ρ( v 1 2 - v 2 2 ) + ρ g ( h 1 - h 2 ) .

The total mechanical energy per unit volume E = P + 1 2 ρ v 2 + ρ g h remains constant along the path. The simulator computes E at the inlet, then updates each term as the parcel advances, verifying that the sum changes only within numerical error. Deviations appear in the caption as an energy drift percentage. Because the equations are algebraic, the animation does not solve differential equations; instead it interpolates the velocity and height between the endpoints and applies the analytic formulas at each frame.

4. Numerical update scheme

The particle starts at the left end of the canvas with velocity v 1 . Each animation frame advances its position using an explicit Euler step xn+1 = xn + v(xn)Δt , where v(x) interpolates linearly between v 1 and v 2 . Height follows a similar interpolation. At each new position the code computes pressure from the rearranged Bernoulli equation and updates the energy bars: orange for pressure energy P , blue for kinetic energy 1 2 ρ v^2, and green for potential energy ρ g h. The bars' widths represent fractions of the inlet total. Because the analytic expression guarantees constant E , the integration is numerically stable, but extremely large Δt values can cause the particle to skip past the outlet; therefore the controls bound the step size and allow pausing or resetting if the motion becomes erratic.

5. Worked example

Water (ρ = 1000 kg/m³) flows through a horizontal pipe that narrows from a wide inlet to a constriction. At the inlet the pressure is 200 kPa and the speed is 2 m/s; in the constriction continuity forces the speed up to 8 m/s. With no elevation change (h₁ = h₂ = 0), Bernoulli's equation predicts the constriction pressure:

P2 = 200000 + 12 (1000) (2282) = 170000 Pa

The half-ρ term is ½(1000)(4 − 64) = −30,000 Pa, so the pressure drops from 200 kPa to 170 kPa as the water speeds up — the classic Bernoulli trade of pressure for kinetic energy. Enter ρ = 1000, P₁ = 200000, v₁ = 2, h₁ = 0, v₂ = 8, h₂ = 0 and press Play: the parcel accelerates through the contracting pipe while the orange pressure bar shrinks and the blue kinetic bar grows, and the caption reports negligible energy drift, confirming numerical consistency. Press Pause at mid-travel to read intermediate values, or download the CSV to analyze how pressure varies with position.

6. Comparison table

The table contrasts the baseline constriction with two variations: a faster stream and the same speed carried 3 m uphill. Pressures are computed using the analytic expression above with P₁ = 200 kPa, v₁ = 2 m/s, and ρ = 1000 kg/m³.

Case v₂ (m/s) h₂ (m) P₂ (kPa)
Baseline 8 0 170
Faster stream 12 0 130
Uphill 8 3 141

7. Reading the animation

The canvas renders a horizontal pipe whose diameter tapers to reflect the velocity change dictated by continuity. The parcel's speed is indicated by its horizontal motion, while the pipe's centerline follows the specified elevations. The energy bars beneath the canvas portray the instantaneous partition: orange for pressure, blue for kinetic, green for potential. Their striped patterns ensure legibility without relying on color alone. The figcaption and hidden text summary narrate the current position, pressure, and energy drift for screen-reader users.

8. Limitations

The calculation assumes inviscid, steady, one-dimensional flow with no pumps, turbines, or losses. Real pipes exhibit friction, shocks, and secondary flows at bends. Pressures below vapor pressure can trigger cavitation, an effect absent here. Rapid transients, compressibility, and turbulence also violate the assumptions. The animation's interpolation ignores entrance effects and the true shape of streamlines through complex geometries. Nevertheless, for modest velocities in smooth pipes the simulator captures the essence of Bernoulli's balance.

9. Extensions

Future upgrades could add head-loss terms, couple multiple pipe segments, or integrate a Reynolds-number check with the Reynolds Number Calculator. Combining this tool with the Hagen–Poiseuille Flow Simulator or the Venturi Effect Calculator would allow exploration of energy losses and flow measurements in more complex systems.

10. References

Plain-text formula: P2 = P1 + 0.5 * rho * (v1^2 - v2^2) + rho * g * (h1 - h2), with g = 9.81 m/s^2 and all quantities in SI units (Pa, kg/m^3, m/s, m).

11. Bernoulli's equation: frequently asked questions

Why pair Bernoulli's equation with animation?

Bernoulli's principle links pressure, velocity, and elevation along a streamline, but on paper the flow looks static. The simulator turns the algebra into motion: a parcel slides through a pipe that narrows or rises, and three energy bars show pressure trading for kinetic and potential energy in real time, which makes the balance concrete rather than abstract.

Why does pressure fall where the pipe narrows?

Continuity forces the fluid to speed up in a constriction, and Bernoulli's equation says the total mechanical energy per unit volume is conserved along a streamline. The extra kinetic energy has to come from somewhere, so at constant elevation the pressure term drops by exactly ½·ρ·(v₂² − v₁²). That is why the worked example falls from 200 kPa to 170 kPa as the speed rises from 2 to 8 m/s.

Can the calculated pressure be negative, and what does that mean?

Yes. If the chosen velocities and elevation demand more energy than the inlet pressure can supply, the formula returns a negative absolute pressure, which is physically impossible and signals that real flow would cavitate or simply not reach those conditions. The simulator flags negative results rather than hiding them, so treat a negative P₂ as a sign that the scenario is unrealistic.

Time step is clamped between 0.001 s and 0.1 s for smooth animation.

Enter values and press Play.
Simulation summary will appear here.

Bernoulli Head Balancer

Test your feel for Bernoulli’s equation by trimming a nozzle to keep the downstream pressure inside a safe head band while gusts, pump boosts, and elevation shifts perturb the flow seeded by your inputs.

Current P₂
Target P₂
Stability band
±— Pa
Score
0

Balance head, dodge surges

Click to play · objective: Keep total head level

Drag/tap nozzle or use ← → keys

Set the calculator inputs, then press play to start balancing head.