TRANS_FACTOR
Overview
The TRANS_FACTOR function converts between the Darcy friction factor and the transmission factor, two dimensionless quantities used in compressible gas pipeline flow calculations. This bidirectional conversion is essential for engineers working with natural gas transmission systems, where the transmission factor is the preferred parameter in pipeline flow equations.
The transmission factor (F) is a dimensionless parameter that characterizes the flow efficiency of a gas pipeline. It is inversely related to the Darcy friction factor (f_d), which quantifies frictional resistance in pipe flow. The relationship between these parameters is defined by:
F = \frac{2}{\sqrt{f_d}}
Conversely, the Darcy friction factor can be calculated from the transmission factor as:
f_d = \frac{4}{F^2}
Higher transmission factors indicate lower frictional resistance and more efficient gas flow, which is why this parameter is commonly used in gas pipeline design and operations. Transmission factors typically range from 10 to 25 for commercial pipelines, with higher values indicating smoother pipe surfaces.
This implementation uses the fluids library, an open-source Python package for fluid dynamics calculations. The function accepts either the Darcy friction factor (fd) or the transmission factor (F) as input and returns the corresponding converted value. For more details, see the fluids.friction documentation.
The transmission factor concept is discussed extensively in gas pipeline hydraulics literature, including Menon’s Gas Pipeline Hydraulics (CRC Press, 2005), which serves as a primary reference for these equations.
This example function is provided as-is without any representation of accuracy.
Excel Usage
=TRANS_FACTOR(fd, F)
fd(float, optional, default: null): Darcy friction factor, [-]F(float, optional, default: null): Transmission factor, [-]
Returns (float): Transmission factor (if fd given) or Darcy friction factor (if F given), [-] or str error message if input is invalid.
Examples
Example 1: Convert typical Darcy friction factor to transmission factor
Inputs:
| fd |
|---|
| 0.0185 |
Excel formula:
=TRANS_FACTOR(0.0185)
Expected output:
14.7043
Example 2: Convert typical transmission factor to Darcy friction factor
Inputs:
| F |
|---|
| 20 |
Excel formula:
=TRANS_FACTOR(20)
Expected output:
0.01
Example 3: Convert high friction factor to transmission factor
Inputs:
| fd |
|---|
| 0.04 |
Excel formula:
=TRANS_FACTOR(0.04)
Expected output:
10
Example 4: Convert low transmission factor to Darcy friction factor
Inputs:
| F |
|---|
| 10 |
Excel formula:
=TRANS_FACTOR(10)
Expected output:
0.04
Python Code
import micropip
await micropip.install(["fluids"])
from fluids.friction import transmission_factor as fluids_transmission_factor
def trans_factor(fd=None, F=None):
"""
Convert between Darcy friction factor and transmission factor for compressible gas pipeline flow.
See: https://fluids.readthedocs.io/fluids.friction.html#fluids.friction.transmission_factor
This example function is provided as-is without any representation of accuracy.
Args:
fd (float, optional): Darcy friction factor, [-] Default is None.
F (float, optional): Transmission factor, [-] Default is None.
Returns:
float: Transmission factor (if fd given) or Darcy friction factor (if F given), [-] or str error message if input is invalid.
"""
# Check if both parameters are provided
if fd is not None and F is not None:
return "Error: Provide only one of fd or F, not both."
# Check if neither parameter is provided
if fd is None and F is None:
return "Error: Provide either fd or F."
# Validate and convert fd if provided
if fd is not None:
try:
fd = float(fd)
except (ValueError, TypeError):
return "Error: fd must be a number."
if fd <= 0:
return "Error: fd must be positive."
# Validate and convert F if provided
if F is not None:
try:
F = float(F)
except (ValueError, TypeError):
return "Error: F must be a number."
if F <= 0:
return "Error: F must be positive."
try:
result = fluids_transmission_factor(fd=fd, F=F)
# Handle NaN and infinity
if result != result: # NaN check
return "nan"
if result == float('inf'):
return "inf"
if result == float('-inf'):
return "-inf"
return float(result)
except Exception as e:
return f"Error computing trans_factor: {str(e)}"