1
1
using ModelingToolkit, OrdinaryDiffEq, Test
2
2
import ModelingToolkitStandardLibrary. Hydraulic. IsothermalCompressible as IC
3
3
import ModelingToolkitStandardLibrary. Blocks as B
4
+ import ModelingToolkitStandardLibrary. Mechanical. Translational as T
4
5
5
6
6
7
@@ -67,23 +68,89 @@ prob25 = ODEProblem(cc25, [], (0,t_end))
67
68
68
69
dt = 1e-4
69
70
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
+
75
79
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
76
90
77
91
78
92
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
+
79
145
using GLMakie
80
146
fig = Figure ()
81
147
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