@@ -213,11 +213,11 @@ mutable struct TearingState{T <: AbstractSystem} <: AbstractTearingState{T}
213
213
end
214
214
215
215
TransformationState (sys:: AbstractSystem ) = TearingState (sys)
216
- function system_subset (ts:: TearingState , ieqs:: Vector{Int} )
216
+ function system_subset (ts:: TearingState , ieqs:: Vector{Int} , ivars :: Vector{Int} )
217
217
eqs = equations (ts)
218
218
@set! ts. original_eqs = ts. original_eqs[ieqs]
219
219
@set! ts. sys. eqs = eqs[ieqs]
220
- @set! ts. structure = system_subset (ts. structure, ieqs)
220
+ @set! ts. structure = system_subset (ts. structure, ieqs, ivars )
221
221
if all (eq -> eq. rhs isa StateMachineOperator, get_eqs (ts. sys))
222
222
names = Symbol[]
223
223
for eq in get_eqs (ts. sys)
@@ -234,22 +234,33 @@ function system_subset(ts::TearingState, ieqs::Vector{Int})
234
234
else
235
235
@set! ts. statemachines = eltype (ts. statemachines)[]
236
236
end
237
+ @set! ts. fullvars = ts. fullvars[ivars]
237
238
ts
238
239
end
239
240
240
- function system_subset (structure:: SystemStructure , ieqs:: Vector{Int} )
241
- @unpack graph, eq_to_diff = structure
241
+ function system_subset (structure:: SystemStructure , ieqs:: Vector{Int} , ivars :: Vector{Int} )
242
+ @unpack graph = structure
242
243
fadj = Vector{Int}[]
243
244
eq_to_diff = DiffGraph (length (ieqs))
245
+ var_to_diff = DiffGraph (length (ivars))
246
+
244
247
ne = 0
248
+ old_to_new_var = zeros (Int, ndsts (graph))
249
+ for (i, iv) in enumerate (ivars)
250
+ old_to_new_var[iv] = i
251
+ structure. var_to_diff[iv] === nothing && continue
252
+ var_to_diff[i] = old_to_new_var[structure. var_to_diff[iv]]
253
+ end
245
254
for (j, eq_i) in enumerate (ieqs)
246
- ivars = copy (graph. fadjlist[eq_i])
247
- ne += length (ivars)
248
- push! (fadj, ivars)
255
+ var_adj = [old_to_new_var[i] for i in graph. fadjlist[eq_i]]
256
+ @assert all (! iszero, var_adj)
257
+ ne += length (var_adj)
258
+ push! (fadj, var_adj)
249
259
eq_to_diff[j] = structure. eq_to_diff[eq_i]
250
260
end
251
- @set! structure. graph = complete (BipartiteGraph (ne, fadj, ndsts (graph )))
261
+ @set! structure. graph = complete (BipartiteGraph (ne, fadj, length (ivars )))
252
262
@set! structure. eq_to_diff = eq_to_diff
263
+ @set! structure. var_to_diff = complete (var_to_diff)
253
264
structure
254
265
end
255
266
@@ -433,7 +444,8 @@ function TearingState(sys; quick_cancel = false, check = true, sort_eqs = true)
433
444
isdelay (v, iv) && continue
434
445
435
446
if ! symbolic_contains (v, dvs)
436
- isvalid = iscall (v) && (operation (v) isa Shift || is_transparent_operator (operation (v)))
447
+ isvalid = iscall (v) &&
448
+ (operation (v) isa Shift || is_transparent_operator (operation (v)))
437
449
v′ = v
438
450
while ! isvalid && iscall (v′) && operation (v′) isa Union{Differential, Shift}
439
451
v′ = arguments (v′)[1 ]
0 commit comments