@@ -952,16 +952,20 @@ $(SIGNATURES)
952
952
953
953
Structurally simplify algebraic equations in a system and compute the
954
954
topological sort of the observed equations. When `simplify=true`, the `simplify`
955
- function will be applied during the tearing process. It also takes kwargs
955
+ function will be applied during the tearing process. When `simplify_constants=true`
956
+ `eliminate_constants` will be applied prior to tearing. It also takes kwargs
956
957
`allow_symbolic=false` and `allow_parameter=true` which limits the coefficient
957
958
types during tearing.
958
959
959
960
The optional argument `io` may take a tuple `(inputs, outputs)`.
960
961
This will convert all `inputs` to parameters and allow them to be unconnected, i.e.,
961
962
simplification will allow models where `n_states = n_equations - n_inputs`.
962
963
"""
963
- function structural_simplify (sys:: AbstractSystem , io = nothing ; simplify = false , kwargs... )
964
+ function structural_simplify (sys:: AbstractSystem , io = nothing ; simplify = false , simplify_constants = true , kwargs... )
964
965
sys = expand_connections (sys)
966
+ if simplify_constants
967
+ sys = eliminate_constants (sys)
968
+ end
965
969
state = TearingState (sys)
966
970
has_io = io != = nothing
967
971
has_io && markio! (state, io... )
@@ -979,6 +983,20 @@ function structural_simplify(sys::AbstractSystem, io = nothing; simplify = false
979
983
return has_io ? (sys, input_idxs) : sys
980
984
end
981
985
986
+
987
+ """ Replace constants in dynamical equations with their literal values."""
988
+ function eliminate_constants (sys:: AbstractSystem )
989
+ if has_eqs (sys)
990
+ eqs = get_eqs (sys)
991
+ eq_cs = collect_constants (eqs)
992
+ if ! isempty (eq_cs)
993
+ new_eqs = eliminate_constants (eqs, eq_cs)
994
+ @set! sys. eqs = new_eqs
995
+ end
996
+ end
997
+ return sys
998
+ end
999
+
982
1000
function io_preprocessing (sys:: AbstractSystem , inputs,
983
1001
outputs; simplify = false , kwargs... )
984
1002
sys, input_idxs = structural_simplify (sys, (inputs, outputs); simplify, kwargs... )
0 commit comments