@@ -47,25 +47,31 @@ function matching(g::BipartiteGraph, varwhitelist=nothing, eqwhitelist=nothing)
47
47
return assign
48
48
end
49
49
50
- throw_unbalanced (n_highest_vars, neqs, msg, values) = throw (InvalidSystemException (
51
- " The system is unbalanced. "
52
- * " There are $n_highest_vars highest order derivative variables "
53
- * " and $neqs equations.\n "
54
- * msg
55
- * values
56
- ))
57
-
58
- function fill_unassigned! (unassigned_list, vars, fullvars)
59
- for (vj, eq) in enumerate (vars)
60
- if eq === UNASSIGNED
61
- push! (unassigned_list, fullvars[vj])
62
- end
50
+ function error_reporting (sys, bad_idxs, n_highest_vars, iseqs)
51
+ io = IOBuffer ()
52
+ if iseqs
53
+ error_title = " More equations than variables:\n "
54
+ out_arr = equations (sys)[bad_idxs]
55
+ else
56
+ error_title = " More variables than equations:\n "
57
+ out_arr = structure (sys). fullvars[bad_idxs]
63
58
end
59
+
60
+ msg = String (take! (Base. print_array (io, out_arr)))
61
+ neqs = length (equations (sys))
62
+ throw (InvalidSystemException (
63
+ " The system is unbalanced. "
64
+ * " There are $n_highest_vars highest order derivative variables "
65
+ * " and $neqs equations.\n "
66
+ * msg
67
+ ))
64
68
end
69
+
65
70
# ##
66
71
# ## Structural check
67
72
# ##
68
- function check_consistency (s:: SystemStructure )
73
+ function check_consistency (sys:: AbstractSystem )
74
+ s = structure (sys)
69
75
@unpack varmask, graph, varassoc, fullvars = s
70
76
n_highest_vars = count (varmask)
71
77
neqs = nsrcs (graph)
@@ -74,21 +80,16 @@ function check_consistency(s::SystemStructure)
74
80
if neqs > 0 && ! is_balanced
75
81
varwhitelist = varassoc .== 0
76
82
assign = matching (graph, varwhitelist) # not assigned
77
- unassigned_var = []
78
- if n_highest_vars > neqs
79
- fill_unassigned! (unassigned_var, assign, fullvars)
80
- io = IOBuffer ()
81
- Base. print_array (io, unassigned_var)
82
- unassigned_var_str = String (take! (io))
83
- throw_unbalanced (n_highest_vars, neqs, " More variables than equations:\n " , unassigned_var_str)
83
+ # Just use `error_reporting` to do conditional
84
+ iseqs = n_highest_vars > neqs
85
+
86
+ if iseqs
87
+ bad_idxs = findall (isequal (UNASSIGNED), assign)
84
88
else
85
89
inv_assign = inverse_mapping (assign) # extra equations
86
- fill_unassigned! (unassigned_var, inv_assign, fullvars)
87
- io = IOBuffer ()
88
- Base. print_array (io, unassigned_var)
89
- unassigned_var_str = String (take! (io))
90
- throw_unbalanced (n_highest_vars, neqs, " More equations than variables:\n " , unassigned_var_str)
90
+ bad_idxs = findall (iszero, inv_assign)
91
91
end
92
+ error_reporting (sys, bad_idxs, n_highest_vars, iseqs)
92
93
end
93
94
94
95
# This is defined to check if Pantelides algorithm terminates. For more
0 commit comments