@@ -366,7 +366,6 @@ function generate_derivative_variables!(ts::TearingState, neweqs, var_eq_matchin
366366 eq_var_matching = invview (var_eq_matching)
367367 diff_to_var = invview (var_to_diff)
368368 is_discrete = is_only_discrete (structure)
369- lower_varname = is_discrete ? lower_shift_varname : lower_varname_with_unit
370369 linear_eqs = mm === nothing ? Dict {Int, Int} () :
371370 Dict (reverse (en) for en in enumerate (mm. nzrows))
372371
@@ -375,9 +374,9 @@ function generate_derivative_variables!(ts::TearingState, neweqs, var_eq_matchin
375374 for v in 1 : length (var_to_diff)
376375 dv = var_to_diff[v]
377376 # For discrete systems, directly substitute lowest-order shift
378- if is_discrete && diff_to_var[v] == nothing
379- operation (fullvars[v]) isa Shift && (fullvars[v] = lower_varname (fullvars[v], iv))
380- end
377+ # if is_discrete && diff_to_var[v] == nothing
378+ # operation(fullvars[v]) isa Shift && (fullvars[v] = lower_shift_varname_with_unit (fullvars[v], iv))
379+ # end
381380 dv isa Int || continue
382381 solved = var_eq_matching[dv] isa Int
383382 solved && continue
@@ -395,7 +394,8 @@ function generate_derivative_variables!(ts::TearingState, neweqs, var_eq_matchin
395394
396395 dx = fullvars[dv]
397396 order, lv = var_order (dv, diff_to_var)
398- x_t = is_discrete ? lower_varname (fullvars[dv], iv) : lower_varname (fullvars[lv], iv, order)
397+ x_t = is_discrete ? lower_shift_varname_with_unit (fullvars[dv], iv) :
398+ Symbolics. diff2term (fullvars[dv])
399399
400400 # Add `x_t` to the graph
401401 v_t = add_dd_variable! (structure, fullvars, x_t, dv)
@@ -467,11 +467,15 @@ function generate_system_equations!(state::TearingState, neweqs, var_eq_matching
467467
468468 total_sub = Dict ()
469469 if is_only_discrete (structure)
470- for v in fullvars
470+ for (i, v) in enumerate ( fullvars)
471471 op = operation (v)
472- op isa Shift && (op. steps < 0 ) && (total_sub[v] = lower_shift_varname (v, iv))
472+ op isa Shift && (op. steps < 0 ) && begin
473+ lowered = lower_shift_varname_with_unit (v, iv)
474+ total_sub[v] = lowered
475+ fullvars[i] = lowered
476+ end
473477 end
474- end
478+ end
475479
476480 # if var is like D(x) or Shift(t, 1)(x)
477481 isdervar = let diff_to_var = diff_to_var
0 commit comments