Skip to content

Bernoulli Equation

Module Reference

Bernoulli equation and mechanical energy conservation.

Assumptions: - Steady flow - Incompressible fluid - Constant density - No dissipative energy losses - No external shaft work

All dimensional quantities use SI units. Elevation is positive upwards. Pressure values must use a consistent reference.

ENGINEERING_GRAVITY module-attribute

ENGINEERING_GRAVITY: Final[float] = 9.81

WATER_DENSITY module-attribute

WATER_DENSITY: Final[float] = 998.2

as_float_array

as_float_array(value: ArrayLike, name: str) -> np.ndarray

Convert input to a finite floating-point array.

Source code in src/fluidmec/core/_validation.py
13
14
15
16
17
18
19
20
21
22
23
24
def as_float_array(
    value: ArrayLike,
    name: str,
) -> np.ndarray:
    """Convert input to a finite floating-point array."""

    array = np.asarray(value, dtype=float)

    if not np.all(np.isfinite(array)):
        raise ValueError(f"{name} must be finite.")

    return array

format_output

format_output(result: ArrayLike) -> float | np.ndarray

Return a Python float for scalar results.

Source code in src/fluidmec/core/_validation.py
69
70
71
72
73
74
75
76
77
78
79
def format_output(
    result: ArrayLike,
) -> float | np.ndarray:
    """Return a Python float for scalar results."""

    result = np.asarray(result, dtype=float)

    if result.ndim == 0:
        return float(result)

    return result

validate_non_negative

validate_non_negative(value: ArrayLike, name: str) -> np.ndarray

Validate non-negative numerical inputs.

Source code in src/fluidmec/core/_validation.py
41
42
43
44
45
46
47
48
49
50
51
52
def validate_non_negative(
    value: ArrayLike,
    name: str,
) -> np.ndarray:
    """Validate non-negative numerical inputs."""

    array = as_float_array(value, name)

    if np.any(array < 0):
        raise ValueError(f"{name} must be non-negative.")

    return array

validate_positive

validate_positive(value: ArrayLike, name: str) -> np.ndarray

Validate strictly positive numerical inputs.

Source code in src/fluidmec/core/_validation.py
27
28
29
30
31
32
33
34
35
36
37
38
def validate_positive(
    value: ArrayLike,
    name: str,
) -> np.ndarray:
    """Validate strictly positive numerical inputs."""

    array = as_float_array(value, name)

    if np.any(array <= 0):
        raise ValueError(f"{name} must be positive.")

    return array

pressure_head

pressure_head(pressure: ArrayLike, density: ArrayLike = WATER_DENSITY, gravity: ArrayLike = ENGINEERING_GRAVITY) -> float | np.ndarray

Calculate pressure head in metres.

H = p / (rho * g)

Pressure is a signed gauge pressure in Pa.

Source code in src/fluidmec/core/hydrostatics.py
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
def pressure_head(
    pressure: ArrayLike,
    density: ArrayLike = WATER_DENSITY,
    gravity: ArrayLike = ENGINEERING_GRAVITY,
) -> float | np.ndarray:
    """
    Calculate pressure head in metres.

    H = p / (rho * g)

    Pressure is a signed gauge pressure in Pa.
    """

    pressure = as_float_array(pressure, "Pressure")

    density = validate_positive(density, "Density")

    gravity = validate_positive(gravity, "Gravity")

    return format_output(pressure / (density * gravity))

velocity_head

velocity_head(velocity: ArrayLike, gravity: ArrayLike = ENGINEERING_GRAVITY) -> float | np.ndarray

Calculate kinetic energy head in metres.

H_v = U² / (2g)

Source code in src/fluidmec/core/bernoulli.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
def velocity_head(
    velocity: ArrayLike,
    gravity: ArrayLike = ENGINEERING_GRAVITY,
) -> float | np.ndarray:
    """
    Calculate kinetic energy head in metres.

    H_v = U² / (2g)
    """

    velocity = as_float_array(velocity, "Velocity")
    gravity = validate_positive(gravity, "Gravity")

    return format_output(velocity**2 / (2 * gravity))

piezometric_head

piezometric_head(pressure: ArrayLike, elevation: ArrayLike = 0.0, density: ArrayLike = WATER_DENSITY, gravity: ArrayLike = ENGINEERING_GRAVITY) -> float | np.ndarray

Calculate piezometric head in metres.

H_p = p / (rho * g) + z

Source code in src/fluidmec/core/bernoulli.py
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def piezometric_head(
    pressure: ArrayLike,
    elevation: ArrayLike = 0.0,
    density: ArrayLike = WATER_DENSITY,
    gravity: ArrayLike = ENGINEERING_GRAVITY,
) -> float | np.ndarray:
    """
    Calculate piezometric head in metres.

    H_p = p / (rho * g) + z
    """

    elevation = as_float_array(elevation, "Elevation")

    head = pressure_head(pressure, density, gravity)

    return format_output(head + elevation)

total_energy_head

total_energy_head(pressure: ArrayLike, velocity: ArrayLike, elevation: ArrayLike = 0.0, density: ArrayLike = WATER_DENSITY, gravity: ArrayLike = ENGINEERING_GRAVITY) -> float | np.ndarray

Calculate total mechanical energy head in metres.

H = p / (rho * g) + U² / (2g) + z

Source code in src/fluidmec/core/bernoulli.py
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
def total_energy_head(
    pressure: ArrayLike,
    velocity: ArrayLike,
    elevation: ArrayLike = 0.0,
    density: ArrayLike = WATER_DENSITY,
    gravity: ArrayLike = ENGINEERING_GRAVITY,
) -> float | np.ndarray:
    """
    Calculate total mechanical energy head in metres.

    H = p / (rho * g) + U² / (2g) + z
    """

    hydraulic_head = piezometric_head(
        pressure,
        elevation,
        density,
        gravity,
    )

    kinetic_head = velocity_head(velocity, gravity)

    return format_output(hydraulic_head + kinetic_head)

dynamic_pressure

dynamic_pressure(velocity: ArrayLike, density: ArrayLike = WATER_DENSITY) -> float | np.ndarray

Calculate dynamic pressure in Pa.

q = 0.5 * rho * U²

Source code in src/fluidmec/core/bernoulli.py
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
def dynamic_pressure(
    velocity: ArrayLike,
    density: ArrayLike = WATER_DENSITY,
) -> float | np.ndarray:
    """
    Calculate dynamic pressure in Pa.

    q = 0.5 * rho * U²
    """

    velocity = as_float_array(velocity, "Velocity")

    density = validate_positive(density, "Density")

    return format_output(0.5 * density * velocity**2)

stagnation_pressure

stagnation_pressure(pressure: ArrayLike, velocity: ArrayLike, density: ArrayLike = WATER_DENSITY) -> float | np.ndarray

Calculate ideal incompressible stagnation pressure.

p0 = p + 0.5 * rho * U²

Assumes no elevation change or energy loss. Returns pressure in Pa.

Source code in src/fluidmec/core/bernoulli.py
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
def stagnation_pressure(
    pressure: ArrayLike,
    velocity: ArrayLike,
    density: ArrayLike = WATER_DENSITY,
) -> float | np.ndarray:
    """
    Calculate ideal incompressible stagnation pressure.

    p0 = p + 0.5 * rho * U²

    Assumes no elevation change or energy loss.
    Returns pressure in Pa.
    """

    pressure = as_float_array(pressure, "Pressure")

    q = dynamic_pressure(velocity, density)

    return format_output(pressure + q)

bernoulli_pressure

bernoulli_pressure(pressure_1: ArrayLike, velocity_1: ArrayLike, velocity_2: ArrayLike, elevation_1: ArrayLike = 0.0, elevation_2: ArrayLike = 0.0, density: ArrayLike = WATER_DENSITY, gravity: ArrayLike = ENGINEERING_GRAVITY) -> float | np.ndarray

Solve Bernoulli's equation for pressure at point 2.

p2 = p1 + rho/2 * (U1² - U2²) + rhog(z1 - z2)

Returns pressure in Pa using the same pressure reference as pressure_1.

Source code in src/fluidmec/core/bernoulli.py
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
def bernoulli_pressure(
    pressure_1: ArrayLike,
    velocity_1: ArrayLike,
    velocity_2: ArrayLike,
    elevation_1: ArrayLike = 0.0,
    elevation_2: ArrayLike = 0.0,
    density: ArrayLike = WATER_DENSITY,
    gravity: ArrayLike = ENGINEERING_GRAVITY,
) -> float | np.ndarray:
    """
    Solve Bernoulli's equation for pressure at point 2.

    p2 = p1 + rho/2 * (U1² - U2²)
            + rho*g*(z1 - z2)

    Returns pressure in Pa using the same
    pressure reference as pressure_1.
    """

    p1 = as_float_array(pressure_1, "Pressure 1")

    u1 = as_float_array(velocity_1, "Velocity 1")

    u2 = as_float_array(velocity_2, "Velocity 2")

    z1 = as_float_array(elevation_1, "Elevation 1")

    z2 = as_float_array(elevation_2, "Elevation 2")

    rho = validate_positive(density, "Density")

    g = validate_positive(gravity, "Gravity")

    result = p1 + 0.5 * rho * (u1**2 - u2**2) + rho * g * (z1 - z2)

    return format_output(result)

bernoulli_velocity

bernoulli_velocity(pressure_1: ArrayLike, pressure_2: ArrayLike, velocity_1: ArrayLike = 0.0, elevation_1: ArrayLike = 0.0, elevation_2: ArrayLike = 0.0, density: ArrayLike = WATER_DENSITY, gravity: ArrayLike = ENGINEERING_GRAVITY) -> float | np.ndarray

Solve Bernoulli's equation for speed at point 2.

U2 = sqrt( U1² + 2(p1-p2)/rho + 2g*(z1-z2) )

Returns non-negative speed in m/s. Raises ValueError for inconsistent energy conditions.

Source code in src/fluidmec/core/bernoulli.py
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
def bernoulli_velocity(
    pressure_1: ArrayLike,
    pressure_2: ArrayLike,
    velocity_1: ArrayLike = 0.0,
    elevation_1: ArrayLike = 0.0,
    elevation_2: ArrayLike = 0.0,
    density: ArrayLike = WATER_DENSITY,
    gravity: ArrayLike = ENGINEERING_GRAVITY,
) -> float | np.ndarray:
    """
    Solve Bernoulli's equation for speed at point 2.

    U2 = sqrt(
        U1² + 2*(p1-p2)/rho + 2*g*(z1-z2)
    )

    Returns non-negative speed in m/s.
    Raises ValueError for inconsistent energy conditions.
    """

    p1 = as_float_array(pressure_1, "Pressure 1")

    p2 = as_float_array(pressure_2, "Pressure 2")

    u1 = as_float_array(velocity_1, "Velocity 1")

    z1 = as_float_array(elevation_1, "Elevation 1")

    z2 = as_float_array(elevation_2, "Elevation 2")

    rho = validate_positive(density, "Density")

    g = validate_positive(gravity, "Gravity")

    kinetic = u1**2

    pressure_term = 2 * (p1 - p2) / rho

    elevation_term = 2 * g * (z1 - z2)

    radicand = kinetic + pressure_term + elevation_term

    # Allow tiny negative values caused by
    # floating-point cancellation.

    scale = np.abs(kinetic) + np.abs(pressure_term) + np.abs(elevation_term)

    tolerance = 32 * np.finfo(float).eps * scale

    if np.any(radicand < -tolerance):
        raise ValueError("Bernoulli conditions produce a negative squared velocity.")

    radicand = np.maximum(radicand, 0.0)

    return format_output(np.sqrt(radicand))

torricelli_velocity

torricelli_velocity(head: ArrayLike, gravity: ArrayLike = ENGINEERING_GRAVITY) -> float | np.ndarray

Calculate ideal reservoir efflux speed.

U = sqrt(2 * g * h)

Head in m. Returns speed in m/s.

Source code in src/fluidmec/core/bernoulli.py
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
def torricelli_velocity(
    head: ArrayLike,
    gravity: ArrayLike = ENGINEERING_GRAVITY,
) -> float | np.ndarray:
    """
    Calculate ideal reservoir efflux speed.

    U = sqrt(2 * g * h)

    Head in m.
    Returns speed in m/s.
    """

    head = validate_non_negative(head, "Head")

    gravity = validate_positive(gravity, "Gravity")

    return format_output(np.sqrt(2 * gravity * head))

ideal_discharge

ideal_discharge(area: ArrayLike, head: ArrayLike, gravity: ArrayLike = ENGINEERING_GRAVITY) -> float | np.ndarray

Calculate theoretical reservoir discharge.

Q = A * sqrt(2 * g * h)

Area in m². Head in m. Returns discharge in m³/s.

Source code in src/fluidmec/core/bernoulli.py
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
def ideal_discharge(
    area: ArrayLike,
    head: ArrayLike,
    gravity: ArrayLike = ENGINEERING_GRAVITY,
) -> float | np.ndarray:
    """
    Calculate theoretical reservoir discharge.

    Q = A * sqrt(2 * g * h)

    Area in m².
    Head in m.
    Returns discharge in m³/s.
    """

    area = validate_positive(area, "Area")

    velocity = torricelli_velocity(head, gravity)

    return format_output(area * velocity)

bernoulli_residual

bernoulli_residual(pressure_1: ArrayLike, velocity_1: ArrayLike, pressure_2: ArrayLike, velocity_2: ArrayLike, elevation_1: ArrayLike = 0.0, elevation_2: ArrayLike = 0.0, density: ArrayLike = WATER_DENSITY, gravity: ArrayLike = ENGINEERING_GRAVITY) -> float | np.ndarray

Calculate the signed Bernoulli energy residual.

R = H1 - H2

Returns residual in metres of fluid head. Ideal energy conservation gives R = 0.

Source code in src/fluidmec/core/bernoulli.py
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
def bernoulli_residual(
    pressure_1: ArrayLike,
    velocity_1: ArrayLike,
    pressure_2: ArrayLike,
    velocity_2: ArrayLike,
    elevation_1: ArrayLike = 0.0,
    elevation_2: ArrayLike = 0.0,
    density: ArrayLike = WATER_DENSITY,
    gravity: ArrayLike = ENGINEERING_GRAVITY,
) -> float | np.ndarray:
    """
    Calculate the signed Bernoulli energy residual.

    R = H1 - H2

    Returns residual in metres of fluid head.
    Ideal energy conservation gives R = 0.
    """

    head_1 = total_energy_head(
        pressure_1,
        velocity_1,
        elevation_1,
        density,
        gravity,
    )

    head_2 = total_energy_head(
        pressure_2,
        velocity_2,
        elevation_2,
        density,
        gravity,
    )

    return format_output(head_1 - head_2)