Skip to content

Commit 59a1093

Browse files
authored
Merge pull request #179 from ven-k/vkb/con-conductor
Fix the ConvectiveConductor equation and adds `ConvectiveElement1D`
2 parents c52d2bd + 86b653b commit 59a1093

File tree

5 files changed

+64
-31
lines changed

5 files changed

+64
-31
lines changed

docs/src/API/hydraulic.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ModelingToolkit Standard Library: Hydrualic Components
1+
# ModelingToolkit Standard Library: Hydraulic Components
22

33
```@contents
44
Pages = ["hydraulic.md"]

src/Hydraulic/Hydraulic.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Library of hydrualic models.
2+
Library of hydraulic models.
33
"""
44
module Hydraulic
55

src/Hydraulic/IsothermalCompressible/components.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"""
33
Cap(; p_int, name)
44
5-
Caps a hydrualic port to prevent mass flow in or out.
5+
Caps a hydraulic port to prevent mass flow in or out.
66
77
# Parameters:
88
- `p_int`: [Pa] initial pressure (set by `p_int` argument)
@@ -42,7 +42,7 @@ end
4242
"""
4343
TubeBase(add_inertia = true; p_int, area, length_int, head_factor = 1, perimeter = 2 * sqrt(area * pi), shape_factor = 64, name)
4444
45-
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.
45+
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.
4646
4747
# States:
4848
- `x`: [m] length of the pipe
@@ -53,7 +53,7 @@ Variable length internal flow model of the fully developed incompressible flow f
5353
- `area`: [m^2] tube cross sectional area
5454
- `length_int`: [m] initial tube length
5555
- `perimeter`: [m] perimeter of the pipe cross section (needed only for non-circular pipes)
56-
- `shape_factor`: shape factor, see `friction_factor` function
56+
- `shape_factor`: shape factor, see `friction_factor` function
5757
- `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.
5858
5959
# Connectors:
@@ -120,14 +120,14 @@ end
120120
"""
121121
Tube(N, add_inertia=true; p_int, area, length, head_factor=1, perimeter = 2 * sqrt(area * pi), shape_factor = 64, name)
122122
123-
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.
123+
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.
124124
125125
# Parameters:
126126
- `p_int`: [Pa] initial pressure
127127
- `area`: [m^2] tube cross sectional area
128128
- `length`: [m] real length of the tube
129129
- `perimeter`: [m] perimeter of the pipe cross section (needed only for non-circular pipes)
130-
- `shape_factor`: shape factor, see `friction_factor` function
130+
- `shape_factor`: shape factor, see `friction_factor` function
131131
- `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.
132132
133133
# Connectors:
@@ -209,7 +209,7 @@ end
209209
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.
210210
211211
# Parameters:
212-
- `p_int`: [Pa] initial pressure
212+
- `p_int`: [Pa] initial pressure
213213
- `n`: divide flow from `port_a` to `port_b` by `n`
214214
215215
# Connectors:
@@ -407,14 +407,14 @@ end
407407
"""
408408
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)
409409
410-
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.
410+
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.
411411
412412
```
413413
┌─────────────────┐ ───
414414
│ │ ▲
415415
│ │
416416
dm ────► │ │ area
417-
│ │
417+
│ │
418418
│ │ ▼
419419
└─────────────────┤ ───
420420
@@ -431,14 +431,14 @@ dm ────► │ │ area
431431
- `area`: [m^2] moving wall area
432432
- `x_int`: [m] initial wall position
433433
- `x_max`: [m] max wall position, needed for volume discretization to apply the correct volume sizing as a function of `x`
434-
- `x_min`: [m] wall position that shuts off flow and prevents negative volume.
434+
- `x_min`: [m] wall position that shuts off flow and prevents negative volume.
435435
- `x_damp`: [m] wall position that initiates a linear damping region before reaching full flow shut off. Helps provide a smooth end stop.
436436
437437
- `direction`: [+/-1] applies the direction conversion from the `flange` to `x`
438438
439439
## flow resistance
440440
- `perimeter`: [m] perimeter of the cross section (needed only for non-circular volumes)
441-
- `shape_factor`: shape factor, see `friction_factor` function
441+
- `shape_factor`: shape factor, see `friction_factor` function
442442
- `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.
443443
444444
## flow shut off and damping

src/Thermal/HeatTransfer/ideal_components.jl

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Lumped thermal element for heat convection.
9797
9898
# States:
9999
100-
- `dT`: [`K`] Temperature difference across the component solid.T - fluid.T
100+
- `dT`: [`K`] Temperature difference across the component `solid.T` - `fluid.T`
101101
- `Q_flow`: [`W`] Heat flow rate from `solid` -> `fluid`
102102
103103
# Connectors:
@@ -110,15 +110,13 @@ Lumped thermal element for heat convection.
110110
- `G`: [W/K] Convective thermal conductance
111111
"""
112112
@component function ConvectiveConductor(; name, G)
113-
@named solid = HeatPort()
114-
@named fluid = HeatPort()
113+
@named convective_element1d = ConvectiveElement1D()
114+
@unpack Q_flow, dT = convective_element1d
115115
@parameters G = G
116-
sts = @variables Q_flow(t)=0.0 dT(t)=0.0
117-
eqs = [dT ~ solid.T - fluid.T
118-
solid.Q_flow ~ Q_flow
119-
fluid.Q_flow ~ -Q_flow
120-
dT ~ G * Q_flow]
121-
ODESystem(eqs, t, sts, [G]; systems = [solid, fluid], name = name)
116+
eqs = [
117+
Q_flow ~ G * dT,
118+
]
119+
extend(ODESystem(eqs, t, [], [G]; name = name), convective_element1d)
122120
end
123121

124122
"""
@@ -128,7 +126,7 @@ Lumped thermal element for heat convection.
128126
129127
# States:
130128
131-
- `dT`: [`K`] Temperature difference across the component solid.T - fluid.T
129+
- `dT`: [`K`] Temperature difference across the component `solid.T` - `fluid.T`
132130
- `Q_flow`: [`W`] Heat flow rate from `solid` -> `fluid`
133131
134132
# Connectors:
@@ -141,15 +139,13 @@ Lumped thermal element for heat convection.
141139
- `R`: [`K/W`] Constant thermal resistance of material
142140
"""
143141
@component function ConvectiveResistor(; name, R)
144-
@named solid = HeatPort()
145-
@named fluid = HeatPort()
142+
@named convective_element1d = ConvectiveElement1D()
143+
@unpack Q_flow, dT = convective_element1d
146144
@parameters R = R
147-
sts = @variables Q_flow(t)=0.0 dT(t)=0.0
148-
eqs = [dT ~ solid.T - fluid.T
149-
solid.Q_flow ~ Q_flow
150-
fluid.Q_flow ~ -Q_flow
151-
dT ~ R * Q_flow]
152-
ODESystem(eqs, t, sts, [R]; systems = [solid, fluid], name = name)
145+
eqs = [
146+
dT ~ R * Q_flow,
147+
]
148+
extend(ODESystem(eqs, t, [], [R]; name = name), convective_element1d)
153149
end
154150

155151
"""

src/Thermal/utils.jl

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Port for a thermal system.
1818
""" HeatPort
1919

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

5353
return compose(ODESystem(eqs, t, sts, []; name = name), port_a, port_b)
5454
end
55+
56+
"""
57+
ConvectiveElement1D(; name, dT_start = 0.0, Q_flow_start = 0.0)
58+
59+
This partial model contains the basic connectors and variables to allow heat
60+
transfer models to be created that do not store energy. This model defines and
61+
includes equations for the temperature drop across the element, `dT`, and the heat
62+
flow rate through the element from `solid` to `fluid`, `Q_flow`.
63+
64+
# States:
65+
66+
- `dT`: [`K`] Temperature difference across the component `solid.T` - `fluid.T`
67+
- `Q_flow`: [`W`] Heat flow rate from `solid` -> `fluid`
68+
69+
# Connectors:
70+
71+
`solid`
72+
`fluid`
73+
74+
# Parameters:
75+
76+
- `dT_start`: [K] Initial temperature difference across the component `solid.T` - `fluid.T`
77+
- `Q_flow_start`: [W] Initial heat flow rate from `solid` -> `fluid`
78+
"""
79+
@component function ConvectiveElement1D(; name, dT_start = 0.0, Q_flow_start = 0.0)
80+
@named solid = HeatPort()
81+
@named fluid = HeatPort()
82+
sts = @variables begin
83+
dT(t) = dT_start
84+
Q_flow(t) = Q_flow_start
85+
end
86+
eqs = [dT ~ solid.T - fluid.T
87+
solid.Q_flow ~ Q_flow
88+
solid.Q_flow + fluid.Q_flow ~ 0]
89+
90+
return compose(ODESystem(eqs, t, sts, []; name = name), solid, fluid)
91+
end

0 commit comments

Comments
 (0)