I’m trying to figure out how to define “analysis points” in my MTK models, and how to use such to linearize the model.
Initial questions:
- Is the “analysis points” facility part of the standard library, or of MTK?
- It seems like “analysis points” can be inserted in between two causal blocks. I assume this means that one can use blocks from the standard library to do this?
Here is what I have tried…
using ModelingToolkit, ModelingToolkitStandardLibrary.Blocks
using DifferentialEquations
@variables t
Dt = Differential(t)
@mtkmodel Tank_m 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"]
# ṁ_i(t), [description = "Influent mass flow rate"]
ṁ_e(t), [description = "Effluent mass flow rate"]
V(t), [description = "Liquid volume"]
h(t), [description = "level"]
end
# Components from ModelingToolkitStandardLibrary
@components begin
# We move ṁ_i from "variables" to "components"
ṁ_i = RealInput() # Influent mass flow rate
y_ṁ_e = RealOutput()
end
# Providing model equations
@equations begin
Dt(m) ~ ṁ_i.u - ṁ_e
m ~ ρ*V
V ~ A*h
ṁ_e ~ K*sqrt(h/h_ς)
y_ṁ_e.u ~ ṁ_e
end
end
@mtkmodel Sys2Tank_m begin
# Components used
@components begin
ṁ = Constant(k=2)
tank_1 = Tank_m()
tank_2 = Tank_m()
end
# Equations for connecting components
@equations begin
connect(ṁ.output, :u1, tank_1.ṁ_i)
connect(tank_1.y_ṁ_e, :u2, tank_2.ṁ_i)
end
end
@mtkbuild s2t = Sys2Tank_m()
This code works for standard simulation, e.g.,
tspan = (0,10)
prob = ODEProblem(s2t,[],tspan)
sol = solve(prob)
My attempt of “analysis points” is :u1
and :u2
inserted in the @equations
block of the Sys2Tank_m
model/connect statements.
I have then assumed that…
- Specifying
ṁ = Constant(k=2)
in theSys2Tank_m
model qualifies as makingṁ
output from a causal block (i.e., fromConstant
). - Specifying
ṁ_i = RealInput()
in theTank_m
model qualifies as makingTank_m
a “causal block” withṁ_i
as input.
In other words, that it is correct to define :u1
and :u2
as analysis points via the statements:
@equations begin
connect(ṁ.output, :u1, tank_1.ṁ_i)
connect(tank_1.y_ṁ_e, :u2, tank_2.ṁ_i)
end
Question 1: Is my understand correct so far, or is it horribly wrong? [If wrong, what is wrong?]
Question 2: If correct so far, what method can I use to linearize the model? Is there some function linearize
in ModelingToolkit
or ControlSystems
or ControlSystemsMTK
, etc. that can be used?
[I tried with:
linsys = linearize(s2t, :u1, tank_2.m)
but am told that tank_2
doesn’t exist. Still:
states(s2t)
responds with
If I instead try with:
linsys = linearize(s2t, :u1, s2t.tank_2.m)
I’m told:
Any tips on where to go from here?]