Skip to content

Commit c0c2885

Browse files
author
Brad Carman
committed
added documentation
1 parent 5ae8ae3 commit c0c2885

File tree

3 files changed

+253
-291
lines changed

3 files changed

+253
-291
lines changed

src/Hydraulic/IsothermalCompressible/components.jl

Lines changed: 122 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,207 +1,232 @@
11
"""
2-
Source(;name, p)
2+
Source(; p, name)
33
44
Fixed pressure source
55
66
# Parameters:
7-
8-
- `p`: [Pa] set pressure
7+
- `p`: [Pa] set pressure (set by `p` argument)
98
109
# Connectors:
11-
12-
- `port`: hydraulic port
10+
- `port`: hydraulic port
1311
"""
14-
function Source(;name, p)
15-
pars = @parameters begin
16-
p = p
17-
end
12+
@component function Source(; p, name)
13+
pars = @parameters begin p = p end
1814

1915
vars = []
20-
21-
systems = @named begin
22-
port = HydraulicPort(; p_int = p)
23-
end
24-
16+
17+
systems = @named begin port = HydraulicPort(; p_int = p) end
18+
2519
eqs = [
26-
port.p ~ p
20+
port.p ~ p,
2721
]
2822

2923
ODESystem(eqs, t, vars, pars; name, systems)
3024
end
3125

26+
"""
27+
InputSource(; p_int, name)
3228
29+
Fixed pressure source
3330
34-
function InputSource(;name, p_int)
35-
pars = @parameters begin
36-
p_int = p_int
37-
end
31+
# Parameters:
32+
- `p_int`: [Pa] initial pressure (set by `p_int` argument)
33+
34+
# Connectors:
35+
- `port`: hydraulic port
36+
"""
37+
@component function InputSource(; p_int, name)
38+
pars = @parameters begin p_int = p_int end
3839

3940
vars = []
40-
41+
4142
systems = @named begin
4243
port = HydraulicPort(; p_int)
4344
input = RealInput()
4445
end
45-
46+
4647
eqs = [
47-
port.p ~ input.u
48+
port.p ~ input.u,
4849
]
4950

5051
ODESystem(eqs, t, vars, pars; name, systems)
5152
end
5253

53-
5454
"""
55-
FixedVolume(fluid; name, vol, p_int)
55+
FixedVolume(; vol, p_int, name)
5656
57-
fixed fluid volume where `fluid` specifies the medium
57+
Fixed fluid volume.
5858
5959
# Parameters:
60-
61-
- `vol`: [m^3] fixed volume
62-
- `p_int`: [Pa] Initial pressure
63-
60+
- `vol`: [m^3] fixed volume
61+
- `p_int`: [Pa] initial pressure
6462
6563
# Connectors:
66-
67-
- `port`: hydraulic port
64+
- `port`: hydraulic port
6865
"""
69-
function FixedVolume(; name, fluid, vol, p_int)
66+
@component function FixedVolume(; vol, p_int, name)
7067
pars = @parameters begin
7168
vol = vol
7269
p_int = p_int
73-
fluid=fluid
7470
end
7571

72+
systems = @named begin port = HydraulicPort(; p_int) end
73+
7674
vars = @variables begin
77-
rho(t) = density(fluid, p_int)
75+
rho(t) = density(port, p_int)
7876
drho(t) = 0
7977
end
80-
81-
systems = @named begin
82-
port = HydraulicPort(; p_int)
83-
end
8478

8579
# let -------------------
8680
dm = port.dm
87-
88-
eqs = [
89-
D(rho) ~ drho
90-
rho ~ density(fluid, port.p)
91-
92-
dm ~ drho*vol
93-
]
81+
82+
eqs = [D(rho) ~ drho
83+
rho ~ density(port, port.p)
84+
dm ~ drho * vol]
9485

9586
ODESystem(eqs, t, vars, pars; name, systems)
9687
end
9788

9889
"""
99-
LaminarResistance(fluid, shape=:circle; name, p_int, area, length, perimeter=2*sqrt(area*pi))
90+
PipeBase(; p_int, area, length, perimeter=2*sqrt(area*pi), shape_factor=64, name)
10091
101-
laminar pipe resistance
92+
Pipe segement which models purely the fully developed flow friction, ignoring any compressibility.
10293
10394
# Parameters:
104-
105-
- `vol`: [m^3] fixed volume
106-
- `p_int`: [Pa] Initial pressure
107-
95+
- `p_int`: [Pa] initial pressure (set by `p_int` argument)
96+
- `area`: [m^2] tube cross sectional area (set by `area` argument)
97+
- `length`: [m] length of the pipe (set by `length` argument)
98+
- `perimeter`: [m] perimeter of the pipe cross section (set by optional `perimeter` argument, needed only for non-circular pipes)
99+
- `Φ`: shape factor, see `friction_factor` function (set by optional `shape_factor` argument, needed only for non-circular pipes).
108100
109101
# Connectors:
110-
111-
- `port`: hydraulic port
102+
- `port_a`: hydraulic port
103+
- `port_b`: hydraulic port
112104
"""
113-
function PipeBase(;name, fluid, shape=Shapes.circle, p_int, area, length, perimeter=2*sqrt(area*pi))
105+
@component function PipeBase(; p_int, area, length, perimeter = 2 * sqrt(area * pi),
106+
shape_factor = 64, name)
114107
pars = @parameters begin
115108
p_int = p_int
116109
area = area
117110
length = length
118111
perimeter = perimeter
119-
fluid=fluid
120-
shape=shape
112+
Φ = shape_factor
121113
end
122114

123115
vars = []
124-
116+
125117
systems = @named begin
126118
port_a = HydraulicPort(; p_int)
127119
port_b = HydraulicPort(; p_int)
128120
end
129-
130121

131122
# let ----------------------
132123
Δp = port_a.p - port_b.p
133124
dm = port_a.dm
134-
p = (port_a.p + port_b.p)/2
135125

136-
d_h = 4*area/perimeter
126+
d_h = 4 * area / perimeter
127+
128+
ρ = (density(port_a, port_a.p) + density(port_b, port_b.p)) / 2
129+
μ = viscosity(port_a)
137130

138-
ρ = density(fluid, p)
139-
μ = viscosity(fluid)
140-
Φ = shape_factor(shape)
141131
f = friction_factor(dm, area, d_h, ρ, μ, Φ)
142-
u = dm/*area)
132+
u = dm /* area)
143133

144-
eqs = [
145-
Δp ~ 1/2 * ρ * u^2 * f * (length/d_h)
146-
0 ~ port_a.dm + port_b.dm
147-
]
134+
eqs = [Δp ~ 1 / 2 * ρ * u^2 * f * (length / d_h)
135+
0 ~ port_a.dm + port_b.dm]
148136

149137
ODESystem(eqs, t, vars, pars; name, systems)
150138
end
151139

152-
function Pipe(N; name, fluid, shape=Shapes.circle, p_int, area, length, perimeter=2*sqrt(area*pi))
140+
"""
141+
Pipe(N; p_int, area, length, perimeter=2*sqrt(area*pi), shape_factor=64, name)
142+
143+
Pipe modeled with `N` segements which models the fully developed flow friction and compressibility.
153144
154-
@assert(N>1, "the pipe component must be defined with more than 1 segment (i.e. N>1), found N=$N")
145+
# Parameters:
146+
- `p_int`: [Pa] initial pressure (set by `p_int` argument)
147+
- `area`: [m^2] tube cross sectional area (set by `area` argument)
148+
- `length`: [m] length of the pipe (set by `length` argument)
149+
- `perimeter`: [m] perimeter of the pipe cross section (set by optional `perimeter` argument, needed only for non-circular pipes)
150+
- `Φ`: shape factor, see `friction_factor` function (set by optional `shape_factor` argument, needed only for non-circular pipes).
151+
152+
# Connectors:
153+
- `port_a`: hydraulic port
154+
- `port_b`: hydraulic port
155+
"""
156+
@component function Pipe(N; p_int, area, length, perimeter = 2 * sqrt(area * pi),
157+
shape_factor = 64, name)
158+
@assert(N>1,
159+
"the pipe component must be defined with more than 1 segment (i.e. N>1), found N=$N")
155160

156161
pars = @parameters begin
157162
p_int = p_int
158163
area = area
159164
length = length
160165
perimeter = perimeter
161-
fluid=fluid
162-
shape=shape
166+
Φ = shape_factor
163167
end
164-
168+
165169
vars = []
166-
170+
167171
ports = @named begin
168172
port_a = HydraulicPort(; p_int)
169173
port_b = HydraulicPort(; p_int)
170174
end
171175

172-
173176
pipe_bases = []
174-
for i=1:N-1
175-
x = PipeBase(;name=Symbol("p$i"), fluid=ParentScope(fluid), shape=ParentScope(shape), p_int=ParentScope(p_int), area=ParentScope(area), length=ParentScope(length)/(N-1), perimeter=ParentScope(perimeter))
177+
for i in 1:(N - 1)
178+
x = PipeBase(; name = Symbol("p$i"), shape_factor = ParentScope(Φ),
179+
p_int = ParentScope(p_int), area = ParentScope(area),
180+
length = ParentScope(length) / (N - 1),
181+
perimeter = ParentScope(perimeter))
176182
push!(pipe_bases, x)
177183
end
178184

179185
volumes = []
180-
for i=1:N
181-
x = FixedVolume(; name=Symbol("v$i"), fluid=ParentScope(fluid), vol=ParentScope(area)*ParentScope(length)/N, p_int=ParentScope(p_int))
186+
for i in 1:N
187+
x = FixedVolume(; name = Symbol("v$i"),
188+
vol = ParentScope(area) * ParentScope(length) / N,
189+
p_int = ParentScope(p_int))
182190
push!(volumes, x)
183191
end
184-
185192

186-
eqs = [
187-
connect(volumes[1].port, pipe_bases[1].port_a, port_a)
188-
connect(volumes[end].port, pipe_bases[end].port_b, port_b)
189-
]
193+
eqs = [connect(volumes[1].port, pipe_bases[1].port_a, port_a)
194+
connect(volumes[end].port, pipe_bases[end].port_b, port_b)]
190195

191-
for i=2:N-1
192-
eq = connect(volumes[i].port, pipe_bases[i-1].port_b, pipe_bases[i].port_a)
196+
for i in 2:(N - 1)
197+
eq = connect(volumes[i].port, pipe_bases[i - 1].port_b, pipe_bases[i].port_a)
193198
push!(eqs, eq)
194199
end
195200

196-
197-
ODESystem(eqs, t, vars, pars; name, systems=[ports; pipe_bases; volumes])
201+
ODESystem(eqs, t, vars, pars; name, systems = [ports; pipe_bases; volumes])
198202
end
199203

204+
"""
205+
DynamicVolume(; p_int, x_int=0, area, dead_volume=0, direction=+1, name)
206+
207+
Volume with moving wall. 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.
208+
_________
209+
| |
210+
--> d.v. |
211+
|_________|
212+
└─► x (= ∫ flange.v * direction)
213+
200214
201-
function Actuator(direction; name, fluid, p_int, x_int, area, dead_volume)
215+
# Parameters:
216+
- `p_int`: [Pa] initial pressure (set by `p_int` argument)
217+
- `x_int`: [m] initial position of the moving wall (set by the `x_int` argument)
218+
- `area`: [m^2] moving wall area (set by the `area` argument)
219+
- `dead_volume`: [m^3] perimeter of the pipe cross section (set by optional `perimeter` argument, needed only for non-circular pipes)
220+
221+
# Connectors:
222+
- `port`: hydraulic port
223+
- `flange`: mechanical translational port
224+
"""
225+
@component function DynamicVolume(; p_int, x_int = 0, area, dead_volume = 0, direction = +1,
226+
name)
227+
@assert (direction == +1)||(direction == -1) "direction arument must be +/-1, found $direction"
202228

203229
pars = @parameters begin
204-
fluid = fluid
205230
p_int = p_int
206231
x_int = x_int
207232
area = area
@@ -221,19 +246,14 @@ function Actuator(direction; name, fluid, p_int, x_int, area, dead_volume)
221246
end
222247

223248
# let -------------
224-
vol = dead_volume + area*x
249+
vol = dead_volume + area * x
225250

226-
eqs = [
227-
D(x) ~ dx
228-
D(rho) ~ drho
229-
230-
dx ~ flange.v*direction
231-
rho ~ density(fluid, port.p)
232-
233-
port.dm ~ drho*vol + rho*area*dx
234-
flange.f ~ -port.p*area*direction
235-
]
251+
eqs = [D(x) ~ dx
252+
D(rho) ~ drho
253+
dx ~ flange.v * direction
254+
rho ~ density(fluid, port.p)
255+
port.dm ~ drho * vol + rho * area * dx
256+
flange.f ~ -port.p * area * direction]
236257

237258
ODESystem(eqs, t, vars, pars; name, systems)
238259
end
239-

0 commit comments

Comments
 (0)