Skip to content

Commit 0a405f1

Browse files
feat: track connections removed by analysis point transformations
1 parent ddb385a commit 0a405f1

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

src/systems/analysis_points.jl

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,27 @@ function get_analysis_variable(var, name, iv; perturb = true)
412412
return pvar, default
413413
end
414414

415+
function with_analysis_point_ignored(sys::AbstractSystem, ap::AnalysisPoint)
416+
has_ignored_connections(sys) || return sys
417+
ignored = get_ignored_connections(sys)
418+
if ignored === nothing
419+
ignored = (ODESystem[], BasicSymbolic[])
420+
else
421+
ignored = copy.(ignored)
422+
end
423+
if ap.outputs === nothing
424+
error("Empty analysis point")
425+
end
426+
for x in ap.outputs
427+
if x isa ODESystem
428+
push!(ignored[1], x)
429+
else
430+
push!(ignored[2], unwrap(x))
431+
end
432+
end
433+
return @set sys.ignored_connections = ignored
434+
end
435+
415436
#### PRIMITIVE TRANSFORMATIONS
416437

417438
const DOC_WILL_REMOVE_AP = """
@@ -469,7 +490,9 @@ function apply_transformation(tf::Break, sys::AbstractSystem)
469490
ap = breaksys_eqs[ap_idx].rhs
470491
deleteat!(breaksys_eqs, ap_idx)
471492

472-
tf.add_input || return sys, ()
493+
breaksys = with_analysis_point_ignored(breaksys, ap)
494+
495+
tf.add_input || return breaksys, ()
473496

474497
ap_ivar = ap_var(ap.input)
475498
new_var, new_def = get_analysis_variable(ap_ivar, nameof(ap), get_iv(sys))
@@ -511,7 +534,7 @@ function apply_transformation(tf::GetInput, sys::AbstractSystem)
511534
ap_idx === nothing &&
512535
error("Analysis point $(nameof(tf.ap)) not found in system $(nameof(sys)).")
513536
# get the anlysis point
514-
ap_sys_eqs = copy(get_eqs(ap_sys))
537+
ap_sys_eqs = get_eqs(ap_sys)
515538
ap = ap_sys_eqs[ap_idx].rhs
516539

517540
# input variable
@@ -570,6 +593,7 @@ function apply_transformation(tf::PerturbOutput, sys::AbstractSystem)
570593
ap = ap_sys_eqs[ap_idx].rhs
571594
# remove analysis point
572595
deleteat!(ap_sys_eqs, ap_idx)
596+
ap_sys = with_analysis_point_ignored(ap_sys, ap)
573597

574598
# add equations involving new variable
575599
ap_ivar = ap_var(ap.input)
@@ -634,7 +658,7 @@ function apply_transformation(tf::AddVariable, sys::AbstractSystem)
634658
ap_idx = analysis_point_index(ap_sys, tf.ap)
635659
ap_idx === nothing &&
636660
error("Analysis point $(nameof(tf.ap)) not found in system $(nameof(sys)).")
637-
ap_sys_eqs = copy(get_eqs(ap_sys))
661+
ap_sys_eqs = get_eqs(ap_sys)
638662
ap = ap_sys_eqs[ap_idx].rhs
639663

640664
# add equations involving new variable

0 commit comments

Comments
 (0)