Skip to content

Hydrostatic Forces

Module Reference

Hydrostatic force and centre of pressure calculations.

All dimensional quantities use SI units.

Depth is positive downwards. Inclination angles are measured from the horizontal and supplied in degrees.

Analytical gate calculations assume fully submerged plane surfaces and constant fluid density.

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

hydrostatic_pressure

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

Calculate hydrostatic gauge pressure in Pa.

p = rho * g * h

Parameters:

Name Type Description Default
depth ArrayLike

Depth below the fluid surface in m.

required
density ArrayLike

Fluid density in kg/m³.

WATER_DENSITY
gravity ArrayLike

Gravitational acceleration in m/s².

ENGINEERING_GRAVITY
Source code in src/fluidmec/core/hydrostatics.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def hydrostatic_pressure(
    depth: ArrayLike,
    density: ArrayLike = WATER_DENSITY,
    gravity: ArrayLike = ENGINEERING_GRAVITY,
) -> float | np.ndarray:
    """
    Calculate hydrostatic gauge pressure in Pa.

    p = rho * g * h

    Parameters
    ----------
    depth : ArrayLike
        Depth below the fluid surface in m.
    density : ArrayLike
        Fluid density in kg/m³.
    gravity : ArrayLike
        Gravitational acceleration in m/s².
    """

    depth = validate_non_negative(depth, "Depth")
    density = validate_positive(density, "Density")
    gravity = validate_positive(gravity, "Gravity")

    return format_output(density * gravity * depth)

_inclination_sine

_inclination_sine(angle: ArrayLike) -> np.ndarray

Validate inclination and return its sine.

Source code in src/fluidmec/core/hydrostatic_forces.py
30
31
32
33
34
35
36
37
38
39
40
def _inclination_sine(
    angle: ArrayLike,
) -> np.ndarray:
    """Validate inclination and return its sine."""

    angle = as_float_array(angle, "Angle")

    if np.any((angle < 0) | (angle > 90)):
        raise ValueError("Angle must be between 0 and 90 degrees.")

    return np.sin(np.deg2rad(angle))

hydrostatic_force

hydrostatic_force(area: ArrayLike, centroid_depth: ArrayLike, density: ArrayLike = WATER_DENSITY, gravity: ArrayLike = ENGINEERING_GRAVITY) -> float | np.ndarray

Calculate resultant hydrostatic force in N.

F = rho * g * h_c * A

Area in m². Centroid depth in m.

Source code in src/fluidmec/core/hydrostatic_forces.py
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
def hydrostatic_force(
    area: ArrayLike,
    centroid_depth: ArrayLike,
    density: ArrayLike = WATER_DENSITY,
    gravity: ArrayLike = ENGINEERING_GRAVITY,
) -> float | np.ndarray:
    """
    Calculate resultant hydrostatic force in N.

    F = rho * g * h_c * A

    Area in m².
    Centroid depth in m.
    """

    area = validate_positive(area, "Area")

    pressure = hydrostatic_pressure(
        centroid_depth,
        density,
        gravity,
    )

    return format_output(pressure * area)

centre_of_pressure

centre_of_pressure(area: ArrayLike, centroid_depth: ArrayLike, second_moment: ArrayLike, angle: ArrayLike = 90.0) -> float | np.ndarray

Calculate vertical centre of pressure depth in m.

h_cp = h_c + I_G * sin(theta)^2 / (A * h_c)

Second moment of area in m^4.

Source code in src/fluidmec/core/hydrostatic_forces.py
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
def centre_of_pressure(
    area: ArrayLike,
    centroid_depth: ArrayLike,
    second_moment: ArrayLike,
    angle: ArrayLike = 90.0,
) -> float | np.ndarray:
    """
    Calculate vertical centre of pressure depth in m.

    h_cp = h_c + I_G * sin(theta)^2 / (A * h_c)

    Second moment of area in m^4.
    """

    area = validate_positive(area, "Area")

    hc = validate_positive(centroid_depth, "Centroid depth")

    inertia = validate_non_negative(second_moment, "Second moment of area")

    sin_theta = _inclination_sine(angle)

    result = hc + (inertia * sin_theta**2) / (area * hc)

    return format_output(result)

rectangular_gate_force

rectangular_gate_force(width: ArrayLike, length: ArrayLike, top_depth: ArrayLike = 0.0, angle: ArrayLike = 90.0, density: ArrayLike = WATER_DENSITY, gravity: ArrayLike = ENGINEERING_GRAVITY) -> float | np.ndarray

Calculate hydrostatic force on a rectangular gate.

Width is parallel to the free surface. Length is measured along the inclined gate. Top depth is the vertical depth of its upper edge.

Source code in src/fluidmec/core/hydrostatic_forces.py
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
def rectangular_gate_force(
    width: ArrayLike,
    length: ArrayLike,
    top_depth: ArrayLike = 0.0,
    angle: ArrayLike = 90.0,
    density: ArrayLike = WATER_DENSITY,
    gravity: ArrayLike = ENGINEERING_GRAVITY,
) -> float | np.ndarray:
    """
    Calculate hydrostatic force on a rectangular gate.

    Width is parallel to the free surface.
    Length is measured along the inclined gate.
    Top depth is the vertical depth of its upper edge.
    """

    width = validate_positive(width, "Width")
    length = validate_positive(length, "Length")

    top_depth = validate_non_negative(top_depth, "Top depth")

    sin_theta = _inclination_sine(angle)

    area = width * length

    hc = top_depth + (length * sin_theta / 2)

    return hydrostatic_force(area, hc, density, gravity)

rectangular_gate_centre_of_pressure

rectangular_gate_centre_of_pressure(width: ArrayLike, length: ArrayLike, top_depth: ArrayLike = 0.0, angle: ArrayLike = 90.0) -> float | np.ndarray

Calculate vertical centre of pressure depth for a fully submerged rectangular gate.

Source code in src/fluidmec/core/hydrostatic_forces.py
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
def rectangular_gate_centre_of_pressure(
    width: ArrayLike,
    length: ArrayLike,
    top_depth: ArrayLike = 0.0,
    angle: ArrayLike = 90.0,
) -> float | np.ndarray:
    """
    Calculate vertical centre of pressure depth
    for a fully submerged rectangular gate.
    """

    width = validate_positive(width, "Width")
    length = validate_positive(length, "Length")

    top_depth = validate_non_negative(top_depth, "Top depth")

    sin_theta = _inclination_sine(angle)

    area = width * length

    hc = top_depth + (length * sin_theta / 2)

    inertia = width * length**3 / 12

    return centre_of_pressure(area, hc, inertia, angle)

_validate_circular_gate

_validate_circular_gate(radius: ArrayLike, centre_depth: ArrayLike, angle: ArrayLike) -> tuple[np.ndarray, np.ndarray]

Validate a fully submerged circular gate.

Source code in src/fluidmec/core/hydrostatic_forces.py
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
def _validate_circular_gate(
    radius: ArrayLike,
    centre_depth: ArrayLike,
    angle: ArrayLike,
) -> tuple[np.ndarray, np.ndarray]:
    """Validate a fully submerged circular gate."""

    radius = validate_positive(radius, "Radius")

    hc = validate_non_negative(centre_depth, "Centre depth")

    sin_theta = _inclination_sine(angle)

    if np.any(hc < radius * sin_theta):
        raise ValueError("Circular gate must be fully submerged.")

    return radius, hc

circular_gate_force

circular_gate_force(radius: ArrayLike, centre_depth: ArrayLike, angle: ArrayLike = 90.0, density: ArrayLike = WATER_DENSITY, gravity: ArrayLike = ENGINEERING_GRAVITY) -> float | np.ndarray

Calculate force on a fully submerged circular gate.

Source code in src/fluidmec/core/hydrostatic_forces.py
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
def circular_gate_force(
    radius: ArrayLike,
    centre_depth: ArrayLike,
    angle: ArrayLike = 90.0,
    density: ArrayLike = WATER_DENSITY,
    gravity: ArrayLike = ENGINEERING_GRAVITY,
) -> float | np.ndarray:
    """
    Calculate force on a fully submerged circular gate.
    """

    radius, hc = _validate_circular_gate(radius, centre_depth, angle)

    area = np.pi * radius**2

    hc, _ = np.broadcast_arrays(hc, _inclination_sine(angle))

    return hydrostatic_force(area, hc, density, gravity)

circular_gate_centre_of_pressure

circular_gate_centre_of_pressure(radius: ArrayLike, centre_depth: ArrayLike, angle: ArrayLike = 90.0) -> float | np.ndarray

Calculate vertical centre of pressure depth for a fully submerged circular gate.

Source code in src/fluidmec/core/hydrostatic_forces.py
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
def circular_gate_centre_of_pressure(
    radius: ArrayLike,
    centre_depth: ArrayLike,
    angle: ArrayLike = 90.0,
) -> float | np.ndarray:
    """
    Calculate vertical centre of pressure depth
    for a fully submerged circular gate.
    """

    radius, hc = _validate_circular_gate(radius, centre_depth, angle)

    area = np.pi * radius**2

    inertia = np.pi * radius**4 / 4

    return centre_of_pressure(area, hc, inertia, angle)

hydrostatic_moment

hydrostatic_moment(force: ArrayLike, lever_arm: ArrayLike) -> float | np.ndarray

Calculate signed moment in N.m.

M = F * d

Lever arm is the perpendicular distance from the axis to the force's line of action.

Its sign defines the moment direction.

Source code in src/fluidmec/core/hydrostatic_forces.py
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
def hydrostatic_moment(
    force: ArrayLike,
    lever_arm: ArrayLike,
) -> float | np.ndarray:
    """
    Calculate signed moment in N.m.

    M = F * d

    Lever arm is the perpendicular distance
    from the axis to the force's line of action.

    Its sign defines the moment direction.
    """

    force = validate_non_negative(force, "Force")

    lever_arm = as_float_array(lever_arm, "Lever arm")

    return format_output(force * lever_arm)

_validate_pressure_profile

_validate_pressure_profile(coordinate: ArrayLike, pressure: ArrayLike, width: ArrayLike) -> tuple[np.ndarray, np.ndarray]

Validate a sampled plane-surface pressure profile.

Coordinate is distance along the surface. Width is perpendicular to that coordinate within the plane of the surface.

Source code in src/fluidmec/core/hydrostatic_forces.py
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
def _validate_pressure_profile(
    coordinate: ArrayLike,
    pressure: ArrayLike,
    width: ArrayLike,
) -> tuple[np.ndarray, np.ndarray]:
    """
    Validate a sampled plane-surface pressure profile.

    Coordinate is distance along the surface.
    Width is perpendicular to that coordinate
    within the plane of the surface.
    """

    coordinate = as_float_array(coordinate, "Coordinate")

    pressure = validate_non_negative(pressure, "Pressure")

    width = validate_non_negative(width, "Width")

    if coordinate.ndim != 1:
        raise ValueError("Coordinate must be a 1D array.")

    if coordinate.size < 2:
        raise ValueError("At least two points are required.")

    if pressure.shape != coordinate.shape:
        raise ValueError("Pressure and coordinate must have equal shapes.")

    if width.ndim != 0:
        if width.shape != coordinate.shape:
            raise ValueError(
                "Width must be scalar or have the same shape as coordinate."
            )

    if np.any(np.diff(coordinate) <= 0):
        raise ValueError("Coordinate must increase strictly.")

    load_per_length = pressure * width

    return coordinate, load_per_length

_trapezoidal_integral

_trapezoidal_integral(coordinate: ndarray, values: ndarray) -> float

Integrate sampled values using trapezoids.

Source code in src/fluidmec/core/hydrostatic_forces.py
275
276
277
278
279
280
281
282
283
284
285
def _trapezoidal_integral(
    coordinate: np.ndarray,
    values: np.ndarray,
) -> float:
    """Integrate sampled values using trapezoids."""

    intervals = np.diff(coordinate)

    averages = (values[:-1] + values[1:]) / 2

    return float(np.sum(averages * intervals))

integrated_pressure_force

integrated_pressure_force(coordinate: ArrayLike, pressure: ArrayLike, width: ArrayLike = 1.0) -> float

Numerically integrate pressure over a plane.

F = integral(p * b * ds)

Coordinate in m. Pressure in Pa. Width in m.

Returns force in N.

Source code in src/fluidmec/core/hydrostatic_forces.py
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
def integrated_pressure_force(
    coordinate: ArrayLike,
    pressure: ArrayLike,
    width: ArrayLike = 1.0,
) -> float:
    """
    Numerically integrate pressure over a plane.

    F = integral(p * b * ds)

    Coordinate in m.
    Pressure in Pa.
    Width in m.

    Returns force in N.
    """

    coordinate, load = _validate_pressure_profile(coordinate, pressure, width)

    return _trapezoidal_integral(coordinate, load)

integrated_centre_of_pressure

integrated_centre_of_pressure(coordinate: ArrayLike, pressure: ArrayLike, width: ArrayLike = 1.0) -> float

Calculate centre of pressure along a surface.

s_cp = integral(s * p * b * ds) / F

Returns the position in the supplied coordinate system, not necessarily vertical depth.

Source code in src/fluidmec/core/hydrostatic_forces.py
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
def integrated_centre_of_pressure(
    coordinate: ArrayLike,
    pressure: ArrayLike,
    width: ArrayLike = 1.0,
) -> float:
    """
    Calculate centre of pressure along a surface.

    s_cp = integral(s * p * b * ds) / F

    Returns the position in the supplied
    coordinate system, not necessarily vertical depth.
    """

    coordinate, load = _validate_pressure_profile(coordinate, pressure, width)

    force = _trapezoidal_integral(coordinate, load)

    if force <= 0:
        raise ValueError("Resultant force must be positive.")

    moment = _trapezoidal_integral(
        coordinate,
        coordinate * load,
    )

    return moment / force

buoyancy_force

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

Calculate upward buoyancy force in N.

F_B = rho * g * V

Displaced volume in m³.

Source code in src/fluidmec/core/hydrostatic_forces.py
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
def buoyancy_force(
    displaced_volume: ArrayLike,
    density: ArrayLike = WATER_DENSITY,
    gravity: ArrayLike = ENGINEERING_GRAVITY,
) -> float | np.ndarray:
    """
    Calculate upward buoyancy force in N.

    F_B = rho * g * V

    Displaced volume in m³.
    """

    volume = validate_non_negative(displaced_volume, "Displaced volume")

    density = validate_positive(density, "Density")

    gravity = validate_positive(gravity, "Gravity")

    return format_output(density * gravity * volume)