TubeBase IconTubeBase
Models the pressure drop in a fluid-carrying tube considering friction and optional inertia.
This component calculates the pressure drop ($\Delta p$) across a tube as a function of the mass flow rate (m_flow). The calculation includes frictional losses, represented by the sheer variable, based on the Darcy-Weisbach equation. The friction factor ($ff$) is determined from flow conditions, fluid properties (density $\rho$ and dynamic viscosity $\mu$), tube geometry (length length, cross-sectional area area, hydraulic diameter d_h), and a shape_factor. An additional head_factor can scale these frictional losses. Fluid density and viscosity are obtained from the medium properties at port_a. The hydraulic diameter is defined as:
\[d_h = \frac{4 \cdot \text{area}}{\text{perimeter}}\]
The fluid velocity is:
\[\text{velocity} = \frac{\text{m_flow}}{\rho \cdot \text{area}}\]
The pressure drop due to friction (sheer) is calculated as:
\[\text{sheer} = 0.5 \cdot \rho \cdot \text{velocity}^2 \cdot ff \cdot \text{head_factor} \cdot \frac{\text{length}}{d_h}\]
The total pressure drop ($\Delta p$) can optionally incorporate fluid inertia, adding a dynamic pressure component proportional to the rate of change of mass flow rate (der(m_flow)):
\[\Delta p = \text{sheer} + \begin{cases} \frac{\text{length}}{\text{area}} \frac{d(\text{m_flow})}{dt} & \text{if add_inertia is true} \\ 0 & \text{if add_inertia is false} \end{cases}\]
This component extends from TwoPorts
Usage
HydraulicComponents.TubeBase(area, length, perimeter, shape_factor, head_factor, add_inertia=false, d_h=4 * area / perimeter, m_flow0)
Parameters:
| Name | Description | Units | Default value |
|---|---|---|---|
area | Cross-sectional area of the tube | m2 | |
length | Length of the tube | m | |
perimeter | Wetted perimeter of the tube's cross-section | m | |
shape_factor | Factor accounting for non-circular cross-section in friction calculation | – | |
head_factor | Multiplier for head losses (e.g., minor losses, bends) | – | |
add_inertia | Flag to include (if true) or exclude (if false) fluid inertial effects | – | false |
m_flow0 | Initial guess or value for the mass flow rate | kg/s |
Connectors
Variables
| Name | Description | Units |
|---|---|---|
Δp | Pressure difference across the component, defined as porta.p - portb.p | Pa |
m_flow | Overall mass flow rate through the component | kg/s |
rho | Density of the fluid | kg/m3 |
mu | Dynamic viscosity of the fluid | Pa.s |
velocity | Average velocity of the fluid in the tube | m/s |
sheer | Pressure drop component due to frictional shear | Pa |
ff | Darcy friction factor | – |
Behavior
Behavior of this component cannot be rendered because it includes path variables.
Source
"""
Models the pressure drop in a fluid-carrying tube considering friction and optional inertia.
This component calculates the pressure drop ($\Delta p$) across a tube as a function of the mass flow rate (`m_flow`).
The calculation includes frictional losses, represented by the `sheer` variable, based on the Darcy-Weisbach equation.
The friction factor ($ff$) is determined from flow conditions, fluid properties (density $\rho$ and dynamic viscosity $\mu$),
tube geometry (length `length`, cross-sectional area `area`, hydraulic diameter `d_h`), and a `shape_factor`.
An additional `head_factor` can scale these frictional losses. Fluid density and viscosity are obtained from the medium properties at `port_a`.
The hydraulic diameter is defined as:math d_h = \frac{4 \cdot \text{area}}{\text{perimeter}}
The fluid velocity is:
math \text{velocity} = \frac{\text{m_flow}}{\rho \cdot \text{area}}
The pressure drop due to friction (`sheer`) is calculated as:
math \text{sheer} = 0.5 \cdot \rho \cdot \text{velocity}^2 \cdot ff \cdot \text{headfactor} \cdot \frac{\text{length}}{dh}
The total pressure drop ($\Delta p$) can optionally incorporate fluid inertia, adding a dynamic pressure component
proportional to the rate of change of mass flow rate (`der(m_flow)`):
math \Delta p = \text{sheer} + \begin{cases} \frac{\text{length}}{\text{area}} \frac{d(\text{mflow})}{dt} & \text{if addinertia is true} \ 0 & \text{if add_inertia is false} \end{cases}
"""</span>
<span class="hljs-keyword">component</span> TubeBase
<span class="hljs-keyword">extends</span> <span class="hljs-link"><a href="https://help.juliahub.com/dyad/dev/stdlib/HydraulicComponents/types/TwoPorts.html">TwoPorts</a></span>
<span class="hljs-comment">"Cross-sectional area of the tube"</span>
<span class="hljs-keyword">parameter</span> <span class="hljs-symbol">area</span>::<span class="hljs-link"><a href="https://help.juliahub.com/dyad/dev/stdlib/Dyad/types/Area.html">Area</a></span>
<span class="hljs-comment">"Length of the tube"</span>
<span class="hljs-keyword">parameter</span> <span class="hljs-symbol">length</span>::<span class="hljs-link"><a href="https://help.juliahub.com/dyad/dev/stdlib/Dyad/types/Length.html">Length</a></span>
<span class="hljs-comment">"Wetted perimeter of the tube's cross-section"</span>
<span class="hljs-keyword">parameter</span> <span class="hljs-symbol">perimeter</span>::<span class="hljs-link"><a href="https://help.juliahub.com/dyad/dev/stdlib/Dyad/types/Length.html">Length</a></span>
<span class="hljs-comment">"Factor accounting for non-circular cross-section in friction calculation"</span>
<span class="hljs-keyword">parameter</span> <span class="hljs-symbol">shape_factor</span>::<span>Real</span>
<span class="hljs-comment">"Multiplier for head losses (e.g., minor losses, bends)"</span>
<span class="hljs-keyword">parameter</span> <span class="hljs-symbol">head_factor</span>::<span>Real</span>
<span class="hljs-comment">"Flag to include (if true) or exclude (if false) fluid inertial effects"</span>
<span class="hljs-keyword">parameter</span> <span class="hljs-symbol">add_inertia</span>::<span>Boolean</span> = false
<span class="hljs-comment">"Calculated hydraulic diameter of the tube"</span>
<span class="hljs-keyword">final</span> <span class="hljs-keyword">parameter</span> <span class="hljs-symbol">d_h</span>::<span class="hljs-link"><a href="https://help.juliahub.com/dyad/dev/stdlib/Dyad/types/Length.html">Length</a></span> = 4 * area / perimeter
<span class="hljs-comment">"Density of the fluid"</span>
<span class="hljs-keyword">variable</span> <span class="hljs-symbol">rho</span>::<span class="hljs-link"><a href="https://help.juliahub.com/dyad/dev/stdlib/Dyad/types/Density.html">Density</a></span>
<span class="hljs-comment">"Dynamic viscosity of the fluid"</span>
<span class="hljs-keyword">variable</span> <span class="hljs-symbol">mu</span>::<span class="hljs-link"><a href="https://help.juliahub.com/dyad/dev/stdlib/Dyad/types/DynamicViscosity.html">DynamicViscosity</a></span>
<span class="hljs-comment">"Average velocity of the fluid in the tube"</span>
<span class="hljs-keyword">variable</span> <span class="hljs-symbol">velocity</span>::<span class="hljs-link"><a href="https://help.juliahub.com/dyad/dev/stdlib/Dyad/types/Velocity.html">Velocity</a></span>
<span class="hljs-comment">"Pressure drop component due to frictional shear"</span>
<span class="hljs-keyword">variable</span> <span class="hljs-symbol">sheer</span>::<span class="hljs-link"><a href="https://help.juliahub.com/dyad/dev/stdlib/Dyad/types/Pressure.html">Pressure</a></span>
<span class="hljs-comment">"Darcy friction factor"</span>
<span class="hljs-keyword">variable</span> <span class="hljs-symbol">ff</span>::<span>Real</span>
<span class="hljs-comment">"Initial guess or value for the mass flow rate"</span>
<span class="hljs-keyword">parameter</span> <span class="hljs-symbol">m_flow0</span>::<span class="hljs-link"><a href="https://help.juliahub.com/dyad/dev/stdlib/Dyad/types/MassFlowRate.html">MassFlowRate</a></span>
<span class="hljs-keyword">relations</span>
<span class="hljs-keyword">initial</span> m_flow = m_flow0
rho = density(port_a.medium, port_a.p)
mu = viscosity(port_a.medium)
velocity = m_flow / (rho * area)
ff = friction_factor(m_flow, area, d_h, mu, shape_factor)
sheer = 0.5 * rho * reg_pow(velocity, 2) * ff * head_factor * (length / d_h)
Δp = add_inertia ? sheer + (length / area) * der(m_flow) : sheer
m_flow = port_a.m_flow
<span class="hljs-keyword">metadata</span> {
"Dyad": {
"labels": [{"label": "$(instance)", "x": 500, "y": 1100, "rot": 0}],
"icons": {"default": "dyad://HydraulicComponents/TubeBase.svg"}
}
}
<span class="hljs-keyword">end</span></code></pre>
Flattened Source
"""
Models the pressure drop in a fluid-carrying tube considering friction and optional inertia.
This component calculates the pressure drop ($\Delta p$) across a tube as a function of the mass flow rate (`m_flow`).
The calculation includes frictional losses, represented by the `sheer` variable, based on the Darcy-Weisbach equation.
The friction factor ($ff$) is determined from flow conditions, fluid properties (density $\rho$ and dynamic viscosity $\mu$),
tube geometry (length `length`, cross-sectional area `area`, hydraulic diameter `d_h`), and a `shape_factor`.
An additional `head_factor` can scale these frictional losses. Fluid density and viscosity are obtained from the medium properties at `port_a`.
The hydraulic diameter is defined as:math d_h = \frac{4 \cdot \text{area}}{\text{perimeter}}
The fluid velocity is:
math \text{velocity} = \frac{\text{m_flow}}{\rho \cdot \text{area}}
The pressure drop due to friction (`sheer`) is calculated as:
math \text{sheer} = 0.5 \cdot \rho \cdot \text{velocity}^2 \cdot ff \cdot \text{headfactor} \cdot \frac{\text{length}}{dh}
The total pressure drop ($\Delta p$) can optionally incorporate fluid inertia, adding a dynamic pressure component
proportional to the rate of change of mass flow rate (`der(m_flow)`):
math \Delta p = \text{sheer} + \begin{cases} \frac{\text{length}}{\text{area}} \frac{d(\text{mflow})}{dt} & \text{if addinertia is true} \ 0 & \text{if add_inertia is false} \end{cases}
"""</span>
<span class="hljs-keyword">component</span> TubeBase
<span class="hljs-comment">"The first fluid port of the component"</span>
<span class="hljs-symbol">port_a</span> = <span>Port</span>() {
"Dyad": {
"placement": {
"diagram": {"x1": -20, "x2": 20, "y1": 480, "y2": 520, "sh": 1, "sw": 1, "rot": 0}
}
}
}
<span class="hljs-comment">"The second fluid port of the component"</span>
<span class="hljs-symbol">port_b</span> = <span>Port</span>() {
"Dyad": {
"placement": {
"diagram": {"x1": 980, "x2": 1020, "y1": 480, "y2": 520, "sh": 0.04, "sw": 0.04, "rot": 0}
}
}
}
<span class="hljs-comment">"Pressure difference across the component, defined as port_a.p - port_b.p"</span>
<span class="hljs-keyword">variable</span> <span class="hljs-symbol">Δp</span>::<span>AbsolutePressure</span>
<span class="hljs-comment">"Overall mass flow rate through the component"</span>
<span class="hljs-keyword">variable</span> <span class="hljs-symbol">m_flow</span>::<span>MassFlowRate</span>
<span class="hljs-comment">"Cross-sectional area of the tube"</span>
<span class="hljs-keyword">parameter</span> <span class="hljs-symbol">area</span>::<span>Area</span>
<span class="hljs-comment">"Length of the tube"</span>
<span class="hljs-keyword">parameter</span> <span class="hljs-symbol">length</span>::<span>Length</span>
<span class="hljs-comment">"Wetted perimeter of the tube's cross-section"</span>
<span class="hljs-keyword">parameter</span> <span class="hljs-symbol">perimeter</span>::<span>Length</span>
<span class="hljs-comment">"Factor accounting for non-circular cross-section in friction calculation"</span>
<span class="hljs-keyword">parameter</span> <span class="hljs-symbol">shape_factor</span>::<span>Real</span>
<span class="hljs-comment">"Multiplier for head losses (e.g., minor losses, bends)"</span>
<span class="hljs-keyword">parameter</span> <span class="hljs-symbol">head_factor</span>::<span>Real</span>
<span class="hljs-comment">"Flag to include (if true) or exclude (if false) fluid inertial effects"</span>
<span class="hljs-keyword">parameter</span> <span class="hljs-symbol">add_inertia</span>::<span>Boolean</span> = false
<span class="hljs-comment">"Calculated hydraulic diameter of the tube"</span>
<span class="hljs-keyword">final</span> <span class="hljs-keyword">parameter</span> <span class="hljs-symbol">d_h</span>::<span>Length</span> = 4 * area / perimeter
<span class="hljs-comment">"Density of the fluid"</span>
<span class="hljs-keyword">variable</span> <span class="hljs-symbol">rho</span>::<span>Density</span>
<span class="hljs-comment">"Dynamic viscosity of the fluid"</span>
<span class="hljs-keyword">variable</span> <span class="hljs-symbol">mu</span>::<span>DynamicViscosity</span>
<span class="hljs-comment">"Average velocity of the fluid in the tube"</span>
<span class="hljs-keyword">variable</span> <span class="hljs-symbol">velocity</span>::<span>Velocity</span>
<span class="hljs-comment">"Pressure drop component due to frictional shear"</span>
<span class="hljs-keyword">variable</span> <span class="hljs-symbol">sheer</span>::<span>Pressure</span>
<span class="hljs-comment">"Darcy friction factor"</span>
<span class="hljs-keyword">variable</span> <span class="hljs-symbol">ff</span>::<span>Real</span>
<span class="hljs-comment">"Initial guess or value for the mass flow rate"</span>
<span class="hljs-keyword">parameter</span> <span class="hljs-symbol">m_flow0</span>::<span>MassFlowRate</span>
<span class="hljs-keyword">relations</span>
<span class="hljs-built_in">continuity</span>(port_a.medium, port_b.medium)
port_a.m_flow + port_b.m_flow = 0
Δp = port_a.p - port_b.p
<span class="hljs-keyword">initial</span> m_flow = m_flow0
rho = density(port_a.medium, port_a.p)
mu = viscosity(port_a.medium)
velocity = m_flow / (rho * area)
ff = friction_factor(m_flow, area, d_h, mu, shape_factor)
sheer = 0.5 * rho * reg_pow(velocity, 2) * ff * head_factor * (length / d_h)
Δp = add_inertia ? sheer + (length / area) * der(m_flow) : sheer
m_flow = port_a.m_flow
<span class="hljs-keyword">metadata</span> {
"Dyad": {
"labels": [{"label": "$(instance)", "x": 500, "y": 1100, "rot": 0}],
"icons": {"default": "dyad://HydraulicComponents/TubeBase.svg"}
}
}
<span class="hljs-keyword">end</span></code></pre>
Test Cases
No test cases defined.
Related
- Examples
- Experiments
- Analyses
- Tests