86
86
function connect (c:: Connection ; check= true )
87
87
@unpack inners, outers = c
88
88
89
- flow_eqs = Equation[]
90
- other_eqs = Equation[]
91
-
92
- ncnts = length (inners) + length (outers)
93
89
cnts = Iterators. flatten ((inners, outers))
94
90
fs, ss = Iterators. peel (cnts)
95
91
splitting_idx = length (inners) # anything after the splitting_idx is outer.
@@ -111,33 +107,21 @@ function connect(c::Connection; check=true)
111
107
vtype = get_connection_type (fix_val)
112
108
vtype === Stream && continue
113
109
114
- isarr = isarray (fix_val)
115
-
116
110
if vtype === Flow
117
- rhs = isarr ? zeros (Int, ncnts) : 0
118
- for (i, c) in enumerate (cnts)
119
- isinner = i <= splitting_idx
120
- # https://specification.modelica.org/v3.4/Ch15.html
121
- var = scalarize (getproperty (c, name))
122
- rhs += isinner ? var : - var
123
- end
124
- if isarr
125
- for r in rhs
126
- push! (ceqs, 0 ~ r)
111
+ for j in eachindex (fix_val)
112
+ rhs = 0
113
+ for (i, c) in enumerate (cnts)
114
+ isinner = i <= splitting_idx
115
+ var = getproperty (c, name)
116
+ rhs += isinner ? var[j] : - var[j]
127
117
end
128
- else
129
118
push! (ceqs, 0 ~ rhs)
130
119
end
131
120
else # Equality
132
121
for c in ss
133
122
var = getproperty (c, name)
134
- if isarr
135
- vs = scalarize (var)
136
- for (i, v) in enumerate (vs)
137
- push! (ceqs, fix_val[i] ~ v)
138
- end
139
- else
140
- push! (ceqs, fix_val ~ var)
123
+ for (i, v) in enumerate (var)
124
+ push! (ceqs, fix_val[i] ~ v)
141
125
end
142
126
end
143
127
end
0 commit comments