@@ -298,19 +298,19 @@ function ModelingToolkit.linearization_function(sys::ModelingToolkit.AbstractSys
298298 Symbol (ns, :_ , nameof (x)) ∈ (input_name, output_name)
299299 end
300300 end
301- t = get_iv (sys)
302- @variables u (t) = 0 [input = true ]
303- @variables y (t) = 0 [output = true ]
304- namespace = Ref {Union{Nothing, Symbol }} (nothing )
305- apr = Ref {Union{Nothing, AnalysisPoint}} (nothing )
306- replace = let u = u, y = y, namespace = namespace, apr = apr
301+
302+ namespace_u = Ref {Union{Nothing, Symbol}} ( nothing )
303+ namespace_y = Ref {Union{Nothing, Symbol}} ( nothing )
304+ apr_u = Ref {Union{Nothing, AnalysisPoint }} (nothing )
305+ apr_y = Ref {Union{Nothing, AnalysisPoint}} (nothing )
306+ replace = let u = u, y = y, namespace_u = namespace_u, apr_u = apr_u, namespace_y = namespace_y, apr_y = apr_y
307307 function (ap, ns)
308- namespace[] = ns # Save the namespace to make it available for renamespace below
309- apr[] = ap
310- if nameof (ap) === input_name
308+ namespace_u[] = ns # Save the namespace to make it available for renamespace below
309+ apr_u[] = ap
311310 [ap. out. u ~ ap. in. u + u], u
312311 # input.in.u ~ 0] # We only need to ground one of the ends, hence not including this equation
313- elseif nameof (ap) === output_name
312+ namespace_y[] = ns # Save the namespace to make it available for renamespace below
313+ apr_y[] = ap
314314 [ap. in. u ~ y
315315 ap. out. u ~ ap. in. u], y
316316 else
@@ -319,12 +319,15 @@ function ModelingToolkit.linearization_function(sys::ModelingToolkit.AbstractSys
319319 end
320320 end
321321 sys = expand_connections (sys, find, replace)
322- (ap = apr []) === nothing && error (" Did not find analysis point $ap " )
323- if (ns = namespace []) != = nothing
324- y = ModelingToolkit . renamespace (ns, y)
325- u = ModelingToolkit. renamespace (ns, u)
322+ (ap = apr_u []) === nothing && error (" Did not find analysis point $input_name " )
323+ (ap = apr_y []) === nothing && error ( " Did not find analysis point $output_name " )
324+ if (ns = namespace_u[]) != = nothing
325+ inputs[ 1 ] = ModelingToolkit. renamespace (ns, inputs[ 1 ]) # u
326326 end
327- ModelingToolkit. linearization_function (sys, [u], [y]; kwargs... )
327+ if (ns = namespace_y[]) != = nothing
328+ outputs[1 ] = ModelingToolkit. renamespace (ns, outputs[1 ]) # y
329+ end
330+ ModelingToolkit. linearization_function (sys, inputs, outputs; kwargs... )
328331end
329332
330333# Add a method to get_sensitivity that accepts the name of an AnalysisPoint
0 commit comments