ModelingToolkit.jl
ModelingToolkit.jl copied to clipboard
Dynamic State Selection and Variable Index DAEs
Hi,
If r=0.0, the following model does not actually have any states, but states(ss) reports it has one, capacitor.vc. No wonder since structural_simplify analyzes only the system structure, doesn't it? Dynamic state selection similar to Dymola's/OpenModelica's should help with this singular Jacobian matrix case. However, here we have a more complicated case indeed: the actual DAE index is higher than expected.
using ModelingToolkit, OrdinaryDiffEq
import ModelingToolkitStandardLibrary.Electrical:
OnePort,
Voltage,
Ground
import ModelingToolkitStandardLibrary.Blocks:
Constant
@variables t
D = Differential(t)
function NonIdealCapacitor(; name, c=1e-6, r=1e-6, g=0.0, vc_start=0.0)
@named oneport = OnePort()
@unpack v, i = oneport
vars = @variables vc(t) = vc_start
pars = @parameters begin
c = c
r = r
g = g
end
eqs = [
v ~ i*r + vc
i ~ c*D(vc) + g*vc
]
return extend(ODESystem(eqs, t, vars, pars; name=name), oneport)
end
@named voltage_source = Voltage()
@named voltage_signal = Constant(k=1.0)
@named capacitor = NonIdealCapacitor(c=1.0, r=0.0)
@named ground = Ground()
eqs = [
connect(voltage_source.V, voltage_signal.output)
connect(voltage_source.p, capacitor.p)
connect(voltage_source.n, capacitor.n, ground.g)
]
@named os = ODESystem(eqs, t, systems=[voltage_source, voltage_signal, capacitor, ground])
ss = structural_simplify(os)
problem = ODAEProblem(ss, Pair[], (0.0, 10.0))
solution = solve(problem, RadauIIA5())
My environment is:
[6e4b80f9] BenchmarkTools v1.3.1
[e2ed5e7c] Bijections v0.1.4
[336ed68f] CSV v0.10.4
[a6e380b2] ControlSystems v1.2.0
[a93c6f00] DataFrames v1.3.4
[abce61dc] Decimals v0.4.1
[0c46a032] DifferentialEquations v7.2.0
[31c24e10] Distributions v0.25.66
[e30172f5] Documenter v0.27.22
[59287772] Formatting v0.4.2
[ff7dd447] FromFile v0.1.5
[86223c79] Graphs v1.7.1
[615f187c] IfElse v0.1.1
[a98d9a8b] Interpolations v0.14.3
[682c06a0] JSON v0.21.3
[98e50ef6] JuliaFormatter v1.0.8
[093fc24a] LightGraphs v1.3.5
[33e6dc65] MKL v0.5.0
[626554b9] MetaGraphs v0.7.1
[961ee093] ModelingToolkit v8.18.4
[16a59e39] ModelingToolkitStandardLibrary v1.5.0
[1dea7af3] OrdinaryDiffEq v6.19.3
[9b87118b] PackageCompiler v2.0.7
[91a5bcdd] Plots v1.31.5
[c3572dad] Sundials v4.9.4
[0c5d862f] Symbolics v4.10.3
[1986cc42] Unitful v1.11.0
[c2297ded] ZMQ v1.2.1
[37e2e46d] LinearAlgebra
[56ddb016] Logging
[9a3f8284] Random
[cf7118a7] UUIDs
Thanks for providing this example! Implementing dynamic state selection is planned. This is a rather hard example. Do you know how do Dymola/OpenModelica handle this?