The util submodule
Hydraulic utility functions and conversion helpers.
This module contains standalone helpers used across fluidsolve for common engineering calculations and unit-safe conversions. It is not centered on a single class; instead, it provides reusable computational primitives.
Main responsibilities:
pressure/head/velocity/flow conversion utilities,
helper formulas for hydraulic loss calculations,
convenience wrappers around selected
fluidscorrelations,small numerical helper routines shared by components and tools.
Design intent:
keep frequently reused equations in one importable location,
avoid duplicating conversion logic in component classes,
preserve unit consistency by using the shared quantity system.
Typical usage:
H = PtoH(2.0 * u.bar, 998 * u.kg / u.m**3)
P = Htop(10 * u.m, 998 * u.kg / u.m**3)
out = calcOrifice(Q=2.5 * u.m**3 / u.h, d=50 * u.mm, orifice=20 * u.mm)
These helpers are intended as low-level building blocks used by higher-level objects such as components, paths, and network solvers.
- fluidsolve.util.calcOrifice(**kwargs: Any) Any[source]
- This function calculates either the flow rate, the upstream pressure,
the second pressure or the orifice diameter for an orifice.
For details see https://fluids.readthedocs.io/fluids.flow_meter.html
- Parameters:
medium (Medium, optional) – The medium to be used. Defaults to water
Q (int | float | Quantity, optional) – The flow rate. If not provided, this is the variable to be calculated.
d (int | float | Quantity, optional) – The pipe diameter (in mm) If not provided, this is the variable to be calculated.
orifice (int | float | Quantity | str, optional) – The orifice diameter size (in mm). If not provided, this is the variable to be calculated.
Pin (int | float | Quantity, optional) – The pressure before the orifice (in bar). If not provided, this is the variable to be calculated.
Pout (int | float | Quantity, optional) – The pressure after the orifice (in bar). If not provided, this is the variable to be calculated.
meter (str, optional) – Fluids orifice meter type.
orifice – Orifice diameter (in mm) or, when used as the orifice_taps slot, the tap position string (e.g.
'corner').
- fluidsolve.util.calcOrifice2(circuit: ~typing.Any, Q: ~typing.Any, d: ~typing.Any, Puit: ~typing.Any = <Quantity(1, 'bar')>, meter_type: ~typing.Any = 'ISO 5167 orifice', orifice_taps: ~typing.Any = 'corner') Any[source]
Solve for the orifice beta ratio that matches a given flow rate and circuit head.
- Parameters:
circuit – Circuit object providing fluid properties and head curve.
Q (Quantity) – Flow rate.
d (Quantity) – Pipe diameter.
Puit (Quantity, optional) – Downstream pressure.
meter_type (str, optional) – Fluids orifice meter type.
orifice_taps (str, optional) – Fluids orifice taps.
- Returns:
Orifice diameter.
- Return type:
Quantity
- fluidsolve.util.KtoFd(K: int | float, L: int | float | Quantity, D: int | float | Quantity) float[source]
Calculate friction factor Fd from loss coefficient K
- Parameters:
K (int | float) – loss coefficient
L (int | float | Quantity) – Length (default in m)
D (int | float | Quantity) – (Hydraulic) Diameter (default in mm)
- Returns:
friction factor
- Return type:
float
- fluidsolve.util.FdtoK(Fd: int | float, L: int | float | Quantity, D: int | float | Quantity) float[source]
Calculate loss coefficient K from friction factor Fd
- Parameters:
Fd (int | float) – friction factor
L (int | float | Quantity) – Length (default in m)
D (int | float | Quantity) – (Hydraulic) Diameter (default in mm)
- Returns:
loss coefficient
- Return type:
float
- fluidsolve.util.KvtoK(Kv: int | float | Quantity, D: int | float | Quantity) float[source]
Calculate loss coefficient K from valve flow coefficient Kv
- Parameters:
Kv (int | float| Quantity) – valve flow coefficient (default in m3/h)
D (int | float | Quantity) – (Hydraulic) Diameter (default in mm)
- Returns:
loss coefficient
- Return type:
float
- fluidsolve.util.KtoKv(K: int | float, D: int | float | Quantity) Quantity[source]
Calculate valve flow coefficient Kv from loss coefficient K
- Parameters:
K (int | float) – loss coefficient
D (int | float | Quantity) – (Hydraulic) Diameter (default in mm)
- Returns:
valve flow coefficient (in m3/h)
- Return type:
Quantity
- fluidsolve.util.CvtoK(Cv: int | float | Quantity, D: int | float | Quantity) float[source]
Calculate loss coefficient K from imperial valve flow coefficient Cv
- Parameters:
Cv (int | float| Quantity) – imperial valve flow coefficient (default in gallons/min)
D (int | float | Quantity) – (Hydraulic) Diameter (default in mm)
- Returns:
loss coefficient
- Return type:
float
- fluidsolve.util.KtoCv(K: int | float, D: int | float | Quantity) Quantity[source]
Calculate imperial valve flow coefficient Kv from loss coefficient K
- Parameters:
K (int | float) – loss coefficient
D (int | float | Quantity) – (Hydraulic) Diameter (default in mm)
- Returns:
valve flow coefficient (in gallons/min)
- Return type:
Quantity
- fluidsolve.util.CvtoKv(Cv: int | float | Quantity) float[source]
Calculate valve flow coefficient Kv from imperial valve flow coefficient Cv
- Parameters:
Cv (int | float| Quantity) – imperial valve flow coefficient (default in gallons/min)
- Returns:
valve flow coefficient (in m3/h)
- Return type:
Quantity
- fluidsolve.util.KvtoCv(Kv: int | float | Quantity) float[source]
Calculate imperial valve flow coefficient Cv from valve flow coefficient Kv
- Parameters:
Kv (int | float | Quantity) – valve flow coefficient (default in m3/h)
- Returns:
imperial valve flow coefficient (in gallons/min)
- Return type:
Quantity
- fluidsolve.util.KtoH(K: int | float, v: int | float | Quantity) Quantity[source]
Calculate hydraulic height from loss coefficient K
- Parameters:
K (int | float) – loss coefficient
v (int | float | Quantity) – fluid velocity (default in m/s)
- Returns:
hydraulic heigh (in m)
- Return type:
Quantity
- fluidsolve.util.Ktop(K: int | float, v: int | float | Quantity, rho: int | float | Quantity) Quantity[source]
Calculate hydraulic pressure from loss coefficient K
- Parameters:
K (int | float) – loss coefficient
v (int | float | Quantity) – fluid velocity (default in m/s)
rho (int | float | Quantity) – density (default in kg/m3)
- Returns:
hydraulic pressure (in bar)
- Return type:
Quantity
- fluidsolve.util.Htop(H: int | float | Quantity, rho: int | float | Quantity) Quantity[source]
Calculate hydraulic pressure from hydraulic height
- Parameters:
H (int | float | Quantity) – hydraulic height (default in m)
rho (int | float | Quantity) – density (default in kg/m3)
- Returns:
hydraulic pressure (in bar)
- Return type:
Quantity
- fluidsolve.util.ptoH(p: int | float | Quantity, rho: int | float | Quantity) Quantity[source]
Calculate hydraulic height from hydraulic pressure
- Parameters:
p (int | float | Quantity) – hydraulic pressure (default in bar)
rho (int | float | Quantity) – density (default in kg/m3)
- Returns:
hydraulic height (in m)
- Return type:
Quantity
- fluidsolve.util.Qtov(Q: int | float | Quantity, D: int | float | Quantity) Quantity[source]
Calculate velocity (in m/s) from flow rate depending on diameter.
- Parameters:
Q (int | float | Quantity) – Flow to convert (default in m3/h).
D (int | float | Quantity) – diameter (default in mm).
- Returns:
Corresponding velocity (in m/s).
- Return type:
Quantity
- fluidsolve.util.vtoQ(v: int | float | Quantity, D: int | float | Quantity) Quantity[source]
Calculate flow rate (in m/s) from velocity depending on diameter.
- Parameters:
v (int | float | Quantity) – Velocity to convert (default in m/s).
D (int | float | Quantity) – diameter (default in mm).
- Returns:
Corresponding flow rate (in m3/h).
- Return type:
Quantity
- fluidsolve.util.calcCurve(xb: Any, xe: Any, xn: Any, yfun: Any, yb: Any, ye: Any) Any[source]
Sample a function over a range and return clipped x/y arrays.
- Parameters:
xb (float) – Start of x range.
xe (float) – End of x range.
xn (int) – Number of sample points.
yfun (Callable) – Function mapping x values to y values.
yb (float) – Lower y clip bound.
ye (float) – Upper y clip bound.
- Returns:
Clipped x and y arrays.
- Return type:
tuple[np.ndarray, np.ndarray]