285
285
286
286
const SymOrVec = Union{Symbol, Vector{Symbol}}
287
287
288
- function get_sensitivity_function (sys, ap_name:: SymOrVec ; loop_openings = nothing ,
288
+ function get_sensitivity_function (
289
+ sys, ap_name:: SymOrVec ; loop_openings = nothing , system_modifier = identity,
289
290
kwargs... )
290
291
find = namespaced_ap_match (ap_name, loop_openings)
291
292
t = get_iv (sys)
@@ -311,10 +312,12 @@ function get_sensitivity_function(sys, ap_name::SymOrVec; loop_openings = nothin
311
312
permutation = _check_and_sort! (ap_name, aps, namespaces, multiplicities)
312
313
dn = ModelingToolkit. renamespace .(namespaces, d[permutation])
313
314
un = ModelingToolkit. renamespace .(namespaces, u[permutation])
315
+ sys = system_modifier (sys)
314
316
ModelingToolkit. linearization_function (sys, dn, un; kwargs... )
315
317
end
316
318
317
- function get_comp_sensitivity_function (sys, ap_name:: SymOrVec ; loop_openings = nothing ,
319
+ function get_comp_sensitivity_function (
320
+ sys, ap_name:: SymOrVec ; loop_openings = nothing , system_modifier = identity,
318
321
kwargs... )
319
322
find = namespaced_ap_match (ap_name, loop_openings)
320
323
t = get_iv (sys)
@@ -340,10 +343,12 @@ function get_comp_sensitivity_function(sys, ap_name::SymOrVec; loop_openings = n
340
343
permutation = _check_and_sort! (ap_name, aps, namespaces, multiplicities)
341
344
dn = ModelingToolkit. renamespace .(namespaces, d[permutation])
342
345
un = ModelingToolkit. renamespace .(namespaces, u[permutation])
346
+ sys = system_modifier (sys)
343
347
ModelingToolkit. linearization_function (sys, dn, un; kwargs... )
344
348
end
345
349
346
- function get_looptransfer_function (sys, ap_name:: SymOrVec ; loop_openings = nothing ,
350
+ function get_looptransfer_function (
351
+ sys, ap_name:: SymOrVec ; loop_openings = nothing , system_modifier = identity,
347
352
kwargs... )
348
353
find = namespaced_ap_match (ap_name, loop_openings)
349
354
t = get_iv (sys)
@@ -366,6 +371,7 @@ function get_looptransfer_function(sys, ap_name::SymOrVec; loop_openings = nothi
366
371
y = reduce (vcat, ap_var (ap. in) for ap in aps)
367
372
yn = ModelingToolkit. renamespace .(namespaces, y)# permutation applied in _check_and_sort
368
373
un = ModelingToolkit. renamespace .(namespaces, u)
374
+ sys = system_modifier (sys)
369
375
ModelingToolkit. linearization_function (sys, un, yn; kwargs... )
370
376
end
371
377
@@ -387,7 +393,8 @@ Open the loop at analysis point `ap` by breaking the connection through `ap`.
387
393
388
394
See also [`get_sensitivity`](@ref), [`get_comp_sensitivity`](@ref), [`get_looptransfer`](@ref).
389
395
"""
390
- function open_loop (sys, ap_name:: Symbol ; ground_input = false , kwargs... )
396
+ function open_loop (
397
+ sys, ap_name:: Symbol ; ground_input = false , system_modifier = identity, kwargs... )
391
398
find = namespaced_ap_match (ap_name, nothing )
392
399
t = get_iv (sys)
393
400
@variables u (t)= 0 [input = true ]
@@ -407,12 +414,13 @@ function open_loop(sys, ap_name::Symbol; ground_input = false, kwargs...)
407
414
end
408
415
sys = expand_connections (sys, find, replace)
409
416
(ap = apr[]) === nothing && error (" Did not find analysis point $ap_name " )
410
- sys
417
+ sys = system_modifier (sys)
411
418
end
412
419
413
420
function ModelingToolkit. linearization_function (sys:: ModelingToolkit.AbstractSystem ,
414
421
input_name:: SymOrVec , output_name;
415
422
loop_openings = nothing ,
423
+ system_modifier = identity, # This is used to, e.g., apply JuliaSimCompiler.IRSystem after analysis-point handling
416
424
kwargs... )
417
425
t = get_iv (sys)
418
426
@variables u (t)= 0 [input = true ]
@@ -474,7 +482,7 @@ function ModelingToolkit.linearization_function(sys::ModelingToolkit.AbstractSys
474
482
else
475
483
yn = output_name
476
484
end
477
- ModelingToolkit. linearization_function (sys, un, yn; kwargs... )
485
+ ModelingToolkit. linearization_function (system_modifier ( sys) , un, yn; kwargs... )
478
486
end
479
487
480
488
# Add a method to get_sensitivity that accepts the name of an AnalysisPoint
@@ -497,9 +505,10 @@ for f in [:get_sensitivity, :get_comp_sensitivity, :get_looptransfer]
497
505
loop_openings = nothing ,
498
506
op = Dict (),
499
507
p = DiffEqBase. NullParameters (),
508
+ system_modifier = identity,
500
509
kwargs... )
501
510
lin_fun, ssys = $ (Symbol (string (f) * " _function" ))(sys, ap, args... ; op, p,
502
- loop_openings,
511
+ loop_openings, system_modifier,
503
512
kwargs... )
504
513
ModelingToolkit. linearize (ssys, lin_fun; op, p, kwargs... ), ssys
505
514
end
@@ -513,9 +522,9 @@ Linearize a system between two analysis points. To get a loop-transfer function,
513
522
The output is allowed to be either an analysis-point name, or a vector of symbolic variables like the standard interface to `linearize`. The input must be an analysis-point name.
514
523
"""
515
524
function ModelingToolkit. linearize (sys, input_name:: SymOrVec , output_name;
516
- loop_openings = nothing , kwargs... )
517
- lin_fun, ssys = linearization_function (sys, input_name, output_name; loop_openings,
518
- kwargs... )
525
+ loop_openings = nothing , system_modifier = identity, kwargs... )
526
+ lin_fun, ssys = linearization_function (sys, input_name, output_name;
527
+ loop_openings, system_modifier, kwargs... )
519
528
ModelingToolkit. linearize (ssys, lin_fun; kwargs... ), ssys
520
529
end
521
530
0 commit comments