Skip to content

Commit 60b8c58

Browse files
committed
Working out Tests
Search for "Need Help" in isothermal_compressible.jl under Hydraulic/test
1 parent e9dc864 commit 60b8c58

File tree

2 files changed

+118
-138
lines changed

2 files changed

+118
-138
lines changed

src/Hydraulic/IsothermalCompressible/components.jl

Lines changed: 46 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,8 @@ Reduces the flow from `port_a` to `port_b` by `n`. Useful for modeling parallel
268268
ODESystem(eqs, t, vars, pars; name, systems)
269269
end
270270

271-
@component function ValveBase(reversible = false; minimum_area = 0,
272-
area_int, Cd, Cd_reverse = Cd, name)
271+
@component function ValveBase(reversible = false; minimum_area = 0, Cd, Cd_reverse = Cd, name)
273272
pars = @parameters begin
274-
area_int = area_int
275273
Cd = Cd
276274
Cd_reverse = Cd_reverse
277275
minimum_area = minimum_area
@@ -283,8 +281,8 @@ end
283281
end
284282

285283
vars = @variables begin
286-
area(t) = area_int
287-
y(t) = area_int
284+
area(t)
285+
y(t)
288286
end
289287

290288
# let
@@ -333,11 +331,10 @@ Valve with `area` input and discharge coefficient `Cd` defined by https://en.wik
333331
- `area`: real input setting the valve `area`. When `reversible = true`, negative input reverses flow direction, otherwise a floor of `minimum_area` is enforced.
334332
"""
335333
@component function Valve(reversible = false;
336-
area_int, Cd, Cd_reverse = Cd,
334+
Cd, Cd_reverse = Cd,
337335
minimum_area = 0,
338336
name)
339337
pars = @parameters begin
340-
area_int = area_int
341338
Cd = Cd
342339
Cd_reverse = Cd_reverse
343340
minimum_area = minimum_area
@@ -347,7 +344,7 @@ Valve with `area` input and discharge coefficient `Cd` defined by https://en.wik
347344
port_a = HydraulicPort()
348345
port_b = HydraulicPort()
349346
area = RealInput()
350-
base = ValveBase(reversible; area_int, Cd, Cd_reverse,
347+
base = ValveBase(reversible; Cd, Cd_reverse,
351348
minimum_area)
352349
end
353350

@@ -360,10 +357,9 @@ Valve with `area` input and discharge coefficient `Cd` defined by https://en.wik
360357
ODESystem(eqs, t, vars, pars; name, systems)
361358
end
362359

363-
@component function VolumeBase(; x_int = 0, area, dead_volume = 0, Χ1 = 1, Χ2 = 1,
364-
name)
360+
@component function VolumeBase(; area, dead_volume = 0, Χ1 = 1, Χ2 = 1,
361+
name) # x_int = 0,
365362
pars = @parameters begin
366-
x_int = x_int
367363
area = area
368364
dead_volume = dead_volume
369365
end
@@ -373,11 +369,11 @@ end
373369
end
374370

375371
vars = @variables begin
376-
x(t) = x_int
372+
x(t)
377373
dx(t), [guess=0]
378374
rho(t), [guess = liquid_density(port)]
379375
drho(t), [guess=0]
380-
vol(t) = dead_volume + area * x_int
376+
vol(t) # = dead_volume + area * x_int
381377
end
382378

383379
# let
@@ -468,12 +464,6 @@ dm ────► │ │ area
468464
See also [`FixedVolume`](@ref), [`DynamicVolume`](@ref)
469465
"""
470466
@component function Volume(;
471-
#initial conditions
472-
x,
473-
dx = 0,
474-
p,
475-
drho = 0,
476-
dm = 0,
477467

478468
#parameters
479469
area,
@@ -483,13 +473,13 @@ See also [`FixedVolume`](@ref), [`DynamicVolume`](@ref)
483473
end
484474

485475
vars = @variables begin
486-
x(t) = x
487-
dx(t) = dx
488-
p(t) = p
489-
f(t) = p * area
476+
x(t)
477+
dx(t)
478+
p(t)
479+
f(t)
490480
rho(t)
491-
drho(t) = drho
492-
dm(t) = dm
481+
drho(t)
482+
dm(t)
493483
end
494484

495485
systems = @named begin
@@ -539,9 +529,7 @@ dm ────► │ │ area
539529
540530
# Parameters:
541531
## volume
542-
- `p_int`: [Pa] initial pressure
543532
- `area`: [m^2] moving wall area
544-
- `x_int`: [m] initial wall position
545533
- `x_max`: [m] max wall position, needed for volume discretization to apply the correct volume sizing as a function of `x`
546534
- `x_min`: [m] wall position that shuts off flow and prevents negative volume.
547535
- `x_damp`: [m] wall position that initiates a linear damping region before reaching full flow shut off. Helps provide a smooth end stop.
@@ -563,9 +551,9 @@ dm ────► │ │ area
563551
- `flange`: mechanical translational port
564552
"""
565553
@component function DynamicVolume(N, add_inertia = true, reversible = false;
566-
p_int,
554+
# p_int,
567555
area,
568-
x_int = 0,
556+
# x_int = 0,
569557
x_max,
570558
x_min = 0,
571559
x_damp = x_min,
@@ -587,10 +575,10 @@ dm ────► │ │ area
587575

588576
#TODO: How to set an assert effective_length >= length ??
589577
pars = @parameters begin
590-
p_int = p_int
578+
# p_int = p_int
591579
area = area
592580

593-
x_int = x_int
581+
# x_int = x_int
594582
x_max = x_max
595583
x_min = x_min
596584
x_damp = x_damp
@@ -606,15 +594,12 @@ dm ────► │ │ area
606594
minimum_area = minimum_area
607595
end
608596

609-
vars = @variables x(t)=x_int vol(t)=x_int * area
597+
vars = @variables x(t) vol(t)
610598

611599
ports = @named begin
612-
port = HydraulicPort(; p_int)
613-
flange = MechanicalPort(; f = -direction * p_int * area)
600+
port = HydraulicPort(;)
601+
flange = MechanicalPort(;)
614602
damper = ValveBase(reversible;
615-
p_a_int = p_int,
616-
p_b_int = p_int,
617-
area_int = 1,
618603
Cd,
619604
Cd_reverse,
620605
minimum_area)
@@ -624,7 +609,7 @@ dm ────► │ │ area
624609
for i in 1:N
625610
comp = TubeBase(add_inertia; name = Symbol("p$i"),
626611
shape_factor = ParentScope(shape_factor),
627-
p_int = ParentScope(p_int), area = ParentScope(area),
612+
area = ParentScope(area),
628613
length_int = 0, #set in equations
629614
head_factor = ParentScope(head_factor),
630615
perimeter = ParentScope(perimeter))
@@ -634,12 +619,11 @@ dm ────► │ │ area
634619
#TODO: How to handle x_int?
635620
#TODO: Handle direction
636621
@named moving_volume = VolumeBase(;
637-
p_int,
638-
x_int = 0,
622+
# x_int = 0,
639623
area,
640-
dead_volume = N == 0 ? area * x_int : 0,
624+
dead_volume = N == 0 ? area * x_min : 0,
641625
Χ1 = N == 0 ? 1 : 0,
642-
Χ2 = 1)
626+
Χ2 = 1) # changed x_int to x_min
643627

644628
ratio = (x - x_min) / (x_damp - x_min)
645629

@@ -657,7 +641,7 @@ dm ────► │ │ area
657641
volumes = []
658642
if N > 0
659643
Δx = ParentScope(x_max) / N
660-
x₀ = ParentScope(x_int)
644+
x₀ = ParentScope(x) # x_int
661645

662646
for i in 1:N
663647
length = ifelse(x₀ > Δx * i,
@@ -666,8 +650,8 @@ dm ────► │ │ area
666650
x₀ - Δx * (i - 1),
667651
zero(Δx)))
668652

669-
comp = VolumeBase(; name = Symbol("v$i"), p_int = ParentScope(p_int),
670-
x_int = 0,
653+
comp = VolumeBase(; name = Symbol("v$i"),
654+
# x_int = 0,
671655
area = ParentScope(area),
672656
dead_volume = ParentScope(area) * length, Χ1 = 1, Χ2 = 0)
673657

@@ -720,25 +704,21 @@ Spool valve with `x` valve opening input as mechanical flange port and `d` diame
720704
721705
See [`Valve`](@ref) for more information.
722706
"""
723-
@component function SpoolValve(reversible = false; p_a_int, p_b_int, x_int, Cd, d, name)
707+
@component function SpoolValve(reversible = false; Cd, d, name)
724708
pars = @parameters begin
725-
p_a_int = p_a_int
726-
p_b_int = p_b_int
727709
d = d
728-
x_int = x_int
729710
Cd = Cd
730711
end
731712

732713
systems = @named begin
733-
port_a = HydraulicPort(; p_int = p_a_int)
734-
port_b = HydraulicPort(; p_int = p_b_int)
714+
port_a = HydraulicPort(; )
715+
port_b = HydraulicPort(; )
735716
flange = MechanicalPort()
736-
valve = ValveBase(reversible; p_a_int, p_b_int,
737-
area_int = ParentScope(x_int) * 2π * ParentScope(d), Cd)
717+
valve = ValveBase(reversible; Cd)
738718
end
739719

740720
vars = @variables begin
741-
x(t) = x_int
721+
x(t)
742722
dx(t)
743723
end
744724

@@ -777,19 +757,12 @@ end
777757
778758
See [`SpoolValve`](@ref) for more information.
779759
"""
780-
@component function SpoolValve2Way(reversible = false; p_s_int, p_a_int, p_b_int, p_r_int,
781-
m, g, x_int, Cd, d, name)
760+
@component function SpoolValve2Way(reversible = false; m, g, Cd, d, name)
782761
pars = @parameters begin
783-
p_s_int = p_s_int
784-
p_a_int = p_a_int
785-
p_b_int = p_b_int
786-
p_r_int = p_r_int
787762

788763
m = m
789764
g = g
790765

791-
x_int = x_int
792-
793766
d = d
794767

795768
Cd = Cd
@@ -798,13 +771,13 @@ See [`SpoolValve`](@ref) for more information.
798771
vars = []
799772

800773
systems = @named begin
801-
vSA = SpoolValve(reversible; p_a_int = p_s_int, p_b_int = p_a_int, x_int, Cd, d)
802-
vBR = SpoolValve(reversible; p_a_int = p_b_int, p_b_int = p_r_int, x_int, Cd, d)
774+
vSA = SpoolValve(reversible; Cd, d)
775+
vBR = SpoolValve(reversible; Cd, d)
803776

804-
port_s = HydraulicPort(; p_int = p_s_int)
805-
port_a = HydraulicPort(; p_int = p_a_int)
806-
port_b = HydraulicPort(; p_int = p_b_int)
807-
port_r = HydraulicPort(; p_int = p_r_int)
777+
port_s = HydraulicPort(; )
778+
port_a = HydraulicPort(; )
779+
port_b = HydraulicPort(; )
780+
port_r = HydraulicPort(; )
808781

809782
mass = Mass(; m = m, g = g)
810783

@@ -888,21 +861,17 @@ Actuator made of two DynamicVolumes connected in opposite direction with body ma
888861
- `flange`: mechanical translational port
889862
"""
890863
@component function Actuator(N, add_inertia = true, reversible = false;
891-
p_a_int,
892-
p_b_int,
864+
total_length,
893865
area_a,
894866
area_b,
895867
perimeter_a = 2 * sqrt(area_a * pi),
896868
perimeter_b = 2 * sqrt(area_b * pi),
897-
length_a_int,
898-
length_b_int,
899869
shape_factor_a = 64,
900870
shape_factor_b = 64,
901871
head_factor_a = 1,
902872
head_factor_b = 1,
903873
m,
904874
g,
905-
x_int = 0,
906875
minimum_volume_a = 0,
907876
minimum_volume_b = 0,
908877
damping_volume_a = minimum_volume_a,
@@ -911,8 +880,6 @@ Actuator made of two DynamicVolumes connected in opposite direction with body ma
911880
Cd_reverse = Cd,
912881
name)
913882
pars = @parameters begin
914-
p_a_int = p_a_int
915-
p_b_int = p_b_int
916883
area_a = area_a
917884
area_b = area_b
918885
perimeter_a = perimeter_a
@@ -921,9 +888,6 @@ Actuator made of two DynamicVolumes connected in opposite direction with body ma
921888
shape_factor_b = shape_factor_b
922889
head_factor_a = head_factor_a
923890
head_factor_b = head_factor_b
924-
x_int = x_int
925-
length_a_int = length_a_int
926-
length_b_int = length_b_int
927891
minimum_volume_a = minimum_volume_a
928892
minimum_volume_b = minimum_volume_b
929893
damping_volume_a = damping_volume_a
@@ -935,18 +899,16 @@ Actuator made of two DynamicVolumes connected in opposite direction with body ma
935899
end
936900

937901
vars = @variables begin
938-
x(t) = x_int
902+
x(t)
939903
dx(t)
940904
end
941905

942-
total_length = length_a_int + length_b_int
906+
# total_length = length_a_int + length_b_int # Need parameters to define the total length.
943907

944908
#TODO: include effective_length
945909
systems = @named begin
946910
vol_a = DynamicVolume(N, add_inertia, reversible; direction = +1,
947-
p_int = p_a_int,
948911
area = area_a,
949-
x_int = length_a_int,
950912
x_max = total_length,
951913
x_min = minimum_volume_a / area_a,
952914
x_damp = damping_volume_a / area_a,
@@ -957,9 +919,7 @@ Actuator made of two DynamicVolumes connected in opposite direction with body ma
957919
Cd_reverse)
958920

959921
vol_b = DynamicVolume(N, add_inertia, reversible; direction = -1,
960-
p_int = p_b_int,
961922
area = area_b,
962-
x_int = length_b_int,
963923
x_max = total_length,
964924
x_min = minimum_volume_b / area_b,
965925
x_damp = damping_volume_b / area_b,
@@ -969,8 +929,8 @@ Actuator made of two DynamicVolumes connected in opposite direction with body ma
969929
Cd,
970930
Cd_reverse)
971931
mass = Mass(; m, g)
972-
port_a = HydraulicPort(; p_int = p_a_int)
973-
port_b = HydraulicPort(; p_int = p_b_int)
932+
port_a = HydraulicPort(; )
933+
port_b = HydraulicPort(; )
974934
flange = MechanicalPort()
975935
end
976936

0 commit comments

Comments
 (0)