Skip to content

Open Channel Flow

Module Reference

Open-channel hydraulics.

Includes channel geometry, uniform flow, specific energy, critical depth, normal depth and hydraulic jumps.

All dimensional quantities use SI units.

ENGINEERING_GRAVITY module-attribute

ENGINEERING_GRAVITY: Final[float] = 9.81

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

froude_number

froude_number(velocity: ArrayLike, length: ArrayLike, gravity: float = 9.81) -> float | np.ndarray

Calculate Froude number.

Fr = abs(U) / sqrt(g * L)

Velocity in m/s, length in m, gravity in m/s².

Source code in src/fluidmec/core/dimensionless.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
def froude_number(
    velocity: ArrayLike,
    length: ArrayLike,
    gravity: float = 9.81,
) -> float | np.ndarray:
    """
    Calculate Froude number.

    Fr = abs(U) / sqrt(g * L)

    Velocity in m/s, length in m,
    gravity in m/s².
    """

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

    return format_output(np.abs(velocity) / np.sqrt(gravity * length))

_validate_geometry

_validate_geometry(bed_width, depth, side_slope)

Validate trapezoidal channel geometry.

Source code in src/fluidmec/core/open_channel.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
def _validate_geometry(bed_width, depth, side_slope):
    """Validate trapezoidal channel geometry."""

    b = validate_non_negative(bed_width, "Bed width")

    y = validate_non_negative(depth, "Water depth")

    m = validate_non_negative(side_slope, "Side slope")

    b, y, m = np.broadcast_arrays(b, y, m)

    if np.any((b == 0) & (m == 0)):
        raise ValueError("Bed width and side slope cannot both be zero.")

    return b, y, m

trapezoidal_area

trapezoidal_area(bed_width: ArrayLike, depth: ArrayLike, side_slope: ArrayLike = 0.0) -> float | np.ndarray

Calculate cross-sectional flow area in m².

A = by + my²

Source code in src/fluidmec/core/open_channel.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
def trapezoidal_area(
    bed_width: ArrayLike,
    depth: ArrayLike,
    side_slope: ArrayLike = 0.0,
) -> float | np.ndarray:
    """
    Calculate cross-sectional flow area in m².

    A = b*y + m*y²
    """

    b, y, m = _validate_geometry(bed_width, depth, side_slope)

    return format_output(b * y + m * y**2)

trapezoidal_wetted_perimeter

trapezoidal_wetted_perimeter(bed_width: ArrayLike, depth: ArrayLike, side_slope: ArrayLike = 0.0) -> float | np.ndarray

Calculate wetted perimeter in metres.

P = b + 2ysqrt(1 + m²)

Returns zero for a completely dry channel.

Source code in src/fluidmec/core/open_channel.py
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
def trapezoidal_wetted_perimeter(
    bed_width: ArrayLike,
    depth: ArrayLike,
    side_slope: ArrayLike = 0.0,
) -> float | np.ndarray:
    """
    Calculate wetted perimeter in metres.

    P = b + 2*y*sqrt(1 + m²)

    Returns zero for a completely dry channel.
    """

    b, y, m = _validate_geometry(bed_width, depth, side_slope)

    result = np.where(
        y == 0,
        0.0,
        b + 2 * y * np.sqrt(1 + m**2),
    )

    return format_output(result)

trapezoidal_top_width

trapezoidal_top_width(bed_width: ArrayLike, depth: ArrayLike, side_slope: ArrayLike = 0.0) -> float | np.ndarray

Calculate geometric top width in metres.

T = b + 2my

Source code in src/fluidmec/core/open_channel.py
80
81
82
83
84
85
86
87
88
89
90
91
92
93
def trapezoidal_top_width(
    bed_width: ArrayLike,
    depth: ArrayLike,
    side_slope: ArrayLike = 0.0,
) -> float | np.ndarray:
    """
    Calculate geometric top width in metres.

    T = b + 2*m*y
    """

    b, y, m = _validate_geometry(bed_width, depth, side_slope)

    return format_output(b + 2 * m * y)

hydraulic_radius

hydraulic_radius(area: ArrayLike, wetted_perimeter: ArrayLike) -> float | np.ndarray

Calculate hydraulic radius in metres.

R = A / P

Source code in src/fluidmec/core/open_channel.py
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
def hydraulic_radius(
    area: ArrayLike,
    wetted_perimeter: ArrayLike,
) -> float | np.ndarray:
    """
    Calculate hydraulic radius in metres.

    R = A / P
    """

    area = validate_non_negative(area, "Area")

    perimeter = validate_positive(wetted_perimeter, "Wetted perimeter")

    return format_output(area / perimeter)

hydraulic_depth

hydraulic_depth(area: ArrayLike, top_width: ArrayLike) -> float | np.ndarray

Calculate hydraulic depth in metres.

Dh = A / T

Source code in src/fluidmec/core/open_channel.py
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
def hydraulic_depth(
    area: ArrayLike,
    top_width: ArrayLike,
) -> float | np.ndarray:
    """
    Calculate hydraulic depth in metres.

    Dh = A / T
    """

    area = validate_non_negative(area, "Area")

    width = validate_positive(top_width, "Top width")

    return format_output(area / width)

manning_velocity

manning_velocity(hydraulic_radius: ArrayLike, slope: ArrayLike, roughness: ArrayLike) -> float | np.ndarray

Calculate mean uniform-flow velocity in m/s.

U = R^(2/3) * sqrt(S) / n

Source code in src/fluidmec/core/open_channel.py
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
def manning_velocity(
    hydraulic_radius: ArrayLike,
    slope: ArrayLike,
    roughness: ArrayLike,
) -> float | np.ndarray:
    """
    Calculate mean uniform-flow velocity in m/s.

    U = R^(2/3) * sqrt(S) / n
    """

    radius = validate_non_negative(hydraulic_radius, "Hydraulic radius")

    slope = validate_non_negative(slope, "Friction slope")

    n = validate_positive(roughness, "Manning roughness")

    result = radius ** (2.0 / 3.0) * np.sqrt(slope) / n

    return format_output(result)

manning_discharge

manning_discharge(area: ArrayLike, hydraulic_radius: ArrayLike, slope: ArrayLike, roughness: ArrayLike) -> float | np.ndarray

Calculate uniform-flow discharge in m³/s.

Q = A * R^(2/3) * sqrt(S) / n

Source code in src/fluidmec/core/open_channel.py
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
def manning_discharge(
    area: ArrayLike,
    hydraulic_radius: ArrayLike,
    slope: ArrayLike,
    roughness: ArrayLike,
) -> float | np.ndarray:
    """
    Calculate uniform-flow discharge in m³/s.

    Q = A * R^(2/3) * sqrt(S) / n
    """

    area = validate_non_negative(area, "Area")

    velocity = manning_velocity(
        hydraulic_radius,
        slope,
        roughness,
    )

    return format_output(area * velocity)

chezy_velocity

chezy_velocity(hydraulic_radius: ArrayLike, slope: ArrayLike, coefficient: ArrayLike) -> float | np.ndarray

Calculate Chézy mean velocity in m/s.

U = C * sqrt(R*S)

Source code in src/fluidmec/core/open_channel.py
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
def chezy_velocity(
    hydraulic_radius: ArrayLike,
    slope: ArrayLike,
    coefficient: ArrayLike,
) -> float | np.ndarray:
    """
    Calculate Chézy mean velocity in m/s.

    U = C * sqrt(R*S)
    """

    radius = validate_non_negative(hydraulic_radius, "Hydraulic radius")

    slope = validate_non_negative(slope, "Friction slope")

    coefficient = validate_positive(coefficient, "Chezy coefficient")

    return format_output(coefficient * np.sqrt(radius * slope))

specific_energy

specific_energy(depth: ArrayLike, velocity: ArrayLike, gravity: ArrayLike = ENGINEERING_GRAVITY, alpha: ArrayLike = 1.0) -> float | np.ndarray

Calculate specific energy head in metres.

E = y + alphaU²/(2g)

Alpha is the kinetic energy correction coefficient.

Source code in src/fluidmec/core/open_channel.py
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
def specific_energy(
    depth: ArrayLike,
    velocity: ArrayLike,
    gravity: ArrayLike = ENGINEERING_GRAVITY,
    alpha: ArrayLike = 1.0,
) -> float | np.ndarray:
    """
    Calculate specific energy head in metres.

    E = y + alpha*U²/(2*g)

    Alpha is the kinetic energy correction coefficient.
    """

    depth = validate_non_negative(depth, "Water depth")

    velocity = as_float_array(velocity, "Velocity")

    gravity = validate_positive(gravity, "Gravity")

    alpha = validate_positive(alpha, "Energy correction coefficient")

    if np.any(alpha < 1):
        raise ValueError("Energy correction coefficient must be >= 1.")

    return format_output(depth + alpha * velocity**2 / (2 * gravity))

critical_depth

critical_depth(unit_discharge: ArrayLike, gravity: ArrayLike = ENGINEERING_GRAVITY) -> float | np.ndarray

Calculate critical depth for a rectangular channel.

yc = (q²/g)^(1/3)

Assumes a kinetic energy correction factor of one.

Source code in src/fluidmec/core/open_channel.py
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
def critical_depth(
    unit_discharge: ArrayLike,
    gravity: ArrayLike = ENGINEERING_GRAVITY,
) -> float | np.ndarray:
    """
    Calculate critical depth for a rectangular channel.

    yc = (q²/g)^(1/3)

    Assumes a kinetic energy correction factor of one.
    """

    q = as_float_array(unit_discharge, "Unit discharge")

    gravity = validate_positive(gravity, "Gravity")

    return format_output(np.cbrt(q**2 / gravity))

_scalar

_scalar(value, name, validator)

Validate a scalar solver parameter.

Source code in src/fluidmec/core/open_channel.py
242
243
244
245
246
247
248
249
250
def _scalar(value, name, validator):
    """Validate a scalar solver parameter."""

    result = validator(value, name)

    if result.ndim != 0:
        raise ValueError(f"{name} must be scalar.")

    return float(result)

normal_depth

normal_depth(discharge: float, bed_width: float, slope: float, roughness: float, side_slope: float = 0.0, tolerance: float = 1e-08, max_iterations: int = 200) -> float

Solve Manning's equation for normal depth.

Supports rectangular, trapezoidal and triangular prismatic channels.

Uses automatic root bracketing followed by bisection.

Parameters:

Name Type Description Default
discharge float

Flow discharge in m³/s.

required
bed_width float

Channel bed width in metres.

required
slope float

Positive bed slope.

required
roughness float

Manning roughness coefficient.

required
side_slope float

Horizontal-to-vertical side slope.

0.0
tolerance float

Absolute depth tolerance in metres.

1e-08
max_iterations int

Maximum bisection iterations.

200

Returns:

Type Description
float

Normal water depth in metres.

Source code in src/fluidmec/core/open_channel.py
253
254
255
256
257
258
259
260
261
262
263
264
265
266
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
def normal_depth(
    discharge: float,
    bed_width: float,
    slope: float,
    roughness: float,
    side_slope: float = 0.0,
    tolerance: float = 1e-8,
    max_iterations: int = 200,
) -> float:
    """
    Solve Manning's equation for normal depth.

    Supports rectangular, trapezoidal and triangular
    prismatic channels.

    Uses automatic root bracketing followed by bisection.

    Parameters
    ----------
    discharge : float
        Flow discharge in m³/s.
    bed_width : float
        Channel bed width in metres.
    slope : float
        Positive bed slope.
    roughness : float
        Manning roughness coefficient.
    side_slope : float
        Horizontal-to-vertical side slope.
    tolerance : float
        Absolute depth tolerance in metres.
    max_iterations : int
        Maximum bisection iterations.

    Returns
    -------
    float
        Normal water depth in metres.
    """

    Q = _scalar(
        discharge,
        "Discharge",
        validate_non_negative,
    )

    b = _scalar(
        bed_width,
        "Bed width",
        validate_non_negative,
    )

    S = _scalar(
        slope,
        "Bed slope",
        validate_positive,
    )

    n = _scalar(
        roughness,
        "Manning roughness",
        validate_positive,
    )

    m = _scalar(
        side_slope,
        "Side slope",
        validate_non_negative,
    )

    tol = _scalar(
        tolerance,
        "Tolerance",
        validate_positive,
    )

    if b == 0 and m == 0:
        raise ValueError("Invalid channel geometry.")

    if (
        isinstance(max_iterations, bool)
        or not isinstance(max_iterations, (int, np.integer))
        or max_iterations < 1
    ):
        raise ValueError("Maximum iterations must be a positive integer.")

    if Q == 0:
        return 0.0

    def residual(y):
        """Calculated discharge minus target discharge."""

        if y == 0:
            return -Q

        area = b * y + m * y**2

        perimeter = b + 2 * y * np.sqrt(1 + m**2)

        radius = area / perimeter

        calculated = area * radius ** (2.0 / 3.0) * np.sqrt(S) / n

        return calculated - Q

    # Stage 1: bracket the positive root.

    lower = 0.0
    upper = 1.0

    for _ in range(100):
        if residual(upper) >= 0:
            break

        upper *= 2

    else:
        raise RuntimeError("Unable to bracket normal depth.")

    # Stage 2: bisection.

    for _ in range(max_iterations):
        midpoint = (lower + upper) / 2.0

        value = residual(midpoint)

        if value == 0:
            return float(midpoint)

        if (upper - lower) / 2.0 <= tol:
            return float(midpoint)

        if value > 0:
            upper = midpoint

        else:
            lower = midpoint

    raise RuntimeError("Normal-depth solver did not converge.")

sequent_depth

sequent_depth(upstream_depth: ArrayLike, upstream_froude: ArrayLike) -> float | np.ndarray

Calculate downstream hydraulic jump depth.

Assumes a horizontal rectangular channel.

y2 = y1 * (sqrt(1 + 8*Fr1²) - 1) / 2

Source code in src/fluidmec/core/open_channel.py
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
def sequent_depth(
    upstream_depth: ArrayLike,
    upstream_froude: ArrayLike,
) -> float | np.ndarray:
    """
    Calculate downstream hydraulic jump depth.

    Assumes a horizontal rectangular channel.

    y2 = y1 * (sqrt(1 + 8*Fr1²) - 1) / 2
    """

    y1 = validate_positive(upstream_depth, "Upstream depth")

    fr = validate_positive(upstream_froude, "Upstream Froude number")

    if np.any(fr < 1):
        raise ValueError("Hydraulic jump requires Fr >= 1.")

    result = y1 * (np.sqrt(1 + 8 * fr**2) - 1) / 2

    return format_output(result)

hydraulic_jump_energy_loss

hydraulic_jump_energy_loss(upstream_depth: ArrayLike, downstream_depth: ArrayLike) -> float | np.ndarray

Calculate hydraulic jump energy loss in metres.

Assumes conjugate depths in a horizontal rectangular channel.

dE = (y2-y1)³ / (4y1y2)

Source code in src/fluidmec/core/open_channel.py
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
def hydraulic_jump_energy_loss(
    upstream_depth: ArrayLike,
    downstream_depth: ArrayLike,
) -> float | np.ndarray:
    """
    Calculate hydraulic jump energy loss in metres.

    Assumes conjugate depths in a horizontal
    rectangular channel.

    dE = (y2-y1)³ / (4*y1*y2)
    """

    y1 = validate_positive(upstream_depth, "Upstream depth")

    y2 = validate_positive(downstream_depth, "Downstream depth")

    if np.any(y2 < y1):
        raise ValueError("Downstream depth must be >= upstream depth.")

    return format_output((y2 - y1) ** 3 / (4 * y1 * y2))

specific_force

specific_force(depth: ArrayLike, unit_discharge: ArrayLike, gravity: ArrayLike = ENGINEERING_GRAVITY) -> float | np.ndarray

Calculate momentum function per unit width.

Rectangular channel, momentum correction factor = 1.

M = y²/2 + q²/(g*y)

Returns units of m².

Source code in src/fluidmec/core/open_channel.py
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
def specific_force(
    depth: ArrayLike,
    unit_discharge: ArrayLike,
    gravity: ArrayLike = ENGINEERING_GRAVITY,
) -> float | np.ndarray:
    """
    Calculate momentum function per unit width.

    Rectangular channel, momentum correction factor = 1.

    M = y²/2 + q²/(g*y)

    Returns units of m².
    """

    depth = validate_positive(depth, "Water depth")

    q = as_float_array(unit_discharge, "Unit discharge")

    gravity = validate_positive(gravity, "Gravity")

    return format_output(depth**2 / 2 + q**2 / (gravity * depth))

flow_regime

flow_regime(velocity: ArrayLike, hydraulic_depth: ArrayLike, gravity: ArrayLike = ENGINEERING_GRAVITY, tolerance: float = 1e-06) -> str | np.ndarray

Classify open-channel flow using Froude number.

Returns: "subcritical" "critical" "supercritical"

Scalar inputs return a string. Array inputs return a NumPy string array.

Source code in src/fluidmec/core/open_channel.py
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
def flow_regime(
    velocity: ArrayLike,
    hydraulic_depth: ArrayLike,
    gravity: ArrayLike = ENGINEERING_GRAVITY,
    tolerance: float = 1e-6,
) -> str | np.ndarray:
    """
    Classify open-channel flow using Froude number.

    Returns:
        "subcritical"
        "critical"
        "supercritical"

    Scalar inputs return a string.
    Array inputs return a NumPy string array.
    """

    tol = _scalar(
        tolerance,
        "Tolerance",
        validate_non_negative,
    )

    if tol >= 1:
        raise ValueError("Froude tolerance must be less than 1.")

    fr = np.asarray(
        froude_number(
            velocity,
            hydraulic_depth,
            gravity,
        ),
        dtype=float,
    )

    result = np.where(
        np.abs(fr - 1) <= tol,
        "critical",
        np.where(
            fr < 1,
            "subcritical",
            "supercritical",
        ),
    )

    if result.ndim == 0:
        return str(result.item())

    return result