Skip to content

Commit 92e7d64

Browse files
authored
Merge pull request #1473 from visr/connectarr
fix flow over >2 connectors with arrays
2 parents 25184c8 + fecf3bb commit 92e7d64

File tree

2 files changed

+15
-28
lines changed

2 files changed

+15
-28
lines changed

src/systems/connectors.jl

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,6 @@ end
8686
function connect(c::Connection; check=true)
8787
@unpack inners, outers = c
8888

89-
flow_eqs = Equation[]
90-
other_eqs = Equation[]
91-
92-
ncnts = length(inners) + length(outers)
9389
cnts = Iterators.flatten((inners, outers))
9490
fs, ss = Iterators.peel(cnts)
9591
splitting_idx = length(inners) # anything after the splitting_idx is outer.
@@ -111,33 +107,21 @@ function connect(c::Connection; check=true)
111107
vtype = get_connection_type(fix_val)
112108
vtype === Stream && continue
113109

114-
isarr = isarray(fix_val)
115-
116110
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]
127117
end
128-
else
129118
push!(ceqs, 0 ~ rhs)
130119
end
131120
else # Equality
132121
for c in ss
133122
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)
141125
end
142126
end
143127
end

test/stream_connectors.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,15 @@ end
224224

225225
@named vp1 = VecPin()
226226
@named vp2 = VecPin()
227+
@named vp3 = VecPin()
227228

228-
@named simple = ODESystem([connect(vp1, vp2)], t)
229-
sys = expand_connections(compose(simple, [vp1, vp2]))
229+
@named simple = ODESystem([connect(vp1, vp2, vp3)], t)
230+
sys = expand_connections(compose(simple, [vp1, vp2, vp3]))
230231
@test equations(sys) == [
231232
vp1.v[1] ~ vp2.v[1]
232233
vp1.v[2] ~ vp2.v[2]
233-
0 ~ -vp1.i[1] - vp2.i[1]
234-
0 ~ -vp1.i[2] - vp2.i[2]
234+
vp1.v[1] ~ vp3.v[1]
235+
vp1.v[2] ~ vp3.v[2]
236+
0 ~ -vp1.i[1] - vp2.i[1] - vp3.i[1]
237+
0 ~ -vp1.i[2] - vp2.i[2] - vp3.i[2]
235238
]

0 commit comments

Comments
 (0)