1
1
using ModelingToolkit, Test
2
- using ModelingToolkit: get_gui_metadata
2
+ using ModelingToolkit: get_gui_metadata, VariableDescription, getdefault
3
3
using URIs: URI
4
4
5
5
ENV [" MTK_ICONS_DIR" ] = " $(@__DIR__ ) /icons"
10
10
@connector RealOutput begin
11
11
u (t), [output = true ]
12
12
end
13
- @model Constant begin
13
+ @model Constant (; k = 1 ) begin
14
14
@components begin
15
15
output = RealOutput ()
16
16
end
17
17
@parameters begin
18
- k, [description = " Constant output value of block" ]
18
+ k = k , [description = " Constant output value of block" ]
19
19
end
20
20
@equations begin
21
21
output. u ~ k
61
61
end
62
62
63
63
resistor_log = " $(@__DIR__ ) /logo/resistor.svg"
64
- @model Resistor begin
64
+ @model Resistor (; R = 1 ) begin
65
65
@extend v, i = oneport = OnePort ()
66
66
@parameters begin
67
- R = 1
67
+ R = R
68
68
end
69
69
@icon begin
70
70
""" <?xml version="1.0" encoding="UTF-8"?>
@@ -87,10 +87,10 @@ l15 0" stroke="black" stroke-width="1" stroke-linejoin="bevel" fill="none"></pat
87
87
end
88
88
end
89
89
90
- @model Capacitor begin
90
+ @model Capacitor (; C = 1 ) begin
91
91
@extend v, i = oneport = OnePort ()
92
92
@parameters begin
93
- C = 1
93
+ C = C
94
94
end
95
95
@icon " https://upload.wikimedia.org/wikipedia/commons/7/78/Capacitor_symbol.svg"
96
96
@equations begin
110
110
111
111
@model RC begin
112
112
@components begin
113
- resistor = Resistor ()
114
- capacitor = Capacitor ()
113
+ resistor = Resistor (; R )
114
+ capacitor = Capacitor (; C = 10 )
115
115
source = Voltage ()
116
116
constant = Constant ()
117
117
ground = Ground ()
123
123
connect (capacitor. n, source. n, ground. g)
124
124
end
125
125
end
126
- @named rc = RC ()
126
+
127
+ @named rc = RC (; resistor. R = 20 )
128
+ @test getdefault (rc. resistor. R) == 20
129
+ @test getdefault (rc. capacitor. C) == 10
130
+ @test getdefault (rc. constant. k) == 1
127
131
128
132
@test get_gui_metadata (rc. resistor). layout == Resistor. structure[:icon ] ==
129
133
read (joinpath (ENV [" MTK_ICONS_DIR" ], " resistor.svg" ), String)
137
141
URI (" file:///" * abspath (ENV [" MTK_ICONS_DIR" ], " pin.png" ))
138
142
139
143
@test length (equations (structural_simplify (rc))) == 1
144
+
145
+ @model MockModel (; cval, gval, jval = 6 ) begin
146
+ @parameters begin
147
+ a
148
+ b (t)
149
+ c (t) = cval
150
+ d = 2
151
+ e, [description = " e" ]
152
+ f = 3 , [description = " f" ]
153
+ g = gval, [description = " g" ]
154
+ h (t), [description = " h(t)" ]
155
+ i (t) = 5 , [description = " i(t)" ]
156
+ j (t) = jval, [description = " j(t)" ]
157
+ end
158
+ end
159
+
160
+ @named model = MockModel (cval = 1 , gval = 4 )
161
+
162
+ @test hasmetadata (model. e, VariableDescription)
163
+ @test hasmetadata (model. f, VariableDescription)
164
+ @test hasmetadata (model. g, VariableDescription)
165
+ @test hasmetadata (model. h, VariableDescription)
166
+ @test hasmetadata (model. i, VariableDescription)
167
+ @test hasmetadata (model. j, VariableDescription)
168
+
169
+ @test getdefault (model. c) == 1
170
+ @test getdefault (model. d) == 2
171
+ @test getdefault (model. f) == 3
172
+ @test getdefault (model. g) == 4
173
+ @test getdefault (model. i) == 5
174
+ @test getdefault (model. j) == 6
0 commit comments