SIZE_CONTROL_VALVE_G
Overview
The SIZE_CONTROL_VALVE_G function calculates the flow coefficient of a control valve passing a gas according to IEC 60534 using the fluids library. This function is used in engineering applications to properly size control valves for gas flow applications, ensuring the valve can handle the required flow rate while maintaining proper pressure drop characteristics.
The function accounts for gas properties such as compressibility, molecular weight, and specific heat capacity to determine the metric Kv valve flow coefficient. The Kv value represents the flow rate of water (in mÂł/hr) that will pass through the valve at a pressure drop of 1 bar.
For more details, see the fluids library size_control_valve_g documentation .
This function simplifies the interface by only supporting the required parameters (temperature, molecular weight, viscosity, specific heat capacity ratio, compressibility factor, inlet and outlet pressures, and flow rate). It does not expose optional parameters like pipe diameters (D1, D2, d), valve characteristics (FL, Fd, xT), or output options (allow_choked, allow_laminar, full_output). This example function is provided as-is without any representation of accuracy.
Usage
To use the function in Excel:
=SIZE_CONTROL_VALVE_G(t, mw, mu, gamma, z, p_in, p_out, q)t(float, required): Temperature of the gas at the inlet [K].mw(float, required): Molecular weight of the gas [g/mol].mu(float, required): Viscosity of the fluid at inlet conditions [Pa*s].gamma(float, required): Specific heat capacity ratio [-].z(float, required): Compressibility factor at inlet conditions [-].p_in(float, required): Inlet pressure of the gas before valves and reducers [Pa].p_out(float, required): Outlet pressure of the gas after valves and reducers [Pa].q(float, required): Volumetric flow rate of the gas at STP [m^3/s].
The function returns a float representing the Kv - Metric Kv valve flow coefficient [m^3/hr], or an error message (string) if the input is invalid.
Examples
Example 1: Basic Gas Valve Sizing
Inputs:
| t | mw | mu | gamma | z | p_in | p_out | q |
|---|---|---|---|---|---|---|---|
| 433.0 | 44.01 | 0.000147 | 1.3 | 0.988 | 680000.0 | 310000.0 | 1.056 |
Excel formula:
=SIZE_CONTROL_VALVE_G(433.0, 44.01, 0.000147, 1.3, 0.988, 680000.0, 310000.0, 1.056)Expected output: 58.600
Example 2: Small Flow Valve
Inputs:
| t | mw | mu | gamma | z | p_in | p_out | q |
|---|---|---|---|---|---|---|---|
| 320.0 | 39.95 | 5.625E-05 | 1.67 | 1.0 | 280000.0 | 130000.0 | 0.000128 |
Excel formula:
=SIZE_CONTROL_VALVE_G(320.0, 39.95, 5.625E-05, 1.67, 1.0, 280000.0, 130000.0, 0.000128)Expected output: 0.0131
Example 3: High Pressure Gas
Inputs:
| t | mw | mu | gamma | z | p_in | p_out | q |
|---|---|---|---|---|---|---|---|
| 300.0 | 28.97 | 1.8E-05 | 1.4 | 1.0 | 500000.0 | 200000.0 | 0.1 |
Excel formula:
=SIZE_CONTROL_VALVE_G(300.0, 28.97, 1.8E-05, 1.4, 1.0, 500000.0, 200000.0, 0.1)Expected output: 4.930
Example 4: Low Temperature Gas
Inputs:
| t | mw | mu | gamma | z | p_in | p_out | q |
|---|---|---|---|---|---|---|---|
| 250.0 | 16.04 | 1.0E-05 | 1.3 | 0.95 | 400000.0 | 300000.0 | 0.05 |
Excel formula:
=SIZE_CONTROL_VALVE_G(250.0, 16.04, 1.0E-05, 1.3, 0.95, 400000.0, 300000.0, 0.05)Expected output: 2.590
Python Code
import math
from typing import Union
from fluids.control_valve import size_control_valve_g as fluids_size_control_valve_g
def size_control_valve_g(t: float, mw: float, mu: float, gamma: float, z: float, p_in: float, p_out: float, q: float) -> Union[float, str]:
"""
Calculates flow coefficient of a control valve passing a gas according to IEC 60534 using fluids.control_valve.size_control_valve_g. See https://fluids.readthedocs.io/fluids.control_valve.html#fluids.control_valve.size_control_valve_g for details.
Args:
t: Temperature of the gas at the inlet [K]
mw: Molecular weight of the gas [g/mol]
mu: Viscosity of the fluid at inlet conditions [Pa*s]
gamma: Specific heat capacity ratio [-]
z: Compressibility factor at inlet conditions [-]
p_in: Inlet pressure of the gas before valves and reducers [Pa]
p_out: Outlet pressure of the gas after valves and reducers [Pa]
q: Volumetric flow rate of the gas at STP [m^3/s]
Returns:
float: Kv - Metric Kv valve flow coefficient [m^3/hr], or an error message (str) if input is invalid.
This example function is provided as-is without any representation of accuracy.
"""
def _error(message: str) -> str:
return message
# Validate input parameters
try:
t = float(t)
mw = float(mw)
mu = float(mu)
gamma = float(gamma)
z = float(z)
p_in = float(p_in)
p_out = float(p_out)
q = float(q)
except (TypeError, ValueError):
return _error("All parameters must be numeric values.")
# Check for non-finite values
if any(not math.isfinite(val) for val in [t, mw, mu, gamma, z, p_in, p_out, q]):
return _error("All parameters must be finite numbers.")
# Check for negative values where not allowed
if t <= 0:
return _error("Temperature (t) must be positive.")
if mw <= 0:
return _error("Molecular weight (mw) must be positive.")
if mu < 0:
return _error("Viscosity (mu) must be non-negative.")
if gamma <= 0:
return _error("Specific heat capacity ratio (gamma) must be positive.")
if z <= 0:
return _error("Compressibility factor (z) must be positive.")
if p_in <= 0:
return _error("Inlet pressure (p_in) must be positive.")
if p_out < 0:
return _error("Outlet pressure (p_out) must be non-negative.")
if q < 0:
return _error("Volumetric flow rate (q) must be non-negative.")
# Pressure should not be equal to avoid division by zero in some calculations
if p_in == p_out:
return _error("Inlet pressure (p_in) and outlet pressure (p_out) cannot be equal.")
try:
# Call the fluids library function
result = fluids_size_control_valve_g(T=t, MW=mw, mu=mu, gamma=gamma, Z=z, P1=p_in, P2=p_out, Q=q)
# Check if result is a valid float (not an error from the library)
if isinstance(result, dict):
# If full_output is used (which it shouldn't be), extract Kv
result = result.get('Kv')
if result is None or not isinstance(result, (int, float)):
return _error(f"Fluids library returned invalid result: {result}")
# Ensure the result is finite
if not math.isfinite(result):
return _error("Calculated flow coefficient is not finite.")
return float(result)
except Exception as e:
return _error(f"Error calculating control valve sizing: {str(e)}")