From 7dd7cba9c70da83ca6503ce8bf2ede82c1d1ba48 Mon Sep 17 00:00:00 2001 From: matthew-kapp Date: Wed, 5 Mar 2025 12:26:48 +0200 Subject: [PATCH 01/12] Hydraulic library updated to use macros Changes include: - sources.jl - MassFlow(; name, p_int) - FixedPressure(; p, name) - Pressure(; name) --- .gitignore | 3 ++ .../IsothermalCompressible/sources.jl | 52 +++++++++++-------- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index 29126e47b..f93853bd4 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,6 @@ docs/site/ # committed for packages, but should be committed for applications that require a static # environment. Manifest.toml + + +src/Hydraulic/changes.md \ No newline at end of file diff --git a/src/Hydraulic/IsothermalCompressible/sources.jl b/src/Hydraulic/IsothermalCompressible/sources.jl index ee21959d7..07e0eacd6 100644 --- a/src/Hydraulic/IsothermalCompressible/sources.jl +++ b/src/Hydraulic/IsothermalCompressible/sources.jl @@ -8,20 +8,22 @@ Hydraulic mass flow input source - `port`: hydraulic port - `dm`: real input """ -@component function MassFlow(; name) - pars = [] +@mtkmodel MassFlow begin + + @parameters begin + end + + @variables begin + end - systems = @named begin + @components begin port = HydraulicPort() dm = RealInput() end - vars = [] - eqs = [ + @equations begin port.dm ~ -dm.u - ] - - ODESystem(eqs, t, vars, pars; name, systems) + end end """ @@ -35,22 +37,23 @@ Fixed pressure source # Connectors: - `port`: hydraulic port """ -@component function FixedPressure(; p, name) - pars = @parameters begin - p = p +@mtkmodel FixedPressure begin + + @parameters begin + p end - vars = [] + @variables begin + end - systems = @named begin + @components begin port = HydraulicPort() end - eqs = [ + @equations begin port.p ~ p - ] + end - ODESystem(eqs, t, vars, pars; name, systems) end @deprecate Source FixedPressure @@ -63,19 +66,22 @@ input pressure source - `port`: hydraulic port - `p`: real input """ -@component function Pressure(; name) - pars = [] - vars = [] +@mtkmodel Pressure begin + + @parameters begin + end - systems = @named begin + @variables begin + end + + @components begin port = HydraulicPort() p = RealInput() end - eqs = [ + @equations begin port.p ~ p.u - ] + end - ODESystem(eqs, t, vars, pars; name, systems) end @deprecate InputSource Pressure From 59432e6f5cfd61d3edf19b17d608e70b22d0be7b Mon Sep 17 00:00:00 2001 From: matthew-kapp Date: Wed, 5 Mar 2025 13:17:26 +0200 Subject: [PATCH 02/12] Hydraulic library updated to use macros Changes include: - sources.jl - MassFlow(; name, p_int) - FixedPressure(; p, name) - Pressure(; name) - components.jl - Cap(; p_int, name) - Open(; p_int, name) - --- .../IsothermalCompressible/components.jl | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/Hydraulic/IsothermalCompressible/components.jl b/src/Hydraulic/IsothermalCompressible/components.jl index be891ee4c..42fc47cf8 100644 --- a/src/Hydraulic/IsothermalCompressible/components.jl +++ b/src/Hydraulic/IsothermalCompressible/components.jl @@ -10,17 +10,24 @@ Caps a hydraulic port to prevent mass flow in or out. # Connectors: - `port`: hydraulic port """ -@component function Cap(; name) - vars = @variables p(t), [guess = 0] +@mtkmodel Cap begin - systems = @named begin + @parameters begin + end + + @variables begin + p(t), [guess = 0] + end + + @components begin port = HydraulicPort() end - eqs = [port.p ~ p - port.dm ~ 0] + @equations begin + port.p ~ p + port.dm ~ 0 + end - ODESystem(eqs, t, vars, []; name, systems) end """ @@ -34,22 +41,25 @@ Provides an "open" boundary condition for a hydraulic port such that mass flow ` # Connectors: - `port`: hydraulic port """ -@component function Open(; name) - pars = [] +@mtkmodel Open begin + + @parameters begin + end - vars = @variables begin + @variables begin p(t), [guess = 0] dm(t), [guess = 0] end - systems = @named begin + @components begin port = HydraulicPort() end - eqs = [port.p ~ p - port.dm ~ dm] + @equations begin + port.p ~ p + port.dm ~ dm + end - ODESystem(eqs, t, vars, pars; name, systems) end """ From 418c060412136caa73065b4c0bc503be21ec045c Mon Sep 17 00:00:00 2001 From: matthew-kapp Date: Wed, 5 Mar 2025 14:00:43 +0200 Subject: [PATCH 03/12] Hydraulic library updated to use macros Only non-breaking changes were made. Changes include: - sources.jl - MassFlow - FixedPressure - Pressure - components.jl - Cap - Open - FlowDivider - VolumeBase - FixedVolume - Volume The following were NOT changed, as the changes would be breaking: - components.jl - TubeBase - Tube - ValveBase - Valve - DynamicVolume - SpoolValve - SpoolValve2Way - Actuator --- .../IsothermalCompressible/components.jl | 128 +++++++++--------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/src/Hydraulic/IsothermalCompressible/components.jl b/src/Hydraulic/IsothermalCompressible/components.jl index 42fc47cf8..97c51f253 100644 --- a/src/Hydraulic/IsothermalCompressible/components.jl +++ b/src/Hydraulic/IsothermalCompressible/components.jl @@ -248,33 +248,33 @@ Reduces the flow from `port_a` to `port_b` by `n`. Useful for modeling parallel - `port_a`: full flow hydraulic port - `port_b`: part flow hydraulic port """ -@component function FlowDivider(; n, name) +@mtkmodel FlowDivider begin #TODO: assert n >= 1 - pars = @parameters begin + @parameters begin n = n end - vars = @variables begin + @variables begin dm_a(t), [guess = 0] dm_b(t), [guess = 0] end - systems = @named begin + @components begin port_a = HydraulicPort() port_b = HydraulicPort() open = Open() end - eqs = [connect(port_a, port_b, open.port) - dm_a ~ port_a.dm - dm_b ~ dm_a / n - open.dm ~ dm_a - dm_b # extra flow dumps into an open port - # port_b.dm ~ dm_b # divided flow goes to port_b - ] + @equations begin + connect(port_a, port_b, open.port) + dm_a ~ port_a.dm + dm_b ~ dm_a / n + open.dm ~ dm_a - dm_b # extra flow dumps into an open port + # port_b.dm ~ dm_b # divided flow goes to port_b + end - ODESystem(eqs, t, vars, pars; name, systems) end @component function ValveBase( @@ -367,18 +367,16 @@ Valve with `area` input and discharge coefficient `Cd` defined by https://en.wik ODESystem(eqs, t, vars, pars; name, systems) end -@component function VolumeBase(; area, dead_volume = 0, Χ1 = 1, Χ2 = 1, - name) - pars = @parameters begin +@mtkmodel VolumeBase begin + + @parameters begin area = area dead_volume = dead_volume + x1 = 1 + x2 = 1 end - systems = @named begin - port = HydraulicPort() - end - - vars = @variables begin + @variables begin x(t) dx(t), [guess = 0] rho(t), [guess = liquid_density(port)] @@ -386,17 +384,20 @@ end vol(t) end - # let - dm = port.dm - p = port.p + @components begin + port = HydraulicPort() + end - eqs = [vol ~ dead_volume + area * x - D(x) ~ dx - D(rho) ~ drho - rho ~ full_density(port, p) - dm ~ drho * vol * Χ1 + rho * area * dx * Χ2] + @equations begin + dm = port.dm + p = port.p + vol ~ dead_volume + area * x + D(x) ~ dx + D(rho) ~ drho + rho ~ full_density(port, p) + dm ~ drho * vol * Χ1 + rho * area * dx * Χ2 + end - ODESystem(eqs, t, vars, pars; name, systems) end """ @@ -410,29 +411,29 @@ Fixed fluid volume. # Connectors: - `port`: hydraulic port """ -@component function FixedVolume(; vol, name) - pars = @parameters begin - vol = vol - end +@mtkmodel FixedVolume begin - systems = @named begin - port = HydraulicPort(;) + @parameters begin + Volume end - vars = @variables begin + @variables begin rho(t), [guess = liquid_density(port)] drho(t), [guess = 0] end - # let - dm = port.dm - p = port.p + @components begin + port = HydraulicPort() + end - eqs = [D(rho) ~ drho - rho ~ full_density(port, p) - dm ~ drho * vol] + @equations begin + dm = port.dm + p = port.p + D(rho) ~ drho + rho ~ full_density(port, p) + dm ~ drho * vol + end - ODESystem(eqs, t, vars, pars; name, systems) end """ @@ -473,16 +474,14 @@ dm ────► │ │ area See also [`FixedVolume`](@ref), [`DynamicVolume`](@ref) """ -@component function Volume(; +@mtkmodel Volume begin - #parameters - area, - direction = +1, name) - pars = @parameters begin - area = area + @parameters begin + area + direction = +1 end - vars = @variables begin + @variables begin x(t) dx(t) p(t) @@ -492,28 +491,29 @@ See also [`FixedVolume`](@ref), [`DynamicVolume`](@ref) dm(t) end - systems = @named begin + @components begin port = HydraulicPort() flange = MechanicalPort() end - eqs = [ - # connectors - port.p ~ p - port.dm ~ dm - flange.v * direction ~ dx - flange.f * direction ~ -f + @equations begin + # connectors + port.p ~ p + port.dm ~ dm + flange.v * direction ~ dx + flange.f * direction ~ -f - # differentials - D(x) ~ dx - D(rho) ~ drho + # differentials + D(x) ~ dx + D(rho) ~ drho + + # physics + rho ~ liquid_density(port, p) + f ~ p * area + dm ~ drho * x * area + rho * dx * area + end - # physics - rho ~ liquid_density(port, p) - f ~ p * area - dm ~ drho * x * area + rho * dx * area] - ODESystem(eqs, t, vars, pars; name, systems, defaults = [rho => liquid_density(port)]) end """ From 82c6951872879ef48c37b8170764040c64421d3e Mon Sep 17 00:00:00 2001 From: matthew-kapp Date: Thu, 6 Mar 2025 15:06:20 +0200 Subject: [PATCH 04/12] gitignore reverted --- .gitignore | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index f93853bd4..21caefb64 100644 --- a/.gitignore +++ b/.gitignore @@ -21,7 +21,4 @@ docs/site/ # It records a fixed state of all packages used by the project. As such, it should not be # committed for packages, but should be committed for applications that require a static # environment. -Manifest.toml - - -src/Hydraulic/changes.md \ No newline at end of file +Manifest.toml \ No newline at end of file From 6fad3a0fbf305d2fc32396587068d50d7689c5ba Mon Sep 17 00:00:00 2001 From: matthew-kapp Date: Thu, 6 Mar 2025 15:16:53 +0200 Subject: [PATCH 05/12] reversible=false added to DynamicVolume in docstring --- src/Hydraulic/IsothermalCompressible/components.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Hydraulic/IsothermalCompressible/components.jl b/src/Hydraulic/IsothermalCompressible/components.jl index fac1e4af9..094cfb280 100644 --- a/src/Hydraulic/IsothermalCompressible/components.jl +++ b/src/Hydraulic/IsothermalCompressible/components.jl @@ -507,7 +507,7 @@ See also [`FixedVolume`](@ref), [`DynamicVolume`](@ref) end """ - DynamicVolume(N, add_inertia=true; area, x_int = 0, x_max, x_min = 0, x_damp = x_min, direction = +1, perimeter = 2 * sqrt(area * pi), shape_factor = 64, head_factor = 1, Cd = 1e2, Cd_reverse = Cd, name) +DynamicVolume(N, add_inertia=true, reversible=false; area, x_int = 0, x_max, x_min = 0, x_damp = x_min, direction = +1, perimeter = 2 * sqrt(area * pi), shape_factor = 64, head_factor = 1, Cd = 1e2, Cd_reverse = Cd, name) Volume with moving wall with `flange` connector for converting hydraulic energy to 1D mechanical. The `direction` argument aligns the mechanical port with the hydraulic port, useful when connecting two dynamic volumes together in oppsing directions to create an actuator. From 644d620ffbd383ef8b64aeef83c2f47de1933758 Mon Sep 17 00:00:00 2001 From: matthew-kapp Date: Fri, 7 Mar 2025 12:10:55 +0200 Subject: [PATCH 06/12] Implemented reviewer comments --- .gitignore | 2 +- .../IsothermalCompressible/components.jl | 30 +++++++++++-------- .../IsothermalCompressible/sources.jl | 15 ---------- 3 files changed, 19 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index 21caefb64..29126e47b 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,4 @@ docs/site/ # It records a fixed state of all packages used by the project. As such, it should not be # committed for packages, but should be committed for applications that require a static # environment. -Manifest.toml \ No newline at end of file +Manifest.toml diff --git a/src/Hydraulic/IsothermalCompressible/components.jl b/src/Hydraulic/IsothermalCompressible/components.jl index 094cfb280..0a320f112 100644 --- a/src/Hydraulic/IsothermalCompressible/components.jl +++ b/src/Hydraulic/IsothermalCompressible/components.jl @@ -9,9 +9,6 @@ Caps a hydraulic port to prevent mass flow in or out. """ @mtkmodel Cap begin - @parameters begin - end - @variables begin p(t), [guess = 0] end @@ -36,9 +33,6 @@ Provides an "open" boundary condition for a hydraulic port such that mass flow ` - `port`: hydraulic port """ @mtkmodel Open begin - - @parameters begin - end @variables begin p(t), [guess = 0] @@ -359,11 +353,14 @@ end @mtkmodel VolumeBase begin + @structural_parameters begin + x1 = 1 + x2 = 1 + end + @parameters begin area = area dead_volume = dead_volume - x1 = 1 - x2 = 1 end @variables begin @@ -404,7 +401,7 @@ Fixed fluid volume. @mtkmodel FixedVolume begin @parameters begin - Volume + vol end @variables begin @@ -416,9 +413,12 @@ Fixed fluid volume. port = HydraulicPort() end - @equations begin + begin dm = port.dm p = port.p + end + + @equations begin D(rho) ~ drho rho ~ full_density(port, p) dm ~ drho * vol @@ -427,7 +427,7 @@ Fixed fluid volume. end """ - Volume(; x, dx=0, p, drho=0, dm=0, area, direction = +1, name) + Volume(; x, dx=0, p, drho=0, dm=0, area, direction = 1, name) Volume with moving wall with `flange` connector for converting hydraulic energy to 1D mechanical. The `direction` argument aligns the mechanical port with the hydraulic port, useful when connecting two dynamic volumes together in oppsing directions to create an actuator. @@ -466,9 +466,12 @@ See also [`FixedVolume`](@ref), [`DynamicVolume`](@ref) """ @mtkmodel Volume begin + @structural_parameters begin + direction = 1 + end + @parameters begin area - direction = +1 end @variables begin @@ -503,6 +506,9 @@ See also [`FixedVolume`](@ref), [`DynamicVolume`](@ref) dm ~ drho * x * area + rho * dx * area end + @defaults begin + rho => liquid_density(port) + end end diff --git a/src/Hydraulic/IsothermalCompressible/sources.jl b/src/Hydraulic/IsothermalCompressible/sources.jl index 54d6ff38f..d8ccfacee 100644 --- a/src/Hydraulic/IsothermalCompressible/sources.jl +++ b/src/Hydraulic/IsothermalCompressible/sources.jl @@ -9,12 +9,6 @@ Hydraulic mass flow input source - `dm`: real input """ @mtkmodel MassFlow begin - - @parameters begin - end - - @variables begin - end @components begin port = HydraulicPort() @@ -43,9 +37,6 @@ Fixed pressure source p end - @variables begin - end - @components begin port = HydraulicPort() end @@ -68,12 +59,6 @@ input pressure source """ @mtkmodel Pressure begin - @parameters begin - end - - @variables begin - end - @components begin port = HydraulicPort() p = RealInput() From 7b0fbf9c75102862a140cb824440a5e73a0e0ef7 Mon Sep 17 00:00:00 2001 From: matthew-kapp Date: Fri, 7 Mar 2025 15:58:47 +0200 Subject: [PATCH 07/12] FixedVolume modified to remove free variables --- src/Hydraulic/IsothermalCompressible/components.jl | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/Hydraulic/IsothermalCompressible/components.jl b/src/Hydraulic/IsothermalCompressible/components.jl index 60461f521..383522003 100644 --- a/src/Hydraulic/IsothermalCompressible/components.jl +++ b/src/Hydraulic/IsothermalCompressible/components.jl @@ -423,15 +423,10 @@ Fixed fluid volume. port = HydraulicPort() end - begin - dm = port.dm - p = port.p - end - @equations begin D(rho) ~ drho - rho ~ full_density(port, p) - dm ~ drho * vol + rho ~ full_density(port, port.p) + port.dm ~ drho * vol end end From 449422472289d00dc756c4c6804405eb30da757f Mon Sep 17 00:00:00 2001 From: matthew-kapp Date: Fri, 7 Mar 2025 16:03:45 +0200 Subject: [PATCH 08/12] VolumeBase.structural_parameters: (x1,x2) changed to (X1,X2) - case sensitivity missed --- src/Hydraulic/IsothermalCompressible/components.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Hydraulic/IsothermalCompressible/components.jl b/src/Hydraulic/IsothermalCompressible/components.jl index 383522003..922c047de 100644 --- a/src/Hydraulic/IsothermalCompressible/components.jl +++ b/src/Hydraulic/IsothermalCompressible/components.jl @@ -364,8 +364,8 @@ end @mtkmodel VolumeBase begin @structural_parameters begin - x1 = 1 - x2 = 1 + X1 = 1 + X2 = 1 end @parameters begin From 21c6340c31145106ade97e3f059942e8e942cdd8 Mon Sep 17 00:00:00 2001 From: matthew-kapp Date: Fri, 7 Mar 2025 16:08:40 +0200 Subject: [PATCH 09/12] VolumeBase.structural_parameters: X changed to symbolic(X) --- src/Hydraulic/IsothermalCompressible/components.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Hydraulic/IsothermalCompressible/components.jl b/src/Hydraulic/IsothermalCompressible/components.jl index 922c047de..1329ffc22 100644 --- a/src/Hydraulic/IsothermalCompressible/components.jl +++ b/src/Hydraulic/IsothermalCompressible/components.jl @@ -364,8 +364,8 @@ end @mtkmodel VolumeBase begin @structural_parameters begin - X1 = 1 - X2 = 1 + Χ1 = 1 + Χ2 = 1 end @parameters begin From b65ded4a7e8c49e78215fc6a5e7d1ea346791a8f Mon Sep 17 00:00:00 2001 From: matthew-kapp Date: Tue, 11 Mar 2025 11:49:24 +0200 Subject: [PATCH 10/12] Symbolics pinned to v6.29.2 in Project.toml --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 3d8a35a1f..fd3079a5d 100644 --- a/Project.toml +++ b/Project.toml @@ -30,7 +30,7 @@ PreallocationTools = "0.4.23" SafeTestsets = "0.1" SciMLStructures = "1.4.2" SymbolicIndexingInterface = "0.3.28" -Symbolics = "6.14" +Symbolics = "=6.29.2" Test = "1" julia = "1.10" From e25b17cd578dec894fa623875917b0132d0c229a Mon Sep 17 00:00:00 2001 From: matthew-kapp Date: Tue, 11 Mar 2025 14:58:01 +0200 Subject: [PATCH 11/12] tests failing fixed --- .../IsothermalCompressible/components.jl | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/Hydraulic/IsothermalCompressible/components.jl b/src/Hydraulic/IsothermalCompressible/components.jl index 1329ffc22..f7512bc48 100644 --- a/src/Hydraulic/IsothermalCompressible/components.jl +++ b/src/Hydraulic/IsothermalCompressible/components.jl @@ -369,8 +369,12 @@ end end @parameters begin - area = area - dead_volume = dead_volume + area + dead_volume + end + + @components begin + port = HydraulicPort() end @variables begin @@ -381,18 +385,12 @@ end vol(t) end - @components begin - port = HydraulicPort() - end - @equations begin - dm = port.dm - p = port.p vol ~ dead_volume + area * x D(x) ~ dx D(rho) ~ drho - rho ~ full_density(port, p) - dm ~ drho * vol * Χ1 + rho * area * dx * Χ2 + rho ~ full_density(port, port.p) + port.dm ~ drho * vol * Χ1 + rho * area * dx * Χ2 end end @@ -414,15 +412,15 @@ Fixed fluid volume. vol end + @components begin + port = HydraulicPort(;) + end + @variables begin rho(t), [guess = liquid_density(port)] drho(t), [guess = 0] end - @components begin - port = HydraulicPort() - end - @equations begin D(rho) ~ drho rho ~ full_density(port, port.p) From f4088b533649d1343df2f4b360124dff0930dc74 Mon Sep 17 00:00:00 2001 From: matthew-kapp Date: Thu, 13 Mar 2025 19:36:00 +0200 Subject: [PATCH 12/12] Project.toml reverted --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index fd3079a5d..3d8a35a1f 100644 --- a/Project.toml +++ b/Project.toml @@ -30,7 +30,7 @@ PreallocationTools = "0.4.23" SafeTestsets = "0.1" SciMLStructures = "1.4.2" SymbolicIndexingInterface = "0.3.28" -Symbolics = "=6.29.2" +Symbolics = "6.14" Test = "1" julia = "1.10"