Skip to content

Commit

Permalink
Merge pull request #179 from ven-k/vkb/con-conductor
Browse files Browse the repository at this point in the history
Fix the ConvectiveConductor equation and adds `ConvectiveElement1D`
  • Loading branch information
YingboMa authored May 30, 2023
2 parents c52d2bd + 86b653b commit 59a1093
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 31 deletions.
2 changes: 1 addition & 1 deletion docs/src/API/hydraulic.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ModelingToolkit Standard Library: Hydrualic Components
# ModelingToolkit Standard Library: Hydraulic Components

```@contents
Pages = ["hydraulic.md"]
Expand Down
2 changes: 1 addition & 1 deletion src/Hydraulic/Hydraulic.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Library of hydrualic models.
Library of hydraulic models.
"""
module Hydraulic

Expand Down
20 changes: 10 additions & 10 deletions src/Hydraulic/IsothermalCompressible/components.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""
Cap(; p_int, name)
Caps a hydrualic port to prevent mass flow in or out.
Caps a hydraulic port to prevent mass flow in or out.
# Parameters:
- `p_int`: [Pa] initial pressure (set by `p_int` argument)
Expand Down Expand Up @@ -42,7 +42,7 @@ end
"""
TubeBase(add_inertia = true; p_int, area, length_int, head_factor = 1, perimeter = 2 * sqrt(area * pi), shape_factor = 64, name)
Variable length internal flow model of the fully developed incompressible flow friction. Includes optional inertia term when `add_inertia = true` to model wave propagation. Hydraulic ports have equal flow but variable pressure. Density is averaged over the pressures, used to calculated average flow velocity and flow friction.
Variable length internal flow model of the fully developed incompressible flow friction. Includes optional inertia term when `add_inertia = true` to model wave propagation. Hydraulic ports have equal flow but variable pressure. Density is averaged over the pressures, used to calculated average flow velocity and flow friction.
# States:
- `x`: [m] length of the pipe
Expand All @@ -53,7 +53,7 @@ Variable length internal flow model of the fully developed incompressible flow f
- `area`: [m^2] tube cross sectional area
- `length_int`: [m] initial tube length
- `perimeter`: [m] perimeter of the pipe cross section (needed only for non-circular pipes)
- `shape_factor`: shape factor, see `friction_factor` function
- `shape_factor`: shape factor, see `friction_factor` function
- `head_factor`: effective length multiplier, used to account for addition friction from flow development and additional friction such as pipe bends, entrance/exit lossses, etc.
# Connectors:
Expand Down Expand Up @@ -120,14 +120,14 @@ end
"""
Tube(N, add_inertia=true; p_int, area, length, head_factor=1, perimeter = 2 * sqrt(area * pi), shape_factor = 64, name)
Constant length internal flow model discretized by `N` (`FixedVolume`: `N`, `TubeBase`:`N-1`) which models the fully developed flow friction, compressibility (when `N>1`), and inertia effects when `add_inertia = true`. See `TubeBase` and `FixedVolume` for more information.
Constant length internal flow model discretized by `N` (`FixedVolume`: `N`, `TubeBase`:`N-1`) which models the fully developed flow friction, compressibility (when `N>1`), and inertia effects when `add_inertia = true`. See `TubeBase` and `FixedVolume` for more information.
# Parameters:
- `p_int`: [Pa] initial pressure
- `area`: [m^2] tube cross sectional area
- `length`: [m] real length of the tube
- `perimeter`: [m] perimeter of the pipe cross section (needed only for non-circular pipes)
- `shape_factor`: shape factor, see `friction_factor` function
- `shape_factor`: shape factor, see `friction_factor` function
- `head_factor`: effective length multiplier, used to account for addition friction from flow development and additional friction such as pipe bends, entrance/exit lossses, etc.
# Connectors:
Expand Down Expand Up @@ -209,7 +209,7 @@ end
Reduces the flow from `port_a` to `port_b` by `n`. Useful for modeling parallel tubes efficiently by placing a `FlowDivider` on each end of a tube.
# Parameters:
- `p_int`: [Pa] initial pressure
- `p_int`: [Pa] initial pressure
- `n`: divide flow from `port_a` to `port_b` by `n`
# Connectors:
Expand Down Expand Up @@ -407,14 +407,14 @@ end
"""
DynamicVolume(N, add_inertia=true; p_int, area, x_int = 0, x_max, x_min = 0, x_damp = x_min, direction = +1, perimeter = 2 * sqrt(area * pi), shape_factor = 64, head_factor = 1, Cd = 1e2, Cd_reverse = Cd, name)
Volume with moving wall with `flange` connector for converting hydraulic energy to 1D mechanical. The `direction` argument aligns the mechanical port with the hydraulic port, useful when connecting two dynamic volumes together in oppsing directions to create an actuator.
Volume with moving wall with `flange` connector for converting hydraulic energy to 1D mechanical. The `direction` argument aligns the mechanical port with the hydraulic port, useful when connecting two dynamic volumes together in oppsing directions to create an actuator.
```
┌─────────────────┐ ───
│ │ ▲
│ │
dm ────► │ │ area
│ │
│ │
│ │ ▼
└─────────────────┤ ───
Expand All @@ -431,14 +431,14 @@ dm ────► │ │ area
- `area`: [m^2] moving wall area
- `x_int`: [m] initial wall position
- `x_max`: [m] max wall position, needed for volume discretization to apply the correct volume sizing as a function of `x`
- `x_min`: [m] wall position that shuts off flow and prevents negative volume.
- `x_min`: [m] wall position that shuts off flow and prevents negative volume.
- `x_damp`: [m] wall position that initiates a linear damping region before reaching full flow shut off. Helps provide a smooth end stop.
- `direction`: [+/-1] applies the direction conversion from the `flange` to `x`
## flow resistance
- `perimeter`: [m] perimeter of the cross section (needed only for non-circular volumes)
- `shape_factor`: shape factor, see `friction_factor` function
- `shape_factor`: shape factor, see `friction_factor` function
- `head_factor`: effective length multiplier, used to account for addition friction from flow development and additional friction such as pipe bends, entrance/exit lossses, etc.
## flow shut off and damping
Expand Down
32 changes: 14 additions & 18 deletions src/Thermal/HeatTransfer/ideal_components.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Lumped thermal element for heat convection.
# States:
- `dT`: [`K`] Temperature difference across the component solid.T - fluid.T
- `dT`: [`K`] Temperature difference across the component `solid.T` - `fluid.T`
- `Q_flow`: [`W`] Heat flow rate from `solid` -> `fluid`
# Connectors:
Expand All @@ -110,15 +110,13 @@ Lumped thermal element for heat convection.
- `G`: [W/K] Convective thermal conductance
"""
@component function ConvectiveConductor(; name, G)
@named solid = HeatPort()
@named fluid = HeatPort()
@named convective_element1d = ConvectiveElement1D()
@unpack Q_flow, dT = convective_element1d
@parameters G = G
sts = @variables Q_flow(t)=0.0 dT(t)=0.0
eqs = [dT ~ solid.T - fluid.T
solid.Q_flow ~ Q_flow
fluid.Q_flow ~ -Q_flow
dT ~ G * Q_flow]
ODESystem(eqs, t, sts, [G]; systems = [solid, fluid], name = name)
eqs = [
Q_flow ~ G * dT,
]
extend(ODESystem(eqs, t, [], [G]; name = name), convective_element1d)
end

"""
Expand All @@ -128,7 +126,7 @@ Lumped thermal element for heat convection.
# States:
- `dT`: [`K`] Temperature difference across the component solid.T - fluid.T
- `dT`: [`K`] Temperature difference across the component `solid.T` - `fluid.T`
- `Q_flow`: [`W`] Heat flow rate from `solid` -> `fluid`
# Connectors:
Expand All @@ -141,15 +139,13 @@ Lumped thermal element for heat convection.
- `R`: [`K/W`] Constant thermal resistance of material
"""
@component function ConvectiveResistor(; name, R)
@named solid = HeatPort()
@named fluid = HeatPort()
@named convective_element1d = ConvectiveElement1D()
@unpack Q_flow, dT = convective_element1d
@parameters R = R
sts = @variables Q_flow(t)=0.0 dT(t)=0.0
eqs = [dT ~ solid.T - fluid.T
solid.Q_flow ~ Q_flow
fluid.Q_flow ~ -Q_flow
dT ~ R * Q_flow]
ODESystem(eqs, t, sts, [R]; systems = [solid, fluid], name = name)
eqs = [
dT ~ R * Q_flow,
]
extend(ODESystem(eqs, t, [], [R]; name = name), convective_element1d)
end

"""
Expand Down
39 changes: 38 additions & 1 deletion src/Thermal/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Port for a thermal system.
""" HeatPort

"""
Element1D(;name, dT0=0.0, Q_flow0=0.0)
Element1D(; name, dT_start = 0.0, Q_flow_start = 0.0)
This partial model contains the basic connectors and variables to allow heat transfer models to be created that do not
store energy. This model defines and includes equations for the temperature drop across the element, `dT`, and the heat
Expand Down Expand Up @@ -52,3 +52,40 @@ flow rate through the element from `port_a` to `port_b`, `Q_flow`.

return compose(ODESystem(eqs, t, sts, []; name = name), port_a, port_b)
end

"""
ConvectiveElement1D(; name, dT_start = 0.0, Q_flow_start = 0.0)
This partial model contains the basic connectors and variables to allow heat
transfer models to be created that do not store energy. This model defines and
includes equations for the temperature drop across the element, `dT`, and the heat
flow rate through the element from `solid` to `fluid`, `Q_flow`.
# States:
- `dT`: [`K`] Temperature difference across the component `solid.T` - `fluid.T`
- `Q_flow`: [`W`] Heat flow rate from `solid` -> `fluid`
# Connectors:
`solid`
`fluid`
# Parameters:
- `dT_start`: [K] Initial temperature difference across the component `solid.T` - `fluid.T`
- `Q_flow_start`: [W] Initial heat flow rate from `solid` -> `fluid`
"""
@component function ConvectiveElement1D(; name, dT_start = 0.0, Q_flow_start = 0.0)
@named solid = HeatPort()
@named fluid = HeatPort()
sts = @variables begin
dT(t) = dT_start
Q_flow(t) = Q_flow_start
end
eqs = [dT ~ solid.T - fluid.T
solid.Q_flow ~ Q_flow
solid.Q_flow + fluid.Q_flow ~ 0]

return compose(ODESystem(eqs, t, sts, []; name = name), solid, fluid)
end

0 comments on commit 59a1093

Please sign in to comment.