@@ -6,128 +6,130 @@ import ModelingToolkitStandardLibrary.Mechanical.Translational as T
6
6
@parameters t
7
7
D = Differential (t)
8
8
9
- function system (N; name, fluid)
10
- pars = @parameters begin fluid = fluid end
9
+ function system (N; bulk_modulus, name)
10
+ pars = @parameters begin
11
+ bulk_modulus = bulk_modulus
12
+ end
11
13
12
14
systems = @named begin
13
- stp = B . Step (; height = 10e5 , offset = 0 , start_time = 0.005 , duration = Inf ,
14
- smooth = 0 )
15
+ fluid = IC . HydraulicFluid (;bulk_modulus)
16
+ stp = B . Step (; height = 10e5 , offset = 0 , start_time = 0.005 , duration = Inf , smooth = true )
15
17
src = IC. InputSource (; p_int = 0 )
16
- vol = IC. FixedVolume (; p_int = 0 , vol = 10.0 , fluid )
18
+ vol = IC. FixedVolume (; p_int = 0 , vol = 10.0 )
17
19
end
18
20
19
21
if N == 1
20
- @named res = IC. PipeBase (; p_int = 0 , area = 0.01 , length = 500.0 , fluid )
22
+ @named res = IC. PipeBase (; p_int = 0 , area = 0.01 , length = 500.0 )
21
23
else
22
- @named res = IC. Pipe (N; p_int = 0 , area = 0.01 , length = 500.0 , fluid )
24
+ @named res = IC. Pipe (N; p_int = 0 , area = 0.01 , length = 500.0 )
23
25
end
24
26
push! (systems, res)
25
27
26
- eqs = [connect (stp. output, src. input)
27
- connect (src. port, res. port_a)
28
- connect (res. port_b, vol. port)]
28
+ eqs = [ connect (stp. output, src. input)
29
+ connect (fluid, src. port)
30
+ connect (src. port, res. port_a)
31
+ connect (res. port_b, vol. port)]
29
32
30
33
ODESystem (eqs, t, [], pars; name, systems)
31
34
end
32
35
33
- @named user_oil = IC. FluidType ()
34
- user_oil_type = typeof (IC. get_fluid (user_oil))
35
- IC. density (:: user_oil_type ) = 876
36
- IC. bulk_modulus (:: user_oil_type ) = 1.2e9
37
- IC. viscosity (:: user_oil_type ) = 0.034
38
-
39
- @named sys1 = system (1 ; fluid = IC. water_20C)
40
- @named sys2 = system (2 ; fluid = IC. water_20C)
41
- @named sys5 = system (5 ; fluid = IC. water_20C)
42
- @named sys25 = system (25 ; fluid = IC. water_20C)
43
-
44
- cc1 = structural_simplify (sys1; allow_parameter = false )
45
- cc2 = structural_simplify (sys2; allow_parameter = false )
46
- cc5 = structural_simplify (sys5; allow_parameter = false )
47
- cc25 = structural_simplify (sys25; allow_parameter = false )
48
-
49
- t_end = 0.2
50
- prob0 = ODEProblem (cc1, [], (0 , t_end), [complete (sys1). fluid => user_oil])
51
- prob1 = ODEProblem (cc1, [], (0 , t_end))
52
- prob2 = ODEProblem (cc2, [], (0 , t_end))
53
- prob5 = ODEProblem (cc5, [], (0 , t_end))
54
- prob25 = ODEProblem (cc25, [], (0 , t_end))
36
+ @named sys1_2 = system (1 ; bulk_modulus= 2e9 )
37
+ @named sys1_1 = system (1 ; bulk_modulus= 1e9 )
38
+ @named sys5_1 = system (5 ; bulk_modulus= 1e9 )
55
39
56
- dt = 1e-4
57
40
NEWTON = NLNewton (check_div = false , always_new = true , max_iter = 100 , relax = 4 // 10 )
58
- # sol0 = solve(prob0, ImplicitEuler(nlsolve=NEWTON); adaptive=false, dt, initializealg=NoInit())
59
- # sol1 = solve(prob1, ImplicitEuler(nlsolve=NEWTON); adaptive=false, dt, initializealg=NoInit())
60
- # sol2 = solve(prob2, ImplicitEuler(nlsolve=NEWTON); adaptive=false, dt, initializealg=NoInit())
61
- # sol5 = solve(prob5, ImplicitEuler(nlsolve=NEWTON); adaptive=false, dt, initializealg=NoInit())
62
- # sol25 = solve(prob25, ImplicitEuler(nlsolve=NEWTON); adaptive=false, dt, initializealg=NoInit())
63
41
64
- # using GLMakie
42
+ syss = structural_simplify .([sys1_2, sys1_1, sys5_1])
43
+ probs = [ODEProblem (sys, [], (0 , 0.2 )) for sys in syss];
44
+ sols = [solve (prob, ImplicitEuler (nlsolve= NEWTON); initializealg= NoInit ()) for prob in probs];
45
+
46
+ s1_2 = complete (sys1_2)
47
+ s1_1 = complete (sys1_1)
48
+ s5_1 = complete (sys5_1)
49
+
50
+ # higher stiffness should compress more quickly and give a higher pressure
51
+ @test sols[1 ][s1_2. vol. port. p][end ] > sols[2 ][s1_1. vol. port. p][end ]
52
+
53
+ # N=5 pipe is compressible, will pressurize more slowly
54
+ @test sols[2 ][s1_1. vol. port. p][end ] > sols[3 ][s5_1. vol. port. p][end ]
55
+
56
+ # using CairoMakie
65
57
# fig = Figure()
66
58
# ax = Axis(fig[1,1])
67
- # lines!(ax, sol0 .t, sol0[sys1.res.port_a.p] .- sol0[sys1.res.port_b .p]; label="pipe base, oil ", linestyle=:dash )
68
- # lines!(ax, sol1 .t, sol1[sys1.res.port_a.p] .- sol1[sys1.res.port_b .p]; label="pipe base" )
69
- # lines !(ax, sol2 .t, sol2[sys2.res.port_a.p] .- sol2[sys2.res.port_b .p]; label="pipe N=2 ")
70
- # lines !(ax, sol5 .t, sol5[sys5.res.port_a.p] .- sol5[sys5.res.port_b .p]; label="pipe N=5 ")
71
- # lines !(ax, sol25 .t, sol25[sys25.res.port_a.p] .- sol25[sys25.res.port_b .p]; label="pipe N=25 ")
72
- # axislegend( ax)
59
+ # lines!(ax, sols[1] .t, sols[1][s1_2.src.port .p]; label="sorce ", color=:black )
60
+ # # lines!(ax, sols[2] .t, sols[2][s1_1.src.port .p])
61
+ # scatterlines !(ax, sols[1] .t, sols[1][s1_2.vol.port .p]; label="bulk=2e9 ")
62
+ # scatterlines !(ax, sols[2] .t, sols[2][s1_1.vol.port .p]; label="bulk=1e9 ")
63
+ # scatterlines !(ax, sols[3] .t, sols[3][s5_1.vol.port .p]; label="bulk=1e9, N=5 ")
64
+ # Legend(fig[1,2], ax)
73
65
# fig
74
66
75
- function actuator_system (; name, fluid_a, fluid_b = fluid_a)
76
- pars = @parameters begin
77
- fluid_a = fluid_a
78
- fluid_b = fluid_b
79
- end
80
67
81
- systems = @named begin
82
- stp = B. Step (; height = 10e5 , offset = 0 , start_time = 0.005 , duration = Inf ,
83
- smooth = 0 )
84
68
85
- src_a = IC. InputSource (; p_int = 0 )
86
- res_a = IC. Pipe (5 ; p_int = 0 , area = 0.01 , length = 500.0 , fluid = fluid_a)
87
- act_a = IC. Actuator (+ 1 ; fluid = fluid_a, p_int = 0 , x_int = 0 , area = 0.1 ,
88
- dead_volume = 100 )
89
69
90
- src_b = IC . InputSource (; p_int = 0 )
91
- res_b = IC . Pipe ( 5 ; p_int = 0 , area = 0.01 , length = 500.0 , fluid = fluid_b)
92
- act_b = IC . Actuator ( - 1 ; fluid = fluid_b, p_int = 0 , x_int = 0 , area = 0.1 ,
93
- dead_volume = 100 )
70
+ function system (; bulk_modulus, name )
71
+ pars = @parameters begin
72
+ bulk_modulus = bulk_modulus
73
+ end
94
74
95
- m = T. Mass (; m = 1000 )
75
+ systems = @named begin
76
+ fluid = IC. HydraulicFluid (;bulk_modulus)
77
+ stp = B. Step (; height = 10e5 , offset = 0 , start_time = 0.05 , duration = Inf , smooth = 0.001 )
78
+ src = IC. InputSource (; p_int = 0 )
79
+ vol1 = IC. DynamicVolume (; p_int = 0 , area= 0.01 , direction= + 1 )
80
+ vol2 = IC. DynamicVolume (; p_int = 0 , area= 0.01 , direction= - 1 , x_int= 1.0 )
81
+ mass = T. Mass (; m= 1000 , s_0= 0 )
82
+ res = IC. PipeBase (; p_int = 0 , area = 0.001 , length = 50.0 )
83
+ cap = IC. Cap (;p_int= 0 )
96
84
end
97
85
98
- eqs = [connect (stp. output, src_a . input, src_b . input)
99
- connect (src_a . port, res_a . port_a )
100
- connect (res_a . port_b, act_a . port )
101
- connect (src_b . port, res_b . port_a )
102
- connect (res_b . port_b, act_b . port )
103
- connect (act_a . flange, act_b . flange, m . flange )]
86
+ eqs = [ connect (stp. output, src . input)
87
+ connect (fluid, src . port, cap . port )
88
+ connect (src . port, res . port_a )
89
+ connect (res . port_b, vol1 . port )
90
+ connect (vol1 . flange, mass . flange, vol2 . flange )
91
+ connect (vol2 . port, cap . port )]
104
92
105
93
ODESystem (eqs, t, [], pars; name, systems)
106
94
end
107
95
108
- @named act_sys = actuator_system (; fluid_a = IC. water_20C)
109
- cc = structural_simplify (act_sys; allow_parameter = false )
110
-
111
- t_end = 0.5
112
- prob1 = ODEProblem (cc, [], (0 , t_end), [complete (act_sys). fluid_b => user_oil])
113
- prob2 = ODEProblem (cc, [], (0 , t_end))
114
-
115
- sol1 = solve (prob1, ImplicitEuler (nlsolve = NEWTON); adaptive = false , dt,
116
- initializealg = NoInit ())
117
- sol2 = solve (prob2, ImplicitEuler (nlsolve = NEWTON); adaptive = false , dt,
118
- initializealg = NoInit ())
119
-
120
- using GLMakie
121
- fig = Figure ()
122
- ax = Axis (fig[1 , 1 ])
123
- lines! (ax, sol1. t, sol1[act_sys. act_a. x]; color = :red )
124
- lines! (ax, sol1. t, sol1[act_sys. act_b. x]; color = :red , linestyle = :dash )
125
- lines! (ax, sol2. t, sol2[act_sys. act_a. x]; color = :blue )
126
- lines! (ax, sol2. t, sol2[act_sys. act_b. x]; color = :blue , linestyle = :dash )
127
-
128
- ax = Axis (fig[2 , 1 ])
129
- lines! (ax, sol1. t, (sol1[act_sys. act_a. port. p] .- sol1[act_sys. act_b. port. p]) / 1e5 ;
130
- color = :red )
131
- lines! (ax, sol2. t, (sol2[act_sys. act_a. port. p] .- sol2[act_sys. act_b. port. p]) / 1e5 ;
132
- color = :blue )
133
- fig
96
+ @named sys1 = system (; bulk_modulus= 1e9 )
97
+ @named sys2 = system (; bulk_modulus= 2e9 )
98
+
99
+ syss = structural_simplify .([sys1, sys2])
100
+ probs = [ODEProblem (sys, [], (0 , 0.2 )) for sys in syss];
101
+ dt = 1e-4
102
+ sols = [solve (prob, ImplicitEuler (nlsolve= NEWTON); adaptive= false , dt, initializealg= NoInit ()) for prob in probs];
103
+
104
+ s1 = complete (sys1)
105
+ s2 = complete (sys2)
106
+
107
+ # less stiff will compress more
108
+ @test maximum (sols[1 ][s1. mass. s]) > maximum (sols[2 ][s2. mass. s])
109
+
110
+
111
+ # fig = Figure()
112
+ # ax = Axis(fig[1,1])
113
+ # lines!(ax, sols[1].t, sols[1][s1.src.port.p]; label="sorce", color=:black)
114
+ # # lines!(ax, sols[2].t, sols[2][s1_1.src.port.p])
115
+ # scatterlines!(ax, sols[1].t, sols[1][s1.vol1.port.p]; label="bulk=1e9")
116
+ # scatterlines!(ax, sols[2].t, sols[2][s2.vol1.port.p]; label="bulk=2e9")
117
+ # Legend(fig[1,2], ax)
118
+ # fig
119
+
120
+
121
+ # fig = Figure()
122
+ # ax = Axis(fig[1,1])
123
+ # scatterlines!(ax, sols[1].t, sols[1][s1.mass.s]; label="bulk=1e9")
124
+ # scatterlines!(ax, sols[2].t, sols[2][s2.mass.s]; label="bulk=2e9")
125
+ # Legend(fig[1,2], ax)
126
+ # fig
127
+
128
+
129
+ # fig = Figure()
130
+ # ax = Axis(fig[1,1])
131
+ # lines!(ax, sols[1].t, sols[1][s1.vol1.dx]; label="bulk=2e9")
132
+ # lines!(ax, sols[1].t, sols[1][s1.vol2.dx]; label="bulk=2e9")
133
+ # lines!(ax, sols[1].t, sols[1][s1.mass.v]; label="bulk=2e9")
134
+ # Legend(fig[1,2], ax)
135
+ # fig
0 commit comments