Skip to content

Commit 23b98a2

Browse files
committed
Test constants inside submodels.
1 parent ea15f34 commit 23b98a2

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/components.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,3 +258,27 @@ eqs = [
258258
@named big_rc = compose(_big_rc, rc_systems)
259259
ts = TearingState(expand_connections(big_rc))
260260
@test istriu(but_ordered_incidence(ts)[1])
261+
262+
# Test using constants inside subsystems
263+
function FixedResistor(; name, R = 1.0)
264+
@named oneport = OnePort()
265+
@unpack v, i = oneport
266+
@constants R = R
267+
eqs = [
268+
v ~ i * R,
269+
]
270+
extend(ODESystem(eqs, t, [], []; name = name), oneport)
271+
end
272+
capacitor = Capacitor(;name = :c1)
273+
resistor = FixedResistor(; name = :r1)
274+
ground = Ground(; name = :ground)
275+
rc_eqs = [connect(capacitor.n, resistor.p)
276+
connect(resistor.n, capacitor.p)
277+
connect(capacitor.n, ground.g)]
278+
279+
@named _rc_model = ODESystem(rc_eqs, t)
280+
@named rc_model = compose(_rc_model,
281+
[resistor, capacitor, ground])
282+
sys = structural_simplify(rc_model)
283+
prob = ODAEProblem(sys, u0, (0, 10.0))
284+
sol = solve(prob, Tsit5())

0 commit comments

Comments
 (0)