From 02fe980aa78ce68c1d79887f0bb8f34becaf9ed2 Mon Sep 17 00:00:00 2001 From: Yingbo Ma Date: Mon, 5 Feb 2024 17:22:53 -0500 Subject: [PATCH] Format --- src/Blocks/analysis_points.jl | 28 ++--- src/Blocks/continuous.jl | 18 ++-- src/Blocks/sources.jl | 84 +++++++-------- src/Blocks/utils.jl | 2 +- src/Electrical/Digital/logic_vectors.jl | 2 +- src/Electrical/Digital/tables.jl | 2 +- .../IsothermalCompressible/components.jl | 102 +++++++++--------- src/Hydraulic/IsothermalCompressible/utils.jl | 4 +- src/Mechanical/Translational/components.jl | 4 +- .../TranslationalPosition/components.jl | 6 +- 10 files changed, 126 insertions(+), 126 deletions(-) diff --git a/src/Blocks/analysis_points.jl b/src/Blocks/analysis_points.jl index ef95e6f42..a20a1e728 100644 --- a/src/Blocks/analysis_points.jl +++ b/src/Blocks/analysis_points.jl @@ -258,7 +258,7 @@ end const SymOrVec = Union{Symbol, Vector{Symbol}} function get_sensitivity_function(sys, ap_name::SymOrVec; loop_openings = nothing, - kwargs...) + kwargs...) find = namespaced_ap_match(ap_name, loop_openings) t = get_iv(sys) aps = [] @@ -287,7 +287,7 @@ function get_sensitivity_function(sys, ap_name::SymOrVec; loop_openings = nothin end function get_comp_sensitivity_function(sys, ap_name::SymOrVec; loop_openings = nothing, - kwargs...) + kwargs...) find = namespaced_ap_match(ap_name, loop_openings) t = get_iv(sys) aps = [] @@ -316,7 +316,7 @@ function get_comp_sensitivity_function(sys, ap_name::SymOrVec; loop_openings = n end function get_looptransfer_function(sys, ap_name::SymOrVec; loop_openings = nothing, - kwargs...) + kwargs...) find = namespaced_ap_match(ap_name, loop_openings) t = get_iv(sys) aps = [] @@ -383,9 +383,9 @@ function open_loop(sys, ap_name::Symbol; ground_input = false, kwargs...) end function ModelingToolkit.linearization_function(sys::ModelingToolkit.AbstractSystem, - input_name::SymOrVec, output_name; - loop_openings = nothing, - kwargs...) + input_name::SymOrVec, output_name; + loop_openings = nothing, + kwargs...) t = get_iv(sys) @variables u(t)=0 [input = true] names = [input_name;] @@ -447,19 +447,19 @@ for f in [:get_sensitivity, :get_comp_sensitivity, :get_looptransfer, :open_loop end function ModelingToolkit.linearize(sys, input::AnalysisPoint, output::AnalysisPoint; - kwargs...) + kwargs...) ModelingToolkit.linearize(sys, nameof(input), nameof(output); kwargs...) end # Methods above are implemented in terms of linearization_function, the method below creates wrappers for linearize for f in [:get_sensitivity, :get_comp_sensitivity, :get_looptransfer] @eval function $f(sys, - ap, - args...; - loop_openings = nothing, - op = Dict(), - p = DiffEqBase.NullParameters(), - kwargs...) + ap, + args...; + loop_openings = nothing, + op = Dict(), + p = DiffEqBase.NullParameters(), + kwargs...) lin_fun, ssys = $(Symbol(string(f) * "_function"))(sys, ap, args...; op, p, loop_openings, kwargs...) @@ -475,7 +475,7 @@ Linearize a system between two analysis points. To get a loop-transfer function, The output is allowed to be either an analysis-point name, or a vector of symbolic variables like the standard interface to `linearize`. The input must be an analysis-point name. """ function ModelingToolkit.linearize(sys, input_name::SymOrVec, output_name; - loop_openings = nothing, kwargs...) + loop_openings = nothing, kwargs...) lin_fun, ssys = linearization_function(sys, input_name, output_name; loop_openings, kwargs...) ModelingToolkit.linearize(ssys, lin_fun; kwargs...), ssys diff --git a/src/Blocks/continuous.jl b/src/Blocks/continuous.jl index 2661c7124..72bfcc7d2 100644 --- a/src/Blocks/continuous.jl +++ b/src/Blocks/continuous.jl @@ -245,7 +245,7 @@ Text-book version of a PID-controller without actuator saturation and anti-windu See also [`LimPID`](@ref) """ @component function PID(; name, k = 1, Ti = false, Td = false, Nd = 10, int__x = 0, - der__x = 0) + der__x = 0) with_I = !isequal(Ti, false) with_D = !isequal(Td, false) @named err_input = RealInput() # control error @@ -386,13 +386,13 @@ where the transfer function for the derivative includes additional filtering, se - `ctr_output` """ @component function LimPID(; name, k = 1, Ti = false, Td = false, wp = 1, wd = 1, - Ni = Ti == 0 ? Inf : √(max(Td / Ti, 1e-6)), - Nd = 10, - u_max = Inf, - u_min = u_max > 0 ? -u_max : -Inf, - gains = false, - int__x = 0.0, - der__x = 0.0) + Ni = Ti == 0 ? Inf : √(max(Td / Ti, 1e-6)), + Nd = 10, + u_max = Inf, + u_min = u_max > 0 ? -u_max : -Inf, + gains = false, + int__x = 0.0, + der__x = 0.0) with_I = !isequal(Ti, false) with_D = !isequal(Td, false) with_AWM = Ni != Inf @@ -522,7 +522,7 @@ y &= h(x, u) linearized around the operating point `x₀, u₀`, we have `y0, u0 = h(x₀, u₀), u₀`. """ @component function StateSpace(; A, B, C, D = nothing, x = zeros(size(A, 1)), name, - u0 = zeros(size(B, 2)), y0 = zeros(size(C, 1))) + u0 = zeros(size(B, 2)), y0 = zeros(size(C, 1))) nx, nu, ny = size(A, 1), size(B, 2), size(C, 1) size(A, 2) == nx || error("`A` has to be a square matrix.") size(B, 1) == nx || error("`B` has to be of dimension ($nx x $nu).") diff --git a/src/Blocks/sources.jl b/src/Blocks/sources.jl index a3020cbdb..fdd9b92cd 100644 --- a/src/Blocks/sources.jl +++ b/src/Blocks/sources.jl @@ -130,12 +130,12 @@ Generate sine signal. - `output` """ @component function Sine(; name, - frequency, - amplitude = 1, - phase = 0, - offset = 0, - start_time = 0, - smooth = false) + frequency, + amplitude = 1, + phase = 0, + offset = 0, + start_time = 0, + smooth = false) @named output = RealOutput() pars = @parameters offset=offset start_time=start_time amplitude=amplitude frequency=frequency phase=phase equation = if smooth == false @@ -173,12 +173,12 @@ Cosine signal. """ @component function Cosine(; name, - frequency, - amplitude = 1, - phase = 0, - offset = 0, - start_time = 0, - smooth = false) + frequency, + amplitude = 1, + phase = 0, + offset = 0, + start_time = 0, + smooth = false) @named output = RealOutput() pars = @parameters offset=offset start_time=start_time amplitude=amplitude frequency=frequency phase=phase equation = if smooth == false @@ -238,11 +238,11 @@ Generate ramp signal. - `output` """ @component function Ramp(; name, - height = 1, - duration = 1, - offset = 0, - start_time = 0, - smooth = false) + height = 1, + duration = 1, + offset = 0, + start_time = 0, + smooth = false) @named output = RealOutput() pars = @parameters offset=offset start_time=start_time height=height duration=duration equation = if smooth == false @@ -280,7 +280,7 @@ Generate smooth square signal. - `output` """ @component function Square(; name, frequency = 1.0, amplitude = 1.0, - offset = 0.0, start_time = 0.0, smooth = false) + offset = 0.0, start_time = 0.0, smooth = false) @named output = RealOutput() pars = @parameters begin frequency = frequency @@ -322,7 +322,7 @@ Generate step signal. - `output` """ @component function Step(; name, height = 1, offset = 0, start_time = 0, duration = Inf, - smooth = 1e-5) + smooth = 1e-5) @named output = RealOutput() duration_numeric = duration pars = @parameters offset=offset start_time=start_time height=height duration=duration @@ -366,13 +366,13 @@ Exponentially damped sine signal. - `output` """ @component function ExpSine(; name, - frequency, - amplitude = 1, - damping = 0.1, - phase = 0, - offset = 0, - start_time = 0, - smooth = false) + frequency, + amplitude = 1, + damping = 0.1, + phase = 0, + offset = 0, + start_time = 0, + smooth = false) @named output = RealOutput() pars = @parameters offset=offset start_time=start_time amplitude=amplitude frequency=frequency phase=phase damping=damping @@ -413,7 +413,7 @@ Generate smooth triangular signal for frequencies less than or equal to 25 Hz - `output` """ @component function Triangular(; name, amplitude = 1.0, frequency = 1.0, - offset = 0.0, start_time = 0.0, smooth = false) + offset = 0.0, start_time = 0.0, smooth = false) @named output = RealOutput() pars = @parameters begin amplitude = amplitude @@ -559,9 +559,9 @@ function first_order_backwards_difference(t, buffer, Δt, circular_buffer) end function get_sampled_data(t, - buffer::Vector{T}, - dt::T, - circular_buffer = true) where {T <: Real} + buffer::Vector{T}, + dt::T, + circular_buffer = true) where {T <: Real} if t < 0 t = zero(t) end @@ -623,11 +623,11 @@ function Symbolics.derivative(::typeof(get_sampled_data), args::NTuple{4, Any}, first_order_backwards_difference(t, buffer, sample_time, circular_buffer) end function ChainRulesCore.frule((_, ẋ, _), - ::typeof(get_sampled_data), - t, - buffer, - sample_time, - circular_buffer) + ::typeof(get_sampled_data), + t, + buffer, + sample_time, + circular_buffer) first_order_backwards_difference(t, buffer, sample_time, circular_buffer) * ẋ end @@ -651,10 +651,10 @@ data input component. - `output` """ @component function SampledData(::Val{SampledDataType.vector_based}; - name, - buffer, - sample_time, - circular_buffer = true) + name, + buffer, + sample_time, + circular_buffer = true) pars = @parameters begin buffer = buffer #::Vector{Real} sample_time = sample_time #::Real @@ -717,9 +717,9 @@ function SampledData(sample_time::T, circular_buffer = true; name) where {T <: R circular_buffer) end function SampledData(buffer::Vector{<:Real}, - sample_time::Real, - circular_buffer = true; - name) + sample_time::Real, + circular_buffer = true; + name) SampledData(SampledDataType.vector_based; name, buffer, sample_time, circular_buffer) end function SampledData(; name, buffer, sample_time, circular_buffer) diff --git a/src/Blocks/utils.jl b/src/Blocks/utils.jl index d6200d85b..3feb84c5d 100644 --- a/src/Blocks/utils.jl +++ b/src/Blocks/utils.jl @@ -96,7 +96,7 @@ Base class for a multiple input multiple output (MIMO) continuous system block. - `y_start`: Initial value for the output """ @component function MIMO(; name, nin = 1, nout = 1, u_start = zeros(nin), - y_start = zeros(nout)) + y_start = zeros(nout)) @named input = RealInput(nin = nin, u_start = u_start) @named output = RealOutput(nout = nout, u_start = y_start) @variables(u(t)[1:nin]=u_start, [description = "Input of MIMO system $name"], diff --git a/src/Electrical/Digital/logic_vectors.jl b/src/Electrical/Digital/logic_vectors.jl index 8f048249a..590621cd1 100644 --- a/src/Electrical/Digital/logic_vectors.jl +++ b/src/Electrical/Digital/logic_vectors.jl @@ -24,7 +24,7 @@ axes(l::LogicVector) = axes(l.logic) getindex(s::LogicVector, i::Int) = getindex(s.logic, i) function Base.getindex(s::LogicVector, i1::Int, i2::Int, - I::Int...) + I::Int...) getindex(s.logic, i1, i2, I...) end diff --git a/src/Electrical/Digital/tables.jl b/src/Electrical/Digital/tables.jl index b2d7b8983..599ada98e 100644 --- a/src/Electrical/Digital/tables.jl +++ b/src/Electrical/Digital/tables.jl @@ -17,7 +17,7 @@ function Base.getindex(s::LogicTable, i1::Logic, i2::Logic) getindex(s.logic, get_logic_level(i1), get_logic_level(i2)) end function Base.getindex(s::LogicTable, i1::Logic, i2::Logic, - I::Logic...) + I::Logic...) getindex(s.logic, get_logic_level(i1), get_logic_level(i2), get_logic_level(I...)...) end diff --git a/src/Hydraulic/IsothermalCompressible/components.jl b/src/Hydraulic/IsothermalCompressible/components.jl index 91f6bd54c..b7422f35c 100644 --- a/src/Hydraulic/IsothermalCompressible/components.jl +++ b/src/Hydraulic/IsothermalCompressible/components.jl @@ -65,9 +65,9 @@ Variable length internal flow model of the fully developed incompressible flow f - `port_b`: hydraulic port """ @component function TubeBase(add_inertia = true, variable_length = true; p_int, area, - length_int, head_factor = 1, - perimeter = 2 * sqrt(area * pi), - shape_factor = 64, name) + length_int, head_factor = 1, + perimeter = 2 * sqrt(area * pi), + shape_factor = 64, name) pars = @parameters begin p_int = p_int area = area @@ -150,8 +150,8 @@ Constant length internal flow model discretized by `N` (`FixedVolume`: `N`, `Tub - `port_b`: hydraulic port """ @component function Tube(N, add_inertia = true; p_int, area, length, head_factor = 1, - perimeter = 2 * sqrt(area * pi), - shape_factor = 64, name) + perimeter = 2 * sqrt(area * pi), + shape_factor = 64, name) @assert(N>0, "the Tube component must be defined with at least 1 segment (i.e. N>0), found N=$N") @@ -263,7 +263,7 @@ Reduces the flow from `port_a` to `port_b` by `n`. Useful for modeling parallel end @component function ValveBase(reversible = false; p_a_int, p_b_int, minimum_area = 0, - area_int, Cd, Cd_reverse = Cd, name) + area_int, Cd, Cd_reverse = Cd, name) pars = @parameters begin p_a_int = p_a_int p_b_int = p_b_int @@ -329,9 +329,9 @@ Valve with `area` input and discharge coefficient `Cd` defined by https://en.wik - `area`: real input setting the valve `area`. When `reversible = true`, negative input reverses flow direction, otherwise a floor of `minimum_area` is enforced. """ @component function Valve(reversible = false; p_a_int, p_b_int, - area_int, Cd, Cd_reverse = Cd, - minimum_area = 0, - name) + area_int, Cd, Cd_reverse = Cd, + minimum_area = 0, + name) pars = @parameters begin p_a_int = p_a_int p_b_int = p_b_int @@ -359,7 +359,7 @@ Valve with `area` input and discharge coefficient `Cd` defined by https://en.wik end @component function VolumeBase(; p_int, x_int = 0, area, dead_volume = 0, Χ1 = 1, Χ2 = 1, - name) + name) pars = @parameters begin p_int = p_int x_int = x_int @@ -477,24 +477,24 @@ dm ────► │ │ area - `flange`: mechanical translational port """ @component function DynamicVolume(N, add_inertia = true, reversible = false; - p_int, - area, - x_int = 0, - x_max, - x_min = 0, - x_damp = x_min, - direction = +1, - - # Tube - perimeter = 2 * sqrt(area * pi), - shape_factor = 64, - head_factor = 1, - - # Valve - Cd = 1e2, - Cd_reverse = Cd, - minimum_area = 0, - name) + p_int, + area, + x_int = 0, + x_max, + x_min = 0, + x_damp = x_min, + direction = +1, + + # Tube + perimeter = 2 * sqrt(area * pi), + shape_factor = 64, + head_factor = 1, + + # Valve + Cd = 1e2, + Cd_reverse = Cd, + minimum_area = 0, + name) @assert(N>=0, "the Tube component must be defined with 0 or more segments (i.e. N>=0), found N=$N") @assert (direction == +1)||(direction == -1) "direction argument must be +/-1, found $direction" @@ -647,7 +647,7 @@ end end @component function SpoolValve2Way(reversible = false; p_s_int, p_a_int, p_b_int, p_r_int, - m, g, x_int, Cd, d, name) + m, g, x_int, Cd, d, name) pars = @parameters begin p_s_int = p_s_int p_a_int = p_a_int @@ -690,28 +690,28 @@ end end @component function Actuator(N, add_inertia = true, reversible = false; - p_a_int, - p_b_int, - area_a, - area_b, - perimeter_a = 2 * sqrt(area_a * pi), - perimeter_b = 2 * sqrt(area_b * pi), - length_a_int, - length_b_int, - shape_factor_a = 64, - shape_factor_b = 64, - head_factor_a = 1, - head_factor_b = 1, - m, - g, - x_int = 0, - minimum_volume_a = 0, - minimum_volume_b = 0, - damping_volume_a = minimum_volume_a, - damping_volume_b = minimum_volume_b, - Cd = 1e4, - Cd_reverse = Cd, - name) + p_a_int, + p_b_int, + area_a, + area_b, + perimeter_a = 2 * sqrt(area_a * pi), + perimeter_b = 2 * sqrt(area_b * pi), + length_a_int, + length_b_int, + shape_factor_a = 64, + shape_factor_b = 64, + head_factor_a = 1, + head_factor_b = 1, + m, + g, + x_int = 0, + minimum_volume_a = 0, + minimum_volume_b = 0, + damping_volume_a = minimum_volume_a, + damping_volume_b = minimum_volume_b, + Cd = 1e4, + Cd_reverse = Cd, + name) pars = @parameters begin p_a_int = p_a_int p_b_int = p_b_int diff --git a/src/Hydraulic/IsothermalCompressible/utils.jl b/src/Hydraulic/IsothermalCompressible/utils.jl index cc937bbf2..d88f24f42 100644 --- a/src/Hydraulic/IsothermalCompressible/utils.jl +++ b/src/Hydraulic/IsothermalCompressible/utils.jl @@ -51,8 +51,8 @@ Fluid parameter setter for isothermal compressible fluid domain. Defaults given - `p_gas`: [Pa] reference pressure (set by `gas_pressure` argument) """ @connector function HydraulicFluid(; density = 997, bulk_modulus = 2.09e9, - viscosity = 0.0010016, gas_density = 0.0073955, - gas_pressure = -1000, n = 1, let_gas = 1, name) + viscosity = 0.0010016, gas_density = 0.0073955, + gas_pressure = -1000, n = 1, let_gas = 1, name) pars = @parameters begin ρ = density β = bulk_modulus diff --git a/src/Mechanical/Translational/components.jl b/src/Mechanical/Translational/components.jl index a7cb9d130..b6275fab4 100644 --- a/src/Mechanical/Translational/components.jl +++ b/src/Mechanical/Translational/components.jl @@ -117,7 +117,7 @@ Linear 1D translational spring end # default @component function Spring(::Val{:relative}; name, k, delta_s = 0.0, flange_a__v = 0.0, - flange_b__v = 0.0) + flange_b__v = 0.0) pars = @parameters begin k = k end @@ -140,7 +140,7 @@ end const ABS = Val(:absolute) @component function Spring(::Val{:absolute}; name, k, sa = 0, sb = 0, flange_a__v = 0.0, - flange_b__v = 0.0, l = 0) + flange_b__v = 0.0, l = 0) pars = @parameters begin k = k l = l diff --git a/src/Mechanical/TranslationalPosition/components.jl b/src/Mechanical/TranslationalPosition/components.jl index 427738e3c..fd1edb61a 100644 --- a/src/Mechanical/TranslationalPosition/components.jl +++ b/src/Mechanical/TranslationalPosition/components.jl @@ -65,7 +65,7 @@ end const REL = Val(:relative) @component function Spring(::Val{:relative}; name, k, va = 0.0, vb = 0.0, - delta_s = 0, flange_a__s = 0, flange_b__s = 0) + delta_s = 0, flange_a__s = 0, flange_b__s = 0) pars = @parameters begin k = k end @@ -119,8 +119,8 @@ function Spring(; name, k, flange_a__s = 0, flange_b__s = 0, l = 0) end #default function @component function Spring(::Val{:absolute}; - name, k, flange_a__s = 0, - flange_b__s = 0, l = 0) + name, k, flange_a__s = 0, + flange_b__s = 0, l = 0) pars = @parameters begin k = k l = l