Skip to content

Commit 3292cce

Browse files
committed
New formatting
1 parent 5561943 commit 3292cce

File tree

7 files changed

+129
-79
lines changed

7 files changed

+129
-79
lines changed

docs/src/basics/Validation.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ using ModelingToolkit, Unitful
1212
1313
@variables(t, [unit = u"s"], x(t), [unit = u"m"], g(t), w(t), [unit = "Hz"])
1414
15-
@variables(begin t, [unit = u"s"],
16-
x(t), [unit = u"m"],
17-
g(t),
18-
w(t), [unit = "Hz"] end)
15+
@variables(begin
16+
t, [unit = u"s"],
17+
x(t), [unit = u"m"],
18+
g(t),
19+
w(t), [unit = "Hz"]
20+
end)
1921
2022
# Simultaneously set default value (use plain numbers, not quantities)
2123
@variables x=10 [unit = u"m"]

src/systems/systemstructure.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,11 @@ function TearingState(sys; quick_cancel = false, check = true)
262262
var_counter = Ref(0)
263263
var_types = VariableType[]
264264
addvar! = let fullvars = fullvars, var_counter = var_counter, var_types = var_types
265-
var -> begin get!(var2idx, var) do
265+
var -> get!(var2idx, var) do
266266
push!(fullvars, var)
267267
push!(var_types, getvariabletype(var))
268268
var_counter[] += 1
269-
end end
269+
end
270270
end
271271

272272
vars = OrderedSet()

test/model_parsing.jl

+39-13
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
using ModelingToolkit, Test
22

3-
@connector RealInput begin u(t), [input = true] end
4-
@connector RealOutput begin u(t), [output = true] end
3+
@connector RealInput begin
4+
u(t), [input = true]
5+
end
6+
@connector RealOutput begin
7+
u(t), [output = true]
8+
end
59
@model Constant begin
6-
@components begin output = RealOutput() end
7-
@parameters begin k, [description = "Constant output value of block"] end
8-
@equations begin output.u ~ k end
10+
@components begin
11+
output = RealOutput()
12+
end
13+
@parameters begin
14+
k, [description = "Constant output value of block"]
15+
end
16+
@equations begin
17+
output.u ~ k
18+
end
919
end
1020

1121
@variables t
@@ -33,26 +43,42 @@ end
3343
end
3444

3545
@model Ground begin
36-
@components begin g = Pin() end
37-
@equations begin g.v ~ 0 end
46+
@components begin
47+
g = Pin()
48+
end
49+
@equations begin
50+
g.v ~ 0
51+
end
3852
end
3953

4054
@model Resistor begin
4155
@extend v, i = oneport = OnePort()
42-
@parameters begin R = 1 end
43-
@equations begin v ~ i * R end
56+
@parameters begin
57+
R = 1
58+
end
59+
@equations begin
60+
v ~ i * R
61+
end
4462
end
4563

4664
@model Capacitor begin
4765
@extend v, i = oneport = OnePort()
48-
@parameters begin C = 1 end
49-
@equations begin D(v) ~ i / C end
66+
@parameters begin
67+
C = 1
68+
end
69+
@equations begin
70+
D(v) ~ i / C
71+
end
5072
end
5173

5274
@model Voltage begin
5375
@extend v, i = oneport = OnePort()
54-
@components begin V = RealInput() end
55-
@equations begin v ~ V.u end
76+
@components begin
77+
V = RealInput()
78+
end
79+
@equations begin
80+
v ~ V.u
81+
end
5682
end
5783

5884
@model RC begin

test/runtests.jl

+49-49
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
11
using SafeTestsets, Test
22

3-
@safetestset "Linear Algebra Test" begin include("linalg.jl") end
4-
@safetestset "AbstractSystem Test" begin include("abstractsystem.jl") end
5-
@safetestset "Variable Scope Tests" begin include("variable_scope.jl") end
6-
@safetestset "Symbolic Parameters Test" begin include("symbolic_parameters.jl") end
7-
@safetestset "Parsing Test" begin include("variable_parsing.jl") end
8-
@safetestset "Simplify Test" begin include("simplify.jl") end
9-
@safetestset "Direct Usage Test" begin include("direct.jl") end
10-
@safetestset "System Linearity Test" begin include("linearity.jl") end
11-
@safetestset "Linearization Tests" begin include("linearize.jl") end
12-
@safetestset "Input Output Test" begin include("input_output_handling.jl") end
13-
@safetestset "Clock Test" begin include("clock.jl") end
14-
@safetestset "DiscreteSystem Test" begin include("discretesystem.jl") end
15-
@safetestset "ODESystem Test" begin include("odesystem.jl") end
16-
@safetestset "Unitful Quantities Test" begin include("units.jl") end
17-
@safetestset "LabelledArrays Test" begin include("labelledarrays.jl") end
18-
@safetestset "Mass Matrix Test" begin include("mass_matrix.jl") end
19-
@safetestset "SteadyStateSystem Test" begin include("steadystatesystems.jl") end
20-
@safetestset "SDESystem Test" begin include("sdesystem.jl") end
21-
@safetestset "NonlinearSystem Test" begin include("nonlinearsystem.jl") end
22-
@safetestset "PDE Construction Test" begin include("pde.jl") end
23-
@safetestset "JumpSystem Test" begin include("jumpsystem.jl") end
24-
@safetestset "Constraints Test" begin include("constraints.jl") end
25-
@safetestset "Reduction Test" begin include("reduction.jl") end
26-
@safetestset "ODAEProblem Test" begin include("odaeproblem.jl") end
27-
@safetestset "Components Test" begin include("components.jl") end
28-
@safetestset "Model Parsing Test" begin include("model_parsing.jl") end
29-
@safetestset "print_tree" begin include("print_tree.jl") end
30-
@safetestset "Error Handling" begin include("error_handling.jl") end
31-
@safetestset "StructuralTransformations" begin include("structural_transformation/runtests.jl") end
32-
@safetestset "State Selection Test" begin include("state_selection.jl") end
33-
@safetestset "Symbolic Event Test" begin include("symbolic_events.jl") end
34-
@safetestset "Stream Connnect Test" begin include("stream_connectors.jl") end
35-
@safetestset "Lowering Integration Test" begin include("lowering_solving.jl") end
36-
@safetestset "Test Big System Usage" begin include("bigsystem.jl") end
37-
@safetestset "Depdendency Graph Test" begin include("dep_graphs.jl") end
38-
@safetestset "Function Registration Test" begin include("function_registration.jl") end
39-
@safetestset "Precompiled Modules Test" begin include("precompile_test.jl") end
40-
@testset "Distributed Test" begin include("distributed.jl") end
41-
@safetestset "Variable Utils Test" begin include("variable_utils.jl") end
42-
@safetestset "Variable Metadata Test" begin include("test_variable_metadata.jl") end
43-
@safetestset "DAE Jacobians Test" begin include("dae_jacobian.jl") end
44-
@safetestset "Jacobian Sparsity" begin include("jacobiansparsity.jl") end
3+
@safetestset "Linear Algebra Test" include("linalg.jl")
4+
@safetestset "AbstractSystem Test" include("abstractsystem.jl")
5+
@safetestset "Variable Scope Tests" include("variable_scope.jl")
6+
@safetestset "Symbolic Parameters Test" include("symbolic_parameters.jl")
7+
@safetestset "Parsing Test" include("variable_parsing.jl")
8+
@safetestset "Simplify Test" include("simplify.jl")
9+
@safetestset "Direct Usage Test" include("direct.jl")
10+
@safetestset "System Linearity Test" include("linearity.jl")
11+
@safetestset "Linearization Tests" include("linearize.jl")
12+
@safetestset "Input Output Test" include("input_output_handling.jl")
13+
@safetestset "Clock Test" include("clock.jl")
14+
@safetestset "DiscreteSystem Test" include("discretesystem.jl")
15+
@safetestset "ODESystem Test" include("odesystem.jl")
16+
@safetestset "Unitful Quantities Test" include("units.jl")
17+
@safetestset "LabelledArrays Test" include("labelledarrays.jl")
18+
@safetestset "Mass Matrix Test" include("mass_matrix.jl")
19+
@safetestset "SteadyStateSystem Test" include("steadystatesystems.jl")
20+
@safetestset "SDESystem Test" include("sdesystem.jl")
21+
@safetestset "NonlinearSystem Test" include("nonlinearsystem.jl")
22+
@safetestset "PDE Construction Test" include("pde.jl")
23+
@safetestset "JumpSystem Test" include("jumpsystem.jl")
24+
@safetestset "Constraints Test" include("constraints.jl")
25+
@safetestset "Reduction Test" include("reduction.jl")
26+
@safetestset "ODAEProblem Test" include("odaeproblem.jl")
27+
@safetestset "Components Test" include("components.jl")
28+
@safetestset "Model Parsing Test" include("model_parsing.jl")
29+
@safetestset "print_tree" include("print_tree.jl")
30+
@safetestset "Error Handling" include("error_handling.jl")
31+
@safetestset "StructuralTransformations" include("structural_transformation/runtests.jl")
32+
@safetestset "State Selection Test" include("state_selection.jl")
33+
@safetestset "Symbolic Event Test" include("symbolic_events.jl")
34+
@safetestset "Stream Connnect Test" include("stream_connectors.jl")
35+
@safetestset "Lowering Integration Test" include("lowering_solving.jl")
36+
@safetestset "Test Big System Usage" include("bigsystem.jl")
37+
@safetestset "Depdendency Graph Test" include("dep_graphs.jl")
38+
@safetestset "Function Registration Test" include("function_registration.jl")
39+
@safetestset "Precompiled Modules Test" include("precompile_test.jl")
40+
@testset "Distributed Test" include("distributed.jl")
41+
@safetestset "Variable Utils Test" include("variable_utils.jl")
42+
@safetestset "Variable Metadata Test" include("test_variable_metadata.jl")
43+
@safetestset "DAE Jacobians Test" include("dae_jacobian.jl")
44+
@safetestset "Jacobian Sparsity" include("jacobiansparsity.jl")
4545
println("Last test requires gcc available in the path!")
46-
@safetestset "C Compilation Test" begin include("ccompile.jl") end
47-
@testset "Serialization" begin include("serialization.jl") end
48-
@safetestset "Modelingtoolkitize Test" begin include("modelingtoolkitize.jl") end
49-
@safetestset "OptimizationSystem Test" begin include("optimizationsystem.jl") end
50-
@safetestset "FuncAffect Test" begin include("funcaffect.jl") end
51-
@safetestset "Constants Test" begin include("constants.jl") end
46+
@safetestset "C Compilation Test" include("ccompile.jl")
47+
@testset "Serialization" include("serialization.jl")
48+
@safetestset "Modelingtoolkitize Test" include("modelingtoolkitize.jl")
49+
@safetestset "OptimizationSystem Test" include("optimizationsystem.jl")
50+
@safetestset "FuncAffect Test" include("funcaffect.jl")
51+
@safetestset "Constants Test" include("constants.jl")
5252
# Reference tests go Last
53-
@safetestset "Latexify recipes Test" begin include("latexify.jl") end
53+
@safetestset "Latexify recipes Test" include("latexify.jl")

test/stream_connectors.jl

+18-6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ end
2525
viscosity = V
2626
end
2727

28-
vars = @variables begin m_flow(t), [connect = Flow] end
28+
vars = @variables begin
29+
m_flow(t), [connect = Flow]
30+
end
2931

3032
# equations ---------------------------
3133
eqs = Equation[m_flow ~ 0]
@@ -41,7 +43,9 @@ function MassFlowSource_h(; name,
4143
m_flow_in = m_flow_in
4244
end
4345

44-
vars = @variables begin P(t) end
46+
vars = @variables begin
47+
P(t)
48+
end
4549

4650
@named port = TwoPhaseFluidPort()
4751

@@ -324,7 +328,9 @@ end
324328
viscosity = V
325329
end
326330

327-
vars = @variables begin dm(t), [connect = Flow] end
331+
vars = @variables begin
332+
dm(t), [connect = Flow]
333+
end
328334

329335
# equations ---------------------------
330336
eqs = [
@@ -335,12 +341,16 @@ end
335341
end
336342

337343
function StepSource(; P, name)
338-
pars = @parameters begin p_int = P end
344+
pars = @parameters begin
345+
p_int = P
346+
end
339347

340348
vars = []
341349

342350
# nodes -------------------------------
343-
systems = @named begin H = HydraulicPort(; P = p_int) end
351+
systems = @named begin
352+
H = HydraulicPort(; P = p_int)
353+
end
344354

345355
# equations ---------------------------
346356
eqs = [
@@ -365,7 +375,9 @@ function StaticVolume(; P, V, name)
365375
end
366376

367377
# nodes -------------------------------
368-
systems = @named begin H = HydraulicPort(; P = p_int) end
378+
systems = @named begin
379+
H = HydraulicPort(; P = p_int)
380+
end
369381

370382
# fluid props ------------------------
371383
rho_0 = H.rho
+12-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
using SafeTestsets
22

3-
@safetestset "Utilities" begin include("utils.jl") end
4-
@safetestset "Index Reduction & SCC" begin include("index_reduction.jl") end
5-
@safetestset "Tearing" begin include("tearing.jl") end
6-
@safetestset "Bareiss" begin include("bareiss.jl") end
3+
@safetestset "Utilities" begin
4+
include("utils.jl")
5+
end
6+
@safetestset "Index Reduction & SCC" begin
7+
include("index_reduction.jl")
8+
end
9+
@safetestset "Tearing" begin
10+
include("tearing.jl")
11+
end
12+
@safetestset "Bareiss" begin
13+
include("bareiss.jl")
14+
end

test/symbolic_parameters.jl

+3-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ pars = @parameters(begin
5353
x0
5454
t
5555
end)
56-
vars = @variables(begin x(t) end)
56+
vars = @variables(begin
57+
x(t)
58+
end)
5759
der = Differential(t)
5860
eqs = [der(x) ~ x]
5961
@named sys = ODESystem(eqs, t, vars, [x0])

0 commit comments

Comments
 (0)