1
1
"""
2
- Source(;name, p )
2
+ Source(; p, name )
3
3
4
4
Fixed pressure source
5
5
6
6
# Parameters:
7
-
8
- - `p`: [Pa] set pressure
7
+ - `p`: [Pa] set pressure (set by `p` argument)
9
8
10
9
# Connectors:
11
-
12
- - `port`: hydraulic port
10
+ - `port`: hydraulic port
13
11
"""
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
18
14
19
15
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
+
25
19
eqs = [
26
- port. p ~ p
20
+ port. p ~ p,
27
21
]
28
22
29
23
ODESystem (eqs, t, vars, pars; name, systems)
30
24
end
31
25
26
+ """
27
+ InputSource(; p_int, name)
32
28
29
+ Fixed pressure source
33
30
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
38
39
39
40
vars = []
40
-
41
+
41
42
systems = @named begin
42
43
port = HydraulicPort (; p_int)
43
44
input = RealInput ()
44
45
end
45
-
46
+
46
47
eqs = [
47
- port. p ~ input. u
48
+ port. p ~ input. u,
48
49
]
49
50
50
51
ODESystem (eqs, t, vars, pars; name, systems)
51
52
end
52
53
53
-
54
54
"""
55
- FixedVolume(fluid; name, vol, p_int)
55
+ FixedVolume(; vol, p_int, name )
56
56
57
- fixed fluid volume where `fluid` specifies the medium
57
+ Fixed fluid volume.
58
58
59
59
# 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
64
62
65
63
# Connectors:
66
-
67
- - `port`: hydraulic port
64
+ - `port`: hydraulic port
68
65
"""
69
- function FixedVolume (; name, fluid, vol, p_int)
66
+ @component function FixedVolume (; vol, p_int, name )
70
67
pars = @parameters begin
71
68
vol = vol
72
69
p_int = p_int
73
- fluid= fluid
74
70
end
75
71
72
+ systems = @named begin port = HydraulicPort (; p_int) end
73
+
76
74
vars = @variables begin
77
- rho (t) = density (fluid , p_int)
75
+ rho (t) = density (port , p_int)
78
76
drho (t) = 0
79
77
end
80
-
81
- systems = @named begin
82
- port = HydraulicPort (; p_int)
83
- end
84
78
85
79
# let -------------------
86
80
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]
94
85
95
86
ODESystem (eqs, t, vars, pars; name, systems)
96
87
end
97
88
98
89
"""
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 )
100
91
101
- laminar pipe resistance
92
+ Pipe segement which models purely the fully developed flow friction, ignoring any compressibility.
102
93
103
94
# 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).
108
100
109
101
# Connectors:
110
-
111
- - `port `: hydraulic port
102
+ - `port_a`: hydraulic port
103
+ - `port_b `: hydraulic port
112
104
"""
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)
114
107
pars = @parameters begin
115
108
p_int = p_int
116
109
area = area
117
110
length = length
118
111
perimeter = perimeter
119
- fluid= fluid
120
- shape= shape
112
+ Φ = shape_factor
121
113
end
122
114
123
115
vars = []
124
-
116
+
125
117
systems = @named begin
126
118
port_a = HydraulicPort (; p_int)
127
119
port_b = HydraulicPort (; p_int)
128
120
end
129
-
130
121
131
122
# let ----------------------
132
123
Δp = port_a. p - port_b. p
133
124
dm = port_a. dm
134
- p = (port_a. p + port_b. p)/ 2
135
125
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)
137
130
138
- ρ = density (fluid, p)
139
- μ = viscosity (fluid)
140
- Φ = shape_factor (shape)
141
131
f = friction_factor (dm, area, d_h, ρ, μ, Φ)
142
- u = dm/ (ρ * area)
132
+ u = dm / (ρ * area)
143
133
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]
148
136
149
137
ODESystem (eqs, t, vars, pars; name, systems)
150
138
end
151
139
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.
153
144
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 " )
155
160
156
161
pars = @parameters begin
157
162
p_int = p_int
158
163
area = area
159
164
length = length
160
165
perimeter = perimeter
161
- fluid= fluid
162
- shape= shape
166
+ Φ = shape_factor
163
167
end
164
-
168
+
165
169
vars = []
166
-
170
+
167
171
ports = @named begin
168
172
port_a = HydraulicPort (; p_int)
169
173
port_b = HydraulicPort (; p_int)
170
174
end
171
175
172
-
173
176
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))
176
182
push! (pipe_bases, x)
177
183
end
178
184
179
185
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))
182
190
push! (volumes, x)
183
191
end
184
-
185
192
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)]
190
195
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)
193
198
push! (eqs, eq)
194
199
end
195
200
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])
198
202
end
199
203
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
+
200
214
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 "
202
228
203
229
pars = @parameters begin
204
- fluid = fluid
205
230
p_int = p_int
206
231
x_int = x_int
207
232
area = area
@@ -221,19 +246,14 @@ function Actuator(direction; name, fluid, p_int, x_int, area, dead_volume)
221
246
end
222
247
223
248
# let -------------
224
- vol = dead_volume + area* x
249
+ vol = dead_volume + area * x
225
250
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]
236
257
237
258
ODESystem (eqs, t, vars, pars; name, systems)
238
259
end
239
-
0 commit comments