Skip to content

Commit

Permalink
Merge pull request #3168 from AayushSabharwal/as/fix-complete
Browse files Browse the repository at this point in the history
fix: fix `complete` not properly expanding systems
  • Loading branch information
ChrisRackauckas authored Oct 30, 2024
2 parents 75fdc56 + 4f89f08 commit 2c694b5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/systems/abstractsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -933,8 +933,8 @@ function complete(sys::AbstractSystem; split = true, flatten = true)
@set! sys.ps = unique!(vcat(get_ps(sys), collect(newparams)))
end
if flatten
if (eqs = equations(sys)) isa Vector &&
any(eq -> eq isa Equation && isconnection(eq.lhs), eqs)
eqs = equations(sys)
if eqs isa AbstractArray && eltype(eqs) <: Equation
newsys = expand_connections(sys)
else
newsys = sys
Expand Down
28 changes: 28 additions & 0 deletions test/odesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1467,3 +1467,31 @@ end
obsfn(buf, prob.u0, prob.p, 0.0)
@test buf [1.0, 1.0, 2.0]
end

@testset "`complete` expands connections" begin
using ModelingToolkitStandardLibrary.Electrical
@mtkmodel RC begin
@parameters begin
R = 1.0
C = 1.0
V = 1.0
end
@components begin
resistor = Resistor(R = R)
capacitor = Capacitor(C = C, v = 0.0)
source = Voltage()
constant = Constant(k = V)
ground = Ground()
end
@equations begin
connect(constant.output, source.V)
connect(source.p, resistor.p)
connect(resistor.n, capacitor.p)
connect(capacitor.n, source.n, ground.g)
end
end
@named sys = RC()
total_eqs = length(equations(expand_connections(sys)))
sys2 = complete(sys)
@test length(equations(sys2)) == total_eqs
end

0 comments on commit 2c694b5

Please sign in to comment.