Structural Transformation
The functions documented on this page are internal implementation details of ModelingToolkit. They are not part of the public API and may change or be removed without notice in non-breaking releases. This documentation is provided to help contributors understand the codebase.
These functions are used for structural analysis and transformation of equation systems, including index reduction, tearing, and other algebraic manipulations used in the simplification process.
Tearing and Algebraic Simplification
ModelingToolkit.StructuralTransformations.tearing
— Functiontearing(sys; simplify=false)
Tear the nonlinear equations in system. When simplify=true
, we simplify the new residual equations after tearing. End users are encouraged to call mtkcompile
instead, which calls this function internally.
ModelingToolkit.StructuralTransformations.tearing_reassemble
— FunctionMain internal function for structural simplification for DAE systems and discrete systems. Generate dummy derivative variables, new equations in terms of variables, return updated system and tearing state.
Terminology and Definition:
A general DAE is in the form of F(u'(t), u(t), p, t) == 0
. We can characterize variables in u(t)
into two classes: differential variables (denoted v(t)
) and algebraic variables (denoted z(t)
). Differential variables are marked as SelectedState
and they are differentiated in the DAE system, i.e. v'(t)
are all the variables in u'(t)
that actually appear in the system. Algebraic variables are variables that are not differential variables.
Arguments
state
: TheTearingState
of the system.var_eq_matching
: The maximal matching after state selection.full_var_eq_matching
: The maximal matching prior to state selection.var_sccs
: The topologically sorted strongly connected components of the system according tofull_var_eq_matching
.
Missing docstring for tearing_substitution
. Check Documenter's build log for details.
Missing docstring for torn_system_jacobian_sparsity
. Check Documenter's build log for details.
Missing docstring for linear_subsys_adjmat!
. Check Documenter's build log for details.
Index Reduction
ModelingToolkit.StructuralTransformations.dae_index_lowering
— Functiondae_index_lowering(sys::System; kwargs...) -> System
Perform the Pantelides algorithm to transform a higher index DAE to an index 1 DAE. kwargs
are forwarded to pantelides!
. End users are encouraged to call mtkcompile
instead, which calls this function internally.
ModelingToolkit.StructuralTransformations.pantelides!
— Functionpantelides!(state::TransformationState; kwargs...)
Perform Pantelides algorithm.
Missing docstring for pantelides_reassemble
. Check Documenter's build log for details.
ModelingToolkit.StructuralTransformations.dummy_derivative
— Functiondummy_derivative(sys)
Perform index reduction and use the dummy derivative technique to ensure that the system is balanced.
Consistency Checking
ModelingToolkit.StructuralTransformations.check_consistency
— Functioncheck_consistency(
state::TransformationState,
orig_inputs;
nothrow
) -> Bool
Check the consistency of state
, given the inputs orig_inputs
. If nothrow == false
, throws an error if the system is under-/over-determined or singular. In this case, if the function returns it will return true
. If nothrow == true
, it will return false
instead of throwing an error. The singular case will print a warning.
Incidence Matrix Operations
ModelingToolkit.StructuralTransformations.sorted_incidence_matrix
— Functionsorted_incidence_matrix(
sys::ModelingToolkit.AbstractSystem
) -> Any
Obtain the incidence matrix of the system sorted by the SCCs. Requires that the system is simplified and has a schedule
.
Missing docstring for but_ordered_incidence
. Check Documenter's build log for details.
Variable Ordering and Masks
Missing docstring for lowest_order_variable_mask
. Check Documenter's build log for details.
Missing docstring for highest_order_variable_mask
. Check Documenter's build log for details.
ModelingToolkit.StructuralTransformations.computed_highest_diff_variables
— Functioncomputed_highest_diff_variables(structure)
Computes which variables are the "highest-differentiated" for purposes of pantelides. Ordinarily this is relatively straightforward. However, in our case, there is one complicating condition:
We allow variables in the structure graph that don't appear in the
system at all. What we are interested in is the highest-differentiated
variable that actually appears in the system.
This function takes care of these complications are returns a boolean array for every variable, indicating whether it is considered "highest-differentiated".
Shift Operations
These functions handle shift operations in discrete-time systems.
ModelingToolkit.StructuralTransformations.shift2term
— FunctionRename a Shift variable with negative shift, Shift(t, k)(x(t)) to xₜ₋ₖ(t).
ModelingToolkit.StructuralTransformations.lower_shift_varname
— FunctionHandle renaming variable names for discrete structural simplification. Three cases:
- positive shift: do nothing
- zero shift: x(t) => Shift(t, 0)(x(t))
- negative shift: rename the variable
ModelingToolkit.StructuralTransformations.simplify_shifts
— FunctionSimplify multiple shifts: Shift(t, k1)(Shift(t, k2)(x)) becomes Shift(t, k1+k2)(x).
ModelingToolkit.StructuralTransformations.distribute_shift
— FunctionDistribute a shift applied to a whole expression or equation. Shift(t, 1)(x + y) will become Shift(t, 1)(x) + Shift(t, 1)(y). Only shifts variables whose independent variable is the same t that appears in the Shift (i.e. constants, time-independent parameters, etc. do not get shifted).
System Structure Types and Functions
Missing docstring for TransformationState
. Check Documenter's build log for details.
Graph Types
Missing docstring for InducedCondensationGraph
. Check Documenter's build log for details.