Skip to content

Commit f4fe2ae

Browse files
committed
style: fix format
1 parent df36063 commit f4fe2ae

File tree

11 files changed

+44
-58
lines changed

11 files changed

+44
-58
lines changed

docs/src/tutorials/input_component.md

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ function MassSpringDamper(; name)
3838
@variables f(t)=0 x(t)=0 dx(t)=0 ddx(t)=0
3939
@parameters m=10 k=1000 d=1
4040
41-
eqs = [
42-
f ~ input.u
41+
eqs = [f ~ input.u
4342
ddx * 10 ~ k * x + d * dx + f
4443
D(x) ~ dx
4544
D(dx) ~ ddx]
@@ -52,10 +51,8 @@ function MassSpringDamperSystem(data, time; name)
5251
@named clk = ContinuousClock()
5352
@named model = MassSpringDamper()
5453
55-
eqs = [
56-
connect(src.input, clk.output)
57-
connect(src.output, model.input)
58-
]
54+
eqs = [connect(src.input, clk.output)
55+
connect(src.output, model.input)]
5956
6057
ODESystem(eqs, t, [], []; name, systems = [src, clk, model])
6158
end
@@ -100,11 +97,10 @@ using Plots
10097
10198
function MassSpringDamper(; name)
10299
@named input = RealInput()
103-
vars = @variables f(t) x(t)=0 dx(t) [guess=0] ddx(t)
100+
vars = @variables f(t) x(t)=0 dx(t) [guess = 0] ddx(t)
104101
pars = @parameters m=10 k=1000 d=1
105102
106-
eqs = [
107-
f ~ input.u
103+
eqs = [f ~ input.u
108104
ddx * 10 ~ k * x + d * dx + f
109105
D(x) ~ dx
110106
D(dx) ~ ddx]
@@ -117,10 +113,8 @@ function MassSpringDamperSystem(data, time; name)
117113
@named clk = ContinuousClock()
118114
@named model = MassSpringDamper()
119115
120-
eqs = [
121-
connect(model.input, src.output)
122-
connect(src.input, clk.output)
123-
]
116+
eqs = [connect(model.input, src.output)
117+
connect(src.input, clk.output)]
124118
125119
ODESystem(eqs, t; name, systems = [src, clk, model])
126120
end
@@ -143,13 +137,15 @@ plot(sol)
143137
```
144138

145139
If we want to run a new data set, this requires only remaking the problem and solving again
140+
146141
```@example parametrized_interpolation
147142
prob2 = remake(prob, p = [sys.src.data => ones(length(df.data))])
148143
sol2 = solve(prob2)
149144
plot(sol2)
150145
```
151146

152147
!!! note
148+
153149
Note that when changing the data, the length of the new data must be the same as the length of the original data.
154150

155151
## Custom Component with External Data
@@ -224,7 +220,7 @@ using ModelingToolkitStandardLibrary.Blocks
224220
using OrdinaryDiffEq
225221

226222
function System(; name)
227-
src = SampledData(Float64, name=:src)
223+
src = SampledData(Float64, name = :src)
228224

229225
vars = @variables f(t)=0 x(t)=0 dx(t)=0 ddx(t)=0
230226
pars = @parameters m=10 k=1000 d=1
@@ -238,22 +234,22 @@ function System(; name)
238234
end
239235

240236
@named system = System()
241-
sys = structural_simplify(system, split=false)
237+
sys = structural_simplify(system, split = false)
242238
s = complete(system)
243239

244240
dt = 4e-4
245241
time = 0:dt:0.1
246242
data1 = sin.(2 * pi * time * 100)
247243
data2 = cos.(2 * pi * time * 50)
248244

249-
prob = ODEProblem(sys, [], (0, time[end]); split=false, tofloat = false, use_union=true)
245+
prob = ODEProblem(sys, [], (0, time[end]); split = false, tofloat = false, use_union = true)
250246
defs = ModelingToolkit.defaults(sys)
251247

252248
function get_prob(data)
253249
defs[s.src.buffer] = Parameter(data, dt)
254250
# ensure p is a uniform type of Vector{Parameter{Float64}} (converting from Vector{Any})
255251
p = Parameter.(ModelingToolkit.varmap_to_vars(defs, parameters(sys); tofloat = false))
256-
remake(prob; p, build_initializeprob=false)
252+
remake(prob; p, build_initializeprob = false)
257253
end
258254

259255
prob1 = get_prob(data1)

src/Blocks/Blocks.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ using ModelingToolkit: getdefault, t_nounits as t, D_nounits as D
1010
export RealInput, RealInputArray, RealOutput, RealOutputArray, SISO
1111
include("utils.jl")
1212

13-
export Gain, Sum, MatrixGain, Feedback, Add, Add3, Product, Division, Power, Modulo, UnaryMinus, Floor, Ceil
13+
export Gain, Sum, MatrixGain, Feedback, Add, Add3, Product, Division, Power, Modulo,
14+
UnaryMinus, Floor, Ceil
1415
export Abs, Sign, Sqrt, Sin, Cos, Tan, Asin, Acos, Atan, Atan2, Sinh, Cosh, Tanh, Exp
1516
export Log, Log10
1617
include("math.jl")

src/Blocks/math.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ Output the exponential with base as the first input and exponent as second input
226226
output = RealOutput()
227227
end
228228
@equations begin
229-
output.u ~ base.u ^ exponent.u
229+
output.u ~ base.u^exponent.u
230230
end
231231
end
232232

src/Hydraulic/IsothermalCompressible/components.jl

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ Caps a hydraulic port to prevent mass flow in or out.
88
- `port`: hydraulic port
99
"""
1010
@mtkmodel Cap begin
11-
1211
@variables begin
1312
p(t), [guess = 0]
1413
end
@@ -21,7 +20,6 @@ Caps a hydraulic port to prevent mass flow in or out.
2120
port.p ~ p
2221
port.dm ~ 0
2322
end
24-
2523
end
2624

2725
"""
@@ -33,7 +31,6 @@ Provides an "open" boundary condition for a hydraulic port such that mass flow `
3331
- `port`: hydraulic port
3432
"""
3533
@mtkmodel Open begin
36-
3734
@variables begin
3835
p(t), [guess = 0]
3936
dm(t), [guess = 0]
@@ -47,7 +44,6 @@ Provides an "open" boundary condition for a hydraulic port such that mass flow `
4744
port.p ~ p
4845
port.dm ~ dm
4946
end
50-
5147
end
5248

5349
"""
@@ -261,7 +257,6 @@ Reduces the flow from `port_a` to `port_b` by `n`. Useful for modeling parallel
261257
open.dm ~ dm_a - dm_b # extra flow dumps into an open port
262258
# port_b.dm ~ dm_b # divided flow goes to port_b
263259
end
264-
265260
end
266261

267262
@component function ValveBase(
@@ -355,7 +350,6 @@ Valve with `area` input and discharge coefficient `Cd` defined by https://en.wik
355350
end
356351

357352
@mtkmodel VolumeBase begin
358-
359353
@structural_parameters begin
360354
Χ1 = 1
361355
Χ2 = 1
@@ -385,7 +379,6 @@ end
385379
rho ~ full_density(port, port.p)
386380
port.dm ~ drho * vol * Χ1 + rho * area * dx * Χ2
387381
end
388-
389382
end
390383

391384
"""
@@ -400,7 +393,6 @@ Fixed fluid volume.
400393
- `port`: hydraulic port
401394
"""
402395
@mtkmodel FixedVolume begin
403-
404396
@parameters begin
405397
vol
406398
end
@@ -419,7 +411,6 @@ Fixed fluid volume.
419411
rho ~ full_density(port, port.p)
420412
port.dm ~ drho * vol
421413
end
422-
423414
end
424415

425416
"""
@@ -461,7 +452,6 @@ dm ────► │ │ area
461452
See also [`FixedVolume`](@ref), [`DynamicVolume`](@ref)
462453
"""
463454
@mtkmodel Volume begin
464-
465455
@structural_parameters begin
466456
direction = 1
467457
end
@@ -505,7 +495,6 @@ See also [`FixedVolume`](@ref), [`DynamicVolume`](@ref)
505495
@defaults begin
506496
rho => liquid_density(port)
507497
end
508-
509498
end
510499

511500
"""

src/Hydraulic/IsothermalCompressible/sources.jl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Hydraulic mass flow input source
99
- `dm`: real input
1010
"""
1111
@mtkmodel MassFlow begin
12-
1312
@components begin
1413
port = HydraulicPort()
1514
dm = RealInput()
@@ -32,7 +31,6 @@ Fixed pressure source
3231
- `port`: hydraulic port
3332
"""
3433
@mtkmodel FixedPressure begin
35-
3634
@parameters begin
3735
p
3836
end
@@ -44,7 +42,6 @@ Fixed pressure source
4442
@equations begin
4543
port.p ~ p
4644
end
47-
4845
end
4946
@deprecate Source FixedPressure
5047

@@ -58,7 +55,6 @@ input pressure source
5855
- `p`: real input
5956
"""
6057
@mtkmodel Pressure begin
61-
6258
@components begin
6359
port = HydraulicPort()
6460
p = RealInput()
@@ -67,6 +63,5 @@ input pressure source
6763
@equations begin
6864
port.p ~ p.u
6965
end
70-
7166
end
7267
@deprecate InputSource Pressure

src/Thermal/HeatTransfer/sources.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ the component FixedHeatFlow is connected, if parameter `Q_flow` is positive.
2828
end
2929

3030
@equations begin
31-
port.Q_flow ~ ifelse(alpha == 0.0,
32-
-Q_flow, # Simplified equation when alpha is 0
33-
-Q_flow * (1 + alpha * (port.T - T_ref)))
31+
port.Q_flow ~ ifelse(alpha == 0.0,
32+
-Q_flow, # Simplified equation when alpha is 0
33+
-Q_flow * (1 + alpha * (port.T - T_ref)))
3434
end
3535
end
3636

src/Thermal/utils.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
@connector function HeatPort(; T = nothing, T_guess = 273.15 + 20, Q_flow = nothing, Q_flow_guess = 0.0, name)
1+
@connector function HeatPort(;
2+
T = nothing, T_guess = 273.15 + 20, Q_flow = nothing, Q_flow_guess = 0.0, name)
23
pars = @parameters begin
34
T_guess = T_guess
45
Q_flow_guess = Q_flow_guess

test/Blocks/math.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ end
180180

181181
@testset "Modulo" begin
182182
@named c1 = Ramp(height = 2, duration = 1, offset = 1, start_time = 0, smooth = false)
183-
@named c2 = Constant(; k = 1)
183+
@named c2 = Constant(; k = 1)
184184
@named modl = Modulo(;)
185185
@named model = ODESystem(
186186
[
@@ -194,7 +194,7 @@ end
194194
sol = solve(prob, Rodas4())
195195
@test isequal(unbound_inputs(sys), [])
196196
@test sol.retcode == Success
197-
@test sol[modl.remainder.u] mod.(2 * sol.t,1)
197+
@test sol[modl.remainder.u] mod.(2 * sol.t, 1)
198198
end
199199

200200
@testset "UnaryMinus" begin
@@ -213,7 +213,7 @@ end
213213
sol = solve(prob, Rodas4())
214214
@test isequal(unbound_inputs(sys), [])
215215
@test sol.retcode == Success
216-
@test sol[minu.output.u] - sin.(2 * pi * sol.t)
216+
@test sol[minu.output.u] -sin.(2 * pi * sol.t)
217217
end
218218

219219
@testset "Floor" begin

test/Blocks/test_analysis_points.jl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ Sinner = sminreal(ss(get_sensitivity(sys_inner, :u)[1]...))
266266

267267
Souter = sminreal(ss(get_sensitivity(sys_outer, sys_outer.sys_inner.u)[1]...))
268268

269-
Sinner2 = sminreal(ss(get_sensitivity(sys_outer, sys_outer.sys_inner.u, loop_openings = [:y2])[1]...))
269+
Sinner2 = sminreal(ss(get_sensitivity(
270+
sys_outer, sys_outer.sys_inner.u, loop_openings = [:y2])[1]...))
270271

271272
@test Sinner.nx == 1
272273
@test Sinner == Sinner2
@@ -332,7 +333,8 @@ eqs = [connect(r.output, F.input)
332333
connect(F.output, sys_inner.add.input1)]
333334
sys_outer = ODESystem(eqs, t, systems = [F, sys_inner, r], name = :outer)
334335

335-
matrices, _ = get_sensitivity(sys_outer, [sys_outer.inner.plant_input, sys_outer.inner.plant_output])
336+
matrices, _ = get_sensitivity(
337+
sys_outer, [sys_outer.inner.plant_input, sys_outer.inner.plant_output])
336338

337339
Ps = tf(1, [1, 1]) |> ss
338340
Cs = tf(1) |> ss
@@ -346,7 +348,8 @@ So = CS.feedback(1, Ps * Cs)
346348
@test tf(G[1, 2]) tf(-CS.feedback(Cs, Ps))
347349
@test tf(G[2, 1]) tf(CS.feedback(Ps, Cs))
348350

349-
matrices, _ = get_comp_sensitivity(sys_outer, [sys_outer.inner.plant_input, sys_outer.inner.plant_output])
351+
matrices, _ = get_comp_sensitivity(
352+
sys_outer, [sys_outer.inner.plant_input, sys_outer.inner.plant_output])
350353

351354
G = CS.ss(matrices...) |> sminreal
352355
Ti = CS.feedback(Cs * Ps)
@@ -369,13 +372,15 @@ L = CS.ss(matrices...) |> sminreal
369372
@test tf(L[1, 1]) -tf(Ps * Cs)
370373

371374
# Calling looptransfer like below is not the intended way, but we can work out what it should return if we did so it remains a valid test
372-
matrices, _ = get_looptransfer(sys_outer, [sys_outer.inner.plant_input, sys_outer.inner.plant_output])
375+
matrices, _ = get_looptransfer(
376+
sys_outer, [sys_outer.inner.plant_input, sys_outer.inner.plant_output])
373377
L = CS.ss(matrices...) |> sminreal
374378
@test tf(L[1, 1]) tf(0)
375379
@test tf(L[2, 2]) tf(0)
376380
@test sminreal(L[1, 2]) ss(-1)
377381
@test tf(L[2, 1]) tf(Ps)
378382

379-
matrices, _ = linearize(sys_outer, [sys_outer.inner.plant_input], [sys_outer.inner.plant_output])
383+
matrices, _ = linearize(
384+
sys_outer, [sys_outer.inner.plant_input], [sys_outer.inner.plant_output])
380385
G = CS.ss(matrices...) |> sminreal
381386
@test tf(G) tf(CS.feedback(Ps, Cs))

test/Thermal/piston.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ using ModelingToolkitStandardLibrary.Blocks
4242
# The initial value doesn't add up to absolute zero, while the rest do. To avoid
4343
# tolerance on the latter, the test is split in two parts.
4444
@test sol[piston.gas.Q_flow][1] + sol[piston.coolant.Q_flow][1]0 atol=1e-6
45-
@test sol[piston.gas.Q_flow][2:end] + sol[piston.coolant.Q_flow][2:end]
46-
zeros(length(sol) - 1) atol = 1e-6
45+
@test sol[piston.gas.Q_flow][2:end] +
46+
sol[piston.coolant.Q_flow][2:end]
47+
zeros(length(sol) - 1) atol=1e-6
4748
end

0 commit comments

Comments
 (0)