Hi, I’m reproducing the Acausal Modeling for Nonlinear Control and Analysis
# ===========================================================
# Example from https://www.youtube.com/watch?v=l3odTEy69UU&t=2488s
# ===========================================================
using JuliaSimControl
using ModelingToolkit, OrdinaryDiffEq, ModelingToolkitStandardLibrary
using ModelingToolkitStandardLibrary.Blocks
using ModelingToolkit:D_nounits as D, t_nounits as t
rc = 0.25 # reference concentration
@mtkmodel MixingTank begin
@parameters begin
c0 = 0.8 # Nominal concentration
T0 = 308.5 # Nominal temperature
a1 = 0.2674
a21 = 1.815
a22 = 0.4682
b = 1.5476
k0 = 1.05e14
ϵ = 34.2894
end
@variables begin
γ(t), [description = "Reaction speed"]
xc(t) = c0, [description = "Concentration"]
xT(t) = T0, [description = "Temperature"]
xT_c(t) = T0, [description = "Cooling temperature"]
end
@components begin
T_c = RealInput()
c = RealOutput()
T = RealOutput()
end
begin
τ0 = 60
wk0 = k0 / c0
wϵ = ϵ * τ0
wa11 = a1 / τ0
wa12 = c0 / τ0
wa13 = c0 * a1 / τ0
wa21 = a21 / τ0
wa22 = a22 / τ0
wa23 = T0 * (a21 - b) / τ0
wb = b / τ0
end
@equations begin
γ ~ xc * wk0 * exp(-wϵ / xT)
D(xc) ~ -wa11 * xc - wa12 * γ + wa13
D(xT) ~ -wa21 * xT + wa22 * γ + wa23 + wb * xT_c
xc ~ c.u
xT ~ T.u
xT_c ~ T_c.u
end
end
tspan = (0.0, 1000.0)
@mtkmodel TankWithInput begin
@components begin
input = Constant(k = 306.25) # Constant cooling temperature input
tank = MixingTank()
end
@equations begin
connect(input.output, :u, tank.T_c)
end
end
let
@named model = TankWithInput()
cmodel = complete(model)
ssys = structural_simplify(model)
prob = ODEProblem(ssys, [], tspan)
sol = solve(prob, Rodas5P())
f1 = plot(sol, layout = 2, title = "Open-loop")
linmod = linearize_named_ss(model, :u, [cmodel.tank.xc, cmodel.tank.xT])
w = exp10.(-4 : 0.01 : 2)
plot(f1,
nyquistplot(linmod, w, legend = :outerright, unit_circle = true, ylims = (-5, 1),
xlims = (-3, 1), ratio = 1, title = "", ylabel = ""),
pzmap(linmod, ratio = 1),
bodeplot(linmod[2, 1], w),
margin = 1Plots.mm,
size = (800, 800),
)
end
but this @named model = TankWithInput()
throws an error as
ERROR: UndefVarError: 'connect' not defined in 'Main'