@@ -258,3 +258,50 @@ closed_loop = ODESystem(connections, t, systems = [model, pid, filt, sensor, r,
258
258
])
259
259
260
260
@test_nowarn linearize (closed_loop, :r , :y )
261
+
262
+ # https://discourse.julialang.org/t/mtk-change-in-linearize/115760/3
263
+ @mtkmodel Tank_noi begin
264
+ # Model parameters
265
+ @parameters begin
266
+ ρ = 1 , [description = " Liquid density" ]
267
+ A = 5 , [description = " Cross sectional tank area" ]
268
+ K = 5 , [description = " Effluent valve constant" ]
269
+ h_ς = 3 , [description = " Scaling level in valve model" ]
270
+ end
271
+ # Model variables, with initial values needed
272
+ @variables begin
273
+ m (t) = 1.5 * ρ * A, [description = " Liquid mass" ]
274
+ md_i (t), [description = " Influent mass flow rate" ]
275
+ md_e (t), [description = " Effluent mass flow rate" ]
276
+ V (t), [description = " Liquid volume" ]
277
+ h (t), [description = " level" ]
278
+ end
279
+ # Providing model equations
280
+ @equations begin
281
+ D (m) ~ md_i - md_e
282
+ m ~ ρ * V
283
+ V ~ A * h
284
+ md_e ~ K * sqrt (h / h_ς)
285
+ end
286
+ end
287
+
288
+ @named tank_noi = Tank_noi ()
289
+ @unpack md_i, h, m = tank_noi
290
+ m_ss = 2.4000000003229878
291
+ @test_nowarn linearize (tank_noi, [md_i], [h]; op = Dict (m => m_ss, md_i => 2 ))
292
+
293
+ # Test initialization
294
+ @variables x (t) y (t) u (t)= 1.0
295
+ @parameters p = 1.0
296
+ eqs = [D (x) ~ p * u, x ~ y]
297
+ @named sys = ODESystem (eqs, t)
298
+
299
+ matrices1, _ = linearize (sys, [u], []; op = Dict (x => 2.0 ))
300
+ matrices2, _ = linearize (sys, [u], []; op = Dict (y => 2.0 ))
301
+ @test matrices1 == matrices2
302
+
303
+ # Ensure parameter values passed as `Dict` are respected
304
+ linfun, _ = linearization_function (sys, [u], []; op = Dict (x => 2.0 ))
305
+ matrices = linfun ([1.0 ], Dict (p => 3.0 ), 1.0 )
306
+ # this would be 1 if the parameter value isn't respected
307
+ @test matrices. f_u[] == 3.0
0 commit comments