Skip to content

Commit e76f5b2

Browse files
committed
Switch initial state guess added
1 parent 2dd943f commit e76f5b2

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/Electrical/Analog/ideal_components.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,20 +419,22 @@ G will therefore be 0 when the input is false [0] and G_on when the input is tru
419419
# Parameters:
420420
421421
- `Gon`: [`S`] Conductance when switch is closed. Value should be finite to avoid a singularity.
422+
- `state_init`: Initial guess for the state of the switch.
422423
"""
423424
@mtkmodel Switch begin
424425
@extend v, i = oneport = OnePort()
425426

426427
@parameters begin
427428
Gon = 1e5, [description = "Conductance when switch is closed"]
429+
state_init = false, [description = "Initial guess for the state of the switch"]
428430
end
429431

430432
@components begin
431433
input = RealInput()
432434
end
433435

434436
@variables begin
435-
state(t)::Bool
437+
state(t)::Bool, [guess = state_init]
436438
G(t)
437439
end
438440

test/Electrical/analog.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ end
723723
switch = Switch()
724724
voltage = Voltage()
725725
resistor = Resistor(R = R)
726-
capacitor = Capacitor(C = C, v = 0.0)
726+
capacitor = Capacitor(C = C)
727727
ground = Ground()
728728
end
729729

@@ -738,7 +738,7 @@ end
738738
end
739739

740740
@mtkbuild sys = SwitchTest()
741-
prob = ODEProblem(sys, [], (0.0, 25.0))
741+
prob = ODEProblem(sys, [sys.capacitor.v => 0.0], (0.0, 25.0))
742742
sol = solve(prob, Rodas4())
743743

744744
@test SciMLBase.successful_retcode(sol)

0 commit comments

Comments
 (0)