I’m trying to simulate a simple circuit of a constant voltage source connected to a resistor, using MTK. But I’m getting empty results when I solve the problem. Bear in mind this is a simple, toy problem, which I could solve using Symbolics or SymPy, but Iḿ looking ahead where I need to simulate the system with varying voltages, etc.
Below is the toy problem:
using ModelingToolkit, OrdinaryDiffEq, Plots
using ModelingToolkitStandardLibrary.Electrical
using ModelingToolkitStandardLibrary.Blocks: Constant
using ModelingToolkit: t_nounits as t
@mtkmodel simple_resistor begin
@parameters begin
V = 800.0
R1 = 4.0*499.0e3
end
@components begin
r1 = Resistor(R = R1)
source = Voltage()
constant = Constant(k = V)
ground = Ground()
end
@equations begin
connect(constant.output, source.V)
connect(source.p, r1.p)
connect(source.n, r1.n, ground.g)
end
end
@mtkbuild sys = simple_resistor()
prob=ODEProblem(sys, [], (0, 10.0))
sol = solve(prob)
The result of solve is:
retcode: Success
Interpolation: 1st order linear
t: 2-element Vector{Float64}:
0.0
10.0
u: 2-element Vector{Vector{Float64}}:
[]
[]
I’m finding another issue when I place a second resistor in series with r1. The updated script is below:
using ModelingToolkit, OrdinaryDiffEq, Plots
using ModelingToolkitStandardLibrary.Electrical
using ModelingToolkitStandardLibrary.Blocks: Constant
using ModelingToolkit: t_nounits as t
@mtkmodel simple_resistor begin
@parameters begin
V = 800.0
R1 = 4.0*499.0e3
R2 = 4.0*499.0e3
end
@components begin
r1 = Resistor(R = R1)
r2 = Resistor(R = R2)
source = Voltage()
constant = Constant(k = V)
ground = Ground()
end
@equations begin
connect(constant.output, source.V)
connect(source.p, r1.p)
connect(r1.n, r2.p)
connect(source.n, r2.n, ground.g)
end
end
@mtkbuild sys = simple_resistor()
prob=ODEProblem(sys, [], (0, 10.0))
sol = solve(prob)
The “prob=ODEProblem(sys, , (0, 10.0))” fails with:
julia> @mtkbuild sys = simple_resistor()
Model sys:
Equations (1):
1 standard: see equations(sys)
Unknowns (1): see unknowns(sys)
r2₊i(t)
Parameters (6): see parameters(sys)
R1 [defaults to 1.996e6]
constant₊k [defaults to V]: Constant output value of block
r2₊R [defaults to R2]: Resistance
R2 [defaults to 1.996e6]
r1₊R [defaults to R1]: Resistance
V [defaults to 800.0]
Observed (21): see observed(sys)
So you need to supply an initial condition for it. In this case, you can supply anything you want and it will be treated as an initial guess for the solver.
If you mean exactly what I quoted there, that is the show method as used by the REPL display. I evaluated the expression from your code in the REPL and quoted what was printed.
If you mean digging in to more details, you can use unknowns(sys), equations(sys), or observed(sys) to show the full list of each.
Oh, when we nest we problems we might need to pass on SII @cryptic.ax .
That’s not the issue here. The system inside sol_NL is an ODESystem. It generates observed functions of the form f(u, p, t), but since sol_NL is not time dependent, SII calls the function has f(u, p) which leads to the above issue. In SII terminology, the index provider is time-dependent but the value provider isn’t.