Simulation summary will appear here.
Water blasting from a hose, air surging through a ventilation duct, and blood racing along an artery all obey the same conservation law. If the fluid is incompressible so that its density remains essentially constant, then whatever volume of fluid enters a segment of pipe per unit time must also leave that segment per unit time. This principle, known as the continuity equation, is normally written as , meaning the product of cross-sectional area and average velocity is constant along the pipe. Typical calculators simply solve this expression for an unknown velocity or area. Here, the relationship is brought to life with an animated stream of particles that accelerate or decelerate as the pipe narrows or widens, letting you see mass conservation unfold in real time.
The simulation models a horizontal pipe of length 1 m whose cross-sectional area varies linearly from at the inlet to at the outlet. A population of massless tracer particles represents equal fluid parcels. Their spacing adapts to the local velocity such that the volume flow rate remains constant. Inputs include the upstream area, upstream velocity, downstream area, fluid density, and numerical time step. Density is only required if you want to see mass flow rate in kilograms per second; otherwise the simulation still depicts volume flow conservation. The fluid is assumed inviscid and incompressible, with laminar flow and no interaction between parcels. Gravity, friction, and pressure variations are ignored so the model isolates the geometric aspects of continuity.
The volume flow rate remains constant and is defined by . Solving for the downstream velocity yields . If density is supplied, the mass flow rate is . To animate the particles, the pipe's local area function is linearly interpolated, and the local velocity follows from . Each particle's position evolves according to , which is integrated with a Runge–Kutta method for stability. All quantities use SI units.
Although a forward Euler step would suffice for the simple differential equation above, the simulator employs a fourth-order Runge–Kutta (RK4) integrator to maintain accuracy even when the time step is relatively large. The step size is clamped between 1×10-4 and 0.1 s to prevent numerical instability. Fifty tracer particles are initialized with positions uniformly distributed along the pipe; each iteration advances them according to RK4 and wraps any particle that exits the pipe back to the inlet. The numerical volume flow rate at the inlet and outlet is recorded each step, and their difference constitutes the flow drift displayed below the canvas. Because an incompressible simulation should conserve flow exactly, any nonzero drift reveals accumulation of floating-point error or an overly aggressive time step. A debounce timer recalculates the velocity profile only after input changes settle, avoiding redundant computations during rapid typing.
Imagine water of density 1000 kg/m³ entering a pipe with area 0.05 m² at 1 m/s and exiting through an area of 0.02 m². The continuity equation predicts a downstream velocity of = 2.5 m/s. The volume flow rate is m³/s, yielding a mass flow rate of 50 kg/s. Running the simulation with these parameters shows blue particles speeding up as they approach the constriction. The live summary reports both upstream and downstream volume flows (identical within numerical error) and displays any difference as a percentage drift. Setting the time step to a very large value, such as 0.05 s, visibly increases the drift, demonstrating why small steps are preferable for accuracy.
Scenario | A₁ (m²) | A₂ (m²) | v₁ (m/s) | v₂ (m/s) |
---|---|---|---|---|
Baseline | 0.05 | 0.02 | 1 | 2.5 |
Wider Outlet | 0.05 | 0.04 | 1 | 1.25 |
Narrower Inlet | 0.02 | 0.02 | 1 | 1 |
The canvas portrays a horizontal pipe whose walls converge or diverge depending on the input areas. Blue particles entering from the left represent equal packets of fluid. Where the pipe narrows, the vertical distance between the walls decreases; the particles accelerate accordingly, and their spacing along the pipe increases so that the product of spacing and cross-sectional area stays constant. The lighter blue bar beneath the canvas gauges the magnitude of flow drift—the difference between upstream and downstream volume flow rates. Zero drift indicates perfect numerical conservation, while a growing bar signals accumulating error. The live summary, mirrored by the “Simulation summary” paragraph for accessibility, lists the computed downstream velocity and both flow rates.
The model omits important physical factors. Viscosity and turbulence, which in reality produce velocity profiles that are not flat across the pipe, are ignored, so the simulation assumes plug flow. Pressure gradients that drive the motion are not computed, nor are energy losses due to friction. The particles are purely visual markers without mass, so momentum exchange is not represented. The pipe length is fixed at one meter, and the cross-section changes linearly; more complicated geometries would require a fuller computational fluid dynamics approach. Numerical diffusion may appear if the time step is too large, causing particles to bunch or spread unrealistically.
Possible enhancements include adding a Bernoulli-based pressure calculation to relate velocity changes to pressure drops, incorporating turbulent flow corrections via empirical coefficients, or rendering a cross-sectional velocity profile that transitions from parabolic (laminar) to flatter (turbulent). Introducing particles of different colors to represent multiple fluids could illustrate mixing problems, while adaptive time stepping would maintain accuracy automatically. Exporting the entire particle distribution rather than just flow rates would enable more sophisticated analysis.
Related calculators: Bernoulli Equation, Reynolds Number, Fluid Continuity (static).