-
-
Notifications
You must be signed in to change notification settings - Fork 47
Closed
Description
I can't seem to get a parallel RLC circuit to work. The series circuit works fine, but the paralell version doesn't work properly. I must be doing something wrong, but I haven't been able to figure it out... It would be a good example to add to tests/docs if we can get it to work.
using ModelingToolkit, OrdinaryDiffEq, PyPlot
using ModelingToolkitStandardLibrary.Electrical
using ModelingToolkitStandardLibrary.Blocks: Constant, Sine
R = 0.1
L = 1.0
C = 1.0
V = 1.0
@variables t
@named resistor = Resistor(R=R)
@named inductor = Inductor(L=L)
@named capacitor = Capacitor(C=C)
@named source = Voltage()
@named voltagefun = Constant(k=0)
@named ground = Ground()
# build the circuit by connecting components
series = false
if series
rlc_eqs = [
connect(voltagefun.output, source.V)
connect(source.p, resistor.p)
connect(resistor.n, inductor.p)
connect(inductor.n, capacitor.p)
connect(capacitor.n, source.n, ground.g)
]
else # parallel
rlc_eqs = [
connect(voltagefun.output, source.V)
connect(source.p, resistor.p)
connect(resistor.p, inductor.p, capacitor.p)
connect(resistor.n, inductor.n, capacitor.n)
connect(resistor.n, source.n, ground.g)
]
end
@named rlc_model = ODESystem(rlc_eqs, t, systems=[resistor, inductor, capacitor, voltagefun, source, ground])
sys = structural_simplify(rlc_model)
u0 = [inductor.i => 2]
prob = ODEProblem(sys, u0, (0, 100.0))
sol = solve(prob, Tsit5())
plot(sol.t, [sol[source.v] sol[inductor.i] sol[capacitor.i]])
Metadata
Metadata
Assignees
Labels
No labels