Skip to content

Commit 3bf38bd

Browse files
feat: better handle loop opening defaults
1 parent c38ab96 commit 3bf38bd

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/systems/analysis_points.jl

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -486,14 +486,19 @@ struct Break <: AnalysisPointTransformation
486486
Whether to add a new input variable connected to all the outputs of `ap`.
487487
"""
488488
add_input::Bool
489+
"""
490+
Whether the default of the added input variable should be the input of `ap`. Only
491+
applicable if `add_input == true`.
492+
"""
493+
default_outputs_to_input::Bool
489494
end
490495

491496
"""
492497
$(TYPEDSIGNATURES)
493498
494-
`Break` the given analysis point `ap` without adding an input.
499+
`Break` the given analysis point `ap`.
495500
"""
496-
Break(ap::AnalysisPoint) = Break(ap, false)
501+
Break(ap::AnalysisPoint, add_input::Bool = false) = Break(ap, add_input, false)
497502

498503
function apply_transformation(tf::Break, sys::AbstractSystem)
499504
modify_nested_subsystem(sys, tf.ap) do breaksys
@@ -517,7 +522,11 @@ function apply_transformation(tf::Break, sys::AbstractSystem)
517522
push!(breaksys_eqs, ap_var(outsys) ~ new_var)
518523
end
519524
defs = copy(get_defaults(breaksys))
520-
defs[new_var] = new_def
525+
defs[new_var] = if ap.default_outputs_to_input
526+
ap_ivar
527+
else
528+
new_def
529+
end
521530
@set! breaksys.defaults = defs
522531
unks = copy(get_unknowns(breaksys))
523532
push!(unks, new_var)
@@ -803,7 +812,7 @@ Given a list of analysis points, break the connection for each and set the outpu
803812
"""
804813
function handle_loop_openings(sys::AbstractSystem, aps)
805814
for ap in canonicalize_ap(sys, aps)
806-
sys, (outvar,) = apply_transformation(Break(ap, true), sys)
815+
sys, (outvar,) = apply_transformation(Break(ap, true, true), sys)
807816
if Symbolics.isarraysymbolic(outvar)
808817
push!(get_eqs(sys), outvar ~ zeros(size(outvar)))
809818
else
@@ -815,7 +824,7 @@ end
815824

816825
const DOC_LOOP_OPENINGS = """
817826
- `loop_openings`: A list of analysis points whose connections should be removed and
818-
the outputs set to zero as a part of the linear analysis.
827+
the outputs set to the input as a part of the linear analysis.
819828
"""
820829

821830
const DOC_SYS_MODIFIER = """

0 commit comments

Comments
 (0)