Skip to content

Commit 17bec3f

Browse files
authored
Merge pull request #2132 from SciML/bgc/domain_bug
Domain support for relay connections
2 parents 8642b4e + 8e0999a commit 17bec3f

File tree

2 files changed

+49
-23
lines changed

2 files changed

+49
-23
lines changed

src/systems/connectors.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,13 @@ function rooted_system_domain_graph(csets::AbstractVector{<:ConnectionSet})
430430
for (j, s) in enumerate(c.set)
431431
ij = (i, j)
432432
push!(id2cset, ij)
433-
n = length(id2cset)
433+
if !haskey(sys2id, nameof(s))
434+
n = length(id2cset)
435+
sys2id[nameof(s)] = n
436+
else
437+
n = sys2id[nameof(s)]
438+
end
434439
push!(cset2id′, n)
435-
sys2id[nameof(s)] = n
436440
is_domain_connector(s.sys.sys) && push!(roots, n)
437441
end
438442
push!(cset2id, cset2id′)

test/stream_connectors.jl

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -350,27 +350,6 @@ function StepSource(; P, name)
350350
ODESystem(eqs, t, vars, pars; name, systems)
351351
end
352352

353-
function Pipe(; P, R, name)
354-
pars = @parameters begin
355-
p_int = P
356-
resistance = R
357-
end
358-
359-
vars = []
360-
361-
# nodes -------------------------------
362-
systems = @named begin
363-
HA = HydraulicPort(; P = p_int)
364-
HB = HydraulicPort(; P = p_int)
365-
end
366-
367-
# equations ---------------------------
368-
eqs = [HA.p - HB.p ~ HA.dm * resistance / HA.viscosity
369-
0 ~ HA.dm + HB.dm]
370-
371-
ODESystem(eqs, t, vars, pars; name, systems)
372-
end
373-
374353
function StaticVolume(; P, V, name)
375354
D = Differential(t)
376355

@@ -401,6 +380,49 @@ function StaticVolume(; P, V, name)
401380
defaults = [vrho => rho_0 * (1 + p_int / H.bulk)])
402381
end
403382

383+
function PipeBase(; P, R, name)
384+
pars = @parameters begin
385+
p_int = P
386+
resistance = R
387+
end
388+
389+
vars = []
390+
391+
# nodes -------------------------------
392+
systems = @named begin
393+
HA = HydraulicPort(; P = p_int)
394+
HB = HydraulicPort(; P = p_int)
395+
end
396+
397+
# equations ---------------------------
398+
eqs = [HA.p - HB.p ~ HA.dm * resistance / HA.viscosity
399+
0 ~ HA.dm + HB.dm]
400+
401+
ODESystem(eqs, t, vars, pars; name, systems)
402+
end
403+
404+
function Pipe(; P, R, name)
405+
pars = @parameters begin
406+
p_int = P
407+
resistance = R
408+
end
409+
410+
vars = []
411+
412+
systems = @named begin
413+
HA = HydraulicPort(; P = p_int)
414+
HB = HydraulicPort(; P = p_int)
415+
p12 = PipeBase(; P = p_int, R = resistance)
416+
v1 = StaticVolume(; P = p_int, V = 0.01)
417+
v2 = StaticVolume(; P = p_int, V = 0.01)
418+
end
419+
420+
eqs = [connect(v1.H, p12.HA, HA)
421+
connect(v2.H, p12.HB, HB)]
422+
423+
ODESystem(eqs, t, vars, pars; name, systems)
424+
end
425+
404426
function TwoFluidSystem(; name)
405427
pars = []
406428
vars = []

0 commit comments

Comments
 (0)