I modified the example on acausal component modelling from ModelingToolkit and I get internal tearing error. In my modification I have a series connected V+R+L+L circuit.
The series connection of inductors/current sources or capacitor/voltage sources is a known problem when solving electrical circuits (see e.g. Chen et al. “A practical regularization technique for modified nodal analysis in large-scale time-domain circuit simulation.” IEEE Transactions on Computer-Aided Design of Integrated Circuits and Systems 31.7 (2012): 1031-1040).
Is there any way I can help the structural_simplify
in simplifying the system?
using ModelingToolkit, DifferentialEquations
function Pin(;name)
@variables v(t) i(t)
ODESystem(Equation[], t, [v, i], [], name=name, defaults=[v=>1.0, i=>1.0])
end
function Ground(;name)
@named g = Pin()
eqs = [g.v ~ 0]
ODESystem(eqs, t, [], [], systems=[g], name=name)
end
function Resistor(;name, R = 1.0)
val = R
@named p = Pin()
@named n = Pin()
@variables v(t)
@parameters R
eqs = [
v ~ p.v - n.v
0 ~ p.i + n.i
v ~ p.i * R
]
ODESystem(eqs, t, [v], [R], systems=[p, n], defaults=Dict(R => val), name=name)
end
function Inductor(; name, L = 1.0)
val = L
@named p = Pin()
@named n = Pin()
@variables v(t) i(t)
@parameters L
D = Differential(t)
eqs = [
v ~ p.v - n.v
0 ~ p.i + n.i
i ~ p.i
D(i) ~ v / L
]
ODESystem(eqs, t, [v, i], [L], systems=[p, n], defaults=Dict(L => val), name=name)
end
function ConstantVoltage(;name, V = 1.0)
val = V
@named p = Pin()
@named n = Pin()
@parameters V
eqs = [
V ~ p.v - n.v
0 ~ p.i + n.i
]
ODESystem(eqs, t, [], [V], systems=[p, n], defaults=Dict(V => val), name=name)
end
function connect_pins(ps...)
eqs = [
0 ~ sum(p->p.i, ps) # KCL
]
# KVL
for i in 1:length(ps)-1
push!(eqs, ps[i].v ~ ps[i+1].v)
end
return eqs
end
@parameters t
@named V1 = ConstantVoltage(V=10.0)
@named R1 = Resistor(R=1.0)
@named L1 = Inductor(L=8.0e-9)
@named L2 = Inductor(L=2.0e-9)
@named GND = Ground()
ckt = [
connect_pins(V1.p, R1.p)
connect_pins(R1.n, L1.p)
connect_pins(L1.n, L2.p)
connect_pins(V1.n, L2.n, GND.g)
]
@named ckt_model = ODESystem(ckt, t, systems=[V1, R1, L1, L2, GND])
sys = structural_simplify(ckt_model)
I get this error message when running this code:
ERROR:
... Internal error in Tearing.jl: vs[1] = 0.
Run with Julia 1.5.4 and Project.toml
:
[deps]
DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa"
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"