Skip to content

Commit 882d3f2

Browse files
committed
MTK9 Initialization Updates
Removed references to p_int and started debugging the first Hydraulics test case (Fluid Domain and Tube)
1 parent 5f5a29c commit 882d3f2

File tree

3 files changed

+127
-37
lines changed

3 files changed

+127
-37
lines changed

src/Hydraulic/IsothermalCompressible/components.jl

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Provides an "open" boundary condition for a hydraulic port such that mass flow `
5454
end
5555

5656
"""
57-
TubeBase(add_inertia = true; p_int, area, length_int, head_factor = 1, perimeter = 2 * sqrt(area * pi), shape_factor = 64, name)
57+
TubeBase(add_inertia = true; area, length_int, head_factor = 1, perimeter = 2 * sqrt(area * pi), shape_factor = 64, name)
5858
5959
Variable length internal flow model of the fully developed incompressible flow friction. Includes optional inertia term when `add_inertia = true` to model wave propagation. Hydraulic ports have equal flow but variable pressure. Density is averaged over the pressures, used to calculated average flow velocity and flow friction.
6060
@@ -63,7 +63,6 @@ Variable length internal flow model of the fully developed incompressible flow f
6363
- `ddm`: [kg/s^2] Rate of change of mass flow rate in control volume.
6464
6565
# Parameters:
66-
- `p_int`: [Pa] initial pressure
6766
- `area`: [m^2] tube cross sectional area
6867
- `length_int`: [m] initial tube length
6968
- `perimeter`: [m] perimeter of the pipe cross section (needed only for non-circular pipes)
@@ -145,12 +144,11 @@ Variable length internal flow model of the fully developed incompressible flow f
145144
end
146145

147146
"""
148-
Tube(N, add_inertia=true; p_int, area, length, head_factor=1, perimeter = 2 * sqrt(area * pi), shape_factor = 64, name)
147+
Tube(N, add_inertia=true; area, length, head_factor=1, perimeter = 2 * sqrt(area * pi), shape_factor = 64, name)
149148
150149
Constant length internal flow model discretized by `N` (`FixedVolume`: `N`, `TubeBase`:`N-1`) which models the fully developed flow friction, compressibility (when `N>1`), and inertia effects when `add_inertia = true`. See `TubeBase` and `FixedVolume` for more information.
151150
152151
# Parameters:
153-
- `p_int`: [Pa] initial pressure
154152
- `area`: [m^2] tube cross sectional area
155153
- `length`: [m] real length of the tube
156154
- `perimeter`: [m] perimeter of the pipe cross section (needed only for non-circular pipes)
@@ -198,7 +196,7 @@ Constant length internal flow model discretized by `N` (`FixedVolume`: `N`, `Tub
198196
for i in 1:(N - 1)
199197
x = TubeBase(add_inertia; name = Symbol("p$i"),
200198
shape_factor = ParentScope(shape_factor),
201-
p_int = ParentScope(p_int), area = ParentScope(area),
199+
area = ParentScope(area),
202200
length_int = ParentScope(length) / (N - 1),
203201
head_factor = ParentScope(head_factor),
204202
perimeter = ParentScope(perimeter))
@@ -208,8 +206,7 @@ Constant length internal flow model discretized by `N` (`FixedVolume`: `N`, `Tub
208206
volumes = []
209207
for i in 1:N
210208
x = FixedVolume(; name = Symbol("v$i"),
211-
vol = ParentScope(area) * ParentScope(length) / N,
212-
p_int = ParentScope(p_int))
209+
vol = ParentScope(area) * ParentScope(length) / N)
213210
push!(volumes, x)
214211
end
215212

@@ -397,29 +394,27 @@ end
397394
end
398395

399396
"""
400-
FixedVolume(; vol, p_int, name)
397+
FixedVolume(; vol, name)
401398
402399
Fixed fluid volume.
403400
404401
# Parameters:
405402
- `vol`: [m^3] fixed volume
406-
- `p_int`: [Pa] initial pressure
407403
408404
# Connectors:
409405
- `port`: hydraulic port
410406
"""
411-
@component function FixedVolume(; vol, p_int, name)
407+
@component function FixedVolume(; vol, name)
412408
pars = @parameters begin
413-
p_int = p_int
414409
vol = vol
415410
end
416411

417412
systems = @named begin
418-
port = HydraulicPort(; p_int)
413+
port = HydraulicPort(;)
419414
end
420415

421416
vars = @variables begin
422-
rho(t), [guess = liquid_density(port)]
417+
rho(t)#, [guess = liquid_density(port)]
423418
drho(t), [guess = 0]
424419
end
425420

src/Hydraulic/IsothermalCompressible/sources.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,10 @@ end
5555
@deprecate Source FixedPressure
5656

5757
"""
58-
Pressure(; p_int, name)
58+
Pressure(; name)
5959
6060
input pressure source
6161
62-
# Parameters:
63-
- `p_int`: [Pa] initial pressure (set by `p_int` argument)
64-
6562
# Connectors:
6663
- `port`: hydraulic port
6764
- `p`: real input

test/Hydraulic/isothermal_compressible.jl

Lines changed: 118 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ using ModelingToolkitStandardLibrary.Blocks: Parameter
88

99
NEWTON = NLNewton(check_div = false, always_new = true, max_iter = 100, relax = 9 // 10)
1010

11-
@testset "Fluid Domain and Tube" begin
11+
#@testset "Fluid Domain and Tube" begin
1212
function System(N; bulk_modulus, name)
1313
pars = @parameters begin
1414
bulk_modulus = bulk_modulus
1515
end
1616

1717
systems = @named begin
1818
fluid = IC.HydraulicFluid(; bulk_modulus)
19-
stp = B.Step(; height = 10e5, offset = 0, start_time = 0.005, duration = Inf,
19+
stp = B.Step(; height = 2*101325, offset = 101325, start_time = 0.05, duration = Inf,
2020
smooth = true)
21-
src = IC.Pressure(; p_int = 0)
22-
vol = IC.FixedVolume(; p_int = 0, vol = 10.0)
23-
res = IC.Tube(N; p_int = 0, area = 0.01, length = 50.0)
21+
src = IC.Pressure(;)
22+
vol = IC.FixedVolume(; vol = 10.0)
23+
res = IC.Tube(N; area = 0.01, length = 50.0)
2424
end
2525

2626
eqs = [connect(stp.output, src.p)
@@ -32,35 +32,84 @@ NEWTON = NLNewton(check_div = false, always_new = true, max_iter = 100, relax =
3232
end
3333

3434
@named sys1_2 = System(1; bulk_modulus = 2e9)
35-
@named sys1_1 = System(1; bulk_modulus = 1e9)
35+
@named sys1_1 = System(1; bulk_modulus = 1e7)
3636
@named sys5_1 = System(5; bulk_modulus = 1e9)
3737

38-
syss = structural_simplify.([sys1_2, sys1_1, sys5_1])
39-
probs = [ODEProblem(sys, ModelingToolkit.missing_variable_defaults(sys), (0, 0.05))
40-
for sys in syss] #
41-
sols = [solve(prob, ImplicitEuler(nlsolve = NEWTON); initializealg = NoInit(),
42-
dt = 1e-4, adaptive = false)
43-
for prob in probs]
38+
# syss = structural_simplify.([sys1_2, sys1_1, sys5_1])
4439

45-
s1_2 = complete(sys1_2)
40+
# system 1_1
41+
sys1_1 = structural_simplify(sys1_1)
42+
initialization_eqs = [sys1_1.vol.port.p ~ 101325, sys1_1.res.port_a.dm ~ 0]
43+
initsys1_1 = ModelingToolkit.generate_initializesystem(sys1_1;initialization_eqs)
44+
# here the structural_simplify of the initialization system fails, this is an indication that something needs to be fixed with the way the defaults/initial equaitons are defined
45+
46+
initsys1_1 = structural_simplify(initsys1_1)
47+
initprob1_1 = NonlinearProblem(initsys1_1, [t=>0])
48+
initsol1_1 = solve(initprob1_1)
49+
initsol1_1[sys.src.port.p]
50+
initsol1_1[sys.src.port.dm]
51+
initsol1_1[sys.vol.port.p]
52+
# probs = [ODEProblem(sys, ModelingToolkit.missing_variable_defaults(sys), (0, 0.05))
53+
# for sys in syss] #
54+
prob1_1 = ODEProblem(sys1_1, ModelingToolkit.missing_variable_defaults(sys), (0, 1.05))
55+
#
56+
57+
# sols = [solve(prob, ImplicitEuler(nlsolve = NEWTON); dt = 1e-4, adaptive = false)
58+
# for prob in probs]
59+
60+
sol1_1 = solve(prob1_1, ImplicitEuler(nlsolve = NEWTON); dt = 1e-4, adaptive = false)
61+
62+
# s1_2 = complete(sys1_2)
4663
s1_1 = complete(sys1_1)
64+
# s5_1 = complete(sys5_1)
65+
66+
# system 1_2
67+
sys1_2 = structural_simplify(sys1_2)
68+
initialization_eqs = [sys1_2.vol.port.p ~ 101800, sys1_2.res.port_a.dm ~ 0]
69+
initsys1_2 = ModelingToolkit.generate_initializesystem(sys1_2;initialization_eqs)
70+
71+
initsys1_2 = structural_simplify(initsys1_2)
72+
initprob1_2 = NonlinearProblem(initsys1_2, [t=>0])
73+
initsol1_2 = solve(initprob1_2)
74+
75+
prob1_2 = ODEProblem(sys1_2, ModelingToolkit.missing_variable_defaults(sys), (0, 1.05))
76+
sol1_2 = solve(prob1_2, ImplicitEuler(nlsolve = NEWTON); dt = 1e-4, adaptive = false)
77+
s1_2 = complete(sys1_2)
78+
# system 5-1
79+
80+
sys5_1 = structural_simplify(sys5_1)
81+
initialization_eqs = [sys5_1.vol.port.p ~ 101325,sys5_1.res.p1.port_a.dm ~ 0,
82+
sys5_1.res.p2.port_a.dm ~ 0,sys5_1.res.p3.port_a.dm ~ 0, sys5_1.res.p4.port_a.dm ~ 0,
83+
sys5_1.res.p1.port_a.p ~ 101325,
84+
sys5_1.res.p2.port_a.p ~ 101325,
85+
sys5_1.src.port.dm~0]
86+
initsys5_1 = ModelingToolkit.generate_initializesystem(sys5_1;initialization_eqs)
87+
88+
initsys5_1 = structural_simplify(initsys5_1)
89+
initprob5_1 = NonlinearProblem(initsys5_1, [t=>0])
90+
initsol5_1 = solve(initprob5_1)
91+
92+
prob5_1 = ODEProblem(sys5_1, ModelingToolkit.missing_variable_defaults(sys), (0, 0.05))
93+
sol5_1 = solve(prob5_1, ImplicitEuler(nlsolve = NEWTON); dt = 1e-4, adaptive = false)
4794
s5_1 = complete(sys5_1)
4895

4996
# higher stiffness should compress more quickly and give a higher pressure
50-
@test sols[1][s1_2.vol.port.p][end] > sols[2][s1_1.vol.port.p][end]
97+
# @test sols[1][s1_2.vol.port.p][end] > sols[2][s1_1.vol.port.p][end]
5198

5299
# N=5 pipe is compressible, will pressurize more slowly
53100
@test sols[2][s1_1.vol.port.p][end] > sols[3][s5_1.vol.port.p][end]
54101

55-
# fig = Figure()
56-
# ax = Axis(fig[1,1])
57-
# # hlines!(ax, 10e5)
58-
# lines!(ax, sols[1][s1_2.vol.port.p])
102+
fig = Figure()
103+
ax = Axis(fig[1,1])
104+
# hlines!(ax, 10e5)
105+
# lines!(ax, sols[1][s1_2.vol.port.p])
59106
# lines!(ax, sols[2][s1_1.vol.port.p])
60107
# lines!(ax, sols[3][s5_1.vol.port.p])
61-
# fig
108+
lines!(ax, sol1_1[s1_1.vol.rho])
109+
lines!(ax, sol1_2[s1_2.vol.rho])
110+
fig
62111

63-
end
112+
#end
64113

65114
@testset "Valve" begin
66115
function System(; name)
@@ -353,4 +402,53 @@ end
353402
# fig
354403
end
355404

405+
@testset "Component Flow Reversals" begin
406+
# Check Component Flow Reversals
407+
function System(; name)
408+
pars = []
409+
410+
systems = @named begin
411+
fluid = IC.HydraulicFluid()
412+
source = IC.Pressure()
413+
sink = IC.FixedPressure(; p = 101325)
414+
pipe = IC.Tube(1, false; area = 0.1, length =.1, head_factor = 1)
415+
osc = Sine(; frequency = 0.01, amplitude = 100, offset = 101325)
416+
end
417+
418+
eqs = [connect(fluid, pipe.port_a)
419+
connect(source.port, pipe.port_a)
420+
connect(pipe.port_b, sink.port)
421+
connect(osc.output, source.p)]
422+
423+
ODESystem(eqs, t, [], []; systems)
424+
end
425+
426+
@named sys = System()
427+
428+
syss = structural_simplify.([sys])
429+
tspan = (0.0, 1000.0)
430+
prob = ODEProblem(sys, tspan) # u0 guess can be supplied or not
431+
@time sol = solve(prob)
432+
433+
end
434+
435+
@testset "Tube Discretization" begin
436+
# Check Tube Discretization
437+
end
438+
439+
@testset "Pressure BC" begin
440+
# Ensure Pressure Boundary Condition Works
441+
end
442+
443+
@testset "Massflow BC" begin
444+
# Ensure Massflow Boundary Condition Works
445+
end
446+
447+
@testset "Splitter Flow Test" begin
448+
# Ensure FlowDivider Splits Flow Properly
449+
# 1) Set flow into port A, expect reduction in port B
450+
451+
# 2) Set flow into port B, expect increase in port B
452+
end
453+
356454
#TODO: Test Valve Inversion

0 commit comments

Comments
 (0)