Skip to content

Commit 9a47c71

Browse files
committed
Format and fix AnalysisPoint
1 parent 02fe980 commit 9a47c71

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+579
-527
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ V = 1.0
6060
@named ground = Ground()
6161

6262
rc_eqs = [connect(constant.output, source.V)
63-
connect(source.p, resistor.p)
64-
connect(resistor.n, capacitor.p)
65-
connect(capacitor.n, source.n, ground.g)]
63+
connect(source.p, resistor.p)
64+
connect(resistor.n, capacitor.p)
65+
connect(capacitor.n, source.n, ground.g)]
6666

6767
@named rc_model = ODESystem(rc_eqs, t,
6868
systems = [resistor, capacitor, constant, source, ground])

docs/pages.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pages = [
55
"Custom Components" => "tutorials/custom_component.md",
66
"Thermal Conduction Model" => "tutorials/thermal_model.md",
77
"DC Motor with Speed Controller" => "tutorials/dc_motor_pi.md",
8-
"SampledData Component" => "tutorials/input_component.md",
8+
"SampledData Component" => "tutorials/input_component.md"
99
],
1010
"About Acausal Connections" => "connectors/connections.md",
1111
"API" => [
@@ -15,6 +15,6 @@ pages = [
1515
"Mechanical Components" => "API/mechanical.md",
1616
"Thermal Components" => "API/thermal.md",
1717
"Hydraulic Components" => "API/hydraulic.md",
18-
"Linear Analysis" => "API/linear_analysis.md",
19-
],
18+
"Linear Analysis" => "API/linear_analysis.md"
19+
]
2020
]

docs/src/API/linear_analysis.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ using ModelingToolkitStandardLibrary.Blocks, ModelingToolkit
6060
@named C = Gain(-1) # A P controller
6161
t = ModelingToolkit.get_iv(P)
6262
eqs = [connect(P.output, :plant_output, C.input) # Connect with an automatically created analysis point called :plant_output
63-
connect(C.output, :plant_input, P.input)]
63+
connect(C.output, :plant_input, P.input)]
6464
sys = ODESystem(eqs, t, systems = [P, C], name = :feedback_system)
6565
6666
matrices_S = get_sensitivity(sys, :plant_input)[1] # Compute the matrices of a state-space representation of the (input)sensitivity function.

docs/src/connectors/connections.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ using Plots
9999
@named ground = Ground()
100100
101101
eqs = [connect(capacitor.p, resistor.p)
102-
connect(resistor.n, ground.g, capacitor.n)]
102+
connect(resistor.n, ground.g, capacitor.n)]
103103
104104
@named model = ODESystem(eqs, t; systems = [resistor, capacitor, ground])
105105
@@ -139,7 +139,7 @@ const TV = ModelingToolkitStandardLibrary.Mechanical.Translational
139139
@named ground = TV.Fixed()
140140
141141
eqs = [connect(damping.flange_a, body.flange)
142-
connect(ground.flange, damping.flange_b)]
142+
connect(ground.flange, damping.flange_b)]
143143
144144
@named model = ODESystem(eqs, t; systems = [damping, body, ground])
145145
@@ -172,7 +172,7 @@ const TP = ModelingToolkitStandardLibrary.Mechanical.TranslationalPosition
172172
@named ground = TP.Fixed(s_0 = 0)
173173
174174
eqs = [connect(damping.flange_a, body.flange)
175-
connect(ground.flange, damping.flange_b)]
175+
connect(ground.flange, damping.flange_b)]
176176
177177
@named model = ODESystem(eqs, t; systems = [damping, body, ground])
178178
@@ -267,7 +267,7 @@ Let's define a quick function to simplify and solve the 2 different systems. Not
267267
```@example connections
268268
function simplify_and_solve(damping, spring, body, ground)
269269
eqs = [connect(spring.flange_a, body.flange, damping.flange_a)
270-
connect(spring.flange_b, damping.flange_b, ground.flange)]
270+
connect(spring.flange_b, damping.flange_b, ground.flange)]
271271
272272
@named model = ODESystem(eqs, t; systems = [ground, body, spring, damping])
273273

docs/src/tutorials/custom_component.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function NonlinearResistor(; name, Ga, Gb, Ve)
4646
Gb * (v + Ve) - Ga * Ve,
4747
ifelse(v > Ve,
4848
Gb * (v - Ve) + Ga * Ve,
49-
Ga * v)),
49+
Ga * v))
5050
]
5151
extend(ODESystem(eqs, t, [], pars; name = name), oneport)
5252
end
@@ -102,14 +102,14 @@ The final model can now be created with the components from the library and the
102102
@named Gnd = Ground()
103103
104104
connections = [connect(L.p, G.p)
105-
connect(G.n, Nr.p)
106-
connect(Nr.n, Gnd.g)
107-
connect(C1.p, G.n)
108-
connect(L.n, Ro.p)
109-
connect(G.p, C2.p)
110-
connect(C1.n, Gnd.g)
111-
connect(C2.n, Gnd.g)
112-
connect(Ro.n, Gnd.g)]
105+
connect(G.n, Nr.p)
106+
connect(Nr.n, Gnd.g)
107+
connect(C1.p, G.n)
108+
connect(L.n, Ro.p)
109+
connect(G.p, C2.p)
110+
connect(C1.n, Gnd.g)
111+
connect(C2.n, Gnd.g)
112+
connect(Ro.n, Gnd.g)]
113113
114114
@named model = ODESystem(connections, t, systems = [L, Ro, G, C1, C2, Nr, Gnd])
115115
nothing # hide

docs/src/tutorials/dc_motor_pi.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,18 @@ The actual model can now be composed.
5050
@named speed_sensor = SpeedSensor()
5151
5252
connections = [connect(fixed.flange, emf.support, friction.flange_b)
53-
connect(emf.flange, friction.flange_a, inertia.flange_a)
54-
connect(inertia.flange_b, load.flange)
55-
connect(inertia.flange_b, speed_sensor.flange)
56-
connect(load_step.output, load.tau)
57-
connect(ref.output, feedback.input1)
58-
connect(speed_sensor.w, :y, feedback.input2)
59-
connect(feedback.output, pi_controller.err_input)
60-
connect(pi_controller.ctr_output, :u, source.V)
61-
connect(source.p, R1.p)
62-
connect(R1.n, L1.p)
63-
connect(L1.n, emf.p)
64-
connect(emf.n, source.n, ground.g)]
53+
connect(emf.flange, friction.flange_a, inertia.flange_a)
54+
connect(inertia.flange_b, load.flange)
55+
connect(inertia.flange_b, speed_sensor.flange)
56+
connect(load_step.output, load.tau)
57+
connect(ref.output, feedback.input1)
58+
connect(speed_sensor.w, :y, feedback.input2)
59+
connect(feedback.output, pi_controller.err_input)
60+
connect(pi_controller.ctr_output, :u, source.V)
61+
connect(source.p, R1.p)
62+
connect(R1.n, L1.p)
63+
connect(L1.n, emf.p)
64+
connect(emf.n, source.n, ground.g)]
6565
6666
@named model = ODESystem(connections, t,
6767
systems = [
@@ -78,7 +78,7 @@ connections = [connect(fixed.flange, emf.support, friction.flange_b)
7878
load_step,
7979
inertia,
8080
friction,
81-
speed_sensor,
81+
speed_sensor
8282
])
8383
nothing # hide
8484
```

docs/src/tutorials/input_component.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ function System(f; name)
2828
pars = @parameters m=10 k=1000 d=1
2929

3030
eqs = [f ~ src.output.u
31-
ddx * 10 ~ k * x + d * dx + f
32-
D(x) ~ dx
33-
D(dx) ~ ddx]
31+
ddx * 10 ~ k * x + d * dx + f
32+
D(x) ~ dx
33+
D(dx) ~ ddx]
3434

3535
ODESystem(eqs, t, vars, pars; systems = [src], name)
3636
end
@@ -74,9 +74,9 @@ function System(; name)
7474
pars = @parameters m=10 k=1000 d=1
7575

7676
eqs = [f ~ get_sampled_data(t)
77-
ddx * 10 ~ k * x + d * dx + f
78-
D(x) ~ dx
79-
D(dx) ~ ddx]
77+
ddx * 10 ~ k * x + d * dx + f
78+
D(x) ~ dx
79+
D(dx) ~ ddx]
8080

8181
ODESystem(eqs, t, vars, pars; name)
8282
end
@@ -115,9 +115,9 @@ function System(; name)
115115
pars = @parameters m=10 k=1000 d=1
116116

117117
eqs = [f ~ src.output.u
118-
ddx * 10 ~ k * x + d * dx + f
119-
D(x) ~ dx
120-
D(dx) ~ ddx]
118+
ddx * 10 ~ k * x + d * dx + f
119+
D(x) ~ dx
120+
D(dx) ~ ddx]
121121

122122
ODESystem(eqs, t, vars, pars; systems = [src], name)
123123
end

docs/src/tutorials/rc_circuit.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ V = 1.0
2222
@named ground = Ground()
2323
2424
rc_eqs = [connect(constant.output, source.V)
25-
connect(source.p, resistor.p)
26-
connect(resistor.n, capacitor.p)
27-
connect(capacitor.n, source.n, ground.g)]
25+
connect(source.p, resistor.p)
26+
connect(resistor.n, capacitor.p)
27+
connect(capacitor.n, source.n, ground.g)]
2828
2929
@named rc_model = ODESystem(rc_eqs, t,
3030
systems = [resistor, capacitor, constant, source, ground])

docs/src/tutorials/thermal_model.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ connections = [
2323
connect(mass1.port, conduction.port_a),
2424
connect(conduction.port_b, mass2.port),
2525
connect(mass1.port, Tsensor1.port),
26-
connect(mass2.port, Tsensor2.port),
26+
connect(mass2.port, Tsensor2.port)
2727
]
2828
2929
@named model = ODESystem(connections, t,

src/Blocks/Blocks.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export Log, Log10
1919
include("math.jl")
2020

2121
export Constant, TimeVaryingFunction, Sine, Cosine, ContinuousClock, Ramp, Step, ExpSine,
22-
Square, Triangular, Parameter, SampledData
22+
Square, Triangular, Parameter, SampledData
2323
include("sources.jl")
2424

2525
export Limiter, DeadZone, SlewRateLimiter
@@ -30,7 +30,7 @@ export PI, LimPI, PID, LimPID
3030
include("continuous.jl")
3131

3232
export AnalysisPoint, get_sensitivity, get_comp_sensitivity,
33-
get_looptransfer, open_loop
33+
get_looptransfer, open_loop
3434
include("analysis_points.jl")
3535

3636
end

src/Blocks/analysis_points.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using ModelingToolkit: get_eqs, vars, @set!, get_iv
22

3-
Base.@kwdef mutable struct AnalysisPoint
3+
Base.@kwdef mutable struct AnalysisPoint <: Real
44
in = nothing
55
out = nothing
66
name::Symbol = :nothing
@@ -420,7 +420,7 @@ function ModelingToolkit.linearization_function(sys::ModelingToolkit.AbstractSys
420420
push!(multiplicities_y, length(yi))
421421
append!(y, yi)
422422
[ap_var(ap.in) .~ yi;
423-
ap_var(ap.out) .~ ap_var(ap.in)], yi
423+
ap_var(ap.out) .~ ap_var(ap.in)], yi
424424
else # loop opening
425425
[ap_var(ap.out) .~ 0;], []
426426
end

src/Blocks/continuous.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ See also [`LimPID`](@ref)
282282
eqs = [
283283
connect(err_input, addPID.input1),
284284
connect(addPID.output, gainPID.input),
285-
connect(gainPID.output, ctr_output),
285+
connect(gainPID.output, ctr_output)
286286
]
287287
if with_I
288288
push!(eqs, connect(err_input, int.input))
@@ -347,7 +347,7 @@ The simplified expression above is given without the anti-windup protection.
347347
connect(err_input, addTrack.input1),
348348
connect(gainTrack.output, addTrack.input2),
349349
connect(addTrack.output, int.input),
350-
connect(int.output, addPI.input2),
350+
connect(int.output, addPI.input2)
351351
]
352352
ODESystem(eqs, t, [], []; name = name, systems = sys)
353353
end
@@ -459,7 +459,7 @@ where the transfer function for the derivative includes additional filtering, se
459459
connect(addP.output, addPID.input1),
460460
connect(addPID.output, gainPID.input),
461461
connect(gainPID.output, limiter.input),
462-
connect(limiter.output, ctr_output),
462+
connect(limiter.output, ctr_output)
463463
]
464464
if with_I
465465
push!(eqs, connect(reference, addI.input1))
@@ -538,7 +538,7 @@ linearized around the operating point `x₀, u₀`, we have `y0, u0 = h(x₀, u
538538
@named input = RealInput(nin = nu)
539539
@named output = RealOutput(nout = ny)
540540
@variables x(t)[1:nx]=x [
541-
description = "State variables of StateSpace system $name",
541+
description = "State variables of StateSpace system $name"
542542
]
543543
# pars = @parameters A=A B=B C=C D=D # This is buggy
544544
eqs = [ # FIXME: if array equations work
@@ -547,7 +547,7 @@ linearized around the operating point `x₀, u₀`, we have `y0, u0 = h(x₀, u
547547
for i in 1:nx]..., # cannot use D here
548548
[output.u[j] ~ sum(C[j, i] * x[i] for i in 1:nx) +
549549
sum(D[j, k] * (input.u[k] - u0[k]) for k in 1:nu) + y0[j]
550-
for j in 1:ny]...,
550+
for j in 1:ny]...
551551
]
552552
compose(ODESystem(eqs, t, vcat(x...), [], name = name), [input, output])
553553
end
@@ -596,11 +596,11 @@ See also [`StateSpace`](@ref) which handles MIMO systems, as well as [ControlSys
596596
@parameters begin
597597
b[1:nb] = b,
598598
[
599-
description = "Numerator coefficients of transfer function (e.g., 2s + 3 is specified as [2,3])",
599+
description = "Numerator coefficients of transfer function (e.g., 2s + 3 is specified as [2,3])"
600600
]
601601
a[1:na] = a,
602602
[
603-
description = "Denominator coefficients of transfer function (e.g., `s² + 2ωs + ω^2` is specified as [1, 2ω, ω^2])",
603+
description = "Denominator coefficients of transfer function (e.g., `s² + 2ωs + ω^2` is specified as [1, 2ω, ω^2])"
604604
]
605605
bb[1:(nbb + nb)] = [zeros(nbb); b]
606606
d = bb[1] / a[1], [description = "Direct feedthrough gain"]
@@ -627,9 +627,9 @@ See also [`StateSpace`](@ref) which handles MIMO systems, as well as [ControlSys
627627
eqs = [y ~ d * u]
628628
else
629629
eqs = [D(x_scaled[1]) ~ (-a[2:na]'x_scaled + a_end * u) / a[1]
630-
D.(x_scaled[2:nx]) .~ x_scaled[1:(nx - 1)]
631-
y ~ ((bb[2:na] - d * a[2:na])'x_scaled) / a_end + d * u
632-
x .~ x_scaled ./ a_end]
630+
D.(x_scaled[2:nx]) .~ x_scaled[1:(nx - 1)]
631+
y ~ ((bb[2:na] - d * a[2:na])'x_scaled) / a_end + d * u
632+
x .~ x_scaled ./ a_end]
633633
end
634634
push!(eqs, input.u ~ u)
635635
push!(eqs, output.u ~ y)

src/Blocks/nonlinear.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ Limit the range of a signal.
2222
@named siso = SISO(u_start = m, y_start = m) # Default signals to center of saturation to minimize risk of saturation while linearizing etc.
2323
@unpack u, y = siso
2424
pars = @parameters y_max=y_max [description = "Maximum allowed output of Limiter $name"] y_min=y_min [
25-
description = "Minimum allowed output of Limiter $name",
25+
description = "Minimum allowed output of Limiter $name"
2626
]
2727
eqs = [
28-
y ~ _clamp(u, y_min, y_max),
28+
y ~ _clamp(u, y_min, y_max)
2929
]
3030
extend(ODESystem(eqs, t, [], pars; name = name), siso)
3131
end

0 commit comments

Comments
 (0)