Skip to content

Commit 2bc4b16

Browse files
committed
Distinguish standard and connecting equations; rename and document n_extra_equations()
1 parent b5b1a8a commit 2bc4b16

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/systems/abstractsystem.jl

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,8 +1856,14 @@ function get_or_construct_tearing_state(sys)
18561856
state
18571857
end
18581858

1859-
# TODO: what about inputs?
1860-
function n_extra_equations(sys::AbstractSystem)
1859+
"""
1860+
n_expanded_connection_equations(sys::AbstractSystem)
1861+
1862+
Returns the number of equations that the connections in `sys` expands to.
1863+
Equivalent to `length(equations(expand_connections(sys))) - length(filter(eq -> !(eq.lhs isa Connection), equations(sys)))`.
1864+
"""
1865+
function n_expanded_connection_equations(sys::AbstractSystem)
1866+
# TODO: what about inputs?
18611867
isconnector(sys) && return length(get_unknowns(sys))
18621868
sys, (csets, _) = generate_connection_set(sys)
18631869
ceqs, instream_csets = generate_connection_equations_and_stream_connections(csets)
@@ -1919,14 +1925,13 @@ function Base.show(io::IO, mime::MIME"text/plain", sys::AbstractSystem; hint = t
19191925
eqs = equations(sys)
19201926
if eqs isa AbstractArray && eltype(eqs) <: Equation
19211927
neqs = count(eq -> !(eq.lhs isa Connection), eqs)
1928+
next = n_expanded_connection_equations(sys)
19221929
nobs = has_observed(sys) ? length(observed(sys)) : 0
1923-
next = n_extra_equations(sys)
1924-
ntot = neqs + nobs + next
1930+
ntot = neqs + next + nobs
19251931
ntot > 0 && printstyled(io, "\nEquations ($ntot):"; bold)
1926-
ntot > 0 && hint && print(io, " see equations(sys)")
1927-
neqs > 0 && print(io, "\n $neqs solvable")
1928-
nobs > 0 && print(io, "\n $nobs observed")
1929-
next > 0 && print(io, "\n $next extra")
1932+
neqs > 0 && print(io, "\n $neqs standard", hint ? ": see equations(sys)" : "")
1933+
next > 0 && print(io, "\n $next connecting", hint ? ": see equations(expand_connections(sys))" : "")
1934+
nobs > 0 && print(io, "\n $nobs observed", hint ? ": see observed(sys)" : "")
19301935
#Base.print_matrix(io, eqs) # usually too long and not useful to print all equations
19311936
end
19321937

test/components.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ end
4141

4242
completed_rc_model = complete(rc_model)
4343
@test isequal(completed_rc_model.resistor.n.i, resistor.n.i)
44-
@test ModelingToolkit.n_extra_equations(capacitor) == 2
44+
@test ModelingToolkit.n_expanded_connection_equations(capacitor) == 2
4545
@test length(equations(structural_simplify(rc_model, allow_parameter = false))) == 2
4646
sys = structural_simplify(rc_model)
4747
@test_throws ModelingToolkit.RepeatedStructuralSimplificationError structural_simplify(sys)

0 commit comments

Comments
 (0)