TubeBaseTubeBase Icon

TubeBase

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:

NameDescriptionUnitsDefault value
areaCross-sectional area of the tubem2
lengthLength of the tubem
perimeterWetted perimeter of the tube's cross-sectionm
shape_factorFactor accounting for non-circular cross-section in friction calculation
head_factorMultiplier for head losses (e.g., minor losses, bends)
add_inertiaFlag to include (if true) or exclude (if false) fluid inertial effectsfalse
m_flow0Initial guess or value for the mass flow ratekg/s

Connectors

Variables

NameDescriptionUnits
ΔpPressure difference across the component, defined as porta.p - portb.pPa
m_flowOverall mass flow rate through the componentkg/s
rhoDensity of the fluidkg/m3
muDynamic viscosity of the fluidPa.s
velocityAverage velocity of the fluid in the tubem/s
sheerPressure drop component due to frictional shearPa
ffDarcy 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
&nbsp;&nbsp;<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>
&nbsp;&nbsp;<span class="hljs-comment">"Cross-sectional area of the tube"</span>
&nbsp;&nbsp;<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>
&nbsp;&nbsp;<span class="hljs-comment">"Length of the tube"</span>
&nbsp;&nbsp;<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>
&nbsp;&nbsp;<span class="hljs-comment">"Wetted perimeter of the tube's cross-section"</span>
&nbsp;&nbsp;<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>
&nbsp;&nbsp;<span class="hljs-comment">"Factor accounting for non-circular cross-section in friction calculation"</span>
&nbsp;&nbsp;<span class="hljs-keyword">parameter</span> <span class="hljs-symbol">shape_factor</span>::<span>Real</span>
&nbsp;&nbsp;<span class="hljs-comment">"Multiplier for head losses (e.g., minor losses, bends)"</span>
&nbsp;&nbsp;<span class="hljs-keyword">parameter</span> <span class="hljs-symbol">head_factor</span>::<span>Real</span>
&nbsp;&nbsp;<span class="hljs-comment">"Flag to include (if true) or exclude (if false) fluid inertial effects"</span>
&nbsp;&nbsp;<span class="hljs-keyword">parameter</span> <span class="hljs-symbol">add_inertia</span>::<span>Boolean</span> = false
&nbsp;&nbsp;<span class="hljs-comment">"Calculated hydraulic diameter of the tube"</span>
&nbsp;&nbsp;<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
&nbsp;&nbsp;<span class="hljs-comment">"Density of the fluid"</span>
&nbsp;&nbsp;<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>
&nbsp;&nbsp;<span class="hljs-comment">"Dynamic viscosity of the fluid"</span>
&nbsp;&nbsp;<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>
&nbsp;&nbsp;<span class="hljs-comment">"Average velocity of the fluid in the tube"</span>
&nbsp;&nbsp;<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>
&nbsp;&nbsp;<span class="hljs-comment">"Pressure drop component due to frictional shear"</span>
&nbsp;&nbsp;<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>
&nbsp;&nbsp;<span class="hljs-comment">"Darcy friction factor"</span>
&nbsp;&nbsp;<span class="hljs-keyword">variable</span> <span class="hljs-symbol">ff</span>::<span>Real</span>
&nbsp;&nbsp;<span class="hljs-comment">"Initial guess or value for the mass flow rate"</span>
&nbsp;&nbsp;<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>
&nbsp;&nbsp;<span class="hljs-keyword">initial</span> m_flow = m_flow0
&nbsp;&nbsp;rho = density(port_a.medium, port_a.p)
&nbsp;&nbsp;mu = viscosity(port_a.medium)
&nbsp;&nbsp;velocity = m_flow / (rho * area)
&nbsp;&nbsp;ff = friction_factor(m_flow, area, d_h, mu, shape_factor)
&nbsp;&nbsp;sheer = 0.5 * rho * reg_pow(velocity, 2) * ff * head_factor * (length / d_h)
&nbsp;&nbsp;Δp = add_inertia ? sheer + (length / area) * der(m_flow) : sheer
&nbsp;&nbsp;m_flow = port_a.m_flow
<span class="hljs-keyword">metadata</span> {
&nbsp;&nbsp;"Dyad": {
&nbsp;&nbsp;&nbsp;&nbsp;"labels": [{"label": "$(instance)", "x": 500, "y": 1100, "rot": 0}],
&nbsp;&nbsp;&nbsp;&nbsp;"icons": {"default": "dyad://HydraulicComponents/TubeBase.svg"}
&nbsp;&nbsp;}
}
<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
&nbsp;&nbsp;<span class="hljs-comment">"The first fluid port of the component"</span>
&nbsp;&nbsp;<span class="hljs-symbol">port_a</span> = <span>Port</span>() {
&nbsp;&nbsp;&nbsp;&nbsp;"Dyad": {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"placement": {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"diagram": {"x1": -20, "x2": 20, "y1": 480, "y2": 520, "sh": 1, "sw": 1, "rot": 0}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;}
&nbsp;&nbsp;<span class="hljs-comment">"The second fluid port of the component"</span>
&nbsp;&nbsp;<span class="hljs-symbol">port_b</span> = <span>Port</span>() {
&nbsp;&nbsp;&nbsp;&nbsp;"Dyad": {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"placement": {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"diagram": {"x1": 980, "x2": 1020, "y1": 480, "y2": 520, "sh": 0.04, "sw": 0.04, "rot": 0}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;}
&nbsp;&nbsp;<span class="hljs-comment">"Pressure difference across the component, defined as port_a.p - port_b.p"</span>
&nbsp;&nbsp;<span class="hljs-keyword">variable</span> <span class="hljs-symbol">Δp</span>::<span>AbsolutePressure</span>
&nbsp;&nbsp;<span class="hljs-comment">"Overall mass flow rate through the component"</span>
&nbsp;&nbsp;<span class="hljs-keyword">variable</span> <span class="hljs-symbol">m_flow</span>::<span>MassFlowRate</span>
&nbsp;&nbsp;<span class="hljs-comment">"Cross-sectional area of the tube"</span>
&nbsp;&nbsp;<span class="hljs-keyword">parameter</span> <span class="hljs-symbol">area</span>::<span>Area</span>
&nbsp;&nbsp;<span class="hljs-comment">"Length of the tube"</span>
&nbsp;&nbsp;<span class="hljs-keyword">parameter</span> <span class="hljs-symbol">length</span>::<span>Length</span>
&nbsp;&nbsp;<span class="hljs-comment">"Wetted perimeter of the tube's cross-section"</span>
&nbsp;&nbsp;<span class="hljs-keyword">parameter</span> <span class="hljs-symbol">perimeter</span>::<span>Length</span>
&nbsp;&nbsp;<span class="hljs-comment">"Factor accounting for non-circular cross-section in friction calculation"</span>
&nbsp;&nbsp;<span class="hljs-keyword">parameter</span> <span class="hljs-symbol">shape_factor</span>::<span>Real</span>
&nbsp;&nbsp;<span class="hljs-comment">"Multiplier for head losses (e.g., minor losses, bends)"</span>
&nbsp;&nbsp;<span class="hljs-keyword">parameter</span> <span class="hljs-symbol">head_factor</span>::<span>Real</span>
&nbsp;&nbsp;<span class="hljs-comment">"Flag to include (if true) or exclude (if false) fluid inertial effects"</span>
&nbsp;&nbsp;<span class="hljs-keyword">parameter</span> <span class="hljs-symbol">add_inertia</span>::<span>Boolean</span> = false
&nbsp;&nbsp;<span class="hljs-comment">"Calculated hydraulic diameter of the tube"</span>
&nbsp;&nbsp;<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
&nbsp;&nbsp;<span class="hljs-comment">"Density of the fluid"</span>
&nbsp;&nbsp;<span class="hljs-keyword">variable</span> <span class="hljs-symbol">rho</span>::<span>Density</span>
&nbsp;&nbsp;<span class="hljs-comment">"Dynamic viscosity of the fluid"</span>
&nbsp;&nbsp;<span class="hljs-keyword">variable</span> <span class="hljs-symbol">mu</span>::<span>DynamicViscosity</span>
&nbsp;&nbsp;<span class="hljs-comment">"Average velocity of the fluid in the tube"</span>
&nbsp;&nbsp;<span class="hljs-keyword">variable</span> <span class="hljs-symbol">velocity</span>::<span>Velocity</span>
&nbsp;&nbsp;<span class="hljs-comment">"Pressure drop component due to frictional shear"</span>
&nbsp;&nbsp;<span class="hljs-keyword">variable</span> <span class="hljs-symbol">sheer</span>::<span>Pressure</span>
&nbsp;&nbsp;<span class="hljs-comment">"Darcy friction factor"</span>
&nbsp;&nbsp;<span class="hljs-keyword">variable</span> <span class="hljs-symbol">ff</span>::<span>Real</span>
&nbsp;&nbsp;<span class="hljs-comment">"Initial guess or value for the mass flow rate"</span>
&nbsp;&nbsp;<span class="hljs-keyword">parameter</span> <span class="hljs-symbol">m_flow0</span>::<span>MassFlowRate</span>
<span class="hljs-keyword">relations</span>
&nbsp;&nbsp;<span class="hljs-built_in">continuity</span>(port_a.medium, port_b.medium)
&nbsp;&nbsp;port_a.m_flow + port_b.m_flow = 0
&nbsp;&nbsp;Δp = port_a.p - port_b.p
&nbsp;&nbsp;<span class="hljs-keyword">initial</span> m_flow = m_flow0
&nbsp;&nbsp;rho = density(port_a.medium, port_a.p)
&nbsp;&nbsp;mu = viscosity(port_a.medium)
&nbsp;&nbsp;velocity = m_flow / (rho * area)
&nbsp;&nbsp;ff = friction_factor(m_flow, area, d_h, mu, shape_factor)
&nbsp;&nbsp;sheer = 0.5 * rho * reg_pow(velocity, 2) * ff * head_factor * (length / d_h)
&nbsp;&nbsp;Δp = add_inertia ? sheer + (length / area) * der(m_flow) : sheer
&nbsp;&nbsp;m_flow = port_a.m_flow
<span class="hljs-keyword">metadata</span> {
&nbsp;&nbsp;"Dyad": {
&nbsp;&nbsp;&nbsp;&nbsp;"labels": [{"label": "$(instance)", "x": 500, "y": 1100, "rot": 0}],
&nbsp;&nbsp;&nbsp;&nbsp;"icons": {"default": "dyad://HydraulicComponents/TubeBase.svg"}
&nbsp;&nbsp;}
}
<span class="hljs-keyword">end</span></code></pre>


Test Cases

No test cases defined.