Skip to content

Commit 134c33e

Browse files
test: add tests for array variable namespacing from solved issues
1 parent 205075f commit 134c33e

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

src/systems/abstractsystem.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,8 @@ function namespace_assignment(eq::Assignment, sys)
870870
Assignment(_lhs, _rhs)
871871
end
872872

873-
function namespace_expr(O, sys, n = nameof(sys); ivs = independent_variables(sys))
873+
function namespace_expr(
874+
O, sys, n = nameof(sys); ivs = independent_variables(sys))
874875
O = unwrap(O)
875876
if any(isequal(O), ivs)
876877
return O

test/odesystem.jl

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,3 +995,57 @@ let # Issue https://github.com/SciML/ModelingToolkit.jl/issues/2322
995995
sol = solve(prob, Rodas4())
996996
@test sol(1)[]0.6065307685451087 rtol=1e-4
997997
end
998+
999+
# Issue#2344
1000+
using ModelingToolkitStandardLibrary.Blocks
1001+
1002+
function FML2(; name)
1003+
@parameters begin
1004+
k2[1:1] = [1.0]
1005+
end
1006+
systems = @named begin
1007+
constant = Constant(k = k2[1])
1008+
end
1009+
@variables begin
1010+
x(t) = 0
1011+
end
1012+
eqs = [
1013+
D(x) ~ constant.output.u + k2[1]
1014+
]
1015+
ODESystem(eqs, t; systems, name)
1016+
end
1017+
1018+
@mtkbuild model = FML2()
1019+
1020+
@test isequal(ModelingToolkit.defaults(model)[model.constant.k], model.k2[1])
1021+
@test_nowarn ODEProblem(model, [], (0.0, 10.0))
1022+
1023+
# Issue#2477
1024+
function RealExpression(; name, y)
1025+
vars = @variables begin
1026+
u(t)
1027+
end
1028+
eqns = [
1029+
u ~ y
1030+
]
1031+
sys = ODESystem(eqns, t, vars, []; name)
1032+
end
1033+
1034+
function sys1(; name)
1035+
vars = @variables begin
1036+
x(t)
1037+
z(t)[1:1]
1038+
end # doing a collect on z doesn't work either.
1039+
@named e1 = RealExpression(y = x) # This works perfectly.
1040+
@named e2 = RealExpression(y = z[1]) # This bugs. However, `full_equations(e2)` works as expected.
1041+
systems = [e1, e2]
1042+
ODESystem(Equation[], t, Iterators.flatten(vars), []; systems, name)
1043+
end
1044+
1045+
@named sys = sys1()
1046+
sys = complete(sys)
1047+
@test Set(equations(sys)) == Set([sys.e1.u ~ sys.x, sys.e2.u ~ sys.z[1]])
1048+
tearing_state = TearingState(expand_connections(sys))
1049+
ts_vars = tearing_state.fullvars
1050+
orig_vars = states(sys)
1051+
@test isempty(setdiff(ts_vars, orig_vars))

0 commit comments

Comments
 (0)