Skip to content

Possible regression when simplifying system to 0 states #2141

@ggkountouras

Description

@ggkountouras

MTK v8.47.0

Result

MethodError: no method matching cleansyms(::Vector{Any}) due to the system getting simplified to 0 states.

Expected result

Precompute everything and leave at least one state for plotting and analysis.

# M(not)WE
using ModelingToolkit, Sundials, DifferentialEquations, Plots
using ModelingToolkitStandardLibrary.Electrical
using ModelingToolkitStandardLibrary.Blocks

function ShockleyDiode(;name, Is = 1.0e-15, eta = 1.0, Vt = 26.0e-3)
    @named oneport = OnePort()
    @unpack v, i = oneport
    ps = @parameters Is=Is eta=eta Vt=Vt
    eqs = [
           i ~ Is*(exp(v/Vt) - 1)
          ]
    extend(ODESystem(eqs, t, [], ps; name=name), oneport)
end

@variables t
@named Vin = Voltage()
@named Vin_V = Ramp(height=0.4, duration=6.0)
@named D = ShockleyDiode(Is=2.5e-10)
@named GND = Ground()
test_eqs = [
       connect(Vin_V.output, Vin.V)
       connect(Vin.p, D.p)
       connect(Vin.n, D.n, GND.g)
       ]
@named test_model = ODESystem(test_eqs, t, systems=[Vin, Vin_V, D, GND])
sys = structural_simplify(test_model)
du0 = fill(0.0, length(states(sys)))
u0 = fill(0.0, length(states(sys)))
prob = DAEProblem(sys, du0, u0, (0, 6.0))
sol = solve(prob, IDA())
plot(sol, idxs=[D.v, D.i])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions