@@ -49,8 +49,7 @@ struct SystemStructure
49
49
varassoc:: Vector{Int}
50
50
algeqs:: BitVector
51
51
graph:: BipartiteGraph{Int,Nothing}
52
- solvable_graph:: BipartiteGraph{Int,Vector{Vector{Int}}}
53
- is_linear_equations:: BitVector
52
+ solvable_graph:: BipartiteGraph{Int,Nothing}
54
53
assign:: Vector{Int}
55
54
inv_assign:: Vector{Int}
56
55
scc:: Vector{Vector{Int}}
@@ -83,7 +82,7 @@ eqtype(s::SystemStructure, eq::Integer)::EquationType = isalgeq(s, eq) ? ALGEBRA
83
82
function initialize_system_structure (sys)
84
83
sys, dxvar_offset, fullvars, varassoc, algeqs, graph = init_graph (flatten (sys))
85
84
86
- solvable_graph = BipartiteGraph (neqs, nvars, metadata = map (_ -> Int[], 1 : nsrcs (graph)) )
85
+ solvable_graph = BipartiteGraph (neqs, nvars)
87
86
88
87
@set sys. structure = SystemStructure (
89
88
dxvar_offset,
@@ -92,7 +91,6 @@ function initialize_system_structure(sys)
92
91
algeqs,
93
92
graph,
94
93
solvable_graph,
95
- falses (ndsts (graph)),
96
94
Int[],
97
95
Int[],
98
96
Vector{Int}[],
@@ -173,15 +171,20 @@ function init_graph(sys)
173
171
sys, dxvar_offset, fullvars, varassoc, algeqs, graph
174
172
end
175
173
176
- function find_solvables! (sys)
174
+ function find_linear_equations (sys)
177
175
s = structure (sys)
178
- @unpack fullvars, graph, solvable_graph, is_linear_equations = s
176
+ @unpack fullvars, graph = s
177
+ is_linear_equations = falses (ndsts (graph))
179
178
eqs = equations (sys)
180
- empty! (solvable_graph)
179
+ eadj = Vector{Int}[]
180
+ cadj = Vector{Int}[]
181
+ coeffs = Int[]
181
182
for (i, eq) in enumerate (eqs); isdiffeq (eq) && continue
182
- term = value (eq . rhs - eq . lhs )
183
+ empty! (coeffs )
183
184
linear_term = 0
184
185
all_int_algvars = true
186
+
187
+ term = value (eq. rhs - eq. lhs)
185
188
for j in 𝑠neighbors (graph, i)
186
189
if ! isalgvar (s, j)
187
190
all_int_algvars = false
@@ -190,14 +193,14 @@ function find_solvables!(sys)
190
193
var = fullvars[j]
191
194
c = expand_derivatives (Differential (var)(term), false )
192
195
# test if `var` is linear in `eq`.
193
- if ! (c isa Symbolic) && c isa Number && c != 0
196
+ if ! (c isa Symbolic) && c isa Number
194
197
if isinteger (c)
195
198
c = convert (Integer, c)
196
199
else
197
200
all_int_algvars = false
198
201
end
199
202
linear_term += c * var
200
- add_edge! (solvable_graph, i, j , c)
203
+ push! (coeffs , c)
201
204
end
202
205
end
203
206
@@ -209,16 +212,13 @@ function find_solvables!(sys)
209
212
# where ``c_i`` ∈ ℤ and ``a_i`` denotes algebraic variables.
210
213
if all_int_algvars && isequal (linear_term, term)
211
214
is_linear_equations[i] = true
215
+ push! (eadj, i)
216
+ push! (cadj, copy (coeff))
212
217
else
213
- # We use 0 as a sentinel value for a nonlinear or non-integer term.
214
-
215
- # Don't move the reference, because it might lead to pointer
216
- # invalidations.
217
218
is_linear_equations[i] = false
218
- fill! (solvable_graph. metadata[i], 0 )
219
219
end
220
220
end
221
- s
221
+ return is_linear_equations, eadj, cadj
222
222
end
223
223
224
224
end # module
0 commit comments