@@ -157,32 +157,13 @@ function dummy_derivative_graph!(state::TransformationState, jac = nothing;
157
157
dummy_derivative_graph! (state. structure, var_eq_matching, jac, state_priority)
158
158
end
159
159
160
- function compute_diff_level (diff_to_x)
161
- nxs = length (diff_to_x)
162
- xlevel = zeros (Int, nxs)
163
- maxlevel = 0
164
- for i in 1 : nxs
165
- level = 0
166
- x = i
167
- while diff_to_x[x] != = nothing
168
- x = diff_to_x[x]
169
- level += 1
170
- end
171
- maxlevel = max (maxlevel, level)
172
- xlevel[i] = level
173
- end
174
- return xlevel, maxlevel
175
- end
176
-
177
160
function dummy_derivative_graph! (structure:: SystemStructure , var_eq_matching, jac,
178
161
state_priority)
179
162
@unpack eq_to_diff, var_to_diff, graph = structure
180
163
diff_to_eq = invview (eq_to_diff)
181
164
diff_to_var = invview (var_to_diff)
182
165
invgraph = invview (graph)
183
166
184
- eqlevel, _ = compute_diff_level (diff_to_eq)
185
-
186
167
var_sccs = find_var_sccs (graph, var_eq_matching)
187
168
eqcolor = falses (nsrcs (graph))
188
169
dummy_derivatives = Int[]
@@ -193,6 +174,7 @@ function dummy_derivative_graph!(structure::SystemStructure, var_eq_matching, ja
193
174
next_var_idxs = Int[]
194
175
new_eqs = Int[]
195
176
new_vars = Int[]
177
+ eqs_set = BitSet ()
196
178
for vars in var_sccs
197
179
empty! (eqs)
198
180
for var in vars
@@ -202,8 +184,6 @@ function dummy_derivative_graph!(structure::SystemStructure, var_eq_matching, ja
202
184
push! (eqs, eq)
203
185
end
204
186
isempty (eqs) && continue
205
- maxlevel = maximum (Base. Fix1 (getindex, eqlevel), eqs)
206
- iszero (maxlevel) && continue
207
187
208
188
rank_matching = Matching (nvars)
209
189
isfirst = true
@@ -219,15 +199,13 @@ function dummy_derivative_graph!(structure::SystemStructure, var_eq_matching, ja
219
199
end
220
200
J = is_all_small_int ? Int .(unwrap .(_J)) : nothing
221
201
end
222
- for level in maxlevel : - 1 : 1
202
+ while true
223
203
nrows = length (eqs)
224
204
iszero (nrows) && break
225
- eqs_set = BitSet (eqs)
226
205
227
206
if state_priority != = nothing && isfirst
228
207
sort! (vars, by = state_priority)
229
208
end
230
- isfirst = false
231
209
# TODO : making the algorithm more robust
232
210
# 1. If the Jacobian is a integer matrix, use Bareiss to check
233
211
# linear independence. (done)
@@ -237,7 +215,7 @@ function dummy_derivative_graph!(structure::SystemStructure, var_eq_matching, ja
237
215
#
238
216
# 3. If the Jacobian is a polynomial matrix, use Gröbner basis (?)
239
217
if J != = nothing
240
- if level < maxlevel
218
+ if ! isfirst
241
219
J = J[next_eq_idxs, next_var_idxs]
242
220
end
243
221
N = ModelingToolkit. nullspace (J; col_order) # modifies col_order
@@ -246,6 +224,8 @@ function dummy_derivative_graph!(structure::SystemStructure, var_eq_matching, ja
246
224
push! (dummy_derivatives, vars[col_order[i]])
247
225
end
248
226
else
227
+ empty! (eqs_set)
228
+ union! (eqs_set, eqs)
249
229
rank = 0
250
230
for var in vars
251
231
eqcolor .= false
@@ -261,7 +241,7 @@ function dummy_derivative_graph!(structure::SystemStructure, var_eq_matching, ja
261
241
fill! (rank_matching, unassigned)
262
242
end
263
243
if rank != nrows
264
- @warn " The DAE system is structurally singular!"
244
+ @warn " The DAE system is singular!"
265
245
end
266
246
267
247
# prepare the next iteration
@@ -293,6 +273,7 @@ function dummy_derivative_graph!(structure::SystemStructure, var_eq_matching, ja
293
273
end
294
274
eqs, new_eqs = new_eqs, eqs
295
275
vars, new_vars = new_vars, vars
276
+ isfirst = false
296
277
end
297
278
end
298
279
0 commit comments