Skip to content

Commit 4875206

Browse files
committed
add option to set state priority as argument to structural_simplify and friends
1 parent 2e10393 commit 4875206

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/systems/abstractsystem.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,16 @@ function markio!(state, orig_inputs, inputs, outputs; check = true)
12851285
state, orig_inputs
12861286
end
12871287

1288+
function set_priorities!(state, priorities)
1289+
fullvars = state.fullvars
1290+
for (i, v) in enumerate(fullvars)
1291+
if v in keys(priorities)
1292+
v = setmetadata(v, VariableStatePriority, priorities[v])
1293+
fullvars[i] = v
1294+
end
1295+
end
1296+
end
1297+
12881298
"""
12891299
(; A, B, C, D), simplified_sys = linearize(sys, inputs, outputs; t=0.0, op = Dict(), allow_input_derivatives = false, kwargs...)
12901300
(; A, B, C, D) = linearize(simplified_sys, lin_fun; t=0.0, op = Dict(), allow_input_derivatives = false)

src/systems/systemstructure.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,12 +521,13 @@ function structural_simplify!(state::TearingState, io = nothing; simplify = fals
521521
end
522522

523523
function _structural_simplify!(state::TearingState, io; simplify = false,
524-
check_consistency = true, kwargs...)
524+
check_consistency = true, priorities = Dict(), kwargs...)
525525
has_io = io !== nothing
526526
orig_inputs = Set()
527527
if has_io
528528
ModelingToolkit.markio!(state, orig_inputs, io...)
529529
end
530+
isempty(priorities) || ModelingToolkit.set_priorities!(state, priorities)
530531
state, input_idxs = ModelingToolkit.inputs_to_parameters!(state, io)
531532
sys, ag = ModelingToolkit.alias_elimination!(state; kwargs...)
532533
if check_consistency

0 commit comments

Comments
 (0)