Skip to content

Commit 746a298

Browse files
authored
Merge pull request #1860 from SciML/myb/iofix
Fix kind check for array variables
2 parents 0a36928 + 0aae5fe commit 746a298

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

src/parameters.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ struct MTKParameterCtx end
44
function isparameter(x)
55
x = unwrap(x)
66

7-
#TODO: Delete this branch
8-
if x isa Symbolic && Symbolics.getparent(x, false) !== false
7+
if x isa Symbolic && (isp = getmetadata(x, MTKParameterCtx, nothing)) !== nothing
8+
return isp
9+
#TODO: Delete this branch
10+
elseif x isa Symbolic && Symbolics.getparent(x, false) !== false
911
p = Symbolics.getparent(x)
1012
isparameter(p) ||
1113
(hasmetadata(p, Symbolics.VariableSource) &&

src/variables.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ struct Stream <: AbstractConnectType end # special stream connector
2020

2121
isvarkind(m, x::Num) = isvarkind(m, value(x))
2222
function isvarkind(m, x)
23-
p = getparent(x, nothing)
24-
p === nothing || (x = p)
23+
iskind = getmetadata(x, m, nothing)
24+
iskind !== nothing && return iskind
25+
x = getparent(x, x)
2526
getmetadata(x, m, false)
2627
end
2728

test/input_output_handling.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,21 @@ xp1 = f_oop(x1, u, pn, 0)
265265

266266
@test xp0 matrices.A * x0 + matrices.B * [u; 0]
267267
@test xp1 matrices.A * x1 + matrices.B * [u; 0]
268+
269+
@parameters t
270+
@variables x(t)[1:3] = 0
271+
@variables u(t)[1:2]
272+
D = Differential(t)
273+
y₁, y₂, y₃ = x
274+
u1, u2 = u
275+
k₁, k₂, k₃ = 1, 1, 1
276+
eqs = [D(y₁) ~ -k₁ * y₁ + k₃ * y₂ * y₃ + u1
277+
D(y₂) ~ k₁ * y₁ - k₃ * y₂ * y₃ - k₂ * y₂^2 + u2
278+
y₁ + y₂ + y₃ ~ 1]
279+
280+
@named sys = ODESystem(eqs, t)
281+
m_inputs = [u[1], u[2]]
282+
m_outputs = [y₂]
283+
sys_simp, input_idxs = structural_simplify(sys, (; inputs = m_inputs, outputs = m_outputs))
284+
@test isequal(states(sys_simp), collect(x[1:2]))
285+
@test length(input_idxs) == 2

0 commit comments

Comments
 (0)