Skip to content

Commit 34a20d7

Browse files
authored
Merge pull request #964 from SciML/myb/ae
Fix faulty alias elimination
2 parents 69b6f09 + 87f0d1d commit 34a20d7

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

src/systems/alias_elimination.jl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,8 @@ using SymbolicUtils: Rewriters
33
const KEEP = typemin(Int)
44

55
function alias_elimination(sys)
6-
# FIXME: update `structure` too
7-
#sys = flatten(sys)
8-
#s = get_structure(sys)
9-
#if !(s isa SystemStructure)
106
sys = initialize_system_structure(sys)
117
s = structure(sys)
12-
#end
138
is_linear_equations, eadj, cadj = find_linear_equations(sys)
149

1510
v_eliminated, v_types, n_null_vars, degenerate_equations, linear_equations = alias_eliminate_graph(

src/systems/systemstructure.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ function find_linear_equations(sys)
227227
c = expand_derivatives(Differential(var)(term), false)
228228
# test if `var` is linear in `eq`.
229229
if !(c isa Symbolic) && c isa Number
230-
if isinteger(c) && !iszero(c)
230+
if c == 1 || c == -1
231231
c = convert(Integer, c)
232232
linear_term += c * var
233233
push!(coeffs, c)

test/reduction.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,33 @@ eqs = [
247247
]
248248
@named sys = ODESystem(eqs, t, sts, params)
249249
@test_throws ModelingToolkit.InvalidSystemException structural_simplify(sys)
250+
251+
# issue #963
252+
@parameters t
253+
D = Differential(t)
254+
@variables v47(t) v57(t) v66(t) v25(t) i74(t) i75(t) i64(t) i71(t) v1(t) v2(t)
255+
256+
eq = [
257+
v47 ~ v1
258+
v47 ~ sin(10t)
259+
v57 ~ v1 - v2
260+
v57 ~ 10.0i64
261+
v66 ~ v2
262+
v66 ~ 5.0i74
263+
v25 ~ v2
264+
i75 ~ 0.005 * D(v25)
265+
0 ~ i74 + i75 - i64
266+
0 ~ i64 + i71]
267+
268+
269+
sys0 = ODESystem(eq, t)
270+
sys = structural_simplify(sys0)
271+
@test length(equations(sys)) == 1
272+
eq = equations(sys)[1]
273+
@test isequal(eq.lhs, 0)
274+
dv25 = ModelingToolkit.value(ModelingToolkit.derivative(eq.rhs, v25))
275+
ddv25 = ModelingToolkit.value(ModelingToolkit.derivative(eq.rhs, D(v25)))
276+
dt = ModelingToolkit.value(ModelingToolkit.derivative(eq.rhs, sin(10t)))
277+
@test dv25 0.3
278+
@test ddv25 == 0.005
279+
@test dt == -0.1

0 commit comments

Comments
 (0)