Skip to content

Commit 0f7ab52

Browse files
committed
Add connector restriction checking
1 parent c2dc287 commit 0f7ab52

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

src/systems/connectors.jl

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,27 @@ struct RegularConnector <: AbstractConnectorType end
3232

3333
function connector_type(sys::AbstractSystem)
3434
sts = get_states(sys)
35-
#TODO: check the criteria for stream connectors
3635
n_stream = 0
3736
n_flow = 0
37+
n_regular = 0 # state that is not input, output, stream, or flow.
3838
for s in sts
3939
vtype = get_connection_type(s)
4040
if vtype === Stream
4141
isarray(s) && error("Array stream variables are not supported. Got $s.")
4242
n_stream += 1
43+
elseif vtype === Flow
44+
n_flow += 1
45+
elseif !(isinput(s) || isoutput(s))
46+
n_regular += 1
4347
end
44-
vtype === Flow && (n_flow += 1)
4548
end
4649
(n_stream > 0 && n_flow > 1) && error("There are multiple flow variables in $(nameof(sys))!")
50+
if n_flow != n_regular
51+
@warn "$(nameof(sys)) contains $n_flow variables, yet $n_regular regular " *
52+
"(non-flow, non-stream, non-input, non-output) variables." *
53+
"This could lead to imbalanced model that are difficult to debug." *
54+
"Consider marking some of the regular variables as input/output variables."
55+
end
4756
n_stream > 0 ? StreamConnector() : RegularConnector()
4857
end
4958

@@ -97,23 +106,6 @@ instream(a) = term(instream, unwrap(a), type=symtype(a))
97106
SymbolicUtils.promote_symtype(::typeof(instream), _) = Real
98107

99108
isconnector(s::AbstractSystem) = has_connector_type(s) && get_connector_type(s) !== nothing
100-
isstreamconnector(s::AbstractSystem) = isconnector(s) && get_connector_type(s) isa StreamConnector
101-
isstreamconnection(c::Connection) = any(isstreamconnector, c.inners) || any(isstreamconnector, c.outers)
102-
103-
function print_with_indent(n, x)
104-
print(" " ^ n)
105-
show(stdout, MIME"text/plain"(), x)
106-
println()
107-
end
108-
109-
function split_sys_var(var)
110-
var_name = string(getname(var))
111-
sidx = findlast(isequal(''), var_name)
112-
sidx === nothing && error("$var is not a namespaced variable")
113-
connector_name = Symbol(var_name[1:prevind(var_name, sidx)])
114-
streamvar_name = Symbol(var_name[nextind(var_name, sidx):end])
115-
connector_name, streamvar_name
116-
end
117109

118110
function flowvar(sys::AbstractSystem)
119111
sts = get_states(sys)

0 commit comments

Comments
 (0)