@@ -32,59 +32,35 @@ struct RegularConnector <: AbstractConnectorType end
32
32
33
33
function connector_type (sys:: AbstractSystem )
34
34
sts = get_states (sys)
35
- # TODO : check the criteria for stream connectors
36
35
n_stream = 0
37
36
n_flow = 0
37
+ n_regular = 0 # state that is not input, output, stream, or flow.
38
38
for s in sts
39
39
vtype = get_connection_type (s)
40
40
if vtype === Stream
41
41
isarray (s) && error (" Array stream variables are not supported. Got $s ." )
42
42
n_stream += 1
43
+ elseif vtype === Flow
44
+ n_flow += 1
45
+ elseif ! (isinput (s) || isoutput (s))
46
+ n_regular += 1
43
47
end
44
- vtype === Flow && (n_flow += 1 )
45
48
end
46
49
(n_stream > 0 && n_flow > 1 ) && error (" There are multiple flow variables in $(nameof (sys)) !" )
47
- n_stream > 0 ? StreamConnector () : RegularConnector ()
48
- end
49
-
50
- Base. @kwdef struct Connection
51
- inners = nothing
52
- outers = nothing
53
- end
54
-
55
- # everything is inner by default until we expand the connections
56
- Connection (syss) = Connection (inners= syss)
57
- get_systems (c:: Connection ) = c. inners
58
- function Base. in (e:: Symbol , c:: Connection )
59
- (c. inners != = nothing && any (k-> nameof (k) === e, c. inners)) ||
60
- (c. outers != = nothing && any (k-> nameof (k) === e, c. outers))
61
- end
62
-
63
- function renamespace (sym:: Symbol , connection:: Connection )
64
- inners = connection. inners === nothing ? [] : renamespace .(sym, connection. inners)
65
- if connection. outers != = nothing
66
- for o in connection. outers
67
- push! (inners, renamespace (sym, o))
68
- end
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."
69
55
end
70
- Connection (;inners = inners )
56
+ n_stream > 0 ? StreamConnector () : RegularConnector ( )
71
57
end
72
58
73
- const EMPTY_VEC = []
74
-
75
- function Base. show (io:: IO , :: MIME"text/plain" , c:: Connection )
76
- # It is a bit unfortunate that the display of an array of `Equation`s won't
77
- # call this.
78
- @unpack outers, inners = c
79
- if outers === nothing && inners === nothing
80
- print (io, " <Connection>" )
81
- else
82
- syss = Iterators. flatten ((something (inners, EMPTY_VEC), something (outers, EMPTY_VEC)))
83
- splitting_idx = length (inners)
84
- sys_str = join ((string (nameof (s)) * (i <= splitting_idx ? (" ::inner" ) : (" ::outer" )) for (i, s) in enumerate (syss)), " , " )
85
- print (io, " <" , sys_str, " >" )
86
- end
59
+ struct Connection
60
+ systems
87
61
end
62
+ Connection () = Connection (nothing )
63
+ get_systems (c:: Connection ) = c. systems
88
64
89
65
# symbolic `connect`
90
66
function connect (sys1:: AbstractSystem , sys2:: AbstractSystem , syss:: AbstractSystem... )
@@ -97,23 +73,6 @@ instream(a) = term(instream, unwrap(a), type=symtype(a))
97
73
SymbolicUtils. promote_symtype (:: typeof (instream), _) = Real
98
74
99
75
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
117
76
118
77
function flowvar (sys:: AbstractSystem )
119
78
sts = get_states (sys)
@@ -259,16 +218,13 @@ function generate_connection_set!(connectionsets, sys::AbstractSystem, namespace
259
218
end
260
219
end
261
220
262
- if namespace != = nothing
263
- # Except for the top level, all connectors are eventually inside
264
- # connectors.
265
- T = ConnectionElement
266
- for s in subsys
267
- isconnector (s) || continue
268
- for v in states (s)
269
- Flow === get_connection_type (v) || continue
270
- push! (connectionsets, ConnectionSet ([T (LazyNamespace (namespace, s), v, false )]))
271
- end
221
+ # all connectors are eventually inside connectors.
222
+ T = ConnectionElement
223
+ for s in subsys
224
+ isconnector (s) || continue
225
+ for v in states (s)
226
+ Flow === get_connection_type (v) || continue
227
+ push! (connectionsets, ConnectionSet ([T (LazyNamespace (namespace, s), v, false )]))
272
228
end
273
229
end
274
230
0 commit comments