From fb90653cdb0f1264943fd4dfb2457bed5c434321 Mon Sep 17 00:00:00 2001 From: matthew-kapp Date: Wed, 5 Mar 2025 16:56:03 +0200 Subject: [PATCH 1/6] unit removed from VariableResistor - all tests pass now --- src/Electrical/Analog/ideal_components.jl | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Electrical/Analog/ideal_components.jl b/src/Electrical/Analog/ideal_components.jl index a4896446d..ef3775727 100644 --- a/src/Electrical/Analog/ideal_components.jl +++ b/src/Electrical/Analog/ideal_components.jl @@ -391,11 +391,9 @@ R = R_const + pos * R_ref * (1 + alpha * (port.T - T_ref)) end @parameters begin - R_ref = 1.0, - [description = "Resistance at temperature T_ref when fully closed (pos=1.0)", - unit = "Ω"] - T_ref = 300.15, [description = "Reference temperature", unit = "K"] - R_const = 1e-3, [description = "Constant resistance between p and n", unit = "Ω"] + R_ref = 1.0, [description = "Resistance at temperature T_ref when fully closed (pos=1.0) (Ω)"] + T_ref = 300.15, [description = "Reference temperature (K)"] + R_const = 1e-3, [description = "Constant resistance between p and n (Ω)"] end @components begin @@ -404,13 +402,13 @@ R = R_const + pos * R_ref * (1 + alpha * (port.T - T_ref)) @variables begin pos(t), [description = "Position of the wiper (normally 0-1)"] - R(t), [description = "Resistance", unit = "Ω"] + R(t), [description = "Resistance (Ω)"] end if T_dep @parameters begin alpha = 1e-3, - [description = "Temperature coefficient of resistance", unit = "K^-1"] + [description = "Temperature coefficient of resistance (K^-1)"] end @components begin port = HeatPort() From 7e01d58cb08f0d053efb1c63df8cc3eaf1c8cf77 Mon Sep 17 00:00:00 2001 From: matthew-kapp Date: Wed, 5 Mar 2025 19:52:05 +0200 Subject: [PATCH 2/6] Reopen PR #362 --- docs/src/assets/Project.toml | 22 ++++++++++++ .../IsothermalCompressible/components.jl | 36 ++++--------------- .../IsothermalCompressible/sources.jl | 2 +- src/Hydraulic/IsothermalCompressible/utils.jl | 6 +--- 4 files changed, 31 insertions(+), 35 deletions(-) create mode 100644 docs/src/assets/Project.toml diff --git a/docs/src/assets/Project.toml b/docs/src/assets/Project.toml new file mode 100644 index 000000000..e6c6be7c7 --- /dev/null +++ b/docs/src/assets/Project.toml @@ -0,0 +1,22 @@ +[deps] +ControlSystemsBase = "aaaaaaaa-a6ca-5380-bf3e-84a91bcd477e" +DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" +DataInterpolations = "82cc6244-b520-54b8-b5a6-8a565e85f1d0" +DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa" +Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" +IfElse = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173" +ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78" +ModelingToolkitStandardLibrary = "16a59e39-deab-5bd0-87e4-056b12336739" +OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" +Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" + +[compat] +ControlSystemsBase = "1.1" +DataFrames = "1.7" +DataInterpolations = "6.4, 7" +DifferentialEquations = "7.6" +Documenter = "1" +IfElse = "0.1" +ModelingToolkit = "9" +OrdinaryDiffEq = "6.31" +Plots = "1.36" diff --git a/src/Hydraulic/IsothermalCompressible/components.jl b/src/Hydraulic/IsothermalCompressible/components.jl index be891ee4c..1ca63150c 100644 --- a/src/Hydraulic/IsothermalCompressible/components.jl +++ b/src/Hydraulic/IsothermalCompressible/components.jl @@ -1,12 +1,9 @@ """ - Cap(; p_int, name) + Cap(; name) Caps a hydraulic port to prevent mass flow in or out. -# Parameters: -- `p_int`: [Pa] initial pressure (set by `p_int` argument) - # Connectors: - `port`: hydraulic port """ @@ -24,13 +21,10 @@ Caps a hydraulic port to prevent mass flow in or out. end """ - Open(; p_int, name) + Open(; name) Provides an "open" boundary condition for a hydraulic port such that mass flow `dm` is non-zero. This is opposite from an un-connected hydraulic port or the `Cap` boundary component which sets the mass flow `dm` to zero. -# Parameters: -- `p_int`: [Pa] initial pressure (set by `p_int` argument) - # Connectors: - `port`: hydraulic port """ @@ -226,12 +220,11 @@ end @deprecate Pipe Tube """ - FlowDivider(;p_int, n, name) + FlowDivider(; n, name) Reduces the flow from `port_a` to `port_b` by `n`. Useful for modeling parallel tubes efficiently by placing a `FlowDivider` on each end of a tube. # Parameters: -- `p_int`: [Pa] initial pressure - `n`: divide flow from `port_a` to `port_b` by `n` # Connectors: @@ -313,14 +306,11 @@ end end """ - Valve(reversible = false; p_a_int, p_b_int, area_int, Cd, Cd_reverse = Cd, minimum_area = 0, name) + Valve(reversible = false; Cd, Cd_reverse = Cd, minimum_area = 0, name) Valve with `area` input and discharge coefficient `Cd` defined by https://en.wikipedia.org/wiki/Discharge_coefficient. The `Cd_reverse` parameter allows for directional flow restriction, making it possible to define a check valve. # Parameters: -- `p_a_int`: [Pa] initial pressure for `port_a` -- `p_b_int`: [Pa] initial pressure for `port_b` -- `area_int`: [m^2] initial valve opening - `Cd`: discharge coefficient flowing from `a → b` - `Cd_reverse`: discharge coefficient flowing from `b → a` - `minimum_area`: when `reversible = false` applies a forced minimum area @@ -507,7 +497,7 @@ See also [`FixedVolume`](@ref), [`DynamicVolume`](@ref) end """ - DynamicVolume(N, add_inertia=true; p_int, 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; 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. @@ -680,14 +670,11 @@ dm ────► │ │ area end """ - SpoolValve(reversible = false; p_a_int, p_b_int, x_int, Cd, d, name) + SpoolValve(reversible = false; Cd, d, name) Spool valve with `x` valve opening input as mechanical flange port and `d` diameter of orifice. See `Valve` for more information. # Parameters: -- `p_a_int`: [Pa] initial pressure for `port_a` -- `p_b_int`: [Pa] initial pressure for `port_b` -- `x_int`: [m] initial valve opening - `d`: [m] orifice diameter - `Cd`: discharge coefficient flowing from `a → b` @@ -727,18 +714,13 @@ See [`Valve`](@ref) for more information. end """ - SpoolValve2Way(reversible = false; p_s_int, p_a_int, p_b_int, p_r_int, m, g, x_int, Cd, d, name) + SpoolValve2Way(reversible = false; m, g, Cd, d, name) 2-ways spool valve with 4 ports and spool mass. Fluid flow direction S → A and B → R when `x` is positive and S → B and A → R when `x` is negative. # Parameters: -- `p_s_int`: [Pa] initial pressure for `port_s` -- `p_a_int`: [Pa] initial pressure for `port_a` -- `p_b_int`: [Pa] initial pressure for `port_b` -- `p_r_int`: [Pa] initial pressure for `port_r` - `m`: [kg] mass of the spool - `g`: [m/s²] gravity field acting on the spool, positive value acts in the positive direction -- `x_int`: [m] initial valve opening - `d`: [m] orifice diameter - `Cd`: discharge coefficient flowing from `s → a` and `b → r` @@ -788,8 +770,6 @@ end """ Actuator(N, add_inertia = true, reversible = false; - p_a_int, - p_b_int, area_a, area_b, perimeter_a = 2 * sqrt(area_a * pi), @@ -819,8 +799,6 @@ Actuator made of two DynamicVolumes connected in opposite direction with body ma # Parameters: ## volume -- `p_a_int`: [Pa] initial pressure for `port_a` -- `p_b_int`: [Pa] initial pressure for `port_b` - `area_a`: [m^2] moving wall area of volume `A` - `area_b`: [m^2] moving wall area of volume `B` - `length_a_int`: [m] initial wall position for `A` diff --git a/src/Hydraulic/IsothermalCompressible/sources.jl b/src/Hydraulic/IsothermalCompressible/sources.jl index ee21959d7..d5d64f5f3 100644 --- a/src/Hydraulic/IsothermalCompressible/sources.jl +++ b/src/Hydraulic/IsothermalCompressible/sources.jl @@ -1,5 +1,5 @@ """ - MassFlow(; name, p_int) + MassFlow(; name) Hydraulic mass flow input source diff --git a/src/Hydraulic/IsothermalCompressible/utils.jl b/src/Hydraulic/IsothermalCompressible/utils.jl index 425686d1f..165c6adc1 100644 --- a/src/Hydraulic/IsothermalCompressible/utils.jl +++ b/src/Hydraulic/IsothermalCompressible/utils.jl @@ -4,14 +4,10 @@ regPow(x, a, delta = 0.01) = x * (x * x + delta * delta)^((a - 1) / 2); regRoot(x, delta = 0.01) = regPow(x, 0.5, delta) """ - HydraulicPort(;p_int, name) + HydraulicPort(; name) Connector port for hydraulic components. -# Arguments: - -- `p_int`: [Pa] initial gauge pressure - # States: - `p`: [Pa] gauge total pressure - `dm`: [kg/s] mass flow From ab660cef22d844d99aae31db8fb74a55ab45272f Mon Sep 17 00:00:00 2001 From: matthew-kapp Date: Wed, 5 Mar 2025 20:11:30 +0200 Subject: [PATCH 3/6] Revert "unit removed from VariableResistor - all tests pass now" This reverts commit fb90653cdb0f1264943fd4dfb2457bed5c434321. --- src/Electrical/Analog/ideal_components.jl | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Electrical/Analog/ideal_components.jl b/src/Electrical/Analog/ideal_components.jl index ef3775727..a4896446d 100644 --- a/src/Electrical/Analog/ideal_components.jl +++ b/src/Electrical/Analog/ideal_components.jl @@ -391,9 +391,11 @@ R = R_const + pos * R_ref * (1 + alpha * (port.T - T_ref)) end @parameters begin - R_ref = 1.0, [description = "Resistance at temperature T_ref when fully closed (pos=1.0) (Ω)"] - T_ref = 300.15, [description = "Reference temperature (K)"] - R_const = 1e-3, [description = "Constant resistance between p and n (Ω)"] + R_ref = 1.0, + [description = "Resistance at temperature T_ref when fully closed (pos=1.0)", + unit = "Ω"] + T_ref = 300.15, [description = "Reference temperature", unit = "K"] + R_const = 1e-3, [description = "Constant resistance between p and n", unit = "Ω"] end @components begin @@ -402,13 +404,13 @@ R = R_const + pos * R_ref * (1 + alpha * (port.T - T_ref)) @variables begin pos(t), [description = "Position of the wiper (normally 0-1)"] - R(t), [description = "Resistance (Ω)"] + R(t), [description = "Resistance", unit = "Ω"] end if T_dep @parameters begin alpha = 1e-3, - [description = "Temperature coefficient of resistance (K^-1)"] + [description = "Temperature coefficient of resistance", unit = "K^-1"] end @components begin port = HeatPort() From eefec54a17db4fe97c28958ec69af8ca3605eb8f Mon Sep 17 00:00:00 2001 From: matthew-kapp Date: Thu, 6 Mar 2025 11:30:52 +0200 Subject: [PATCH 4/6] test and documentation build errors fixed - VariableResistor in src.Electrical.Analog.ideal_components modified -- Unit = descriptor removed -- No longer an UnboundError during Pkg.test() - make.jl in docs modified -- linkcheck_ignore added for the Mathworks link -- It seems the link works and is valid when manually visiting in browser -- No longer a 403 Forbidden error when running docs/make.jl --- docs/make.jl | 1 + src/Electrical/Analog/ideal_components.jl | 12 +++++------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/docs/make.jl b/docs/make.jl index 3a6e05ec8..a0cac1b6d 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -31,6 +31,7 @@ makedocs(sitename = "ModelingToolkitStandardLibrary.jl", ModelingToolkitStandardLibrary.Hydraulic, ModelingToolkitStandardLibrary.Hydraulic.IsothermalCompressible], clean = true, doctest = false, linkcheck = true, + linkcheck_ignore = ["https://www.mathworks.com/help/simscape/ug/basic-principles-of-modeling-physical-networks.html#bq89sba-6"], warnonly = [:docs_block, :missing_docs, :cross_references], format = Documenter.HTML(assets = ["assets/favicon.ico"], canonical = "https://docs.sciml.ai/ModelingToolkitStandardLibrary/stable/"), diff --git a/src/Electrical/Analog/ideal_components.jl b/src/Electrical/Analog/ideal_components.jl index a4896446d..da25edf15 100644 --- a/src/Electrical/Analog/ideal_components.jl +++ b/src/Electrical/Analog/ideal_components.jl @@ -392,10 +392,9 @@ R = R_const + pos * R_ref * (1 + alpha * (port.T - T_ref)) @parameters begin R_ref = 1.0, - [description = "Resistance at temperature T_ref when fully closed (pos=1.0)", - unit = "Ω"] - T_ref = 300.15, [description = "Reference temperature", unit = "K"] - R_const = 1e-3, [description = "Constant resistance between p and n", unit = "Ω"] + [description = "Resistance at temperature T_ref when fully closed (pos=1.0) (Ω)"] + T_ref = 300.15, [description = "Reference temperature (K)"] + R_const = 1e-3, [description = "Constant resistance between p and n (Ω)"] end @components begin @@ -404,13 +403,12 @@ R = R_const + pos * R_ref * (1 + alpha * (port.T - T_ref)) @variables begin pos(t), [description = "Position of the wiper (normally 0-1)"] - R(t), [description = "Resistance", unit = "Ω"] + R(t), [description = "Resistance (Ω)"] end if T_dep @parameters begin - alpha = 1e-3, - [description = "Temperature coefficient of resistance", unit = "K^-1"] + alpha = 1e-3, [description = "Temperature coefficient of resistance (K^-1)"] end @components begin port = HeatPort() From 07c7914a246c4cecac2c130815e874561f45a8c8 Mon Sep 17 00:00:00 2001 From: matthew-kapp Date: Thu, 6 Mar 2025 11:40:52 +0200 Subject: [PATCH 5/6] Hydraulic updates deleted --- docs/src/assets/Project.toml | 22 ------------ .../IsothermalCompressible/components.jl | 36 +++++++++++++++---- .../IsothermalCompressible/sources.jl | 2 +- 3 files changed, 30 insertions(+), 30 deletions(-) delete mode 100644 docs/src/assets/Project.toml diff --git a/docs/src/assets/Project.toml b/docs/src/assets/Project.toml deleted file mode 100644 index e6c6be7c7..000000000 --- a/docs/src/assets/Project.toml +++ /dev/null @@ -1,22 +0,0 @@ -[deps] -ControlSystemsBase = "aaaaaaaa-a6ca-5380-bf3e-84a91bcd477e" -DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" -DataInterpolations = "82cc6244-b520-54b8-b5a6-8a565e85f1d0" -DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa" -Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" -IfElse = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173" -ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78" -ModelingToolkitStandardLibrary = "16a59e39-deab-5bd0-87e4-056b12336739" -OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" -Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" - -[compat] -ControlSystemsBase = "1.1" -DataFrames = "1.7" -DataInterpolations = "6.4, 7" -DifferentialEquations = "7.6" -Documenter = "1" -IfElse = "0.1" -ModelingToolkit = "9" -OrdinaryDiffEq = "6.31" -Plots = "1.36" diff --git a/src/Hydraulic/IsothermalCompressible/components.jl b/src/Hydraulic/IsothermalCompressible/components.jl index 1ca63150c..be891ee4c 100644 --- a/src/Hydraulic/IsothermalCompressible/components.jl +++ b/src/Hydraulic/IsothermalCompressible/components.jl @@ -1,9 +1,12 @@ """ - Cap(; name) + Cap(; p_int, name) Caps a hydraulic port to prevent mass flow in or out. +# Parameters: +- `p_int`: [Pa] initial pressure (set by `p_int` argument) + # Connectors: - `port`: hydraulic port """ @@ -21,10 +24,13 @@ Caps a hydraulic port to prevent mass flow in or out. end """ - Open(; name) + Open(; p_int, name) Provides an "open" boundary condition for a hydraulic port such that mass flow `dm` is non-zero. This is opposite from an un-connected hydraulic port or the `Cap` boundary component which sets the mass flow `dm` to zero. +# Parameters: +- `p_int`: [Pa] initial pressure (set by `p_int` argument) + # Connectors: - `port`: hydraulic port """ @@ -220,11 +226,12 @@ end @deprecate Pipe Tube """ - FlowDivider(; n, name) + FlowDivider(;p_int, n, name) Reduces the flow from `port_a` to `port_b` by `n`. Useful for modeling parallel tubes efficiently by placing a `FlowDivider` on each end of a tube. # Parameters: +- `p_int`: [Pa] initial pressure - `n`: divide flow from `port_a` to `port_b` by `n` # Connectors: @@ -306,11 +313,14 @@ end end """ - Valve(reversible = false; Cd, Cd_reverse = Cd, minimum_area = 0, name) + Valve(reversible = false; p_a_int, p_b_int, area_int, Cd, Cd_reverse = Cd, minimum_area = 0, name) Valve with `area` input and discharge coefficient `Cd` defined by https://en.wikipedia.org/wiki/Discharge_coefficient. The `Cd_reverse` parameter allows for directional flow restriction, making it possible to define a check valve. # Parameters: +- `p_a_int`: [Pa] initial pressure for `port_a` +- `p_b_int`: [Pa] initial pressure for `port_b` +- `area_int`: [m^2] initial valve opening - `Cd`: discharge coefficient flowing from `a → b` - `Cd_reverse`: discharge coefficient flowing from `b → a` - `minimum_area`: when `reversible = false` applies a forced minimum area @@ -497,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; p_int, 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. @@ -670,11 +680,14 @@ dm ────► │ │ area end """ - SpoolValve(reversible = false; Cd, d, name) + SpoolValve(reversible = false; p_a_int, p_b_int, x_int, Cd, d, name) Spool valve with `x` valve opening input as mechanical flange port and `d` diameter of orifice. See `Valve` for more information. # Parameters: +- `p_a_int`: [Pa] initial pressure for `port_a` +- `p_b_int`: [Pa] initial pressure for `port_b` +- `x_int`: [m] initial valve opening - `d`: [m] orifice diameter - `Cd`: discharge coefficient flowing from `a → b` @@ -714,13 +727,18 @@ See [`Valve`](@ref) for more information. end """ - SpoolValve2Way(reversible = false; m, g, Cd, d, name) + SpoolValve2Way(reversible = false; p_s_int, p_a_int, p_b_int, p_r_int, m, g, x_int, Cd, d, name) 2-ways spool valve with 4 ports and spool mass. Fluid flow direction S → A and B → R when `x` is positive and S → B and A → R when `x` is negative. # Parameters: +- `p_s_int`: [Pa] initial pressure for `port_s` +- `p_a_int`: [Pa] initial pressure for `port_a` +- `p_b_int`: [Pa] initial pressure for `port_b` +- `p_r_int`: [Pa] initial pressure for `port_r` - `m`: [kg] mass of the spool - `g`: [m/s²] gravity field acting on the spool, positive value acts in the positive direction +- `x_int`: [m] initial valve opening - `d`: [m] orifice diameter - `Cd`: discharge coefficient flowing from `s → a` and `b → r` @@ -770,6 +788,8 @@ end """ Actuator(N, add_inertia = true, reversible = false; + p_a_int, + p_b_int, area_a, area_b, perimeter_a = 2 * sqrt(area_a * pi), @@ -799,6 +819,8 @@ Actuator made of two DynamicVolumes connected in opposite direction with body ma # Parameters: ## volume +- `p_a_int`: [Pa] initial pressure for `port_a` +- `p_b_int`: [Pa] initial pressure for `port_b` - `area_a`: [m^2] moving wall area of volume `A` - `area_b`: [m^2] moving wall area of volume `B` - `length_a_int`: [m] initial wall position for `A` diff --git a/src/Hydraulic/IsothermalCompressible/sources.jl b/src/Hydraulic/IsothermalCompressible/sources.jl index d5d64f5f3..ee21959d7 100644 --- a/src/Hydraulic/IsothermalCompressible/sources.jl +++ b/src/Hydraulic/IsothermalCompressible/sources.jl @@ -1,5 +1,5 @@ """ - MassFlow(; name) + MassFlow(; name, p_int) Hydraulic mass flow input source From be560a167baa43b705a822ef1d8b5eef1b52ff28 Mon Sep 17 00:00:00 2001 From: matthew-kapp Date: Thu, 6 Mar 2025 11:44:17 +0200 Subject: [PATCH 6/6] src.Hydraulic.IsothermalCOmpressible.utils.jl reverted --- src/Hydraulic/IsothermalCompressible/utils.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Hydraulic/IsothermalCompressible/utils.jl b/src/Hydraulic/IsothermalCompressible/utils.jl index 165c6adc1..425686d1f 100644 --- a/src/Hydraulic/IsothermalCompressible/utils.jl +++ b/src/Hydraulic/IsothermalCompressible/utils.jl @@ -4,10 +4,14 @@ regPow(x, a, delta = 0.01) = x * (x * x + delta * delta)^((a - 1) / 2); regRoot(x, delta = 0.01) = regPow(x, 0.5, delta) """ - HydraulicPort(; name) + HydraulicPort(;p_int, name) Connector port for hydraulic components. +# Arguments: + +- `p_int`: [Pa] initial gauge pressure + # States: - `p`: [Pa] gauge total pressure - `dm`: [kg/s] mass flow