Skip to content

Commit 9e409e7

Browse files
committed
Better n_extra_equations calculation
1 parent f1032d7 commit 9e409e7

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

src/systems/abstractsystem.jl

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -702,18 +702,32 @@ function get_or_construct_tearing_state(sys)
702702
end
703703

704704
# TODO: what about inputs?
705-
function count_unexpanded_flows(sys::AbstractSystem)
706-
nflows = 0
707-
for m in PreOrderDFS(Tree(sys))
708-
isconnector(m) || continue
709-
nflows += count(x->get_connection_type(x) === Flow, get_states(m))
710-
end
711-
nflows
712-
end
713-
714705
function n_extra_equations(sys::AbstractSystem)
715706
isconnector(sys) && return length(get_states(sys))
716-
nextras = count_unexpanded_flows(sys)
707+
sys, csets = generate_connection_set(sys)
708+
ceqs, instream_csets = generate_connection_equations_and_stream_connections(csets)
709+
n_outer_stream_variables = 0
710+
for cset in instream_csets
711+
n_outer_stream_variables += count(x->x.isouter, cset.set)
712+
end
713+
714+
#n_toplevel_unused_flows = 0
715+
#toplevel_flows = Set()
716+
#for cset in csets
717+
# e1 = first(cset.set)
718+
# e1.sys.namespace === nothing || continue
719+
# for e in cset.set
720+
# get_connection_type(e.v) === Flow || continue
721+
# push!(toplevel_flows, e.v)
722+
# end
723+
#end
724+
#for m in get_systems(sys)
725+
# isconnector(m) || continue
726+
# n_toplevel_unused_flows += count(x->get_connection_type(x) === Flow && !(x in toplevel_flows), get_states(m))
727+
#end
728+
729+
730+
nextras = n_outer_stream_variables + length(ceqs)
717731
end
718732

719733
function Base.show(io::IO, ::MIME"text/plain", sys::AbstractSystem)

0 commit comments

Comments
 (0)