Skip to content

Fluid Properties

Module Reference

Fluid property calculations.

All dimensional inputs and outputs use SI units, except explicitly identified Celsius temperatures.

AIR_GAS_CONSTANT module-attribute

AIR_GAS_CONSTANT: Final[float] = 287.05

ATMOSPHERIC_PRESSURE module-attribute

ATMOSPHERIC_PRESSURE: Final[float] = 101325.0

CELSIUS_TO_KELVIN module-attribute

CELSIUS_TO_KELVIN: Final[float] = 273.15

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_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

kinematic_viscosity

kinematic_viscosity(dynamic_viscosity: ArrayLike, density: ArrayLike) -> float | np.ndarray

Calculate kinematic viscosity in m²/s.

nu = mu / rho

Dynamic viscosity in Pa.s. Density in kg/m³.

Source code in src/fluidmec/core/properties.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
def kinematic_viscosity(
    dynamic_viscosity: ArrayLike,
    density: ArrayLike,
) -> float | np.ndarray:
    """
    Calculate kinematic viscosity in m²/s.

    nu = mu / rho

    Dynamic viscosity in Pa.s.
    Density in kg/m³.
    """

    mu = validate_positive(dynamic_viscosity, "Dynamic viscosity")

    rho = validate_positive(density, "Density")

    return format_output(mu / rho)

dynamic_viscosity

dynamic_viscosity(kinematic_viscosity: ArrayLike, density: ArrayLike) -> float | np.ndarray

Calculate dynamic viscosity in Pa.s.

mu = rho * nu

Source code in src/fluidmec/core/properties.py
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
def dynamic_viscosity(
    kinematic_viscosity: ArrayLike,
    density: ArrayLike,
) -> float | np.ndarray:
    """
    Calculate dynamic viscosity in Pa.s.

    mu = rho * nu
    """

    nu = validate_positive(kinematic_viscosity, "Kinematic viscosity")

    rho = validate_positive(density, "Density")

    return format_output(rho * nu)

_validate_water_temperature

_validate_water_temperature(temperature: ArrayLike) -> np.ndarray

Validate freshwater temperature in Celsius.

Empirical model range: 0 to 100°C.

Source code in src/fluidmec/core/properties.py
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
def _validate_water_temperature(
    temperature: ArrayLike,
) -> np.ndarray:
    """
    Validate freshwater temperature in Celsius.

    Empirical model range: 0 to 100°C.
    """

    temperature = as_float_array(temperature, "Temperature")

    if np.any((temperature < 0) | (temperature > 100)):
        raise ValueError("Water temperature must be between 0 and 100 degrees Celsius.")

    return temperature

water_density

water_density(temperature: ArrayLike = 20.0) -> float | np.ndarray

Estimate freshwater density in kg/m³.

Temperature in degrees Celsius.

Assumes liquid freshwater near atmospheric pressure, using an empirical correlation.

Source code in src/fluidmec/core/properties.py
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
def water_density(
    temperature: ArrayLike = 20.0,
) -> float | np.ndarray:
    """
    Estimate freshwater density in kg/m³.

    Temperature in degrees Celsius.

    Assumes liquid freshwater near atmospheric
    pressure, using an empirical correlation.
    """

    T = _validate_water_temperature(temperature)

    result = 1000.0 * (
        1.0 - ((T + 288.9414) * (T - 3.9863) ** 2) / (508929.2 * (T + 68.12963))
    )

    return format_output(result)

water_dynamic_viscosity

water_dynamic_viscosity(temperature: ArrayLike = 20.0) -> float | np.ndarray

Estimate freshwater dynamic viscosity in Pa.s.

Temperature in degrees Celsius.

Source code in src/fluidmec/core/properties.py
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
def water_dynamic_viscosity(
    temperature: ArrayLike = 20.0,
) -> float | np.ndarray:
    """
    Estimate freshwater dynamic viscosity in Pa.s.

    Temperature in degrees Celsius.
    """

    T = _validate_water_temperature(temperature)

    T_kelvin = T + CELSIUS_TO_KELVIN

    result = 2.414e-5 * (10.0 ** (247.8 / (T_kelvin - 140.0)))

    return format_output(result)

water_kinematic_viscosity

water_kinematic_viscosity(temperature: ArrayLike = 20.0) -> float | np.ndarray

Estimate freshwater kinematic viscosity in m²/s.

Temperature in degrees Celsius.

Source code in src/fluidmec/core/properties.py
117
118
119
120
121
122
123
124
125
126
127
128
129
130
def water_kinematic_viscosity(
    temperature: ArrayLike = 20.0,
) -> float | np.ndarray:
    """
    Estimate freshwater kinematic viscosity in m²/s.

    Temperature in degrees Celsius.
    """

    rho = water_density(temperature)

    mu = water_dynamic_viscosity(temperature)

    return kinematic_viscosity(mu, rho)

air_density

air_density(temperature: ArrayLike = 20.0, pressure: ArrayLike = ATMOSPHERIC_PRESSURE) -> float | np.ndarray

Calculate dry air density in kg/m³.

Uses the ideal gas equation.

Temperature in degrees Celsius. Absolute pressure in Pa.

Source code in src/fluidmec/core/properties.py
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
def air_density(
    temperature: ArrayLike = 20.0,
    pressure: ArrayLike = ATMOSPHERIC_PRESSURE,
) -> float | np.ndarray:
    """
    Calculate dry air density in kg/m³.

    Uses the ideal gas equation.

    Temperature in degrees Celsius.
    Absolute pressure in Pa.
    """

    temperature = as_float_array(temperature, "Temperature")

    T_kelvin = validate_positive(
        temperature + CELSIUS_TO_KELVIN,
        "Absolute temperature",
    )

    pressure = validate_positive(pressure, "Pressure")

    result = pressure / (AIR_GAS_CONSTANT * T_kelvin)

    return format_output(result)

reduced_gravity

reduced_gravity(density: ArrayLike, reference_density: ArrayLike, gravity: ArrayLike = ENGINEERING_GRAVITY) -> float | np.ndarray

Calculate signed reduced gravity in m/s².

g_prime = g * (rho - rho_ref) / rho_ref

Density values in kg/m³.

Source code in src/fluidmec/core/properties.py
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
def reduced_gravity(
    density: ArrayLike,
    reference_density: ArrayLike,
    gravity: ArrayLike = ENGINEERING_GRAVITY,
) -> float | np.ndarray:
    """
    Calculate signed reduced gravity in m/s².

    g_prime = g * (rho - rho_ref) / rho_ref

    Density values in kg/m³.
    """

    rho = validate_positive(density, "Density")

    rho_ref = validate_positive(reference_density, "Reference density")

    gravity = validate_positive(gravity, "Gravity")

    result = gravity * (rho - rho_ref) / rho_ref

    return format_output(result)

specific_weight

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

Calculate specific weight in N/m³.

gamma = rho * g

Source code in src/fluidmec/core/properties.py
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
def specific_weight(
    density: ArrayLike,
    gravity: ArrayLike = ENGINEERING_GRAVITY,
) -> float | np.ndarray:
    """
    Calculate specific weight in N/m³.

    gamma = rho * g
    """

    density = validate_positive(density, "Density")

    gravity = validate_positive(gravity, "Gravity")

    return format_output(density * gravity)

specific_gravity

specific_gravity(density: ArrayLike, reference_density: ArrayLike = 1000.0) -> float | np.ndarray

Calculate dimensionless specific gravity.

SG = rho / rho_ref

Default reference density is nominal freshwater density of 1000 kg/m³.

Source code in src/fluidmec/core/properties.py
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
def specific_gravity(
    density: ArrayLike,
    reference_density: ArrayLike = 1000.0,
) -> float | np.ndarray:
    """
    Calculate dimensionless specific gravity.

    SG = rho / rho_ref

    Default reference density is nominal freshwater
    density of 1000 kg/m³.
    """

    density = validate_positive(density, "Density")

    reference_density = validate_positive(reference_density, "Reference density")

    return format_output(density / reference_density)