I took the RC example from the tests of ModelingToolkitStandardLibrary.jl: ModelingToolkitStandardLibrary.jl/test/Electrical/analog.jl at main · SciML/ModelingToolkitStandardLibrary.jl · GitHub
using ModelingToolkitStandardLibrary.Electrical: Resistor, Capacitor, Voltage, Ground
using ModelingToolkitStandardLibrary.Blocks: Constant
using ModelingToolkitBase
@named source = Constant(; k=10.0)
@named voltage = Voltage()
@named resistor = Resistor(; R=1.0)
@named capacitor = Capacitor(; C=1.0, v=0.0)
@named ground = Ground()
connections = [
connect(source.output, voltage.V)
connect(voltage.p, resistor.p)
connect(resistor.n, capacitor.p)
connect(capacitor.n, voltage.n, ground.g)
]
@named model = System(connections, t; systems=[resistor, capacitor, source, voltage, ground])
sys = mtkcompile(model)
prob = ODEProblem(sys, Pair[], (0.0, 10.0))
sol = solve(prob, Tsit5())
but it fails
ERROR: Cyclic guesses detected in the system. Symbolic values were found for the following variables/parameters in the map:
voltage₊n₊i(t) => voltage₊n₊i(t)
ground₊g₊i(t) => ground₊g₊i(t)
capacitor₊p₊i(t) => capacitor₊p₊i(t)
capacitor₊i(t) => capacitor₊i(t)
resistor₊p₊v(t) => resistor₊p₊v(t)
voltage₊i(t) => voltage₊i(t)
voltage₊p₊v(t) => voltage₊p₊v(t)
resistor₊n₊v(t) => resistor₊n₊v(t)
voltage₊v(t) => voltage₊v(t)
resistor₊n₊i(t) => resistor₊n₊i(t)
voltage₊p₊i(t) => voltage₊p₊i(t)
resistor₊v(t) => resistor₊v(t)
resistor₊p₊i(t) => resistor₊p₊i(t)
capacitor₊p₊v(t) => capacitor₊p₊v(t)
voltage₊n₊v(t) => voltage₊n₊v(t)
resistor₊i(t) => resistor₊i(t)
capacitor₊n₊i(t) => capacitor₊n₊i(t)
In order to resolve this, please provide additional numeric guesses so that the chain can be resolved to assign numeric values to each variable. Alternatively, the `missing_guess_value` keyword can be used to set a fallback guess for all variables. The keyword must be passed an instance of the `MissingGuessValue` sum-type.
Stacktrace:
[1] varmap_to_vars(varmap::ModelingToolkitBase.AtomicArrayDict{…}, vars::Vector{…}; tofloat::Bool, use_union::Bool, container_type::Type, buffer_eltype::Type, toterm::Function, check::Bool, allow_symbolic::Bool, is_initializeprob::Bool, substitution_limit::Int64, missing_values::ModelingToolkitBase.MissingGuessValue.var"typeof(MissingGuessValue)")
@ ModelingToolkitBase C:\Users\vkais\.julia\packages\ModelingToolkitBase\lC2g8\src\systems\problem_utils.jl:359
Also, why does equations(sys) still have 19 equations?
Running this on:
[7771a370] ModelingToolkitBase v1.6.3
[16a59e39] ModelingToolkitStandardLibrary v2.26.0