Skip to content

Commit 63c084d

Browse files
committed
Tearing tests pass
1 parent 3678131 commit 63c084d

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

src/structural_transformation/codegen.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ function build_torn_function(
197197
)
198198

199199
s = structure(sys)
200-
states = s.fullvars[diffvars_range(s)]
200+
states = map(i->s.fullvars[i], diffvars_range(s))
201201
syms = map(Symbol, states)
202202

203203
expr = SymbolicUtils.Code.toexpr(
@@ -266,8 +266,8 @@ function build_observed_function(
266266
syms_set = Set(syms)
267267
s = structure(sys)
268268
@unpack partitions, fullvars, graph = s
269-
diffvars = fullvars[diffvars_range(s)]
270-
algvars = fullvars[algvars_range(s)]
269+
diffvars = map(i->fullvars[i], diffvars_range(s))
270+
algvars = map(i->fullvars[i], algvars_range(s))
271271

272272
required_algvars = Set(intersect(algvars, syms_set))
273273
obs = observed(sys)
@@ -337,7 +337,7 @@ function ODAEProblem{iip}(
337337
) where {iip}
338338
s = structure(sys)
339339
@unpack fullvars = s
340-
dvs = fullvars[diffvars_range(s)]
340+
dvs = map(i->fullvars[i], diffvars_range(s))
341341
ps = parameters(sys)
342342
defs = defaults(sys)
343343

src/structural_transformation/tearing.jl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,14 @@ function tearing_reassemble(sys; simplify=false)
177177

178178
obseqs = solvars .~ rhss
179179

180-
@set! sys.structure.graph = newgraph
181-
@set! sys.structure.scc = newscc
182-
@set! sys.structure.fullvars = fullvars[active_vars]
183-
@set! sys.structure.partitions = newpartitions
184-
@set! sys.structure.algeqs = newalgeqs
180+
@set! s.graph = newgraph
181+
@set! s.scc = newscc
182+
@set! s.fullvars = fullvars[active_vars]
183+
@set! s.vartype = s.vartype[active_vars]
184+
@set! s.partitions = newpartitions
185+
@set! s.algeqs = newalgeqs
186+
187+
@set! sys.structure = s
185188
@set! sys.eqs = neweqs
186189
@set! sys.states = newstates
187190
@set! sys.reduced_states = [get_reduced_states(sys); solvars]

src/systems/systemstructure.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ isdervar(s::SystemStructure, var::Integer) = s.vartype[var] === DERIVATIVE_VARIA
6161
isdiffvar(s::SystemStructure, var::Integer) = s.vartype[var] === DIFFERENTIAL_VARIABLE
6262
isalgvar(s::SystemStructure, var::Integer) = s.vartype[var] === ALGEBRAIC_VARIABLE
6363

64-
dervars_range(s::SystemStructure) = Iterators.filter(Base.Fix1(s, isdervar), eachindex(s.vartype))
65-
diffvars_range(s::SystemStructure) = Iterators.filter(Base.Fix1(s, isdiffvar), eachindex(s.vartype))
66-
algvars_range(s::SystemStructure) = Iterators.filter(Base.Fix1(s, isalgeq), eachindex(s.vartype))
64+
dervars_range(s::SystemStructure) = Iterators.filter(Base.Fix1(isdervar, s), eachindex(s.vartype))
65+
diffvars_range(s::SystemStructure) = Iterators.filter(Base.Fix1(isdiffvar, s), eachindex(s.vartype))
66+
algvars_range(s::SystemStructure) = Iterators.filter(Base.Fix1(isalgvar, s), eachindex(s.vartype))
6767

6868
isalgeq(s::SystemStructure, eq::Integer) = s.algeqs[eq]
6969
isdiffeq(s::SystemStructure, eq::Integer) = !isalgeq(s, eq)

test/structural_transformation/tearing.jl

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,12 @@ show(io, sss)
2929
prt = String(take!(io))
3030

3131
if VERSION >= v"1.6"
32-
@test prt == """xvars: Any[]
33-
dxvars: Any[]
34-
algvars: Any[u1(t), u2(t), u3(t), u4(t), u5(t)]
35-
Incidence matrix:
36-
× ⋅ ⋅ ⋅ ×
32+
@test prt == "Incidence matrix:
3733
× × ⋅ ⋅ ⋅
38-
× × × ⋅ ⋅
39-
⋅ × × × ⋅
40-
× ⋅ ⋅ × ×"""
34+
× ⋅ × ⋅ ⋅
35+
× ⋅ × × ⋅
36+
⋅ ⋅ × × ×
37+
× × ⋅ ⋅ ×"
4138
end
4239

4340
# u1 = f1(u5)
@@ -49,8 +46,8 @@ sys = initialize_system_structure(sys)
4946
find_solvables!(sys)
5047
sss = structure(sys)
5148
@unpack graph, solvable_graph, assign, partitions = sss
52-
@test graph.fadjlist == [[1, 5], [1, 2], [1, 2, 3], [2, 3, 4], [1, 4, 5]]
53-
@test solvable_graph.fadjlist == map(x->[x], 1:5)
49+
@test graph.fadjlist == [[1, 2], [1, 3], [1, 3, 4], [3, 4, 5], [1, 2, 5]]
50+
@test solvable_graph.fadjlist == map(x->[x], [1, 3, 4, 5, 2])
5451

5552
tornsys = tearing(sys)
5653
sss = structure(tornsys)
@@ -148,7 +145,7 @@ eqs = [
148145
daesys = ODESystem(eqs, t)
149146
newdaesys = tearing(daesys)
150147
@test equations(newdaesys) == [D(x) ~ z; 0 ~ x + sin(z) - p*t]
151-
@test isequal(states(newdaesys), [x, z])
148+
@test isequal(states(newdaesys), [z, x])
152149
@test_throws ArgumentError ODAEProblem(newdaesys, [x=>1.0], (0, 1.0))
153150
prob = ODAEProblem(newdaesys, [x=>1.0], (0, 1.0), [p=>0.2])
154151
du = [0.0]; u = [1.0]; pr = 0.2; tt = 0.1

0 commit comments

Comments
 (0)