What I did so far:
- I can define a model using ModelingToolkit.jl
- I can simplify the system of equations
- I can simulate the step response of the model
Now I would like to linearize the model. In theory very easy, just one line of code. But it doesn’t work, and I don’t understand how to fix the error.
My code:
using ModelingToolkit, OrdinaryDiffEq, DataInterpolations
Cp=[0.024384377390186646,0.03811829845979822,0.05731175742000688,0.0803120051369546,0.10526323380995135,0.1312349486430945,
0.1588590278697544,0.1882995422205645,0.21937359147848456,0.25269290703920616,0.2882162631147021,0.3240355349501659,
0.3607290350346774,0.39295261085207084,0.4141821251393675,0.4274331262027119,0.43636422894857274,0.4414767530303278,
0.443412806515125,0.44365385445693295,0.44317448744425714,0.44218641629727234,0.4407405317795181,0.43888039054963845,
0.4362875461540461,0.4325702155989231,0.4278606704093836,0.4224263790651815,0.4164272616252002,0.40987027258773945,
0.4027832291503407,0.39518785578723936,0.38719847687832065]
TSR = 2.0:0.25:10.0
cp = CubicSpline(Cp, TSR)
# initial state
U0 = 9.0 # m/s
Pg_0 = 2.302e6 # W
w0 = 1.302
# model
@variables t ω(t)=w0 Pr(t) λ(t) Pg(t)=Pg_0
@parameters J R ρ A U=U0
D = Differential(t)
eqs = [J * D(ω) * ω ~ Pr - Pg,
λ ~ ω * R/U,
Pr ~ 0.5 * ρ * A * U^3 * cp(λ)]
@named sys = ODESystem(eqs, t)
# linearisation
matrices, simplified_sys = ModelingToolkit.linearize(sys, [Pg], [ω])
If I run this code I get the error message:
julia> include("src/mwe.jl")
ERROR: LoadError: ArgumentError: SymbolicUtils.BasicSymbolic{Real}[ωˍt(t)] are missing from the variable map.
Stacktrace:
[1] throw_missingvars(vars::Vector{SymbolicUtils.BasicSymbolic{Real}})
@ ModelingToolkit C:\Users\uwefechner\.julia\packages\ModelingToolkit\XgH0T\src\variables.jl:121
[2] _varmap_to_vars(varmap::Dict{Any, Any}, varlist::Vector{SymbolicUtils.BasicSymbolic{Real}}; defaults::Dict{Any, Any}, check::Bool, toterm::typeof(ModelingToolkit.default_toterm))
@ ModelingToolkit C:\Users\uwefechner\.julia\packages\ModelingToolkit\XgH0T\src\variables.jl:115
[3] varmap_to_vars(varmap::Dict{Any, Any}, varlist::Vector{Any}; defaults::Dict{Any, Any}, check::Bool, toterm::Function, promotetoconcrete::Nothing, tofloat::Bool, use_union::Bool)
@ ModelingToolkit C:\Users\uwefechner\.julia\packages\ModelingToolkit\XgH0T\src\variables.jl:84
[4] get_u0_p(sys::ODESystem, u0map::Dict{Any, Any}, parammap::SciMLBase.NullParameters; use_union::Bool, tofloat::Bool)
@ ModelingToolkit C:\Users\uwefechner\.julia\packages\ModelingToolkit\XgH0T\src\systems\diffeqs\abstractodesystem.jl:589
[5] get_u0_p
@ C:\Users\uwefechner\.julia\packages\ModelingToolkit\XgH0T\src\systems\diffeqs\abstractodesystem.jl:580 [inlined]
[6] linearize(sys::ODESystem, lin_fun::ModelingToolkit.var"#130#133"{Vector{Num}, UnitRange{Int64}, UnitRange{Int64}, UnitRange{Int64}, Vector{Any}, ODEFunction{true, SciMLBase.FullSpecialize, ModelingToolkit.var"#f#531"{RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋arg1, :ˍ₋arg2, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x85b51431, 0x1dd0388c, 0x97d6c70c, 0x979552d7, 0x94638b6f), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1, :ˍ₋arg2, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x33297964, 0x424aff99, 0x47f62688, 0x0209746d, 0x7cebcf48), Nothing}}, Matrix{Float64}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Vector{Symbol}, Symbol, Vector{Symbol}, ModelingToolkit.var"#583#generated_observed#539"{Bool, ODESystem, Dict{Any, Any}}, Nothing, ODESystem}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(Symbol("##arg#13004503558829430822"), Symbol("##arg#8953363045742149305"), :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xa9fbe3ad, 0x73fdf9d6, 0xa00f1e3c, 0x018b49fc, 0xc99f5b11), Nothing}, ForwardDiff.Chunk{1}}; t::Float64, op::Dict{Any, Any}, allow_input_derivatives::Bool, p::SciMLBase.NullParameters)
@ ModelingToolkit C:\Users\uwefechner\.julia\packages\ModelingToolkit\XgH0T\src\systems\abstractsystem.jl:1511
[7] linearize(sys::ODESystem, inputs::Vector{Num}, outputs::Vector{Num}; op::Dict{Any, Any}, t::Float64, allow_input_derivatives::Bool, zero_dummy_der::Bool, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ ModelingToolkit C:\Users\uwefechner\.julia\packages\ModelingToolkit\XgH0T\src\systems\abstractsystem.jl:1563
[8] linearize(sys::ODESystem, inputs::Vector{Num}, outputs::Vector{Num})
@ ModelingToolkit C:\Users\uwefechner\.julia\packages\ModelingToolkit\XgH0T\src\systems\abstractsystem.jl:1554
[9] top-level scope
@ C:\Users\uwefechner\repos\WindTurbines\src\mwe.jl:30
[10] include(fname::String)
@ Base.MainInclude .\client.jl:478
[11] top-level scope
@ REPL[1]:1
in expression starting at C:\Users\uwefechner\repos\WindTurbines\src\mwe.jl:30
Any idea?