fluidmec 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fluidmec/__init__.py +10 -0
- fluidmec/buoyancy/__init__.py +1 -0
- fluidmec/cfd/__init__.py +1 -0
- fluidmec/constants.py +3 -0
- fluidmec/core/__init__.py +185 -0
- fluidmec/core/_dependencies.py +13 -0
- fluidmec/core/_validation.py +79 -0
- fluidmec/core/bernoulli.py +302 -0
- fluidmec/core/boundary_layer.py +48 -0
- fluidmec/core/constants.py +39 -0
- fluidmec/core/continuity.py +318 -0
- fluidmec/core/dimensionless.py +239 -0
- fluidmec/core/hydrostatic_forces.py +358 -0
- fluidmec/core/hydrostatics.py +219 -0
- fluidmec/core/open_channel.py +514 -0
- fluidmec/core/pipe_flow.py +369 -0
- fluidmec/core/properties.py +218 -0
- fluidmec/hydrodynamics/__init__.py +1 -0
- fluidmec/integrations/__init__.py +1 -0
- fluidmec/mesh/__init__.py +1 -0
- fluidmec/ml/__init__.py +1 -0
- fluidmec/numerics/__init__.py +1 -0
- fluidmec/sediment/__init__.py +1 -0
- fluidmec/visualization/__init__.py +1 -0
- fluidmec/waves/__init__.py +1 -0
- fluidmec-0.1.0.dist-info/METADATA +49 -0
- fluidmec-0.1.0.dist-info/RECORD +30 -0
- fluidmec-0.1.0.dist-info/WHEEL +5 -0
- fluidmec-0.1.0.dist-info/licenses/LICENSE +21 -0
- fluidmec-0.1.0.dist-info/top_level.txt +1 -0
fluidmec/__init__.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""Reusable fluid mechanics tools."""
|
|
2
|
+
|
|
3
|
+
"""FluidPy: Scientific computing for fluid mechanics."""
|
|
4
|
+
|
|
5
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
6
|
+
|
|
7
|
+
try:
|
|
8
|
+
__version__ = version("fluidmec")
|
|
9
|
+
except PackageNotFoundError:
|
|
10
|
+
__version__ = "0+unknown"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Buoyancy tools."""
|
fluidmec/cfd/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Cfd tools."""
|
fluidmec/constants.py
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
from .bernoulli import (
|
|
2
|
+
bernoulli_pressure,
|
|
3
|
+
bernoulli_residual,
|
|
4
|
+
bernoulli_velocity,
|
|
5
|
+
dynamic_pressure,
|
|
6
|
+
ideal_discharge,
|
|
7
|
+
piezometric_head,
|
|
8
|
+
stagnation_pressure,
|
|
9
|
+
torricelli_velocity,
|
|
10
|
+
total_energy_head,
|
|
11
|
+
velocity_head,
|
|
12
|
+
)
|
|
13
|
+
from .boundary_layer import (
|
|
14
|
+
stokes_boundary_layer_thickness,
|
|
15
|
+
)
|
|
16
|
+
from .continuity import (
|
|
17
|
+
annular_area,
|
|
18
|
+
circular_area,
|
|
19
|
+
compressible_continuity_velocity,
|
|
20
|
+
continuity_velocity,
|
|
21
|
+
flow_velocity,
|
|
22
|
+
hydraulic_diameter,
|
|
23
|
+
mass_conservation_residual,
|
|
24
|
+
mass_flow_rate,
|
|
25
|
+
rectangular_area,
|
|
26
|
+
venturi_flow_rate,
|
|
27
|
+
volumetric_flow_rate,
|
|
28
|
+
)
|
|
29
|
+
from .dimensionless import (
|
|
30
|
+
froude_number,
|
|
31
|
+
gradient_richardson_number,
|
|
32
|
+
keulegan_carpenter_number,
|
|
33
|
+
oscillatory_frequency_parameter,
|
|
34
|
+
reynolds_number,
|
|
35
|
+
richardson_number,
|
|
36
|
+
strouhal_number,
|
|
37
|
+
vortex_shedding_frequency,
|
|
38
|
+
weber_number,
|
|
39
|
+
)
|
|
40
|
+
from .hydrostatic_forces import (
|
|
41
|
+
buoyancy_force,
|
|
42
|
+
centre_of_pressure,
|
|
43
|
+
circular_gate_centre_of_pressure,
|
|
44
|
+
circular_gate_force,
|
|
45
|
+
hydrostatic_force,
|
|
46
|
+
hydrostatic_moment,
|
|
47
|
+
integrated_centre_of_pressure,
|
|
48
|
+
integrated_pressure_force,
|
|
49
|
+
rectangular_gate_centre_of_pressure,
|
|
50
|
+
rectangular_gate_force,
|
|
51
|
+
)
|
|
52
|
+
from .hydrostatics import (
|
|
53
|
+
absolute_pressure,
|
|
54
|
+
hydrostatic_depth,
|
|
55
|
+
hydrostatic_pressure,
|
|
56
|
+
pressure_difference,
|
|
57
|
+
pressure_head,
|
|
58
|
+
stratified_pressure,
|
|
59
|
+
)
|
|
60
|
+
from .open_channel import (
|
|
61
|
+
chezy_velocity,
|
|
62
|
+
critical_depth,
|
|
63
|
+
flow_regime,
|
|
64
|
+
hydraulic_depth,
|
|
65
|
+
hydraulic_jump_energy_loss,
|
|
66
|
+
hydraulic_radius,
|
|
67
|
+
manning_discharge,
|
|
68
|
+
manning_velocity,
|
|
69
|
+
normal_depth,
|
|
70
|
+
sequent_depth,
|
|
71
|
+
specific_energy,
|
|
72
|
+
specific_force,
|
|
73
|
+
trapezoidal_area,
|
|
74
|
+
trapezoidal_top_width,
|
|
75
|
+
trapezoidal_wetted_perimeter,
|
|
76
|
+
)
|
|
77
|
+
from .pipe_flow import (
|
|
78
|
+
colebrook_friction_factor,
|
|
79
|
+
darcy_friction_factor,
|
|
80
|
+
darcy_head_loss,
|
|
81
|
+
extended_bernoulli_head,
|
|
82
|
+
haaland_friction_factor,
|
|
83
|
+
laminar_friction_factor,
|
|
84
|
+
minor_head_loss,
|
|
85
|
+
pressure_loss,
|
|
86
|
+
pump_power,
|
|
87
|
+
relative_roughness,
|
|
88
|
+
swamee_jain_friction_factor,
|
|
89
|
+
)
|
|
90
|
+
from .properties import (
|
|
91
|
+
air_density,
|
|
92
|
+
dynamic_viscosity,
|
|
93
|
+
kinematic_viscosity,
|
|
94
|
+
reduced_gravity,
|
|
95
|
+
specific_gravity,
|
|
96
|
+
specific_weight,
|
|
97
|
+
water_density,
|
|
98
|
+
water_dynamic_viscosity,
|
|
99
|
+
water_kinematic_viscosity,
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
__all__ = [
|
|
103
|
+
"absolute_pressure",
|
|
104
|
+
"air_density",
|
|
105
|
+
"annular_area",
|
|
106
|
+
"bernoulli_pressure",
|
|
107
|
+
"bernoulli_residual",
|
|
108
|
+
"bernoulli_velocity",
|
|
109
|
+
"buoyancy_force",
|
|
110
|
+
"centre_of_pressure",
|
|
111
|
+
"chezy_velocity",
|
|
112
|
+
"circular_area",
|
|
113
|
+
"circular_gate_centre_of_pressure",
|
|
114
|
+
"circular_gate_force",
|
|
115
|
+
"colebrook_friction_factor",
|
|
116
|
+
"compressible_continuity_velocity",
|
|
117
|
+
"continuity_velocity",
|
|
118
|
+
"critical_depth",
|
|
119
|
+
"darcy_friction_factor",
|
|
120
|
+
"darcy_head_loss",
|
|
121
|
+
"dynamic_pressure",
|
|
122
|
+
"dynamic_viscosity",
|
|
123
|
+
"extended_bernoulli_head",
|
|
124
|
+
"flow_regime",
|
|
125
|
+
"flow_velocity",
|
|
126
|
+
"froude_number",
|
|
127
|
+
"gradient_richardson_number",
|
|
128
|
+
"haaland_friction_factor",
|
|
129
|
+
"hydraulic_depth",
|
|
130
|
+
"hydraulic_diameter",
|
|
131
|
+
"hydraulic_jump_energy_loss",
|
|
132
|
+
"hydraulic_radius",
|
|
133
|
+
"hydrostatic_depth",
|
|
134
|
+
"hydrostatic_force",
|
|
135
|
+
"hydrostatic_moment",
|
|
136
|
+
"hydrostatic_pressure",
|
|
137
|
+
"ideal_discharge",
|
|
138
|
+
"integrated_centre_of_pressure",
|
|
139
|
+
"integrated_pressure_force",
|
|
140
|
+
"keulegan_carpenter_number",
|
|
141
|
+
"kinematic_viscosity",
|
|
142
|
+
"laminar_friction_factor",
|
|
143
|
+
"manning_discharge",
|
|
144
|
+
"manning_velocity",
|
|
145
|
+
"mass_conservation_residual",
|
|
146
|
+
"mass_flow_rate",
|
|
147
|
+
"minor_head_loss",
|
|
148
|
+
"normal_depth",
|
|
149
|
+
"oscillatory_frequency_parameter",
|
|
150
|
+
"piezometric_head",
|
|
151
|
+
"pressure_difference",
|
|
152
|
+
"pressure_head",
|
|
153
|
+
"pressure_loss",
|
|
154
|
+
"pump_power",
|
|
155
|
+
"rectangular_area",
|
|
156
|
+
"rectangular_gate_centre_of_pressure",
|
|
157
|
+
"rectangular_gate_force",
|
|
158
|
+
"reduced_gravity",
|
|
159
|
+
"relative_roughness",
|
|
160
|
+
"reynolds_number",
|
|
161
|
+
"richardson_number",
|
|
162
|
+
"sequent_depth",
|
|
163
|
+
"specific_energy",
|
|
164
|
+
"specific_force",
|
|
165
|
+
"specific_gravity",
|
|
166
|
+
"specific_weight",
|
|
167
|
+
"stagnation_pressure",
|
|
168
|
+
"stokes_boundary_layer_thickness",
|
|
169
|
+
"stratified_pressure",
|
|
170
|
+
"strouhal_number",
|
|
171
|
+
"swamee_jain_friction_factor",
|
|
172
|
+
"torricelli_velocity",
|
|
173
|
+
"total_energy_head",
|
|
174
|
+
"trapezoidal_area",
|
|
175
|
+
"trapezoidal_top_width",
|
|
176
|
+
"trapezoidal_wetted_perimeter",
|
|
177
|
+
"velocity_head",
|
|
178
|
+
"venturi_flow_rate",
|
|
179
|
+
"volumetric_flow_rate",
|
|
180
|
+
"vortex_shedding_frequency",
|
|
181
|
+
"water_density",
|
|
182
|
+
"water_dynamic_viscosity",
|
|
183
|
+
"water_kinematic_viscosity",
|
|
184
|
+
"weber_number",
|
|
185
|
+
]
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""Centralised scientific dependency imports."""
|
|
2
|
+
|
|
3
|
+
try:
|
|
4
|
+
import numpy as np
|
|
5
|
+
|
|
6
|
+
except ImportError as exc:
|
|
7
|
+
raise ImportError(
|
|
8
|
+
"Fluidmec could not initialise NumPy. "
|
|
9
|
+
"Check your Python and NumPy compatibility "
|
|
10
|
+
"and verify that NumPy can be imported independently."
|
|
11
|
+
) from exc
|
|
12
|
+
|
|
13
|
+
__all__ = ["np"]
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Internal validation utilities for Fluidmec.
|
|
3
|
+
|
|
4
|
+
These utilities provide consistent input validation
|
|
5
|
+
and output formatting across engineering modules.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from numpy.typing import ArrayLike
|
|
9
|
+
|
|
10
|
+
from ._dependencies import np
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def as_float_array(
|
|
14
|
+
value: ArrayLike,
|
|
15
|
+
name: str,
|
|
16
|
+
) -> np.ndarray:
|
|
17
|
+
"""Convert input to a finite floating-point array."""
|
|
18
|
+
|
|
19
|
+
array = np.asarray(value, dtype=float)
|
|
20
|
+
|
|
21
|
+
if not np.all(np.isfinite(array)):
|
|
22
|
+
raise ValueError(f"{name} must be finite.")
|
|
23
|
+
|
|
24
|
+
return array
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def validate_positive(
|
|
28
|
+
value: ArrayLike,
|
|
29
|
+
name: str,
|
|
30
|
+
) -> np.ndarray:
|
|
31
|
+
"""Validate strictly positive numerical inputs."""
|
|
32
|
+
|
|
33
|
+
array = as_float_array(value, name)
|
|
34
|
+
|
|
35
|
+
if np.any(array <= 0):
|
|
36
|
+
raise ValueError(f"{name} must be positive.")
|
|
37
|
+
|
|
38
|
+
return array
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def validate_non_negative(
|
|
42
|
+
value: ArrayLike,
|
|
43
|
+
name: str,
|
|
44
|
+
) -> np.ndarray:
|
|
45
|
+
"""Validate non-negative numerical inputs."""
|
|
46
|
+
|
|
47
|
+
array = as_float_array(value, name)
|
|
48
|
+
|
|
49
|
+
if np.any(array < 0):
|
|
50
|
+
raise ValueError(f"{name} must be non-negative.")
|
|
51
|
+
|
|
52
|
+
return array
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def validate_non_zero(
|
|
56
|
+
value: ArrayLike,
|
|
57
|
+
name: str,
|
|
58
|
+
) -> np.ndarray:
|
|
59
|
+
"""Validate non-zero numerical inputs."""
|
|
60
|
+
|
|
61
|
+
array = as_float_array(value, name)
|
|
62
|
+
|
|
63
|
+
if np.any(array == 0):
|
|
64
|
+
raise ValueError(f"{name} must be non-zero.")
|
|
65
|
+
|
|
66
|
+
return array
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def format_output(
|
|
70
|
+
result: ArrayLike,
|
|
71
|
+
) -> float | np.ndarray:
|
|
72
|
+
"""Return a Python float for scalar results."""
|
|
73
|
+
|
|
74
|
+
result = np.asarray(result, dtype=float)
|
|
75
|
+
|
|
76
|
+
if result.ndim == 0:
|
|
77
|
+
return float(result)
|
|
78
|
+
|
|
79
|
+
return result
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Bernoulli equation and mechanical energy conservation.
|
|
3
|
+
|
|
4
|
+
Assumptions:
|
|
5
|
+
- Steady flow
|
|
6
|
+
- Incompressible fluid
|
|
7
|
+
- Constant density
|
|
8
|
+
- No dissipative energy losses
|
|
9
|
+
- No external shaft work
|
|
10
|
+
|
|
11
|
+
All dimensional quantities use SI units.
|
|
12
|
+
Elevation is positive upwards.
|
|
13
|
+
Pressure values must use a consistent reference.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
import numpy as np
|
|
17
|
+
from numpy.typing import ArrayLike
|
|
18
|
+
|
|
19
|
+
from ._validation import (
|
|
20
|
+
as_float_array,
|
|
21
|
+
format_output,
|
|
22
|
+
validate_non_negative,
|
|
23
|
+
validate_positive,
|
|
24
|
+
)
|
|
25
|
+
from .constants import (
|
|
26
|
+
ENGINEERING_GRAVITY,
|
|
27
|
+
WATER_DENSITY,
|
|
28
|
+
)
|
|
29
|
+
from .hydrostatics import pressure_head
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def velocity_head(
|
|
33
|
+
velocity: ArrayLike,
|
|
34
|
+
gravity: ArrayLike = ENGINEERING_GRAVITY,
|
|
35
|
+
) -> float | np.ndarray:
|
|
36
|
+
"""
|
|
37
|
+
Calculate kinetic energy head in metres.
|
|
38
|
+
|
|
39
|
+
H_v = U² / (2g)
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
velocity = as_float_array(velocity, "Velocity")
|
|
43
|
+
gravity = validate_positive(gravity, "Gravity")
|
|
44
|
+
|
|
45
|
+
return format_output(velocity**2 / (2 * gravity))
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def piezometric_head(
|
|
49
|
+
pressure: ArrayLike,
|
|
50
|
+
elevation: ArrayLike = 0.0,
|
|
51
|
+
density: ArrayLike = WATER_DENSITY,
|
|
52
|
+
gravity: ArrayLike = ENGINEERING_GRAVITY,
|
|
53
|
+
) -> float | np.ndarray:
|
|
54
|
+
"""
|
|
55
|
+
Calculate piezometric head in metres.
|
|
56
|
+
|
|
57
|
+
H_p = p / (rho * g) + z
|
|
58
|
+
"""
|
|
59
|
+
|
|
60
|
+
elevation = as_float_array(elevation, "Elevation")
|
|
61
|
+
|
|
62
|
+
head = pressure_head(pressure, density, gravity)
|
|
63
|
+
|
|
64
|
+
return format_output(head + elevation)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def total_energy_head(
|
|
68
|
+
pressure: ArrayLike,
|
|
69
|
+
velocity: ArrayLike,
|
|
70
|
+
elevation: ArrayLike = 0.0,
|
|
71
|
+
density: ArrayLike = WATER_DENSITY,
|
|
72
|
+
gravity: ArrayLike = ENGINEERING_GRAVITY,
|
|
73
|
+
) -> float | np.ndarray:
|
|
74
|
+
"""
|
|
75
|
+
Calculate total mechanical energy head in metres.
|
|
76
|
+
|
|
77
|
+
H = p / (rho * g) + U² / (2g) + z
|
|
78
|
+
"""
|
|
79
|
+
|
|
80
|
+
hydraulic_head = piezometric_head(
|
|
81
|
+
pressure,
|
|
82
|
+
elevation,
|
|
83
|
+
density,
|
|
84
|
+
gravity,
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
kinetic_head = velocity_head(velocity, gravity)
|
|
88
|
+
|
|
89
|
+
return format_output(hydraulic_head + kinetic_head)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def dynamic_pressure(
|
|
93
|
+
velocity: ArrayLike,
|
|
94
|
+
density: ArrayLike = WATER_DENSITY,
|
|
95
|
+
) -> float | np.ndarray:
|
|
96
|
+
"""
|
|
97
|
+
Calculate dynamic pressure in Pa.
|
|
98
|
+
|
|
99
|
+
q = 0.5 * rho * U²
|
|
100
|
+
"""
|
|
101
|
+
|
|
102
|
+
velocity = as_float_array(velocity, "Velocity")
|
|
103
|
+
|
|
104
|
+
density = validate_positive(density, "Density")
|
|
105
|
+
|
|
106
|
+
return format_output(0.5 * density * velocity**2)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def stagnation_pressure(
|
|
110
|
+
pressure: ArrayLike,
|
|
111
|
+
velocity: ArrayLike,
|
|
112
|
+
density: ArrayLike = WATER_DENSITY,
|
|
113
|
+
) -> float | np.ndarray:
|
|
114
|
+
"""
|
|
115
|
+
Calculate ideal incompressible stagnation pressure.
|
|
116
|
+
|
|
117
|
+
p0 = p + 0.5 * rho * U²
|
|
118
|
+
|
|
119
|
+
Assumes no elevation change or energy loss.
|
|
120
|
+
Returns pressure in Pa.
|
|
121
|
+
"""
|
|
122
|
+
|
|
123
|
+
pressure = as_float_array(pressure, "Pressure")
|
|
124
|
+
|
|
125
|
+
q = dynamic_pressure(velocity, density)
|
|
126
|
+
|
|
127
|
+
return format_output(pressure + q)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def bernoulli_pressure(
|
|
131
|
+
pressure_1: ArrayLike,
|
|
132
|
+
velocity_1: ArrayLike,
|
|
133
|
+
velocity_2: ArrayLike,
|
|
134
|
+
elevation_1: ArrayLike = 0.0,
|
|
135
|
+
elevation_2: ArrayLike = 0.0,
|
|
136
|
+
density: ArrayLike = WATER_DENSITY,
|
|
137
|
+
gravity: ArrayLike = ENGINEERING_GRAVITY,
|
|
138
|
+
) -> float | np.ndarray:
|
|
139
|
+
"""
|
|
140
|
+
Solve Bernoulli's equation for pressure at point 2.
|
|
141
|
+
|
|
142
|
+
p2 = p1 + rho/2 * (U1² - U2²)
|
|
143
|
+
+ rho*g*(z1 - z2)
|
|
144
|
+
|
|
145
|
+
Returns pressure in Pa using the same
|
|
146
|
+
pressure reference as pressure_1.
|
|
147
|
+
"""
|
|
148
|
+
|
|
149
|
+
p1 = as_float_array(pressure_1, "Pressure 1")
|
|
150
|
+
|
|
151
|
+
u1 = as_float_array(velocity_1, "Velocity 1")
|
|
152
|
+
|
|
153
|
+
u2 = as_float_array(velocity_2, "Velocity 2")
|
|
154
|
+
|
|
155
|
+
z1 = as_float_array(elevation_1, "Elevation 1")
|
|
156
|
+
|
|
157
|
+
z2 = as_float_array(elevation_2, "Elevation 2")
|
|
158
|
+
|
|
159
|
+
rho = validate_positive(density, "Density")
|
|
160
|
+
|
|
161
|
+
g = validate_positive(gravity, "Gravity")
|
|
162
|
+
|
|
163
|
+
result = p1 + 0.5 * rho * (u1**2 - u2**2) + rho * g * (z1 - z2)
|
|
164
|
+
|
|
165
|
+
return format_output(result)
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def bernoulli_velocity(
|
|
169
|
+
pressure_1: ArrayLike,
|
|
170
|
+
pressure_2: ArrayLike,
|
|
171
|
+
velocity_1: ArrayLike = 0.0,
|
|
172
|
+
elevation_1: ArrayLike = 0.0,
|
|
173
|
+
elevation_2: ArrayLike = 0.0,
|
|
174
|
+
density: ArrayLike = WATER_DENSITY,
|
|
175
|
+
gravity: ArrayLike = ENGINEERING_GRAVITY,
|
|
176
|
+
) -> float | np.ndarray:
|
|
177
|
+
"""
|
|
178
|
+
Solve Bernoulli's equation for speed at point 2.
|
|
179
|
+
|
|
180
|
+
U2 = sqrt(
|
|
181
|
+
U1² + 2*(p1-p2)/rho + 2*g*(z1-z2)
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
Returns non-negative speed in m/s.
|
|
185
|
+
Raises ValueError for inconsistent energy conditions.
|
|
186
|
+
"""
|
|
187
|
+
|
|
188
|
+
p1 = as_float_array(pressure_1, "Pressure 1")
|
|
189
|
+
|
|
190
|
+
p2 = as_float_array(pressure_2, "Pressure 2")
|
|
191
|
+
|
|
192
|
+
u1 = as_float_array(velocity_1, "Velocity 1")
|
|
193
|
+
|
|
194
|
+
z1 = as_float_array(elevation_1, "Elevation 1")
|
|
195
|
+
|
|
196
|
+
z2 = as_float_array(elevation_2, "Elevation 2")
|
|
197
|
+
|
|
198
|
+
rho = validate_positive(density, "Density")
|
|
199
|
+
|
|
200
|
+
g = validate_positive(gravity, "Gravity")
|
|
201
|
+
|
|
202
|
+
kinetic = u1**2
|
|
203
|
+
|
|
204
|
+
pressure_term = 2 * (p1 - p2) / rho
|
|
205
|
+
|
|
206
|
+
elevation_term = 2 * g * (z1 - z2)
|
|
207
|
+
|
|
208
|
+
radicand = kinetic + pressure_term + elevation_term
|
|
209
|
+
|
|
210
|
+
# Allow tiny negative values caused by
|
|
211
|
+
# floating-point cancellation.
|
|
212
|
+
|
|
213
|
+
scale = np.abs(kinetic) + np.abs(pressure_term) + np.abs(elevation_term)
|
|
214
|
+
|
|
215
|
+
tolerance = 32 * np.finfo(float).eps * scale
|
|
216
|
+
|
|
217
|
+
if np.any(radicand < -tolerance):
|
|
218
|
+
raise ValueError("Bernoulli conditions produce a negative squared velocity.")
|
|
219
|
+
|
|
220
|
+
radicand = np.maximum(radicand, 0.0)
|
|
221
|
+
|
|
222
|
+
return format_output(np.sqrt(radicand))
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def torricelli_velocity(
|
|
226
|
+
head: ArrayLike,
|
|
227
|
+
gravity: ArrayLike = ENGINEERING_GRAVITY,
|
|
228
|
+
) -> float | np.ndarray:
|
|
229
|
+
"""
|
|
230
|
+
Calculate ideal reservoir efflux speed.
|
|
231
|
+
|
|
232
|
+
U = sqrt(2 * g * h)
|
|
233
|
+
|
|
234
|
+
Head in m.
|
|
235
|
+
Returns speed in m/s.
|
|
236
|
+
"""
|
|
237
|
+
|
|
238
|
+
head = validate_non_negative(head, "Head")
|
|
239
|
+
|
|
240
|
+
gravity = validate_positive(gravity, "Gravity")
|
|
241
|
+
|
|
242
|
+
return format_output(np.sqrt(2 * gravity * head))
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
def ideal_discharge(
|
|
246
|
+
area: ArrayLike,
|
|
247
|
+
head: ArrayLike,
|
|
248
|
+
gravity: ArrayLike = ENGINEERING_GRAVITY,
|
|
249
|
+
) -> float | np.ndarray:
|
|
250
|
+
"""
|
|
251
|
+
Calculate theoretical reservoir discharge.
|
|
252
|
+
|
|
253
|
+
Q = A * sqrt(2 * g * h)
|
|
254
|
+
|
|
255
|
+
Area in m².
|
|
256
|
+
Head in m.
|
|
257
|
+
Returns discharge in m³/s.
|
|
258
|
+
"""
|
|
259
|
+
|
|
260
|
+
area = validate_positive(area, "Area")
|
|
261
|
+
|
|
262
|
+
velocity = torricelli_velocity(head, gravity)
|
|
263
|
+
|
|
264
|
+
return format_output(area * velocity)
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
def bernoulli_residual(
|
|
268
|
+
pressure_1: ArrayLike,
|
|
269
|
+
velocity_1: ArrayLike,
|
|
270
|
+
pressure_2: ArrayLike,
|
|
271
|
+
velocity_2: ArrayLike,
|
|
272
|
+
elevation_1: ArrayLike = 0.0,
|
|
273
|
+
elevation_2: ArrayLike = 0.0,
|
|
274
|
+
density: ArrayLike = WATER_DENSITY,
|
|
275
|
+
gravity: ArrayLike = ENGINEERING_GRAVITY,
|
|
276
|
+
) -> float | np.ndarray:
|
|
277
|
+
"""
|
|
278
|
+
Calculate the signed Bernoulli energy residual.
|
|
279
|
+
|
|
280
|
+
R = H1 - H2
|
|
281
|
+
|
|
282
|
+
Returns residual in metres of fluid head.
|
|
283
|
+
Ideal energy conservation gives R = 0.
|
|
284
|
+
"""
|
|
285
|
+
|
|
286
|
+
head_1 = total_energy_head(
|
|
287
|
+
pressure_1,
|
|
288
|
+
velocity_1,
|
|
289
|
+
elevation_1,
|
|
290
|
+
density,
|
|
291
|
+
gravity,
|
|
292
|
+
)
|
|
293
|
+
|
|
294
|
+
head_2 = total_energy_head(
|
|
295
|
+
pressure_2,
|
|
296
|
+
velocity_2,
|
|
297
|
+
elevation_2,
|
|
298
|
+
density,
|
|
299
|
+
gravity,
|
|
300
|
+
)
|
|
301
|
+
|
|
302
|
+
return format_output(head_1 - head_2)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Boundary layer calculations for Fluidmec.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from numpy.typing import ArrayLike
|
|
6
|
+
|
|
7
|
+
from ._dependencies import np
|
|
8
|
+
from ._validation import (
|
|
9
|
+
format_output,
|
|
10
|
+
validate_positive,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def stokes_boundary_layer_thickness(
|
|
15
|
+
kinematic_viscosity: ArrayLike,
|
|
16
|
+
period: ArrayLike,
|
|
17
|
+
) -> float | np.ndarray:
|
|
18
|
+
"""
|
|
19
|
+
Calculate Stokes boundary layer thickness.
|
|
20
|
+
|
|
21
|
+
delta = sqrt(nu * T / pi)
|
|
22
|
+
|
|
23
|
+
Parameters
|
|
24
|
+
----------
|
|
25
|
+
kinematic_viscosity : ArrayLike
|
|
26
|
+
Kinematic viscosity in m²/s.
|
|
27
|
+
period : ArrayLike
|
|
28
|
+
Oscillation period in seconds.
|
|
29
|
+
|
|
30
|
+
Returns
|
|
31
|
+
-------
|
|
32
|
+
float or numpy.ndarray
|
|
33
|
+
Boundary layer thickness in metres.
|
|
34
|
+
|
|
35
|
+
Notes
|
|
36
|
+
-----
|
|
37
|
+
Assumes the classical laminar sinusoidal
|
|
38
|
+
oscillatory boundary layer over a flat wall.
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
nu = validate_positive(
|
|
42
|
+
kinematic_viscosity,
|
|
43
|
+
"Kinematic viscosity",
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
period = validate_positive(period, "Period")
|
|
47
|
+
|
|
48
|
+
return format_output(np.sqrt(nu * period / np.pi))
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Physical constants and reference fluid properties.
|
|
3
|
+
|
|
4
|
+
All dimensional values use SI units.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from typing import Final
|
|
8
|
+
|
|
9
|
+
# Physical constants
|
|
10
|
+
|
|
11
|
+
STANDARD_GRAVITY: Final[float] = 9.80665
|
|
12
|
+
ENGINEERING_GRAVITY: Final[float] = 9.81
|
|
13
|
+
|
|
14
|
+
ATMOSPHERIC_PRESSURE: Final[float] = 101325.0
|
|
15
|
+
|
|
16
|
+
UNIVERSAL_GAS_CONSTANT: Final[float] = 8.314462618
|
|
17
|
+
AIR_GAS_CONSTANT: Final[float] = 287.05
|
|
18
|
+
|
|
19
|
+
CELSIUS_TO_KELVIN: Final[float] = 273.15
|
|
20
|
+
|
|
21
|
+
# Approximate freshwater properties at 20°C
|
|
22
|
+
|
|
23
|
+
WATER_DENSITY: Final[float] = 998.2
|
|
24
|
+
WATER_DYNAMIC_VISCOSITY: Final[float] = 1.002e-3
|
|
25
|
+
|
|
26
|
+
WATER_KINEMATIC_VISCOSITY: Final[float] = WATER_DYNAMIC_VISCOSITY / WATER_DENSITY
|
|
27
|
+
|
|
28
|
+
WATER_SURFACE_TENSION: Final[float] = 0.0728
|
|
29
|
+
|
|
30
|
+
# Representative seawater properties
|
|
31
|
+
|
|
32
|
+
SEAWATER_DENSITY: Final[float] = 1025.0
|
|
33
|
+
|
|
34
|
+
# Approximate dry air properties at 20°C and 1 atm
|
|
35
|
+
|
|
36
|
+
AIR_DENSITY: Final[float] = 1.204
|
|
37
|
+
AIR_DYNAMIC_VISCOSITY: Final[float] = 1.81e-5
|
|
38
|
+
|
|
39
|
+
AIR_KINEMATIC_VISCOSITY: Final[float] = AIR_DYNAMIC_VISCOSITY / AIR_DENSITY
|