Reputation: 415
I'm trying to understand the Julia ModellingToolkit interface and am not having a great deal of success.
Taking the code posted on this link, and replacing the capacitor with a second resistor e.g.
@named resistor = Resistor(R=R)
@named r2 = Resistor(R=0.5)
@named source = ConstantVoltage(V=V)
@named ground = Ground()
rc_eqs = [ connect(source.p, resistor.p)
connect(resistor.n, r2.p)
connect(r2.n, source.n)
connect(r2.n, ground.g) ]
@named _rc_model = ODESystem(rc_eqs, t)
@named rc_model = compose(_rc_model, [resistor, r2, source, ground])
Yields the following error
LoadError: MethodError: no method matching oneunit(::Type{Any})
Closest candidates are:oneunit(::Type{Union{Missing, T}}) where T at /auto/users/henney/Documents/Oxford/Julia/julia-1.7.2/share/julia/base/missing.jl:105oneunit(::Type{T}) where T at /auto/users/henney/Documents/Oxford/Julia/julia-1.7.2/share/julia/base/number.jl:358oneunit(::T) where T at /auto/users/henney/Documents/Oxford/Julia/julia-1.7.2/share/julia/base/number.jl:357
From the error message, it seems to be that the type of one of the variables is undefined, but I'm unsure as to which particular variable, and why the error does not occur when a capacitor is used (the only real difference being the presence of Derivative(t)
in the Capacitor
function.
Upvotes: 1
Views: 252
Reputation: 56
It errors because ODAEProblem would reduce all the equations away. It's tracked in https://github.com/SciML/DiffEqBase.jl/issues/650
As a workaround, you can do
prob = ODEProblem(sys, [], (0, 10.0))
solve(prob, Rodas5())
for now.
Upvotes: 1