Skip to content

Commit 875d870

Browse files
YingboMaAayushSabharwal
authored andcommitted
Format
1 parent aa98f86 commit 875d870

File tree

10 files changed

+147
-135
lines changed

10 files changed

+147
-135
lines changed

src/Blocks/analysis_points.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ end
258258
const SymOrVec = Union{Symbol, Vector{Symbol}}
259259

260260
function get_sensitivity_function(sys, ap_name::SymOrVec; loop_openings = nothing,
261-
kwargs...)
261+
kwargs...)
262262
find = namespaced_ap_match(ap_name, loop_openings)
263263
t = get_iv(sys)
264264
aps = []
@@ -287,7 +287,7 @@ function get_sensitivity_function(sys, ap_name::SymOrVec; loop_openings = nothin
287287
end
288288

289289
function get_comp_sensitivity_function(sys, ap_name::SymOrVec; loop_openings = nothing,
290-
kwargs...)
290+
kwargs...)
291291
find = namespaced_ap_match(ap_name, loop_openings)
292292
t = get_iv(sys)
293293
aps = []
@@ -316,7 +316,7 @@ function get_comp_sensitivity_function(sys, ap_name::SymOrVec; loop_openings = n
316316
end
317317

318318
function get_looptransfer_function(sys, ap_name::SymOrVec; loop_openings = nothing,
319-
kwargs...)
319+
kwargs...)
320320
find = namespaced_ap_match(ap_name, loop_openings)
321321
t = get_iv(sys)
322322
aps = []
@@ -383,9 +383,9 @@ function open_loop(sys, ap_name::Symbol; ground_input = false, kwargs...)
383383
end
384384

385385
function ModelingToolkit.linearization_function(sys::ModelingToolkit.AbstractSystem,
386-
input_name::SymOrVec, output_name;
387-
loop_openings = nothing,
388-
kwargs...)
386+
input_name::SymOrVec, output_name;
387+
loop_openings = nothing,
388+
kwargs...)
389389
t = get_iv(sys)
390390
@variables u(t)=0 [input = true]
391391
names = [input_name;]
@@ -447,19 +447,19 @@ for f in [:get_sensitivity, :get_comp_sensitivity, :get_looptransfer, :open_loop
447447
end
448448

449449
function ModelingToolkit.linearize(sys, input::AnalysisPoint, output::AnalysisPoint;
450-
kwargs...)
450+
kwargs...)
451451
ModelingToolkit.linearize(sys, nameof(input), nameof(output); kwargs...)
452452
end
453453

454454
# Methods above are implemented in terms of linearization_function, the method below creates wrappers for linearize
455455
for f in [:get_sensitivity, :get_comp_sensitivity, :get_looptransfer]
456456
@eval function $f(sys,
457-
ap,
458-
args...;
459-
loop_openings = nothing,
460-
op = Dict(),
461-
p = DiffEqBase.NullParameters(),
462-
kwargs...)
457+
ap,
458+
args...;
459+
loop_openings = nothing,
460+
op = Dict(),
461+
p = DiffEqBase.NullParameters(),
462+
kwargs...)
463463
lin_fun, ssys = $(Symbol(string(f) * "_function"))(sys, ap, args...; op, p,
464464
loop_openings,
465465
kwargs...)
@@ -475,7 +475,7 @@ Linearize a system between two analysis points. To get a loop-transfer function,
475475
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.
476476
"""
477477
function ModelingToolkit.linearize(sys, input_name::SymOrVec, output_name;
478-
loop_openings = nothing, kwargs...)
478+
loop_openings = nothing, kwargs...)
479479
lin_fun, ssys = linearization_function(sys, input_name, output_name; loop_openings,
480480
kwargs...)
481481
ModelingToolkit.linearize(ssys, lin_fun; kwargs...), ssys

src/Blocks/continuous.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ Text-book version of a PID-controller without actuator saturation and anti-windu
245245
See also [`LimPID`](@ref)
246246
"""
247247
@component function PID(; name, k = 1, Ti = false, Td = false, Nd = 10, int__x = 0,
248-
der__x = 0)
248+
der__x = 0)
249249
with_I = !isequal(Ti, false)
250250
with_D = !isequal(Td, false)
251251
@named err_input = RealInput() # control error
@@ -386,13 +386,13 @@ where the transfer function for the derivative includes additional filtering, se
386386
- `ctr_output`
387387
"""
388388
@component function LimPID(; name, k = 1, Ti = false, Td = false, wp = 1, wd = 1,
389-
Ni = Ti == 0 ? Inf : (max(Td / Ti, 1e-6)),
390-
Nd = 10,
391-
u_max = Inf,
392-
u_min = u_max > 0 ? -u_max : -Inf,
393-
gains = false,
394-
int__x = 0.0,
395-
der__x = 0.0)
389+
Ni = Ti == 0 ? Inf : (max(Td / Ti, 1e-6)),
390+
Nd = 10,
391+
u_max = Inf,
392+
u_min = u_max > 0 ? -u_max : -Inf,
393+
gains = false,
394+
int__x = 0.0,
395+
der__x = 0.0)
396396
with_I = !isequal(Ti, false)
397397
with_D = !isequal(Td, false)
398398
with_AWM = Ni != Inf
@@ -522,7 +522,7 @@ y &= h(x, u)
522522
linearized around the operating point `x₀, u₀`, we have `y0, u0 = h(x₀, u₀), u₀`.
523523
"""
524524
@component function StateSpace(; A, B, C, D = nothing, x = zeros(size(A, 1)), name,
525-
u0 = zeros(size(B, 2)), y0 = zeros(size(C, 1)))
525+
u0 = zeros(size(B, 2)), y0 = zeros(size(C, 1)))
526526
nx, nu, ny = size(A, 1), size(B, 2), size(C, 1)
527527
size(A, 2) == nx || error("`A` has to be a square matrix.")
528528
size(B, 1) == nx || error("`B` has to be of dimension ($nx x $nu).")

src/Blocks/sources.jl

Lines changed: 63 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,13 @@ Generate sine signal.
130130
- `output`
131131
"""
132132
@component function Sine(; name,
133-
frequency,
134-
amplitude = 1,
135-
phase = 0,
136-
offset = 0,
137-
start_time = 0,
138-
smooth = false,
139-
output__unit = nothing)
133+
frequency,
134+
amplitude = 1,
135+
phase = 0,
136+
offset = 0,
137+
start_time = 0,
138+
smooth = false,
139+
output__unit = nothing)
140140
@named output = RealOutput(; unit = output__unit)
141141
pars = @parameters offset=offset start_time=start_time amplitude=amplitude frequency=frequency phase=phase
142142
equation = if smooth == false
@@ -174,13 +174,13 @@ Cosine signal.
174174
"""
175175

176176
@component function Cosine(; name,
177-
frequency,
178-
amplitude = 1,
179-
phase = 0,
180-
offset = 0,
181-
start_time = 0,
182-
smooth = false,
183-
output__unit = nothing)
177+
frequency,
178+
amplitude = 1,
179+
phase = 0,
180+
offset = 0,
181+
start_time = 0,
182+
smooth = false,
183+
output__unit = nothing)
184184
@named output = RealOutput(; unit = output__unit)
185185
pars = @parameters offset=offset start_time=start_time amplitude=amplitude frequency=frequency phase=phase
186186
equation = if smooth == false
@@ -240,12 +240,12 @@ Generate ramp signal.
240240
- `output`
241241
"""
242242
@component function Ramp(; name,
243-
height = 1,
244-
duration = 1,
245-
offset = 0,
246-
start_time = 0,
247-
smooth = false,
248-
output__unit = nothing)
243+
height = 1,
244+
duration = 1,
245+
offset = 0,
246+
start_time = 0,
247+
smooth = false,
248+
output__unit = nothing)
249249
@named output = RealOutput(; unit = output__unit)
250250
pars = @parameters offset=offset start_time=start_time height=height duration=duration
251251
equation = if smooth == false
@@ -283,8 +283,8 @@ Generate smooth square signal.
283283
- `output`
284284
"""
285285
@component function Square(; name, frequency = 1.0, amplitude = 1.0,
286-
offset = 0.0, start_time = 0.0, smooth = false,
287-
output__unit = nothing)
286+
offset = 0.0, start_time = 0.0, smooth = false,
287+
output__unit = nothing)
288288
@named output = RealOutput(; unit = output__unit)
289289
pars = @parameters begin
290290
frequency = frequency
@@ -326,7 +326,7 @@ Generate step signal.
326326
- `output`
327327
"""
328328
@component function Step(; name, height = 1, offset = 0, start_time = 0, duration = Inf,
329-
smooth = 1e-5, output__unit = nothing)
329+
smooth = 1e-5, output__unit = nothing)
330330
@named output = RealOutput(; unit = output__unit)
331331
duration_numeric = duration
332332
pars = @parameters offset=offset start_time=start_time height=height duration=duration
@@ -370,14 +370,14 @@ Exponentially damped sine signal.
370370
- `output`
371371
"""
372372
@component function ExpSine(; name,
373-
frequency,
374-
amplitude = 1,
375-
damping = 0.1,
376-
phase = 0,
377-
offset = 0,
378-
start_time = 0,
379-
smooth = false,
380-
output__unit = nothing)
373+
frequency,
374+
amplitude = 1,
375+
damping = 0.1,
376+
phase = 0,
377+
offset = 0,
378+
start_time = 0,
379+
smooth = false,
380+
output__unit = nothing)
381381
@named output = RealOutput(; unit = output__unit)
382382
pars = @parameters offset=offset start_time=start_time amplitude=amplitude frequency=frequency phase=phase damping=damping
383383

@@ -418,8 +418,8 @@ Generate smooth triangular signal for frequencies less than or equal to 25 Hz
418418
- `output`
419419
"""
420420
@component function Triangular(; name, amplitude = 1.0, frequency = 1.0,
421-
offset = 0.0, start_time = 0.0, smooth = false,
422-
output__unit = nothing)
421+
offset = 0.0, start_time = 0.0, smooth = false,
422+
output__unit = nothing)
423423
@named output = RealOutput(; unit = output__unit)
424424
pars = @parameters begin
425425
amplitude = amplitude
@@ -569,9 +569,9 @@ function first_order_backwards_difference(t, buffer, Δt, circular_buffer)
569569
end
570570

571571
function get_sampled_data(t,
572-
buffer::Vector{T},
573-
dt::T,
574-
circular_buffer = true) where {T <: Real}
572+
buffer::Vector{T},
573+
dt::T,
574+
circular_buffer = true) where {T <: Real}
575575
if t < 0
576576
t = zero(t)
577577
end
@@ -630,7 +630,12 @@ function Symbolics.derivative(::typeof(get_sampled_data), args::NTuple{4, Any},
630630
circular_buffer = @inbounds args[4]
631631
first_order_backwards_difference(t, buffer, sample_time, circular_buffer)
632632
end
633-
function ChainRulesCore.frule((_, ẋ, _), ::typeof(get_sampled_data), t, buffer, sample_time, circular_buffer)
633+
function ChainRulesCore.frule((_, ẋ, _),
634+
::typeof(get_sampled_data),
635+
t,
636+
buffer,
637+
sample_time,
638+
circular_buffer)
634639
first_order_backwards_difference(t, buffer, sample_time, circular_buffer) *
635640
end
636641

@@ -655,7 +660,11 @@ data input component.
655660
# Connectors:
656661
- `output`
657662
"""
658-
@component function SampledData(::Val{SampledDataType.vector_based}; name, buffer, sample_time, circular_buffer=true)
663+
@component function SampledData(::Val{SampledDataType.vector_based};
664+
name,
665+
buffer,
666+
sample_time,
667+
circular_buffer = true)
659668
pars = @parameters begin
660669
buffer = buffer #::Vector{Real}
661670
sample_time = sample_time #::Real
@@ -704,16 +713,19 @@ SampledData(x::SampledDataType.Option; kwargs...) = SampledData(Val(x); kwargs..
704713
SampledData(T::Type, circular_buffer = true; name) = SampledData(SampledDataType.struct_based; name, buffer = Parameter(T[], zero(T), circular_buffer))
705714

706715
# vector_based
707-
SampledData(sample_time::T, circular_buffer = true; name) where {T <: Real} = SampledData(SampledDataType.vector_based; name, buffer=T[], sample_time, circular_buffer)
708-
SampledData(buffer::Vector{<:Real}, sample_time::Real, circular_buffer = true; name) = SampledData(SampledDataType.vector_based; name, buffer, sample_time, circular_buffer)
709-
SampledData(; name, buffer, sample_time, circular_buffer) = SampledData(SampledDataType.vector_based; name, buffer, sample_time, circular_buffer)
710-
711-
712-
713-
714-
715-
716-
717-
718-
719-
716+
function SampledData(sample_time::T, circular_buffer = true; name) where {T <: Real}
717+
SampledData(SampledDataType.vector_based;
718+
name,
719+
buffer = T[],
720+
sample_time,
721+
circular_buffer)
722+
end
723+
function SampledData(buffer::Vector{<:Real},
724+
sample_time::Real,
725+
circular_buffer = true;
726+
name)
727+
SampledData(SampledDataType.vector_based; name, buffer, sample_time, circular_buffer)
728+
end
729+
function SampledData(; name, buffer, sample_time, circular_buffer)
730+
SampledData(SampledDataType.vector_based; name, buffer, sample_time, circular_buffer)
731+
end

src/Blocks/utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ Base class for a multiple input multiple output (MIMO) continuous system block.
128128
- `y_start`: Initial value for the output
129129
"""
130130
@component function MIMO(; name, nin = 1, nout = 1, u_start = zeros(nin),
131-
y_start = zeros(nout))
131+
y_start = zeros(nout))
132132
@named input = RealInput(nin = nin, u_start = u_start)
133133
@named output = RealOutput(nout = nout, u_start = y_start)
134134
@variables(u(t)[1:nin]=u_start, [description = "Input of MIMO system $name"],

src/Electrical/Digital/logic_vectors.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ axes(l::LogicVector) = axes(l.logic)
2424

2525
getindex(s::LogicVector, i::Int) = getindex(s.logic, i)
2626
function Base.getindex(s::LogicVector, i1::Int, i2::Int,
27-
I::Int...)
27+
I::Int...)
2828
getindex(s.logic, i1, i2, I...)
2929
end
3030

src/Electrical/Digital/tables.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function Base.getindex(s::LogicTable, i1::Logic, i2::Logic)
1717
getindex(s.logic, get_logic_level(i1), get_logic_level(i2))
1818
end
1919
function Base.getindex(s::LogicTable, i1::Logic, i2::Logic,
20-
I::Logic...)
20+
I::Logic...)
2121
getindex(s.logic, get_logic_level(i1), get_logic_level(i2), get_logic_level(I...)...)
2222
end
2323

0 commit comments

Comments
 (0)