Skip to content

Commit a85f702

Browse files
committed
Add methods isdiffeq and isalgeq on a SystemStructure
1 parent a78fbf1 commit a85f702

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/systems/systemstructure.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module SystemStructures
22

33
using ..ModelingToolkit
4-
using ..ModelingToolkit: isdiffeq, var_from_nested_derivative, vars!, flatten
4+
import ..ModelingToolkit: isdiffeq, var_from_nested_derivative, vars!, flatten
55
using SymbolicUtils: arguments
66
using ..BipartiteGraphs
77
using UnPack
@@ -37,7 +37,7 @@ end
3737

3838
export SystemStructure, initialize_system_structure
3939
export diffvars_range, dervars_range, algvars_range
40-
export isdiffvars, isdervars, isalgvars
40+
export isdiffvar, isdervar, isalgvar, isdiffeq, isalgeq
4141
export DIFFERENTIAL_VARIABLE, ALGEBRAIC_VARIABLE, DERIVATIVE_VARIABLE
4242
export DIFFERENTIAL_EQUATION, ALGEBRAIC_EQUATION
4343
export vartype, eqtype
@@ -73,7 +73,9 @@ end
7373

7474
@enum EquationType DIFFERENTIAL_EQUATION ALGEBRAIC_EQUATION
7575

76-
eqtype(s::SystemStructure, eq::Integer)::EquationType = s.algeqs[eq] ? ALGEBRAIC_EQUATION : DIFFERENTIAL_EQUATION
76+
isalgeq(s::SystemStructure, eq::Integer) = s.algeqs[eq]
77+
isdiffeq(s::SystemStructure, eq::Integer) = !isalgeq(s, eq)
78+
eqtype(s::SystemStructure, eq::Integer)::EquationType = isalgeq(s, eq) ? ALGEBRAIC_EQUATION : DIFFERENTIAL_EQUATION
7779

7880
function initialize_system_structure(sys)
7981
sys, dxvar_offset, fullvars, varassoc, algeqs, graph, solvable_graph = init_graph(flatten(sys))
@@ -111,10 +113,10 @@ end
111113
function collect_variables(sys)
112114
dxvars = []
113115
eqs = equations(sys)
114-
algeqs = falses(length(eqs))
116+
algeqs = trues(length(eqs))
115117
for (i, eq) in enumerate(eqs)
116118
if isdiffeq(eq)
117-
algeqs[i] = true
119+
algeqs[i] = false
118120
lhs = eq.lhs
119121
# Make sure that the LHS is a first order derivative of a var.
120122
@assert !(arguments(lhs)[1] isa Differential) "The equation $eq is not first order"

0 commit comments

Comments
 (0)