@@ -127,16 +127,33 @@ t = ModelingToolkitStandardLibrary.Mechanical.Rotational.t
127127@named spring = Spring (; c = 10 )
128128@named damper = Damper (; d = 3 )
129129@named torque = Torque ()
130+ @variables y (t) = 0
130131eqs = [connect (torque. flange, inertia1. flange_a)
131132 connect (inertia1. flange_b, spring. flange_a, damper. flange_a)
132- connect (inertia2. flange_a, spring. flange_b, damper. flange_b)]
133+ connect (inertia2. flange_a, spring. flange_b, damper. flange_b)
134+ y ~ inertia2. w + torque. tau. u]
133135model = ODESystem (eqs, t; systems = [torque, inertia1, inertia2, spring, damper],
134136 name = :name )
135137model_outputs = [inertia1. w, inertia2. w, inertia1. phi, inertia2. phi]
136138model_inputs = [torque. tau. u]
137139matrices, ssys = linearize (model, model_inputs, model_outputs)
138140@test length (ModelingToolkit. outputs (ssys)) == 4
139141
142+ if VERSION >= v " 1.8" # :opaque_closure not supported before
143+ matrices, ssys = linearize (model, model_inputs, [y])
144+ A, B, C, D = matrices
145+ obsf = ModelingToolkit. build_explicit_observed_function (ssys,
146+ [y],
147+ inputs = [torque. tau. u],
148+ drop_expr = identity)
149+ x = randn (size (A, 1 ))
150+ u = randn (size (B, 2 ))
151+ p = getindex .(Ref (ModelingToolkit. defaults (ssys)), parameters (ssys))
152+ y1 = obsf (x, u, p, 0 )
153+ y2 = C * x + D * u
154+ @test y1[] ≈ y2[]
155+ end
156+
140157# # Code generation with unbound inputs
141158
142159@variables t x (t)= 0 u (t)= 0 [input = true ]
0 commit comments