Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
YingboMa committed Feb 5, 2024
1 parent 907060f commit 02fe980
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 126 deletions.
28 changes: 14 additions & 14 deletions src/Blocks/analysis_points.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -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;]
Expand Down Expand Up @@ -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...)
Expand All @@ -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
Expand Down
18 changes: 9 additions & 9 deletions src/Blocks/continuous.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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).")
Expand Down
84 changes: 42 additions & 42 deletions src/Blocks/sources.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Blocks/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
2 changes: 1 addition & 1 deletion src/Electrical/Digital/logic_vectors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/Electrical/Digital/tables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading

0 comments on commit 02fe980

Please sign in to comment.