Skip to content

Commit f2ee244

Browse files
Fix independent variable extraction
1 parent 5f72c30 commit f2ee244

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/equations.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,14 @@ function vars!(vars, op)
3333
args = isa(op, Equation) ? Expression[op.lhs, op.rhs] : op.args
3434

3535
for arg args
36-
isa(arg, Operation) ? vars!(vars, arg) :
37-
isa(arg, Variable) ? push!(vars, arg) :
38-
nothing
36+
if isa(arg, Operation)
37+
vars!(vars, arg)
38+
elseif isa(arg, Variable)
39+
push!(vars, arg)
40+
for dep arg.dependents
41+
push!(vars, dep)
42+
end
43+
end
3944
end
4045

4146
return vars

test/system_construction.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ eqs = [_x ~ y/C,
9191
D(x) ~ -A*x,
9292
D(y) ~ A*x - B*_x]
9393
de = DiffEqSystem(eqs,[t],[x,y],Variable[_x],[A,B,C])
94-
de2 = DiffEqSystem(eqs,[t])
95-
test_vars_extraction(de, de2)
94+
test_vars_extraction(de, DiffEqSystem(eqs,[t]))
95+
test_vars_extraction(de, DiffEqSystem(eqs))
9696
@test eval(ModelingToolkit.generate_ode_function(de))([0.0,0.0],[1.0,2.0],[1,2,3],0.0) -1/3
9797

9898
# Now nonlinear system with only variables

0 commit comments

Comments
 (0)