Skip to content

Commit 37c6897

Browse files
run JuliaFormatter per contributing guidelines. I didn't touch any of these files except ext/MTKFMIExt.jl!
1 parent 559150b commit 37c6897

File tree

10 files changed

+60
-53
lines changed

10 files changed

+60
-53
lines changed

docs/src/internals.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ This section documents the internal implementation details of ModelingToolkit. T
66

77
ModelingToolkit's internal architecture consists of several key components:
88

9-
- **Structural Transformation**: Algorithms for transforming equation systems, including index reduction, tearing, and algebraic simplification
10-
- **Bipartite Graphs**: Graph representations used to analyze relationships between equations and variables
11-
- **System Structure**: Internal representations of system state and transformations
9+
- **Structural Transformation**: Algorithms for transforming equation systems, including index reduction, tearing, and algebraic simplification
10+
- **Bipartite Graphs**: Graph representations used to analyze relationships between equations and variables
11+
- **System Structure**: Internal representations of system state and transformations
1212

1313
These components work together to enable ModelingToolkit's symbolic manipulation and code generation capabilities.
1414

1515
!!! warning
16+
1617
The functions and types documented in this section are internal implementation details. Users should not rely on these APIs as they may change or be removed without deprecation warnings.

docs/src/internals/bipartite_graph.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Bipartite Graphs
22

33
!!! warning "Internal API"
4+
45
The functions documented on this page are internal implementation details of ModelingToolkit. They are not part of the public API and may change or be removed without notice in non-breaking releases. This documentation is provided to help contributors understand the codebase.
56

67
ModelingToolkit uses bipartite graphs to represent relationships between equations and variables in systems. These functions provide tools for working with and analyzing these graphs.
@@ -77,4 +78,4 @@ asdigraph
7778
```@docs
7879
SRC
7980
DST
80-
```
81+
```

docs/src/internals/structural_transformation.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Structural Transformation
22

33
!!! warning "Internal API"
4+
45
The functions documented on this page are internal implementation details of ModelingToolkit. They are not part of the public API and may change or be removed without notice in non-breaking releases. This documentation is provided to help contributors understand the codebase.
56

67
These functions are used for structural analysis and transformation of equation systems, including index reduction, tearing, and other algebraic manipulations used in the simplification process.
@@ -84,4 +85,4 @@ InducedCondensationGraph
8485
MatchedCondensationGraph
8586
Unassigned
8687
unassigned
87-
```
88+
```

ext/MTKFMIExt.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,13 +373,11 @@ function parseFMIVariableName(name::AbstractString)
373373
safe_name = name
374374
end
375375

376-
377376
idx = findfirst(',', safe_name)
378377
if idx === nothing
379378
name = @view name[5:(end - 1)]
380379
der = 1
381380
else
382-
383381
der = parse(Int, @view name[(idx + 1):(end - 1)])
384382
name = @view name[5:(idx - 1)]
385383
end

src/systems/diffeqs/basic_transformations.jl

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,14 @@ sol = solve(prob, radau5(), abstol = 1e-10, reltol = 1e-10)
207207
"""
208208
function fractional_to_ordinary(
209209
eqs, variables, alphas, epsilon, T;
210-
initials = 0, additional_eqs = [], iv = only(@independent_variables t), matrix=false
210+
initials = 0, additional_eqs = [], iv = only(@independent_variables t), matrix = false
211211
)
212212
D = Differential(iv)
213213
i = 0
214214
all_eqs = Equation[]
215215
all_def = Pair[]
216-
217-
function fto_helper(sub_eq, sub_var, α; initial=0)
216+
217+
function fto_helper(sub_eq, sub_var, α; initial = 0)
218218
alpha_0 = α
219219

220220
if> 1)
@@ -250,28 +250,30 @@ function fractional_to_ordinary(
250250
if matrix
251251
new_z = Symbol(, :_, i)
252252
i += 1
253-
γs = diagm([γ_i(index) for index in M:N-1])
254-
cs = [c_i(index) for index in M:N-1]
253+
γs = diagm([γ_i(index) for index in M:(N - 1)])
254+
cs = [c_i(index) for index in M:(N - 1)]
255255

256256
if< 1)
257-
new_z = only(@variables $new_z(iv)[1:N-M])
257+
new_z = only(@variables $new_z(iv)[1:(N - M)])
258258
new_eq = D(new_z) ~ -γs*new_z .+ sub_eq
259259
rhs = dot(cs, new_z) + initial
260260
push!(def, new_z=>zeros(N-M))
261261
else
262-
new_z = only(@variables $new_z(iv)[1:N-M, 1:m])
263-
new_eq = D(new_z) ~ -γs*new_z + hcat(fill(sub_eq, N-M, 1), collect(new_z[:, 1:m-1]*diagm(1:m-1)))
264-
rhs = coeff*sum(cs[i]*new_z[i, m] for i in 1:N-M)
262+
new_z = only(@variables $new_z(iv)[1:(N - M), 1:m])
263+
new_eq = D(new_z) ~
264+
-γs*new_z +
265+
hcat(fill(sub_eq, N-M, 1), collect(new_z[:, 1:(m - 1)]*diagm(1:(m - 1))))
266+
rhs = coeff*sum(cs[i]*new_z[i, m] for i in 1:(N - M))
265267
for (index, value) in enumerate(initial)
266268
rhs += value * iv^(index - 1) / gamma(index)
267269
end
268270
push!(def, new_z=>zeros(N-M, m))
269271
end
270272
push!(new_eqs, new_eq)
271273
else
272-
if< 1)
274+
if< 1)
273275
rhs = initial
274-
for index in range(M, N-1; step=1)
276+
for index in range(M, N-1; step = 1)
275277
new_z = Symbol(, :_, i)
276278
i += 1
277279
new_z = ModelingToolkit.unwrap(only(@variables $new_z(iv)))
@@ -285,12 +287,12 @@ function fractional_to_ordinary(
285287
for (index, value) in enumerate(initial)
286288
rhs += value * iv^(index - 1) / gamma(index)
287289
end
288-
for index in range(M, N-1; step=1)
290+
for index in range(M, N-1; step = 1)
289291
new_z = Symbol(, :_, i)
290292
i += 1
291293
γ = γ_i(index)
292294
base = sub_eq
293-
for k in range(1, m; step=1)
295+
for k in range(1, m; step = 1)
294296
new_z = Symbol(, :_, index-M, :_, k)
295297
new_z = ModelingToolkit.unwrap(only(@variables $new_z(iv)))
296298
new_eq = D(new_z) ~ base - γ*new_z
@@ -307,12 +309,12 @@ function fractional_to_ordinary(
307309
end
308310

309311
for (eq, cur_var, alpha, init) in zip(eqs, variables, alphas, initials)
310-
(new_eqs, def) = fto_helper(eq, cur_var, alpha; initial=init)
312+
(new_eqs, def) = fto_helper(eq, cur_var, alpha; initial = init)
311313
append!(all_eqs, new_eqs)
312314
append!(all_def, def)
313315
end
314316
append!(all_eqs, additional_eqs)
315-
@named sys = System(all_eqs, iv; defaults=all_def)
317+
@named sys = System(all_eqs, iv; defaults = all_def)
316318
return mtkcompile(sys)
317319
end
318320

@@ -338,7 +340,7 @@ sol = solve(prob, radau5(), abstol = 1e-5, reltol = 1e-5)
338340
"""
339341
function linear_fractional_to_ordinary(
340342
degrees, coeffs, rhs, epsilon, T;
341-
initials = 0, symbol = :x, iv = only(@independent_variables t), matrix=false
343+
initials = 0, symbol = :x, iv = only(@independent_variables t), matrix = false
342344
)
343345
previous = Symbol(symbol, :_, 0)
344346
previous = ModelingToolkit.unwrap(only(@variables $previous(iv)))
@@ -371,17 +373,17 @@ function linear_fractional_to_ordinary(
371373
if matrix
372374
new_z = Symbol(, :_, i)
373375
i += 1
374-
γs = diagm([γ_i(index) for index in M:N-1])
375-
cs = [c_i(index) for index in M:N-1]
376+
γs = diagm([γ_i(index) for index in M:(N - 1)])
377+
cs = [c_i(index) for index in M:(N - 1)]
376378

377-
new_z = only(@variables $new_z(iv)[1:N-M])
379+
new_z = only(@variables $new_z(iv)[1:(N - M)])
378380
new_eq = D(new_z) ~ -γs*new_z .+ sub_eq
379381
sum = dot(cs, new_z)
380382
push!(def, new_z=>zeros(N-M))
381383
push!(new_eqs, new_eq)
382384
else
383385
sum = 0
384-
for index in range(M, N-1; step=1)
386+
for index in range(M, N-1; step = 1)
385387
new_z = Symbol(, :_, i)
386388
i += 1
387389
new_z = ModelingToolkit.unwrap(only(@variables $new_z(iv)))
@@ -394,7 +396,7 @@ function linear_fractional_to_ordinary(
394396
return (new_eqs, def, sum)
395397
end
396398

397-
for i in range(1, ceil(Int, degrees[1]); step=1)
399+
for i in range(1, ceil(Int, degrees[1]); step = 1)
398400
new_x = Symbol(symbol, :_, i)
399401
new_x = ModelingToolkit.unwrap(only(@variables $new_x(iv)))
400402
push!(all_eqs, D(previous) ~ new_x)
@@ -417,7 +419,7 @@ function linear_fractional_to_ordinary(
417419
end
418420
end
419421
push!(all_eqs, 0 ~ new_rhs)
420-
@named sys = System(all_eqs, iv; defaults=all_def)
422+
@named sys = System(all_eqs, iv; defaults = all_def)
421423
return mtkcompile(sys)
422424
end
423425

test/components.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,8 @@ end
352352
@named comp1 = System(Equation[], t; systems = [input])
353353
@named output = RealOutput()
354354
@named comp2 = System(Equation[], t; systems = [output])
355-
@named sys = System([connect(comp2.output.u, comp1.input.u)], t; systems = [comp1, comp2])
355+
@named sys = System([connect(comp2.output.u, comp1.input.u)], t; systems = [
356+
comp1, comp2])
356357
eq = only(equations(expand_connections(sys)))
357358
# as opposed to `output.u ~ input.u`
358359
@test isequal(eq, comp1.input.u ~ comp2.output.u)

test/fractional_to_ordinary.jl

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ using Test
66
@independent_variables t
77
@variables x(t)
88
D = Differential(t)
9-
tspan = (0., 1.)
10-
timepoint = [0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.]
9+
tspan = (0.0, 1.0)
10+
timepoint = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
1111

1212
function expect(t, α)
1313
return (3/2*t^/2) - t^4)^2
@@ -19,23 +19,23 @@ eqs += (gamma(9)*t^(8 - α)/gamma(9 - α)) + (3/2*t^(α/2)-t^4)^3 - x^(3/2)
1919
sys = fractional_to_ordinary(eqs, x, α, 10^-7, 1)
2020

2121
prob = ODEProblem(sys, [], tspan)
22-
sol = solve(prob, radau5(), saveat=timepoint, abstol = 1e-10, reltol = 1e-10)
22+
sol = solve(prob, radau5(), saveat = timepoint, abstol = 1e-10, reltol = 1e-10)
2323

2424
for time in 0:0.1:1
25-
@test isapprox(expect(time, α), sol(time, idxs=x), atol=1e-7)
25+
@test isapprox(expect(time, α), sol(time, idxs = x), atol = 1e-7)
2626
time += 0.1
2727
end
2828

2929
α = 0.3
3030
eqs = (9*gamma(1 + α)/4) - (3*t^(4 - α/2)*gamma(5 + α/2)/gamma(5 - α/2))
3131
eqs += (gamma(9)*t^(8 - α)/gamma(9 - α)) + (3/2*t^/2)-t^4)^3 - x^(3/2)
32-
sys = fractional_to_ordinary(eqs, x, α, 10^-7, 1; matrix=true)
32+
sys = fractional_to_ordinary(eqs, x, α, 10^-7, 1; matrix = true)
3333

3434
prob = ODEProblem(sys, [], tspan)
35-
sol = solve(prob, radau5(), saveat=timepoint, abstol = 1e-10, reltol = 1e-10)
35+
sol = solve(prob, radau5(), saveat = timepoint, abstol = 1e-10, reltol = 1e-10)
3636

3737
for time in 0:0.1:1
38-
@test isapprox(expect(time, α), sol(time, idxs=x), atol=1e-7)
38+
@test isapprox(expect(time, α), sol(time, idxs = x), atol = 1e-7)
3939
end
4040

4141
α = 0.9
@@ -44,43 +44,46 @@ eqs += (gamma(9)*t^(8 - α)/gamma(9 - α)) + (3/2*t^(α/2)-t^4)^3 - x^(3/2)
4444
sys = fractional_to_ordinary(eqs, x, α, 10^-7, 1)
4545

4646
prob = ODEProblem(sys, [], tspan)
47-
sol = solve(prob, radau5(), saveat=timepoint, abstol = 1e-10, reltol = 1e-10)
47+
sol = solve(prob, radau5(), saveat = timepoint, abstol = 1e-10, reltol = 1e-10)
4848

4949
for time in 0:0.1:1
50-
@test isapprox(expect(time, α), sol(time, idxs=x), atol=1e-7)
50+
@test isapprox(expect(time, α), sol(time, idxs = x), atol = 1e-7)
5151
end
5252

5353
# Testing for example 2 of Section 7
5454
@independent_variables t
5555
@variables x(t) y(t)
5656
D = Differential(t)
57-
tspan = (0., 220.)
57+
tspan = (0.0, 220.0)
5858

59-
sys = fractional_to_ordinary([1 - 4*x + x^2 * y, 3*x - x^2 * y], [x, y], [1.3, 0.8], 10^-8, 220; initials=[[1.2, 1], 2.8], matrix=true)
59+
sys = fractional_to_ordinary([1 - 4*x + x^2 * y, 3*x - x^2 * y], [x, y], [1.3, 0.8],
60+
10^-8, 220; initials = [[1.2, 1], 2.8], matrix = true)
6061
prob = ODEProblem(sys, [], tspan)
6162
sol = solve(prob, radau5(), abstol = 1e-8, reltol = 1e-8)
6263

63-
@test isapprox(1.0097684171, sol(220, idxs=x), atol=1e-5)
64-
@test isapprox(2.1581264031, sol(220, idxs=y), atol=1e-5)
64+
@test isapprox(1.0097684171, sol(220, idxs = x), atol = 1e-5)
65+
@test isapprox(2.1581264031, sol(220, idxs = y), atol = 1e-5)
6566

6667
#Testing for example 3 of Section 7
6768
@independent_variables t
6869
@variables x_0(t)
6970
D = Differential(t)
70-
tspan = (0., 5000.)
71+
tspan = (0.0, 5000.0)
7172

7273
function expect(t)
7374
return sqrt(2) * sin(t + pi/4)
7475
end
7576

76-
sys = linear_fractional_to_ordinary([3, 2.5, 2, 1, .5, 0], [1, 1, 1, 4, 1, 4], 6*cos(t), 10^-5, 5000; initials=[1, 1, -1])
77+
sys = linear_fractional_to_ordinary([3, 2.5, 2, 1, 0.5, 0], [1, 1, 1, 4, 1, 4],
78+
6*cos(t), 10^-5, 5000; initials = [1, 1, -1])
7779
prob = ODEProblem(sys, [], tspan)
7880
sol = solve(prob, radau5(), abstol = 1e-5, reltol = 1e-5)
7981

80-
@test isapprox(expect(5000), sol(5000, idxs=x_0), atol=1e-5)
82+
@test isapprox(expect(5000), sol(5000, idxs = x_0), atol = 1e-5)
8183

82-
msys = linear_fractional_to_ordinary([3, 2.5, 2, 1, .5, 0], [1, 1, 1, 4, 1, 4], 6*cos(t), 10^-5, 5000; initials=[1, 1, -1], matrix=true)
84+
msys = linear_fractional_to_ordinary([3, 2.5, 2, 1, 0.5, 0], [1, 1, 1, 4, 1, 4], 6*cos(t),
85+
10^-5, 5000; initials = [1, 1, -1], matrix = true)
8386
mprob = ODEProblem(sys, [], tspan)
8487
msol = solve(prob, radau5(), abstol = 1e-5, reltol = 1e-5)
8588

86-
@test isapprox(expect(5000), msol(5000, idxs=x_0), atol=1e-5)
89+
@test isapprox(expect(5000), msol(5000, idxs = x_0), atol = 1e-5)

test/model_parsing.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,16 +1065,16 @@ end
10651065
MyBool => false
10661066
NewInt => 1
10671067
end
1068-
1068+
10691069
@parameters begin
10701070
k = 1.0
10711071
end
1072-
1072+
10731073
@variables begin
10741074
x(t)
10751075
y(t)
10761076
end
1077-
1077+
10781078
@equations begin
10791079
D(x) ~ -k * x
10801080
y ~ x

test/parameter_dependencies.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ end
174174
end
175175

176176
@testset "Change Tunables" begin
177-
@variables θ(t)=π/6 ω(t)=0.
177+
@variables θ(t)=π/6 ω(t)=0.0
178178
@parameters g=9.81 L=1.0 b=0.1 errp=1
179179
eqs = [
180180
D(θ) ~ ω,

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ end
103103
@safetestset "Fractional Differential Equations Tests" include("fractional_to_ordinary.jl")
104104
end
105105
end
106-
106+
107107
if GROUP == "All" || GROUP == "SymbolicIndexingInterface"
108108
@safetestset "SymbolicIndexingInterface test" include("symbolic_indexing_interface.jl")
109109
@safetestset "SciML Problem Input Test" include("sciml_problem_inputs.jl")

0 commit comments

Comments
 (0)