11using ModelingToolkit, Test
22using ModelingToolkit: get_connector_type, get_defaults, get_gui_metadata,
33 get_systems, get_ps, getdefault, getname, readable_code,
4- scalarize, symtype, VariableDescription, RegularConnector
4+ scalarize, symtype, VariableDescription, RegularConnector,
5+ get_unit
56using URIs: URI
67using Distributions
78using DynamicQuantities, OrdinaryDiffEq
@@ -106,14 +107,14 @@ end
106107 @parameters begin
107108 C, [unit = u " F" ]
108109 end
109- @extend OnePort (; v = 0.0 )
110+ @extend OnePort (; v = 0.0 u " V " )
110111 @icon " https://upload.wikimedia.org/wikipedia/commons/7/78/Capacitor_symbol.svg"
111112 @equations begin
112113 D (v) ~ i / C
113114 end
114115end
115116
116- @named capacitor = Capacitor (C = 10 , v = 10.0 )
117+ @named capacitor = Capacitor (C = 10 u " F " , v = 10.0 u " V " )
117118@test getdefault (capacitor. v) == 10.0
118119
119120@mtkmodel Voltage begin
128129
129130@mtkmodel RC begin
130131 @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 "
134135 end
135136 @components begin
136137 resistor = Resistor (; R = R_val)
148149 end
149150end
150151
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 " Ω "
154155@mtkbuild rc = RC (; C_val, R_val, resistor. R = res__R)
155156prob = ODEProblem (rc, [], (0 , 1e9 ))
156157sol = solve (prob, Rodas5P ())
@@ -161,11 +162,11 @@ resistor = getproperty(rc, :resistor; namespace = false)
161162@test getname (rc. resistor. R) === getname (resistor. R)
162163@test getname (rc. resistor. v) === getname (resistor. v)
163164# 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
165166# 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
167168# 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 ])
169170@test getdefault (rc. capacitor. v) == 0.0
170171
171172@test get_gui_metadata (rc. resistor). layout == Resistor. structure[:icon ] ==
0 commit comments