Skip to content

Commit 3d25d78

Browse files
committed
Formatted failing files using JuliaFormatter
1 parent 72f9197 commit 3d25d78

File tree

8 files changed

+38
-32
lines changed

8 files changed

+38
-32
lines changed

Project.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ version = "2.19.0"
77
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
88
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
99
IfElse = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173"
10+
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
1011
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1112
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
1213
PreallocationTools = "d236fae5-4411-538c-8e31-a6e3d9e00b46"
@@ -18,12 +19,13 @@ ChainRulesCore = "1.24"
1819
ControlSystemsBase = "1.4"
1920
DataFrames = "1.7"
2021
DataInterpolations = "6"
21-
ForwardDiff = "0.10"
2222
DiffEqBase = "6.152"
23+
ForwardDiff = "0.10"
2324
IfElse = "0.1"
25+
JuliaFormatter = "1.0.62"
2426
LinearAlgebra = "1.10"
25-
Optimization = "4"
2627
ModelingToolkit = "9.47"
28+
Optimization = "4"
2729
OrdinaryDiffEq = "6.87"
2830
OrdinaryDiffEqDefault = "1.1"
2931
PreallocationTools = "0.4.23"

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/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)