Skip to content

Commit 5ae8ae3

Browse files
author
Brad Carman
committed
added Actuator
1 parent 85729d8 commit 5ae8ae3

File tree

4 files changed

+123
-13
lines changed

4 files changed

+123
-13
lines changed

src/Hydraulic/IsothermalCompressible/IsothermalCompressible.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module IsothermalCompressible
55

66
using ModelingToolkit, Symbolics
77
using ...Blocks: RealInput, RealOutput
8+
using ...Mechanical.Translational: MechanicalPort
89

910
@parameters t
1011
D = Differential(t)

src/Hydraulic/IsothermalCompressible/components.jl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,43 @@ function Pipe(N; name, fluid, shape=Shapes.circle, p_int, area, length, perimete
197197
ODESystem(eqs, t, vars, pars; name, systems=[ports; pipe_bases; volumes])
198198
end
199199

200+
201+
function Actuator(direction; name, fluid, p_int, x_int, area, dead_volume)
202+
203+
pars = @parameters begin
204+
fluid = fluid
205+
p_int = p_int
206+
x_int = x_int
207+
area = area
208+
dead_volume = dead_volume
209+
end
210+
211+
vars = @variables begin
212+
x(t) = x_int
213+
dx(t) = 0
214+
rho(t) = density(fluid, p_int)
215+
drho(t) = 0
216+
end
217+
218+
systems = @named begin
219+
port = HydraulicPort(; p_int)
220+
flange = MechanicalPort()
221+
end
222+
223+
# let -------------
224+
vol = dead_volume + area*x
225+
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+
]
236+
237+
ODESystem(eqs, t, vars, pars; name, systems)
238+
end
239+

src/Hydraulic/IsothermalCompressible/utils.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ shape_factor(::Val{Shapes.rectangle_r4.value}) = 73
106106
shape_factor(::Val{Shapes.rectangle_r8.value}) = 82
107107
shape_factor(::Val{Shapes.rectangle_rinf.value}) = 96
108108

109+
110+
109111
function friction_factor(dm, area, d_h, rho, mu, shape_factor)
110112

111113
u = abs(dm)/(rho*area)

test/Hydraulic/isothermal_compressible.jl

Lines changed: 80 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using ModelingToolkit, OrdinaryDiffEq, Test
22
import ModelingToolkitStandardLibrary.Hydraulic.IsothermalCompressible as IC
33
import ModelingToolkitStandardLibrary.Blocks as B
4+
import ModelingToolkitStandardLibrary.Mechanical.Translational as T
45

56

67

@@ -67,23 +68,89 @@ prob25 = ODEProblem(cc25, [], (0,t_end))
6768

6869
dt = 1e-4
6970
NEWTON = NLNewton(check_div = false, always_new = true, max_iter=100, relax=4//10)
70-
sol0 = solve(prob0, ImplicitEuler(nlsolve=NEWTON); adaptive=false, dt, initializealg=NoInit())
71-
sol1 = solve(prob1, ImplicitEuler(nlsolve=NEWTON); adaptive=false, dt, initializealg=NoInit())
72-
sol2 = solve(prob2, ImplicitEuler(nlsolve=NEWTON); adaptive=false, dt, initializealg=NoInit())
73-
sol5 = solve(prob5, ImplicitEuler(nlsolve=NEWTON); adaptive=false, dt, initializealg=NoInit())
74-
sol25 = solve(prob25, ImplicitEuler(nlsolve=NEWTON); adaptive=false, dt, initializealg=NoInit())
71+
# sol0 = solve(prob0, ImplicitEuler(nlsolve=NEWTON); adaptive=false, dt, initializealg=NoInit())
72+
# sol1 = solve(prob1, ImplicitEuler(nlsolve=NEWTON); adaptive=false, dt, initializealg=NoInit())
73+
# sol2 = solve(prob2, ImplicitEuler(nlsolve=NEWTON); adaptive=false, dt, initializealg=NoInit())
74+
# sol5 = solve(prob5, ImplicitEuler(nlsolve=NEWTON); adaptive=false, dt, initializealg=NoInit())
75+
# sol25 = solve(prob25, ImplicitEuler(nlsolve=NEWTON); adaptive=false, dt, initializealg=NoInit())
76+
77+
78+
7579

80+
# using GLMakie
81+
# fig = Figure()
82+
# ax = Axis(fig[1,1])
83+
# lines!(ax, sol0.t, sol0[sys1.res.port_a.p] .- sol0[sys1.res.port_b.p]; label="pipe base, oil", linestyle=:dash)
84+
# lines!(ax, sol1.t, sol1[sys1.res.port_a.p] .- sol1[sys1.res.port_b.p]; label="pipe base")
85+
# lines!(ax, sol2.t, sol2[sys2.res.port_a.p] .- sol2[sys2.res.port_b.p]; label="pipe N=2")
86+
# lines!(ax, sol5.t, sol5[sys5.res.port_a.p] .- sol5[sys5.res.port_b.p]; label="pipe N=5")
87+
# lines!(ax, sol25.t, sol25[sys25.res.port_a.p] .- sol25[sys25.res.port_b.p]; label="pipe N=25")
88+
# axislegend(ax)
89+
# fig
7690

7791

7892

93+
94+
function actuator_system(; name, fluid_a, fluid_b = fluid_a)
95+
96+
pars = @parameters begin
97+
fluid_a = fluid_a
98+
fluid_b = fluid_b
99+
end
100+
101+
systems = @named begin
102+
stp = B.Step(;height = 10e5, offset = 0, start_time = 0.005, duration = Inf, smooth = 0)
103+
104+
src_a = IC.InputSource(;p_int=0)
105+
res_a = IC.Pipe(5; p_int=0, area=0.01, length=500.0, fluid=fluid_a)
106+
act_a = IC.Actuator(+1; fluid=fluid_a, p_int=0, x_int=0, area=0.1, dead_volume=100)
107+
108+
src_b = IC.InputSource(;p_int=0)
109+
res_b = IC.Pipe(5; p_int=0, area=0.01, length=500.0, fluid=fluid_b)
110+
act_b = IC.Actuator(-1; fluid=fluid_b, p_int=0, x_int=0, area=0.1, dead_volume=100)
111+
112+
m = T.Mass(; m=1000)
113+
114+
end
115+
116+
117+
118+
119+
eqs = [
120+
connect(stp.output, src_a.input, src_b.input)
121+
122+
connect(src_a.port, res_a.port_a)
123+
connect(res_a.port_b, act_a.port)
124+
125+
connect(src_b.port, res_b.port_a)
126+
connect(res_b.port_b, act_b.port)
127+
128+
connect(act_a.flange, act_b.flange, m.flange)
129+
]
130+
131+
ODESystem(eqs, t, [], pars; name, systems)
132+
end
133+
134+
@named act_sys = actuator_system(; fluid_a = IC.water_20C)
135+
cc = structural_simplify(act_sys; allow_parameter=false)
136+
137+
t_end = 0.5
138+
prob1 = ODEProblem(cc, [], (0,t_end), [complete(act_sys).fluid_b => user_oil])
139+
prob2 = ODEProblem(cc, [], (0,t_end))
140+
141+
sol1 = solve(prob1, ImplicitEuler(nlsolve=NEWTON); adaptive=false, dt, initializealg=NoInit())
142+
sol2 = solve(prob2, ImplicitEuler(nlsolve=NEWTON); adaptive=false, dt, initializealg=NoInit())
143+
144+
79145
using GLMakie
80146
fig = Figure()
81147
ax = Axis(fig[1,1])
82-
lines!(ax, sol0.t, sol0[sys1.res.port_a.p] .- sol0[sys1.res.port_b.p]; label="pipe base, oil", linestyle=:dash)
83-
lines!(ax, sol1.t, sol1[sys1.res.port_a.p] .- sol1[sys1.res.port_b.p]; label="pipe base")
84-
lines!(ax, sol2.t, sol2[sys2.res.port_a.p] .- sol2[sys2.res.port_b.p]; label="pipe N=2")
85-
lines!(ax, sol5.t, sol5[sys5.res.port_a.p] .- sol5[sys5.res.port_b.p]; label="pipe N=5")
86-
lines!(ax, sol25.t, sol25[sys25.res.port_a.p] .- sol25[sys25.res.port_b.p]; label="pipe N=25")
87-
axislegend(ax)
88-
fig
89-
148+
lines!(ax, sol1.t, sol1[act_sys.act_a.x]; color=:red)
149+
lines!(ax, sol1.t, sol1[act_sys.act_b.x]; color=:red, linestyle=:dash)
150+
lines!(ax, sol2.t, sol2[act_sys.act_a.x]; color=:blue)
151+
lines!(ax, sol2.t, sol2[act_sys.act_b.x]; color=:blue, linestyle=:dash)
152+
153+
ax = Axis(fig[2,1])
154+
lines!(ax, sol1.t, (sol1[act_sys.act_a.port.p] .- sol1[act_sys.act_b.port.p])/1e5; color=:red)
155+
lines!(ax, sol2.t, (sol2[act_sys.act_a.port.p] .- sol2[act_sys.act_b.port.p])/1e5; color=:blue)
156+
fig

0 commit comments

Comments
 (0)