@@ -948,19 +948,21 @@ function will be applied during the tearing process. It also takes kwargs
948
948
`allow_symbolic=false` and `allow_parameter=true` which limits the coefficient
949
949
types during tearing.
950
950
"""
951
- function structural_simplify (sys:: AbstractSystem ; simplify = false , kwargs... )
951
+ function structural_simplify (sys:: AbstractSystem , io = nothing ; simplify = false , kwargs... )
952
952
sys = expand_connections (sys)
953
953
state = TearingState (sys)
954
- state, = inputs_to_parameters! (state)
954
+ has_io = io != = nothing
955
+ has_io && markio! (state, io... )
956
+ state, input_idxs = inputs_to_parameters! (state, ! has_io)
955
957
sys = alias_elimination! (state)
956
958
state = TearingState (sys)
957
959
check_consistency (state)
958
960
find_solvables! (state; kwargs... )
959
- sys = dummy_derivative (sys, state)
961
+ sys = dummy_derivative (sys, state; simplify )
960
962
fullstates = [map (eq -> eq. lhs, observed (sys)); states (sys)]
961
963
@set! sys. observed = topsort_equations (observed (sys), fullstates)
962
964
invalidate_cache! (sys)
963
- return sys
965
+ return has_io ? (sys, input_idxs) : sys
964
966
end
965
967
966
968
"""
@@ -988,25 +990,8 @@ The `simplified_sys` has undergone [`structural_simplify`](@ref) and had any occ
988
990
See also [`linearize`](@ref) which provides a higher-level interface.
989
991
"""
990
992
function linearization_function (sys:: AbstractSystem , inputs,
991
- outputs; simplify = false ,
992
- kwargs... )
993
- sys = expand_connections (sys)
994
- state = TearingState (sys)
995
- markio! (state, inputs, outputs)
996
- state, input_idxs = inputs_to_parameters! (state, false )
997
- sys = alias_elimination! (state)
998
- state = TearingState (sys)
999
- check_consistency (state)
1000
- if sys isa ODESystem
1001
- sys = dae_order_lowering (dummy_derivative (sys, state))
1002
- end
1003
- state = TearingState (sys)
1004
- find_solvables! (state; kwargs... )
1005
- sys = tearing_reassemble (state, tearing (state), simplify = simplify)
1006
- fullstates = [map (eq -> eq. lhs, observed (sys)); states (sys)]
1007
- @set! sys. observed = topsort_equations (observed (sys), fullstates)
1008
- invalidate_cache! (sys)
1009
-
993
+ outputs; kwargs... )
994
+ sys, input_idxs = structural_simplify (sys, (inputs, outputs); kwargs... )
1010
995
eqs = equations (sys)
1011
996
check_operator_variables (eqs, Differential)
1012
997
# Sort equations and states such that diff.eqs. match differential states and the rest are algebraic
@@ -1130,15 +1115,15 @@ using ModelingToolkit
1130
1115
@variables t
1131
1116
function plant(; name)
1132
1117
@variables x(t) = 1
1133
- @variables u(t)=0 y(t)=0
1118
+ @variables u(t)=0 y(t)=0
1134
1119
D = Differential(t)
1135
1120
eqs = [D(x) ~ -x + u
1136
1121
y ~ x]
1137
1122
ODESystem(eqs, t; name = name)
1138
1123
end
1139
1124
1140
1125
function ref_filt(; name)
1141
- @variables x(t)=0 y(t)=0
1126
+ @variables x(t)=0 y(t)=0
1142
1127
@variables u(t)=0 [input=true]
1143
1128
D = Differential(t)
1144
1129
eqs = [D(x) ~ -2 * x + u
@@ -1203,9 +1188,7 @@ function linearize(sys, lin_fun; t = 0.0, op = Dict(), allow_input_derivatives =
1203
1188
gzgx* f_x gzgx* f_z]
1204
1189
B = [f_u
1205
1190
zeros (nz, nu)]
1206
- C = [
1207
- h_x h_z
1208
- ]
1191
+ C = [h_x h_z]
1209
1192
Bs = - (gz \ (f_x * f_u + g_u))
1210
1193
if ! iszero (Bs)
1211
1194
if ! allow_input_derivatives
0 commit comments