1
1
using ModelingToolkit, Test
2
2
using ModelingToolkit: get_connector_type, get_defaults, get_gui_metadata,
3
3
get_systems, get_ps, getdefault, getname, readable_code,
4
- scalarize, symtype, VariableDescription, RegularConnector
4
+ scalarize, symtype, VariableDescription, RegularConnector,
5
+ get_unit
5
6
using URIs: URI
6
7
using Distributions
7
8
using DynamicQuantities, OrdinaryDiffEq
@@ -106,14 +107,14 @@ end
106
107
@parameters begin
107
108
C, [unit = u " F" ]
108
109
end
109
- @extend OnePort (; v = 0.0 )
110
+ @extend OnePort (; v = 0.0 u " V " )
110
111
@icon " https://upload.wikimedia.org/wikipedia/commons/7/78/Capacitor_symbol.svg"
111
112
@equations begin
112
113
D (v) ~ i / C
113
114
end
114
115
end
115
116
116
- @named capacitor = Capacitor (C = 10 , v = 10.0 )
117
+ @named capacitor = Capacitor (C = 10 u " F " , v = 10.0 u " V " )
117
118
@test getdefault (capacitor. v) == 10.0
118
119
119
120
@mtkmodel Voltage begin
128
129
129
130
@mtkmodel RC begin
130
131
@structural_parameters begin
131
- R_val = 10
132
- C_val = 10
133
- k_val = 10
132
+ R_val = 10 u " Ω "
133
+ C_val = 10 u " F "
134
+ k_val = 10 u " V "
134
135
end
135
136
@components begin
136
137
resistor = Resistor (; R = R_val)
148
149
end
149
150
end
150
151
151
- C_val = 20
152
- R_val = 20
153
- res__R = 100
152
+ C_val = 20 u " F "
153
+ R_val = 20 u " Ω "
154
+ res__R = 100 u " Ω "
154
155
@mtkbuild rc = RC (; C_val, R_val, resistor. R = res__R)
155
156
prob = ODEProblem (rc, [], (0 , 1e9 ))
156
157
sol = solve (prob, Rodas5P ())
@@ -161,11 +162,11 @@ resistor = getproperty(rc, :resistor; namespace = false)
161
162
@test getname (rc. resistor. R) === getname (resistor. R)
162
163
@test getname (rc. resistor. v) === getname (resistor. v)
163
164
# Test that `resistor.R` overrides `R_val` in the argument.
164
- @test getdefault (rc. resistor. R) == res__R != R_val
165
+ @test getdefault (rc. resistor. R) * get_unit (rc . resistor . R) == res__R != R_val
165
166
# Test that `C_val` passed via argument is set as default of C.
166
- @test getdefault (rc. capacitor. C) == C_val
167
+ @test getdefault (rc. capacitor. C) * get_unit (rc . capacitor . C) == C_val
167
168
# Test that `k`'s default value is unchanged.
168
- @test getdefault (rc. constant. k) == RC. structure[:kwargs ][:k_val ][:value ]
169
+ @test getdefault (rc. constant. k) * get_unit (rc . constant . k) == eval ( RC. structure[:kwargs ][:k_val ][:value ])
169
170
@test getdefault (rc. capacitor. v) == 0.0
170
171
171
172
@test get_gui_metadata (rc. resistor). layout == Resistor. structure[:icon ] ==
0 commit comments