I recently asked about a linearization problem I had – the problem persists. However, here I raise another question: ModelingToolkit linearization fails for a simple problem that used to work.
Question: What is it I do incorrectly below?
[I have used Julia v10.4 and ModelingToolkit v9.30 + DifferentialEquations v7.13.0, i.e., updated just now.]
# IMPORTING PACKAGES
using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as Dt
using DifferentialEquations
using ControlSystems
#
# BALANCED SIMULATION MODEL
# Below, macro `mtkmodel` creates a model instantiator/"class" with name `Tank`
#
@mtkmodel Tank begin
# Model parameters
@parameters begin
ρ=1, [description = "Liquid density"]
A=5, [description = "Cross sectional tank area"]
K=5, [description = "Effluent valve constant"]
h_ς=3, [description = "Scaling level in valve model"]
end
# Model variables, with initial values needed
@variables begin
m(t)=1.5*ρ*A, [description = "Liquid mass"]
md_i(t), [description = "Influent mass flow rate"]
md_e(t), [description = "Effluent mass flow rate"]
V(t), [description = "Liquid volume"]
h(t), [description = "level"]
end
# Providing model equations
@equations begin
Dt(m) ~ md_i-md_e
m ~ ρ*V
V ~ A*h
md_e ~ K*sqrt(h/h_ς)
md_i ~ md(t)
end
end
#
# INPUT FUNCTION
md_const(t) = 2
md(t) = md_const(t)
#
# UNBALANCED MODEL FOR LINEARIZATION
#=
The following model Tank_noi [noi: no input] is the same as Tank, except
that the equation connecting variable md_i to the input function md(t) has
been commented out
=#
#
@mtkmodel Tank_noi begin
# Model parameters
@parameters begin
ρ=1, [description = "Liquid density"]
A=5, [description = "Cross sectional tank area"]
K=5, [description = "Effluent valve constant"]
h_ς=3, [description = "Scaling level in valve model"]
end
# Model variables, with initial values needed
@variables begin
m(t)=1.5*ρ*A, [description = "Liquid mass"]
md_i(t), [description = "Influent mass flow rate"]
md_e(t), [description = "Effluent mass flow rate"]
V(t), [description = "Liquid volume"]
h(t), [description = "level"]
end
# Providing model equations
@equations begin
Dt(m) ~ md_i-md_e
m ~ ρ*V
V ~ A*h
md_e ~ K*sqrt(h/h_ς)
# md_i ~ md(t)
end
end
#
# INSTANTIATING SIMULATION MODEL + LINEARIZATION MODEL
@mtkbuild tank = Tank()
@named tank_noi = Tank_noi()
#
# SIMULATING SYSTEM TO FIND STEADY STATE
tspan = (0,1e3)
#
prob = ODEProblem(tank, [], tspan)
sol = solve(prob)
m_ss = sol(tspan[2])[1]
#
# ATTEMPTING TO LINEARIZE SYSTEM
mats_modern, tank_ = linearize(tank_noi, [tank_noi.md_i], [tank_noi.h]; op = Dict(tank_noi.m=>m_ss, tank_noi.md_i=>md(0)))
#ss(mats_modern...)
The error message I get is:
Some specified inputs were not found in system. The following variables were not found Any[tank_noi₊md_i(t)]